<?php
/**
 * Plugin Name: Advanced Ajax Posts Filter For Elementor
 * Plugin URI: https://wordpress.org/plugins/zluck-ajax-posts-filter-for-elementor/
 * Description: A powerful Elementor widget that provides AJAX-based taxonomy filtering for posts with seamless user experience.
 * Version: 1.0
 * Author: Zluck Solutions
 * Author URI: https://zluck.com
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: zluck-ajax-posts-filter-for-elementor
 * Requires Plugins: elementor
 * Requires at least: 5.0
 * Tested up to: 6.9
 * Requires PHP: 7.4
 * Elementor requires at least: 3.0.0
 * Elementor tested up to: 3.24.0
 *
 * @package Zluck_Ajax_Posts_Filter_Elementor
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
	die;
}

/**
 * Plugin version
 */
define( 'AAPF_VERSION', '1.0.0' );

/**
 * Plugin directory path
 */
define( 'AAPF_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );

/**
 * Plugin URL
 */
define( 'AAPF_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

/**
 * Plugin basename
 */
define( 'AAPF_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

// Check if Elementor is installed and activated
if ( ! did_action( 'elementor/loaded' ) && ! class_exists( '\Elementor\Plugin' ) ) {
	// Deactivate plugin and show error
	deactivate_plugins( plugin_basename( __FILE__ ) );
	wp_die( 
		'<h3>' . esc_html__( 'Plugin Activation Failed', 'zluck-ajax-posts-filter-for-elementor' ) . '</h3>' .
		'<p>' . esc_html__( 'Zluck Ajax Posts Filter For Elementor requires Elementor to be installed and activated.', 'zluck-ajax-posts-filter-for-elementor' ) . '</p>' .
		'<p>' . sprintf(
			/* translators: %s: URL to install Elementor plugin */
			wp_kses_post( __( 'Please <a href="%s">install Elementor</a> first, then activate this plugin.', 'zluck-ajax-posts-filter-for-elementor' ) ),
			esc_url( admin_url( 'plugin-install.php?s=elementor&tab=search&type=term' ) )
		) . '</p>' .
		'<p><a href="' . esc_url( admin_url( 'plugins.php' ) ) . '" class="button">&laquo; ' . esc_html__( 'Back', 'zluck-ajax-posts-filter-for-elementor' ) . '</a></p>',
		esc_html__( 'Plugin Activation Failed', 'zluck-ajax-posts-filter-for-elementor' ),
		array( 'response' => 200, 'back_link' => false )
	);
}

/**
 * The code that runs during plugin activation.
 */
function aapf_activate() {
	// Activation logic here if needed
}
register_activation_hook( __FILE__, 'aapf_activate' );

/**
 * Begins execution of the plugin.
 */
function aapf_run() {
	require_once AAPF_PLUGIN_DIR . 'includes/class-plugin.php';
	$aapf_plugin = AAPF_Plugin::get_instance();
	$aapf_plugin->run();
}
add_action( 'plugins_loaded', 'aapf_run' );
