AllTraits.php
1 year ago
Asset_Builder.php
9 months ago
Bootstrap.php
2 weeks ago
Compatibility_Support.php
2 months ago
Elements_Manager.php
7 months ago
Helper.php
1 month ago
Migration.php
5 months ago
Plugin_Usage_Tracker.php
5 months ago
WPDeveloper_Core_Installer.php
5 months ago
WPDeveloper_Notice.php
2 months ago
WPDeveloper_Plugin_Installer.php
5 months ago
WPDeveloper_Setup_Wizard.php
2 months ago
index.php
3 years ago
Bootstrap.php
398 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Essential_Addons_Elementor\Classes; |
| 4 | |
| 5 | if (!defined('ABSPATH')) { |
| 6 | exit; |
| 7 | } // Exit if accessed directly |
| 8 | |
| 9 | use Elementor\Plugin; |
| 10 | use Essential_Addons_Elementor\Traits\Admin; |
| 11 | use Essential_Addons_Elementor\Traits\Core; |
| 12 | use Essential_Addons_Elementor\Traits\Elements; |
| 13 | use Essential_Addons_Elementor\Traits\Enqueue; |
| 14 | use Essential_Addons_Elementor\Traits\Helper; |
| 15 | use Essential_Addons_Elementor\Traits\Library; |
| 16 | use Essential_Addons_Elementor\Traits\Login_Registration; |
| 17 | use Essential_Addons_Elementor\Traits\Woo_Product_Comparable; |
| 18 | use Essential_Addons_Elementor\Traits\Controls; |
| 19 | use Essential_Addons_Elementor\Traits\Facebook_Feed; |
| 20 | use Essential_Addons_Elementor\Classes\Asset_Builder; |
| 21 | use Essential_Addons_Elementor\Traits\Ajax_Handler; |
| 22 | use Essential_Addons_Elementor\Pro\Classes\License\LicenseManager; |
| 23 | |
| 24 | class Bootstrap |
| 25 | { |
| 26 | use Library; |
| 27 | use Core; |
| 28 | use Helper; |
| 29 | use Enqueue; |
| 30 | use Admin; |
| 31 | use Elements; |
| 32 | use Login_Registration; |
| 33 | use Woo_Product_Comparable; |
| 34 | use Controls; |
| 35 | use Facebook_Feed; |
| 36 | use Ajax_Handler; |
| 37 | |
| 38 | // instance container |
| 39 | private static $instance = null; |
| 40 | |
| 41 | // request unique id container |
| 42 | protected $uid = null; |
| 43 | |
| 44 | // registered elements container |
| 45 | protected $registered_elements; |
| 46 | |
| 47 | // registered extensions container |
| 48 | protected $registered_extensions; |
| 49 | |
| 50 | // identify whether pro is enabled |
| 51 | protected $pro_enabled; |
| 52 | |
| 53 | // localize objects |
| 54 | public $localize_objects = []; |
| 55 | |
| 56 | // request data container |
| 57 | protected $request_requires_update; |
| 58 | |
| 59 | // loaded templates in a request |
| 60 | protected $loaded_templates = []; |
| 61 | |
| 62 | // loaded elements in a request |
| 63 | protected $loaded_elements = []; |
| 64 | |
| 65 | // used for internal css |
| 66 | protected $css_strings; |
| 67 | |
| 68 | // used for internal js |
| 69 | protected $js_strings; |
| 70 | |
| 71 | // used to store custom js |
| 72 | protected $custom_js_strings; |
| 73 | |
| 74 | // modules |
| 75 | protected $installer; |
| 76 | |
| 77 | |
| 78 | const EAEL_PROMOTION_FLAG = 21; |
| 79 | const EAEL_ADMIN_MENU_FLAG = 21; |
| 80 | /** |
| 81 | * Singleton instance |
| 82 | * |
| 83 | * @since 3.0.0 |
| 84 | */ |
| 85 | public static function instance() |
| 86 | { |
| 87 | if (self::$instance == null) { |
| 88 | self::$instance = new self; |
| 89 | } |
| 90 | |
| 91 | return self::$instance; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Constructor of plugin class |
| 96 | * |
| 97 | * @since 3.0.0 |
| 98 | */ |
| 99 | private function __construct() |
| 100 | { |
| 101 | // init modules |
| 102 | $this->installer = new WPDeveloper_Plugin_Installer(); |
| 103 | |
| 104 | // before init hook |
| 105 | do_action('eael/before_init'); |
| 106 | |
| 107 | // search for pro version |
| 108 | $this->pro_enabled = apply_filters('eael/pro_enabled', false); |
| 109 | |
| 110 | // elements classmap |
| 111 | $this->registered_elements = apply_filters('eael/registered_elements', $GLOBALS['eael_config']['elements']); |
| 112 | |
| 113 | // extensions classmap |
| 114 | $this->registered_extensions = apply_filters('eael/registered_extensions', $GLOBALS['eael_config']['extensions']); |
| 115 | |
| 116 | // start plugin tracking |
| 117 | if ( ! $this->pro_enabled ) { |
| 118 | add_action( 'init', [ $this, 'start_plugin_tracking' ] ); |
| 119 | } |
| 120 | |
| 121 | // register extensions |
| 122 | $this->register_extensions(); |
| 123 | |
| 124 | // register hooks |
| 125 | $this->register_hooks(); |
| 126 | |
| 127 | if ( $this->is_activate_elementor() ) { |
| 128 | new Asset_Builder( $this->registered_elements, $this->registered_extensions ); |
| 129 | } |
| 130 | |
| 131 | // Compatibility Support |
| 132 | new Compatibility_Support(); |
| 133 | |
| 134 | include_once(EAEL_PLUGIN_PATH . 'includes/bfcm-pointer.php'); |
| 135 | |
| 136 | } |
| 137 | |
| 138 | protected function register_hooks() { |
| 139 | // Core |
| 140 | add_action('init', [$this, 'i18n']); |
| 141 | // TODO::RM |
| 142 | add_filter('eael/active_plugins', [$this, 'is_plugin_active'], 10, 1); |
| 143 | |
| 144 | add_filter('eael/is_plugin_active', [$this, 'is_plugin_active'], 10, 1); |
| 145 | add_action('elementor/editor/after_save', array($this, 'save_global_values'), 10, 2); |
| 146 | add_action('trashed_post', array($this, 'save_global_values_trashed_post'), 10, 1); |
| 147 | |
| 148 | // Enqueue |
| 149 | add_action('eael/before_enqueue_styles', [$this, 'before_enqueue_styles']); |
| 150 | add_action('elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts']); |
| 151 | add_action('elementor/frontend/before_register_scripts', [$this, 'frontend_enqueue_scripts']); |
| 152 | |
| 153 | // Generator |
| 154 | |
| 155 | $this->init_ajax_hooks(); |
| 156 | |
| 157 | // Ajax |
| 158 | add_action('wp_ajax_facebook_feed_load_more', [$this, 'facebook_feed_render_items']); |
| 159 | add_action('wp_ajax_nopriv_facebook_feed_load_more', [$this, 'facebook_feed_render_items']); |
| 160 | |
| 161 | // Compare table |
| 162 | add_action( 'wp_ajax_nopriv_eael_product_grid', [$this, 'get_compare_table']); |
| 163 | add_action( 'wp_ajax_eael_product_grid', [$this, 'get_compare_table']); |
| 164 | |
| 165 | add_action( 'wp_ajax_eael_clear_widget_cache_data', [ $this, 'eael_clear_widget_cache_data' ] ); |
| 166 | |
| 167 | if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 168 | if ( version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) { |
| 169 | add_action( 'elementor/controls/register', array( $this, 'register_controls' ) ); |
| 170 | add_action('elementor/widgets/register', array($this, 'register_elements')); |
| 171 | } else { |
| 172 | add_action( 'elementor/controls/controls_registered', array( $this, 'register_controls' ) ); |
| 173 | add_action('elementor/widgets/widgets_registered', array($this, 'register_elements')); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // Elements |
| 178 | add_action('elementor/elements/categories_registered', array($this, 'register_widget_categories')); |
| 179 | add_filter('elementor/editor/localize_settings', [$this, 'promote_pro_elements']); |
| 180 | add_action('wp_footer', [$this, 'render_global_html']); |
| 181 | add_action('wp_footer', [$this, 'render_advanced_accordion_global_faq']); |
| 182 | |
| 183 | // Controls |
| 184 | add_action('eael/controls/query', [$this, 'query'], 10, 1); |
| 185 | add_action('eael/controls/betterdocs/query', [$this, 'betterdocs_query'], 10, 1); |
| 186 | add_action('eael/controls/layout', [$this, 'layout'], 10, 1); |
| 187 | add_action('eael/controls/terms_style', [$this, 'terms_style'], 10, 1); |
| 188 | add_action('eael/controls/read_more_button_style', [$this, 'read_more_button_style'], 10, 1); |
| 189 | add_action('eael/controls/load_more_button_style', [$this, 'load_more_button_style'], 10, 1); |
| 190 | add_action('eael/controls/custom_positioning', [$this, 'custom_positioning'], 10, 5); |
| 191 | add_action('eael/controls/nothing_found_style', [$this, 'nothing_found_style'], 10, 1); |
| 192 | |
| 193 | add_filter('eael/controls/event-calendar/source', [$this, 'event_calendar_source']); |
| 194 | add_action('eael/controls/advanced-data-table/source', [$this, 'advanced_data_table_source']); |
| 195 | |
| 196 | // Login | Register |
| 197 | add_action('init', [$this, 'login_or_register_user']); |
| 198 | add_filter('wp_new_user_notification_email', array($this, 'new_user_notification_email'), 10, 3); |
| 199 | add_filter('wp_new_user_notification_email_admin', array($this, 'new_user_notification_email_admin'), 10, 3); |
| 200 | |
| 201 | // Email OTP Verification (Login | Register) |
| 202 | add_action('wp_ajax_eael_lr_send_otp', [$this, 'eael_ajax_send_otp']); |
| 203 | add_action('wp_ajax_nopriv_eael_lr_send_otp', [$this, 'eael_ajax_send_otp']); |
| 204 | add_action('wp_ajax_eael_lr_verify_otp', [$this, 'eael_ajax_verify_otp']); |
| 205 | add_action('wp_ajax_nopriv_eael_lr_verify_otp', [$this, 'eael_ajax_verify_otp']); |
| 206 | |
| 207 | // Flag unverified OTP register users in wp-admin → Users. |
| 208 | add_action('admin_footer-users.php', [$this, 'eael_lr_otp_pending_user_flag']); |
| 209 | add_action( 'init', [$this, 'eael_redirect_to_reset_password'] ); |
| 210 | |
| 211 | if( 'on' === get_option( 'eael_custom_profile_fields' ) ){ |
| 212 | add_action( 'show_user_profile', [ $this, 'eael_extra_user_profile_fields' ] ); |
| 213 | add_action( 'edit_user_profile', [ $this, 'eael_extra_user_profile_fields' ] ); |
| 214 | |
| 215 | add_action( 'personal_options_update', [ $this, 'eael_save_extra_user_profile_fields' ] ); |
| 216 | add_action( 'edit_user_profile_update', [ $this, 'eael_save_extra_user_profile_fields' ] ); |
| 217 | } |
| 218 | |
| 219 | //rank math support |
| 220 | add_filter('rank_math/researches/toc_plugins', [$this, 'toc_rank_math_support']); |
| 221 | |
| 222 | // if(defined('WPML_TM_VERSION')){ |
| 223 | // add_filter( 'elementor/documents/get/post_id',[$this, 'eael_wpml_template_translation']); |
| 224 | // } |
| 225 | |
| 226 | //templately plugin support |
| 227 | if( !class_exists('Templately\Plugin') && !get_option('eael_templately_promo_hide') ) { |
| 228 | add_action( 'elementor/editor/before_enqueue_scripts', [$this, 'templately_promo_enqueue_scripts'] ); |
| 229 | add_action( 'eael/before_enqueue_styles', [$this, 'templately_promo_enqueue_style'] ); |
| 230 | add_action( 'elementor/editor/footer', [ $this, 'print_template_views' ] ); |
| 231 | add_action( 'wp_ajax_templately_promo_status', array($this, 'templately_promo_status')); |
| 232 | } |
| 233 | |
| 234 | if( class_exists( 'woocommerce' ) ) { |
| 235 | // Login|Register custom fields on WooCommerce My Account edit-account page |
| 236 | add_action( 'woocommerce_edit_account_form_fields', [ $this, 'eael_wc_account_form_fields' ] ); |
| 237 | add_action( 'woocommerce_save_account_details', [ $this, 'eael_wc_save_account_fields' ] ); |
| 238 | |
| 239 | // quick view |
| 240 | add_action( 'eael_woo_single_product_image', 'woocommerce_show_product_images', 20 ); |
| 241 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_title', 5 ); |
| 242 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_rating', 10 ); |
| 243 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_price', 15 ); |
| 244 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_excerpt', 20 ); |
| 245 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_add_to_cart', 25 ); |
| 246 | add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_meta', 30 ); |
| 247 | |
| 248 | add_filter( 'eael_product_wrapper_class', [ $this, 'eael_product_wrapper_class' ], 10, 3 ); |
| 249 | |
| 250 | add_action('wp_ajax_eael_checkout_cart_qty_update', [$this, 'eael_checkout_cart_qty_update'] ); |
| 251 | add_action('wp_ajax_nopriv_eael_checkout_cart_qty_update', [$this, 'eael_checkout_cart_qty_update'] ); |
| 252 | |
| 253 | add_action( 'wp_loaded', [ $this, 'eael_woo_cart_empty_action' ], 20 ); |
| 254 | add_filter( 'woocommerce_checkout_fields', [ $this, 'eael_customize_woo_checkout_fields' ] ); |
| 255 | |
| 256 | add_action( 'eael_woo_before_product_loop', function ( $layout ) { |
| 257 | if ( $layout === 'eael-product-default' ) { |
| 258 | return; |
| 259 | } |
| 260 | |
| 261 | remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open' ); |
| 262 | remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close' ); |
| 263 | remove_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' ); |
| 264 | remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); |
| 265 | } ); |
| 266 | |
| 267 | add_action( 'eael_woo_after_product_loop', function ( $layout ) { |
| 268 | if ( $layout === 'eael-product-default' ) { |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open' ); |
| 273 | add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close' ); |
| 274 | //Get current active theme |
| 275 | $theme = wp_get_theme(); |
| 276 | $theme = $theme->parent() ? $theme->parent() : $theme; |
| 277 | //Astra Theme |
| 278 | if( function_exists( 'astra_woo_woocommerce_shop_product_content' ) ){ |
| 279 | add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' ); |
| 280 | } else { |
| 281 | add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); |
| 282 | } |
| 283 | //Theme Support |
| 284 | $theme_to_check = ['OceanWP', 'Blocksy', 'Travel Ocean']; |
| 285 | if( in_array( $theme->name, $theme_to_check, true ) ) { |
| 286 | remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ); |
| 287 | } |
| 288 | } ); |
| 289 | |
| 290 | add_filter( 'wcml_multi_currency_ajax_actions', function ( $ajax_actions ) { |
| 291 | $ajax_actions[] = 'load_more'; |
| 292 | |
| 293 | return $ajax_actions; |
| 294 | } ); |
| 295 | } |
| 296 | |
| 297 | // Admin |
| 298 | if ( is_admin() ) { |
| 299 | // Admin |
| 300 | if (!$this->pro_enabled) { |
| 301 | add_action( 'admin_init', [ $this, 'admin_notice' ] ); |
| 302 | } else { |
| 303 | new WPDeveloper_Core_Installer( basename( EAEL_PLUGIN_BASENAME, '.php' ) ); |
| 304 | } |
| 305 | |
| 306 | add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 307 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 308 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_dequeue_scripts' ), 100 ); |
| 309 | |
| 310 | // Core |
| 311 | add_filter('plugin_action_links_' . EAEL_PLUGIN_BASENAME, array($this, 'insert_plugin_links')); |
| 312 | add_filter('plugin_row_meta', array($this, 'insert_plugin_row_meta'), 10, 2); |
| 313 | |
| 314 | // removed activation redirection temporarily |
| 315 | // add_action('admin_init', array($this, 'redirect_on_activation')); |
| 316 | |
| 317 | if ( ! did_action( 'elementor/loaded' ) ) { |
| 318 | add_action( 'admin_notices', array( $this, 'elementor_not_loaded' ) ); |
| 319 | add_action( 'eael_admin_notices', array( $this, 'elementor_not_loaded' ) ); |
| 320 | } |
| 321 | |
| 322 | add_action( 'in_admin_header', [ $this, 'remove_admin_notice' ], 99 ); |
| 323 | |
| 324 | //handle typeform auth token |
| 325 | add_action('admin_init', [$this, 'typeform_auth_handle']); |
| 326 | |
| 327 | |
| 328 | // On Editor - Register WooCommerce frontend hooks before the Editor init. |
| 329 | // Priority = 5, in order to allow plugins remove/add their wc hooks on init. |
| 330 | if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 331 | add_action( 'init', [ $this, 'register_wc_hooks' ], 5 ); |
| 332 | } |
| 333 | |
| 334 | // update admin menu notice flag once visit EA settings page |
| 335 | add_action( 'eael_admin_page_setting', [ $this, 'eael_show_admin_menu_notice' ] ); |
| 336 | |
| 337 | if ( ! current_user_can( 'administrator' ) ) { |
| 338 | add_filter( 'elementor/document/save/data', function ( $data ) { |
| 339 | if ( isset( $data['settings']['eael_custom_js'] ) ) { |
| 340 | $data['settings']['eael_custom_js'] = get_post_meta( get_the_ID(), '_eael_custom_js', true ); |
| 341 | } |
| 342 | |
| 343 | if ( empty( $data['elements'] ) ) { |
| 344 | return $data; |
| 345 | } |
| 346 | |
| 347 | $data['elements'] = Plugin::$instance->db->iterate_data( $data['elements'], function ( $element ) { |
| 348 | if ( isset( $element['widgetType'] ) && $element['widgetType'] === 'eael-login-register' ) { |
| 349 | if ( ! empty( $element['settings']['register_user_role'] ) ) { |
| 350 | $element['settings']['register_user_role'] = ''; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | if ( isset( $element['widgetType'] ) && $element['widgetType'] === 'eicon-woocommerce' ) { |
| 355 | if ( ! empty( $element['settings']['eael_product_grid_products_status'] ) ) { |
| 356 | $element['settings']['eael_product_grid_products_status'] = [ 'publish' ]; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if ( ! current_user_can( 'install_plugins' ) && isset( $element['widgetType'] ) && $element['widgetType'] === 'eaicon-advanced-data-table' ) { |
| 361 | if ( ! empty( $element['settings']['ea_adv_data_table_source'] ) ) { |
| 362 | $element['settings']['ea_adv_data_table_source'] = 'static'; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return $element; |
| 367 | } ); |
| 368 | |
| 369 | return $data; |
| 370 | } ); |
| 371 | } |
| 372 | } else { |
| 373 | add_action( 'wp', [ $this, 'eael_post_view_count' ] ); |
| 374 | } |
| 375 | |
| 376 | // beehive theme compatibility |
| 377 | add_filter( 'beehive_scripts', array( $this, 'beehive_theme_swiper_slider_compatibility' ), 999 ); |
| 378 | |
| 379 | |
| 380 | // init plugin updater with version check |
| 381 | if ( defined( 'EAEL_PRO_PLUGIN_VERSION' ) && version_compare( EAEL_PRO_PLUGIN_VERSION, '6.2.2', '>=' ) && version_compare( EAEL_PRO_PLUGIN_VERSION, '6.2.3', '<=' ) ) { |
| 382 | add_action( 'init', [ $this, 'eael_init_plugin_updater' ], 99 ); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | /** |
| 387 | * Initialize plugin updater |
| 388 | * |
| 389 | * @since 6.1.14 |
| 390 | */ |
| 391 | function eael_init_plugin_updater() { |
| 392 | if ( is_admin() ) { |
| 393 | $license_manager = LicenseManager::get_instance( [] ); |
| 394 | $license_manager->plugin_updater(); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 |