'Plugin Name', 'version' => 'Version', ]; $aelms_plugin_data = get_file_data(AELMS_PLUGIN_FILE, $aelms_default_headers); define('AELMS_VERSION', $aelms_plugin_data['version']); define('AELMS_PLUGIN_BASENAME', plugin_basename(AELMS_PLUGIN_FILE)); define('AELMS_SLUG', 'acadlix-addon-for-elementor'); define('AELMS_PLUGIN_DIR', plugin_dir_path(AELMS_PLUGIN_FILE)); define('AELMS_PLUGIN_URL', plugin_dir_url(AELMS_PLUGIN_FILE)); define('AELMS_ASSETS', trailingslashit(AELMS_PLUGIN_URL . 'assets')); } if (!class_exists('Acadlix_Addon_For_Elementor')) { class Acadlix_Addon_For_Elementor { private static $_instance = null; public function __construct() { register_activation_hook(AELMS_PLUGIN_FILE, array($this, 'activate')); add_action('plugins_loaded', array($this, 'init')); add_action('admin_enqueue_scripts', array($this, 'enqueue_assets')); add_filter('acadlix_options', array($this, 'acadlix_options')); } public function acadlix_options($options) { return array_merge($options, array( 'acadlix_single_course_elementor_template' => get_option('acadlix_single_course_elementor_template', null), 'acadlix_all_course_elementor_template' => get_option('acadlix_all_course_elementor_template', null), 'acadlix_single_course_bundle_elementor_template' => get_option('acadlix_single_course_bundle_elementor_template', null), )); } public function enqueue_assets() { if (!$this->check_required_plugin_active()) { return; } wp_enqueue_script( 'aelms-extend-script', AELMS_ASSETS . 'js/extend.js', [], AELMS_VERSION, true, ); wp_localize_script( 'aelms-extend-script', 'aelms_extend', array( 'baseUrl' => get_site_url(), 'nonce' => wp_create_nonce('wp_rest'), 'templates' => $this->get_elementor_templates(), ) ); } public function get_elementor_templates() { // Check if the post type exists if (!post_type_exists('elementor_library')) { return []; } // Get published Elementor templates $templates = get_posts([ 'post_type' => 'elementor_library', 'post_status' => 'publish', 'posts_per_page' => -1, ]); // Return empty if no templates found if (empty($templates)) { return []; } $formatted = []; foreach ($templates as $template) { $formatted[] = [ 'id' => $template->ID, 'post_title' => get_the_title($template->ID), 'type' => get_post_meta($template->ID, '_elementor_template_type', true), // "section", "page", etc. ]; } return $formatted; } public function activate($network_wide) { } public function init() { require_once AELMS_PLUGIN_DIR . 'includes/Admin/Core.php'; $core = new Acadlix\Elementor\Admin\Core(); if (!$this->check_required_plugin_active()) { deactivate_plugins(AELMS_PLUGIN_BASENAME); // Display an admin notice add_action('admin_notices', [$core, 'show_admin_notice']); add_action('network_admin_notices', [$core, 'show_admin_notice']); } else { require_once AELMS_PLUGIN_DIR . 'includes/Admin/Init.php'; Acadlix\Elementor\Admin\Init::instance(); } } protected function check_required_plugin_active() { if (!function_exists('is_plugin_active')) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } // Check if Acadlix plugin (or function) and Elementor are loaded $acadlix_active = function_exists('acadlix') || is_plugin_active('acadlix/acadlix.php') || is_plugin_active('acadlix-pro/acadlix.php'); $elementor_active = did_action('elementor/loaded'); return $acadlix_active && $elementor_active; } public static function instance() { if (is_null(self::$_instance)) { self::$_instance = new Acadlix_Addon_For_Elementor(); } return self::$_instance; } } } if (!function_exists('aelms_acadlix_addon_for_elementor')) { function aelms_acadlix_addon_for_elementor() { return Acadlix_Addon_For_Elementor::instance(); } } aelms_acadlix_addon_for_elementor();