first commit

This commit is contained in:
2025-02-24 22:33:42 +01:00
commit 737c037e85
18358 changed files with 5392983 additions and 0 deletions

View File

@@ -0,0 +1,512 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
use Elementor\Core\Files\CSS\Post as Post_CSS;
use Elementor\Plugin;
use Essential_Addons_Elementor\Classes\Elements_Manager;
use Essential_Addons_Elementor\Traits\Library;
class Asset_Builder {
/**
* @theTraitAnnotation Library
*/
use Library;
/**
* Post ID
* @var int
*/
protected $post_id;
/**
* @var string
*/
protected $custom_js = '';
/**
* @var string
*/
protected $css_strings = '';
/**
* @var \Essential_Addons_Elementor\Classes\Elements_Manager
*/
protected $elements_manager;
/**
* @var false|mixed|string|void
*/
protected $css_print_method = '';
/**
* @var false|mixed|string|void
*/
protected $js_print_method = '';
/**
* @var array
*/
protected $registered_elements;
/**
* @var array
*/
protected $registered_extensions;
/**
* @var object
*/
protected $localize_objects;
/**
* @var int|int[]|mixed|string[]
*/
protected $custom_js_enable;
/**
* @var bool
*/
protected $main_page;
/**
* construct
*
* @param array $registered_elements
* @param array $registered_extensions
*/
public function __construct( $registered_elements, $registered_extensions ) {
$this->registered_elements = $registered_elements;
$this->registered_extensions = $registered_extensions;
$this->elements_manager = new Elements_Manager( $this->registered_elements, $this->registered_extensions );
$this->elements_manager->css_print_method = $this->css_print_method = get_option( 'elementor_css_print_method' );
$this->elements_manager->js_print_method = $this->js_print_method = get_option( 'eael_js_print_method' );
$this->init_hook();
$this->custom_js_enable = $this->get_settings( 'custom-js' );
}
/**
* init_hook
* Load Hook
*/
protected function init_hook() {
add_action( 'wp_footer', [ $this, 'add_inline_js' ], 100 );
add_action( 'wp_footer', [ $this, 'add_inline_css' ], 15 );
add_action( 'after_delete_post', [ $this, 'delete_cache_data' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'frontend_asset_load' ], 100 );
add_action( 'elementor/frontend/before_enqueue_styles', [ $this, 'ea_before_enqueue_styles' ] );
add_action( 'elementor/theme/register_locations', [ $this, 'load_asset_per_location' ], 20 );
add_filter( 'elementor/files/file_name', [ $this, 'load_asset_per_file' ] );
}
/**
* frontend_asset_load
* Load asset as per condition
* @return false|void
*/
public function frontend_asset_load() {
$handle = 'eael-general';
$this->post_id = get_the_ID();
$this->elements_manager->get_element_list( $this->post_id );
$this->load_commnon_asset();
$this->register_script();
if ( ! $this->is_edit() ) {
wp_enqueue_script( 'eael-general' );
wp_enqueue_style( 'eael-general' );
$this->load_custom_js( $this->post_id );
} else {
$elements = $this->get_settings();
if ( empty( $elements ) ) {
return false;
}
if ( $this->js_print_method == 'internal' ) {
wp_enqueue_script( 'eael-general' );
}
if ( $this->css_print_method == 'internal' ) {
wp_enqueue_style( 'eael-general' );
}
do_action( 'eael/before_enqueue_styles', $elements );
do_action( 'eael/before_enqueue_scripts', $elements );
$this->enqueue_asset( null, $elements, 'edit' );
$this->load_custom_js( $this->post_id );
}
wp_localize_script( $handle, 'localize', $this->localize_objects );
}
/**
* ea_before_enqueue_styles
* @return false|void
*/
public function ea_before_enqueue_styles() {
if ( $this->is_edit() ) {
return false;
}
$this->post_id = get_the_ID();
$this->set_main_page( $this->post_id );
$this->elements_manager->get_element_list( $this->post_id );
$elements = get_post_meta( $this->post_id, '_eael_widget_elements', true );
if ( ! empty( $elements ) ) {
$this->enqueue_asset( $this->post_id, $elements );
}
if ( ! $this->main_page ) {
$this->load_custom_js( $this->post_id );
}
}
/**
* load_asset_per_location
*
* @param $instance
*
* @return false|void
*/
public function load_asset_per_location( $instance ) {
if ( is_admin() || ! ( class_exists( 'ElementorPro\Modules\ThemeBuilder\Module' ) ) ) {
return false;
}
$locations = $instance->get_locations();
foreach ( $locations as $location => $settings ) {
$documents = \ElementorPro\Modules\ThemeBuilder\Module::instance()->get_conditions_manager()->get_documents_for_location( $location );
foreach ( $documents as $document ) {
$post_id = $document->get_post()->ID;
$this->post_id = $post_id;
$this->set_main_page( $this->post_id );
$this->elements_manager->get_element_list( $this->post_id );
$elements = get_post_meta( $this->post_id, '_eael_widget_elements', true );
if ( ! empty( $elements ) ) {
do_action( 'eael/before_enqueue_styles', $elements );
do_action( 'eael/before_enqueue_scripts', $elements );
$this->enqueue_asset( $this->post_id, $elements );
}
if ( ! $this->main_page ) {
$this->load_custom_js( $this->post_id );
}
}
}
}
/**
* load_asset_per_file
* @param $file_name
*
* @return mixed
*/
public function load_asset_per_file( $file_name ) {
if( empty( $file_name ) ){
return $file_name;
}
$post_id = preg_replace( '/[^0-9]/', '', $file_name );
if ( $post_id < 1 ) {
return $file_name;
}
$this->post_id = $post_id;
$type = get_post_meta( $this->post_id, '_elementor_template_type', true );
$template_list = ['popup'];
$this->set_main_page( $this->post_id );
$this->elements_manager->get_element_list( $this->post_id );
$elements = get_post_meta( $this->post_id, '_eael_widget_elements', true );
if ( ! empty( $elements ) ) {
do_action( 'eael/before_enqueue_styles', $elements );
do_action( 'eael/before_enqueue_scripts', $elements );
$this->enqueue_asset( $this->post_id, $elements );
}
if ( ! $this->main_page ) {
$this->load_custom_js( $this->post_id );
}
return $file_name;
}
/**
* add_inline_js
* Load inline js data
*/
public function add_inline_js() {
if ( $this->is_edit_mode() || $this->is_preview_mode() ) {
if ( $this->custom_js ) {
printf( '<script>%1$s</script>', 'var localize =' . wp_json_encode( $this->localize_objects ) );
printf( '<script id="eael-inline-js">%s</script>', $this->custom_js );
}
}
}
/**
* add_inline_css
* Load inline css file
*/
public function add_inline_css() {
if ( $this->is_edit_mode() || $this->is_preview_mode() ) {
if ( $this->css_strings ) {
printf( '<style id="eael-inline-css">%s</style>', $this->css_strings );
}
}
}
public function register_script() {
$css_deps = [ 'elementor-frontend' ];
$js_deps = [ 'jquery' ];
$theme = wp_get_theme(); // gets the current theme
$theme_data = $theme->parent() ? $theme->parent() : $theme;
if ( 'Hello Elementor' === $theme_data->name && version_compare( $theme_data->Version, '2.1.0', '>=' ) && wp_style_is( 'hello-elementor-theme-style', 'registered' ) ) {
array_unshift( $css_deps, 'hello-elementor-theme-style' );
} elseif ( in_array( 'Astra', [ $theme->name, $theme->parent_theme ] ) && wp_style_is( 'astra-theme-css', 'registered' ) ) {
array_unshift( $css_deps, 'astra-theme-css' );
} elseif ( in_array( 'XStore', [ $theme->name, $theme->parent_theme ] ) ) {
$js_deps[] = 'etheme';
}
if ( class_exists( 'Cartflows_Loader' ) && wcf()->utils->is_step_post_type() ) {
$css_deps = [ 'elementor-frontend' ];
}
wp_register_script( 'eael-general', EAEL_PLUGIN_URL . 'assets/front-end/js/view/general.min.js', $js_deps, EAEL_PLUGIN_VERSION, true );
wp_register_style( 'eael-general', EAEL_PLUGIN_URL . "assets/front-end/css/view/general.min.css", $css_deps, EAEL_PLUGIN_VERSION );
}
/**
* load_common_asset
* Load common asset file
*/
public function load_commnon_asset() {
wp_register_style(
'font-awesome-5-all',
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/all.min.css',
false,
EAEL_PLUGIN_VERSION
);
wp_register_style(
'font-awesome-4-shim',
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/v4-shims.min.css',
false,
EAEL_PLUGIN_VERSION
);
wp_register_script(
'font-awesome-4-shim',
ELEMENTOR_ASSETS_URL . 'lib/font-awesome/js/v4-shims.min.js',
false,
EAEL_PLUGIN_VERSION
);
// register reading progress assets
wp_register_style(
'eael-reading-progress',
EAEL_PLUGIN_URL . 'assets/front-end/css/view/reading-progress.min.css',
false,
EAEL_PLUGIN_VERSION
);
wp_register_script(
'eael-reading-progress',
EAEL_PLUGIN_URL . 'assets/front-end/js/view/reading-progress.min.js',
[ 'jquery' ],
EAEL_PLUGIN_VERSION
);
// register Table of contents assets
wp_register_style(
'eael-table-of-content',
EAEL_PLUGIN_URL . 'assets/front-end/css/view/table-of-content.min.css',
false,
EAEL_PLUGIN_VERSION
);
wp_register_script(
'eael-table-of-content',
EAEL_PLUGIN_URL . 'assets/front-end/js/view/table-of-content.min.js',
[ 'jquery' ],
EAEL_PLUGIN_VERSION
);
// register scroll to top assets
wp_register_style(
'eael-scroll-to-top',
EAEL_PLUGIN_URL . 'assets/front-end/css/view/scroll-to-top.min.css',
false,
EAEL_PLUGIN_VERSION
);
wp_register_script(
'eael-scroll-to-top',
EAEL_PLUGIN_URL . 'assets/front-end/js/view/scroll-to-top.min.js',
[ 'jquery' ],
EAEL_PLUGIN_VERSION
);
// localize object
$this->localize_objects = apply_filters( 'eael/localize_objects', [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'essential-addons-elementor' ),
'i18n' => [
'added' => __( 'Added ', 'essential-addons-for-elementor-lite' ),
'compare' => __( 'Compare', 'essential-addons-for-elementor-lite' ),
'loading' => esc_html__( 'Loading...', 'essential-addons-for-elementor-lite' )
],
'eael_translate_text' => [
'required_text' => esc_html__( 'is a required field', 'essential-addons-for-elementor-lite' ),
'invalid_text' => esc_html__( 'Invalid', 'essential-addons-for-elementor-lite' ),
'billing_text' => esc_html__( 'Billing', 'essential-addons-for-elementor-lite' ),
'shipping_text' => esc_html__( 'Shipping', 'essential-addons-for-elementor-lite' ),
'fg_mfp_counter_text' => apply_filters( 'eael/filterble-gallery/mfp-counter-text', __( 'of', 'essential-addons-for-elementor-lite' ) ),
],
'page_permalink' => get_the_permalink(),
'cart_redirectition' => get_option( 'woocommerce_cart_redirect_after_add' ),
'cart_page_url' => function_exists( 'wc_get_cart_url' ) ? wc_get_cart_url() : '',
'el_breakpoints' => method_exists( Plugin::$instance->breakpoints, 'get_breakpoints_config' ) ? Plugin::$instance->breakpoints->get_breakpoints_config() : '',
] );
}
/**
* enqueue_asset
*
* @param int $post_id
* @param array $elements
* @param string $context
*/
public function enqueue_asset( $post_id = null, $elements = [], $context = 'view' ) {
$dynamic_asset_id = ( $post_id ? '-' . $post_id : '' );
if ( $this->css_print_method == 'internal' ) {
$this->css_strings .= $this->elements_manager->generate_strings( $elements, $context, 'css' );
} else {
if ( ! $this->has_asset( $post_id, 'css' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'css' );
}
wp_enqueue_style(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.css' ),
[ 'eael-general' ],
get_post_modified_time()
);
}
if ( $this->js_print_method == 'internal' ) {
$this->custom_js .= $this->elements_manager->generate_strings( $elements, $context, 'js' );
} else {
if ( ! $this->has_asset( $post_id, 'js' ) ) {
$this->elements_manager->generate_script( $post_id, $elements, $context, 'js' );
}
wp_enqueue_script(
'eael' . $dynamic_asset_id,
$this->safe_url( EAEL_ASSET_URL . '/' . 'eael' . $dynamic_asset_id . '.js' ),
[ 'eael-general' ],
get_post_modified_time(),
true
);
}
}
/**
* delete_cache_data
*
* @param int $post_id
*/
public function delete_cache_data( $post_id ) {
$this->elements_manager->remove_files( $post_id );
delete_post_meta( $post_id, '_eael_custom_js' );
delete_post_meta( $post_id, '_eael_widget_elements' );
}
/**
* has_asset
*
* @param int $post_id
* @param string $file
*
* @return bool
*/
public function has_asset( $post_id, $file = 'css' ) {
if ( file_exists( $this->safe_path( EAEL_ASSET_PATH . '/' . 'eael' . ( $post_id ? '-' . $post_id : '' ) . '.' . $file ) ) ) {
return true;
}
return false;
}
public function load_custom_js( $post_id ) {
static $post_ids_array = [];
if ( in_array( $post_id, $post_ids_array ) ) {
return false;
}
$post_ids_array[] = $post_id;
if ( ! $this->custom_js_enable ) {
return false;
}
$custom_js = get_post_meta( $post_id, '_eael_custom_js', true );
if ( $custom_js ) {
// add semicolon if someone misses adding this in custom js code .
$this->custom_js .= $custom_js.';';
}
}
/**
* is_edit
* check is edit page
* @return bool
*/
public function is_edit() {
return (
Plugin::instance()->editor->is_edit_mode() ||
Plugin::instance()->preview->is_preview_mode() ||
is_preview()
);
}
/**
* set_main_page
*
* @param $post_id
*/
protected function set_main_page( $post_id ) {
$this->main_page = get_post_meta( $post_id, '_elementor_template_type', true ) == 'wp-page';
}
}

View File

@@ -0,0 +1,354 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
use Elementor\Plugin;
use Essential_Addons_Elementor\Traits\Admin;
use Essential_Addons_Elementor\Traits\Core;
use Essential_Addons_Elementor\Traits\Elements;
use Essential_Addons_Elementor\Traits\Enqueue;
use Essential_Addons_Elementor\Traits\Helper;
use Essential_Addons_Elementor\Traits\Library;
use Essential_Addons_Elementor\Traits\Login_Registration;
use Essential_Addons_Elementor\Traits\Woo_Product_Comparable;
use Essential_Addons_Elementor\Traits\Controls;
use Essential_Addons_Elementor\Traits\Facebook_Feed;
use Essential_Addons_Elementor\Classes\Asset_Builder;
use Essential_Addons_Elementor\Traits\Ajax_Handler;
class Bootstrap
{
use Library;
use Core;
use Helper;
use Enqueue;
use Admin;
use Elements;
use Login_Registration;
use Woo_Product_Comparable;
use Controls;
use Facebook_Feed;
use Ajax_Handler;
// instance container
private static $instance = null;
// request unique id container
protected $uid = null;
// registered elements container
protected $registered_elements;
// registered extensions container
protected $registered_extensions;
// identify whether pro is enabled
protected $pro_enabled;
// localize objects
public $localize_objects = [];
// request data container
protected $request_requires_update;
// loaded templates in a request
protected $loaded_templates = [];
// loaded elements in a request
protected $loaded_elements = [];
// used for internal css
protected $css_strings;
// used for internal js
protected $js_strings;
// used to store custom js
protected $custom_js_strings;
// modules
protected $installer;
const EAEL_PROMOTION_FLAG = 11;
const EAEL_ADMIN_MENU_FLAG = 11;
/**
* Singleton instance
*
* @since 3.0.0
*/
public static function instance()
{
if (self::$instance == null) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Constructor of plugin class
*
* @since 3.0.0
*/
private function __construct()
{
// init modules
$this->installer = new WPDeveloper_Plugin_Installer();
// before init hook
do_action('eael/before_init');
// search for pro version
$this->pro_enabled = apply_filters('eael/pro_enabled', false);
// elements classmap
$this->registered_elements = apply_filters('eael/registered_elements', $GLOBALS['eael_config']['elements']);
// extensions classmap
$this->registered_extensions = apply_filters('eael/registered_extensions', $GLOBALS['eael_config']['extensions']);
// start plugin tracking
if ( ! $this->pro_enabled ) {
$this->start_plugin_tracking();
}
// register extensions
$this->register_extensions();
// register hooks
$this->register_hooks();
if ( $this->is_activate_elementor() ) {
new Asset_Builder( $this->registered_elements, $this->registered_extensions );
}
}
protected function register_hooks()
{
// Core
add_action('init', [$this, 'i18n']);
// TODO::RM
add_filter('eael/active_plugins', [$this, 'is_plugin_active'], 10, 1);
add_filter('eael/is_plugin_active', [$this, 'is_plugin_active'], 10, 1);
add_action('elementor/editor/after_save', array($this, 'save_global_values'), 10, 2);
add_action('trashed_post', array($this, 'save_global_values_trashed_post'), 10, 1);
// Enqueue
add_action('eael/before_enqueue_styles', [$this, 'before_enqueue_styles']);
add_action('elementor/editor/before_enqueue_scripts', [$this, 'editor_enqueue_scripts']);
add_action('elementor/frontend/before_register_scripts', [$this, 'frontend_enqueue_scripts']);
// Generator
$this->init_ajax_hooks();
// Ajax
add_action('wp_ajax_facebook_feed_load_more', [$this, 'facebook_feed_render_items']);
add_action('wp_ajax_nopriv_facebook_feed_load_more', [$this, 'facebook_feed_render_items']);
// Compare table
add_action( 'wp_ajax_nopriv_eael_product_grid', [$this, 'get_compare_table']);
add_action( 'wp_ajax_eael_product_grid', [$this, 'get_compare_table']);
add_action( 'wp_ajax_eael_clear_widget_cache_data', [ $this, 'eael_clear_widget_cache_data' ] );
if ( defined( 'ELEMENTOR_VERSION' ) ) {
if ( version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) {
add_action( 'elementor/controls/register', array( $this, 'register_controls' ) );
add_action('elementor/widgets/register', array($this, 'register_elements'));
} else {
add_action( 'elementor/controls/controls_registered', array( $this, 'register_controls' ) );
add_action('elementor/widgets/widgets_registered', array($this, 'register_elements'));
}
}
// Elements
add_action('elementor/elements/categories_registered', array($this, 'register_widget_categories'));
add_filter('elementor/editor/localize_settings', [$this, 'promote_pro_elements']);
add_action('wp_footer', [$this, 'render_global_html']);
add_action('wp_footer', [$this, 'render_advanced_accordion_global_faq']);
// Controls
add_action('eael/controls/query', [$this, 'query'], 10, 1);
add_action('eael/controls/betterdocs/query', [$this, 'betterdocs_query'], 10, 1);
add_action('eael/controls/layout', [$this, 'layout'], 10, 1);
add_action('eael/controls/terms_style', [$this, 'terms_style'], 10, 1);
add_action('eael/controls/read_more_button_style', [$this, 'read_more_button_style'], 10, 1);
add_action('eael/controls/load_more_button_style', [$this, 'load_more_button_style'], 10, 1);
add_action('eael/controls/custom_positioning', [$this, 'custom_positioning'], 10, 5);
add_action('eael/controls/nothing_found_style', [$this, 'nothing_found_style'], 10, 1);
add_filter('eael/controls/event-calendar/source', [$this, 'event_calendar_source']);
add_action('eael/controls/advanced-data-table/source', [$this, 'advanced_data_table_source']);
// Login | Register
add_action('init', [$this, 'login_or_register_user']);
add_filter('wp_new_user_notification_email', array($this, 'new_user_notification_email'), 10, 3);
add_filter('wp_new_user_notification_email_admin', array($this, 'new_user_notification_email_admin'), 10, 3);
add_action( 'login_init', [$this, 'eael_redirect_to_reset_password'] );
if( 'on' === get_option( 'eael_custom_profile_fields' ) ){
add_action( 'show_user_profile', [ $this, 'eael_extra_user_profile_fields' ] );
add_action( 'edit_user_profile', [ $this, 'eael_extra_user_profile_fields' ] );
add_action( 'personal_options_update', [ $this, 'eael_save_extra_user_profile_fields' ] );
add_action( 'edit_user_profile_update', [ $this, 'eael_save_extra_user_profile_fields' ] );
}
//rank math support
add_filter('rank_math/researches/toc_plugins', [$this, 'toc_rank_math_support']);
// if(defined('WPML_TM_VERSION')){
// add_filter( 'elementor/documents/get/post_id',[$this, 'eael_wpml_template_translation']);
// }
//templately plugin support
if( !class_exists('Templately\Plugin') && !get_option('eael_templately_promo_hide') ) {
add_action( 'elementor/editor/before_enqueue_scripts', [$this, 'templately_promo_enqueue_scripts'] );
add_action( 'eael/before_enqueue_styles', [$this, 'templately_promo_enqueue_style'] );
add_action( 'elementor/editor/footer', [ $this, 'print_template_views' ] );
add_action( 'wp_ajax_templately_promo_status', array($this, 'templately_promo_status'));
}
//Essential Blocks Promo
if ( ! class_exists( 'Classic_Editor' ) && ! class_exists( 'EssentialBlocks' ) && ( ! get_option( 'eael_eb_optin_hide' ) || ! get_option( 'eael_gb_eb_popup_hide' ) ) ) {
add_action( 'enqueue_block_editor_assets', [ $this, 'essential_blocks_promo_enqueue_scripts' ] );
add_action( 'admin_notices', [ $this, 'essential_block_optin' ] );
add_action( 'eael_admin_notices', [ $this, 'essential_block_special_optin' ], 100 );
add_action( 'wp_ajax_eael_eb_optin_notice_dismiss', [ $this, 'eael_eb_optin_notice_dismiss' ] );
add_action( 'wp_ajax_eael_gb_eb_popup_dismiss', [ $this, 'eael_gb_eb_popup_dismiss' ] );
}
if( class_exists( 'woocommerce' ) ) {
// quick view
add_action( 'eael_woo_single_product_image', 'woocommerce_show_product_images', 20 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_title', 5 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_rating', 10 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_price', 15 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_add_to_cart', 25 );
add_action( 'eael_woo_single_product_summary', 'woocommerce_template_single_meta', 30 );
add_filter( 'woocommerce_product_get_rating_html', [ $this, 'eael_rating_markup' ], 10, 3 );
add_filter( 'eael_product_wrapper_class', [ $this, 'eael_product_wrapper_class' ], 10, 3 );
add_action('wp_ajax_eael_checkout_cart_qty_update', [$this, 'eael_checkout_cart_qty_update'] );
add_action('wp_ajax_nopriv_eael_checkout_cart_qty_update', [$this, 'eael_checkout_cart_qty_update'] );
add_action( 'wp_loaded', [ $this, 'eael_woo_cart_empty_action' ], 20 );
add_filter( 'woocommerce_checkout_fields', [ $this, 'eael_customize_woo_checkout_fields' ] );
add_action( 'eael_woo_before_product_loop', function ( $layout ) {
if ( $layout === 'eael-product-default' ) {
return;
}
remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open' );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close' );
remove_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
} );
add_action( 'eael_woo_after_product_loop', function ( $layout ) {
if ( $layout === 'eael-product-default' ) {
return;
}
add_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open' );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close' );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
if( function_exists( 'astra_woo_woocommerce_shop_product_content' ) ){
add_action( 'woocommerce_after_shop_loop_item', 'astra_woo_woocommerce_shop_product_content' );
}
} );
}
// Admin
if ( is_admin() ) {
// Admin
if (!$this->pro_enabled) {
$this->admin_notice();
} else {
new WPDeveloper_Core_Installer( basename( EAEL_PLUGIN_BASENAME, '.php' ) );
}
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_dequeue_scripts' ), 100 );
// Core
add_filter('plugin_action_links_' . EAEL_PLUGIN_BASENAME, array($this, 'insert_plugin_links'));
add_filter('plugin_row_meta', array($this, 'insert_plugin_row_meta'), 10, 2);
// removed activation redirection temporarily
// add_action('admin_init', array($this, 'redirect_on_activation'));
if ( ! did_action( 'elementor/loaded' ) ) {
add_action( 'admin_notices', array( $this, 'elementor_not_loaded' ) );
add_action( 'eael_admin_notices', array( $this, 'elementor_not_loaded' ) );
}
add_action( 'in_admin_header', [ $this, 'remove_admin_notice' ], 99 );
//handle typeform auth token
add_action('admin_init', [$this, 'typeform_auth_handle']);
// On Editor - Register WooCommerce frontend hooks before the Editor init.
// Priority = 5, in order to allow plugins remove/add their wc hooks on init.
if ( ! empty( $_REQUEST['action'] ) && 'elementor' === $_REQUEST['action'] ) {
add_action( 'init', [ $this, 'register_wc_hooks' ], 5 );
}
// update admin menu notice flag once visit EA settings page
add_action( 'eael_admin_page_setting', [ $this, 'eael_show_admin_menu_notice' ] );
// Black Friday Optin
add_action( 'admin_notices', [ $this, 'eael_black_friday_optin' ] );
add_action( 'eael_admin_notices', [ $this, 'eael_black_friday_optin' ] );
add_action( 'wp_ajax_eael_black_friday_optin_dismiss', [ $this, 'eael_black_friday_optin_dismiss' ] );
if ( ! current_user_can( 'administrator' ) ) {
add_filter( 'elementor/document/save/data', function ( $data ) {
if ( isset( $data['settings']['eael_custom_js'] ) ) {
$data['settings']['eael_custom_js'] = get_post_meta( get_the_ID(), '_eael_custom_js', true );
}
if ( empty( $data['elements'] ) ) {
return $data;
}
$data['elements'] = Plugin::$instance->db->iterate_data( $data['elements'], function ( $element ) {
if ( isset( $element['widgetType'] ) && $element['widgetType'] === 'eael-login-register' ) {
if ( ! empty( $element['settings']['register_user_role'] ) ) {
$element['settings']['register_user_role'] = '';
}
}
if ( isset( $element['widgetType'] ) && $element['widgetType'] === 'eicon-woocommerce' ) {
if ( ! empty( $element['settings']['eael_product_grid_products_status'] ) ) {
$element['settings']['eael_product_grid_products_status'] = [ 'publish' ];
}
}
return $element;
} );
return $data;
} );
}
} else {
add_action( 'wp', [ $this, 'eael_post_view_count' ] );
}
// beehive theme compatibility
add_filter( 'beehive_scripts', array( $this, 'beehive_theme_swiper_slider_compatibility' ), 999 );
}
}

View File

@@ -0,0 +1,400 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly
use Elementor\Plugin;
use Essential_Addons_Elementor\Traits\Library;
class Elements_Manager {
use Library;
/**
* custom key name which are used for store widget list in option table
*/
const ELEMENT_KEY = '_eael_widget_elements';
/**
* This is hold custom js data in option table
*/
const JS_KEY = '_eael_custom_js';
public $css_print_method;
public $js_print_method;
/**
* Post id
* @var string
*/
protected $post_id;
/**
* registered element list from essential addons settings
* @var array
*/
protected $registered_elements;
/**
* registered extensions list from essential addons settings
* @var array
*/
protected $registered_extensions;
/**
* __construct
* @param array $registered_elements
* @param array $registered_extensions
*/
public function __construct( $registered_elements, $registered_extensions ) {
$this->registered_elements = $registered_elements;
$this->registered_extensions = $registered_extensions;
add_action( 'elementor/editor/after_save', array( $this, 'eael_elements_cache' ), 10, 2 );
}
/**
* eael_elements_cache
* Save widget name list in option table for improve performance.
* @param int $post_id
* @param array $data
*/
public function eael_elements_cache( $post_id, $data ) {
$widget_list = $this->get_widget_list( $data );
$page_setting = get_post_meta( $post_id, '_elementor_page_settings', true );
$custom_js = isset( $page_setting['eael_custom_js'] ) ? trim( $page_setting['eael_custom_js'] ) : '';
$this->save_widgets_list( $post_id, $widget_list, $custom_js );
}
/**
* get_widget_list
* get widget names
* @param array $data
*
* @return array
*/
public function get_widget_list( $data ) {
$widget_list = [];
$replace = $this->replace_widget_name();
if ( is_object( Plugin::$instance->db ) ) {
Plugin::$instance->db->iterate_data( $data, function ( $element ) use ( &$widget_list, $replace ) {
if ( empty( $element['widgetType'] ) ) {
$type = $element['elType'];
} else {
$type = $element['widgetType'];
}
if ( ! empty( $element['widgetType'] ) && $element['widgetType'] === 'global' ) {
$document = Plugin::$instance->documents->get( $element['templateID'] );
$type = is_object( $document ) ? current( $this->get_widget_list( $document->get_elements_data() ) ) : $type;
if ( ! empty( $type ) ) {
$type = 'eael-' . $type;
}
}
if ( ! empty( $type ) && ! is_array( $type ) ) {
if ( isset( $replace[ $type ] ) ) {
$type = $replace[ $type ];
}
if ( strpos( $type, 'eael-' ) !== false ) {
$type = str_replace( 'eael-', '', $type );
if ( ! isset( $widget_list[ $type ] ) ) {
$widget_list[ $type ] = $type;
}
}
$widget_list += $this->get_extension_list( $element );
}
} );
}
return $widget_list;
}
/**
* get_element_list
* get cached widget list
* @param $post_id
*
* @return bool
*/
public function get_element_list( $post_id ) {
if ( is_object( Plugin::instance()->editor ) && Plugin::instance()->editor->is_edit_mode() ) {
return false;
}
if ( $this->has_exist( $post_id ) ) {
return false;
}
$document = is_object( Plugin::$instance->documents ) ? Plugin::$instance->documents->get( $post_id ) : [];
$data = is_object( $document ) ? $document->get_elements_data() : [];
$data = $this->get_widget_list( $data );
$this->save_widgets_list( $post_id, $data, false );
return true;
}
/**
* get_extension_list
* get extension name those name had been changed for some reason.
* @param array $element
*
* @return array
*/
public function get_extension_list( $element ) {
$list = [];
if ( isset( $element['elType'] ) && ( $element['elType'] == 'section' || $element['elType'] == 'container' ) ) {
if ( ! empty( $element['settings']['eael_particle_switch'] ) ) {
$list['section-particles'] = 'section-particles';
}
if ( ! empty( $element['settings']['eael_parallax_switcher'] ) ) {
$list['section-parallax'] = 'section-parallax';
}
} else {
if ( ! empty( $element['settings']['eael_tooltip_section_enable'] ) ) {
$list['tooltip-section'] = 'tooltip-section';
}
if ( ! empty( $element['settings']['eael_ext_content_protection'] ) ) {
$list['content-protection'] = 'content-protection';
}
}
if ( ! empty( $element['settings']['eael_wrapper_link_switch'] ) ) {
$list['wrapper-link'] = 'wrapper-link';
}
if ( ! empty( $element['settings']['eael_ext_advanced_dynamic_tags'] ) ) {
$list['advanced-dynamic-tags'] = 'advanced-dynamic-tags';
}
//Smooth Animation
if ( ! empty( $element['settings']['eael_smooth_animation_section'] ) ) {
$list['smooth-animation'] = 'smooth-animation';
}
//Hover Interactions
if ( ! empty( $element['settings']['eael_hover_effect_switch'] ) ) {
$list['special-hover-effect'] = 'special-hover-effect';
}
return $list;
}
/*
* replace_widget_name
* Added backward compatibility
*/
public static function replace_widget_name() {
return [
'eicon-woocommerce' => 'eael-product-grid',
'eael-countdown' => 'eael-count-down',
'eael-creative-button' => 'eael-creative-btn',
'eael-team-member' => 'eael-team-members',
'eael-testimonial' => 'eael-testimonials',
'eael-weform' => 'eael-weforms',
'eael-cta-box' => 'eael-call-to-action',
'eael-dual-color-header' => 'eael-dual-header',
'eael-pricing-table' => 'eael-price-table',
'eael-filterable-gallery' => 'eael-filter-gallery',
'eael-one-page-nav' => 'eael-one-page-navigation',
'eael-interactive-card' => 'eael-interactive-cards',
'eael-image-comparison' => 'eael-img-comparison',
'eael-dynamic-filterable-gallery' => 'eael-dynamic-filter-gallery',
'eael-google-map' => 'eael-adv-google-map',
'eael-instafeed' => 'eael-instagram-gallery',
'eael-ninja' => 'eael-ninja-form',
];
}
/**
* save_widgets_list
* save widget list and custom js data in option table
* @param int $post_id
* @param array $list
* @param string $custom_js
*
* @return bool|mixed
*/
public function save_widgets_list( $post_id, $list, $custom_js = '' ) {
if ( \defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
$documents = is_object( Plugin::$instance->documents ) ? Plugin::$instance->documents->get( $post_id ) : [];
if ( ! in_array( get_post_status( $post_id ), [ 'publish', 'private' ] ) || ( is_object( $documents ) && ! $documents->is_built_with_elementor() ) ) {
return false;
}
if ( in_array( get_post_meta( $post_id, '_elementor_template_type', true ), $this->excluded_template_type() ) ) {
return false;
}
if ( $custom_js !== false ) {
update_post_meta( $post_id, '_eael_custom_js', $custom_js );
}
if ( md5( implode( '', (array) $list ) ) == md5( implode( '', (array) get_post_meta( $post_id, self::ELEMENT_KEY, true ) ) ) ) {
return false;
}
try {
update_post_meta( $post_id, self::ELEMENT_KEY, $list );
$this->remove_files( $post_id );
if ( $this->has_exist( $post_id ) ) {
$this->update_asset( $post_id, $list );
}
return true;
} catch ( \Exception $e ) {
return false;
}
}
/**
* generate_script
* create js/css file as per widget loaded in page
* @param int $post_id
* @param array $elements
* @param string $context
* @param string $ext
*/
public function generate_script( $post_id, $elements, $context, $ext ) {
// if folder not exists, create new folder
if ( ! file_exists( EAEL_ASSET_PATH ) ) {
wp_mkdir_p( EAEL_ASSET_PATH );
}
// naming asset file
$file_name = 'eael' . ( $post_id ? '-' . $post_id : '' ) . '.' . $ext;
// output asset string
$output = $this->generate_strings( $elements, $context, $ext );
// write to file
$file_path = $this->safe_path( EAEL_ASSET_PATH . DIRECTORY_SEPARATOR . $file_name );
file_put_contents( $file_path, $output );
}
/**
* generate_strings
* Load assets for inline loading
* @param string $elements
* @param string $context
* @param string $ext
*
* @return string
*/
public function generate_strings( $elements, $context, $ext ) {
$output = '';
$paths = $this->generate_dependency( $elements, $context, $ext );
if ( ! empty( $paths ) ) {
foreach ( $paths as $path ) {
$output .= file_get_contents( $this->safe_path( $path ) );
}
}
return $output;
}
/**
* generate_dependency
* Load core library for widget list which are defined on config.php file
* @param array $elements
* @param string $context
* @param string $type
*
* @return array
*/
public function generate_dependency( $elements, $context, $type ) {
$lib = [ 'view' => [], 'edit' => [] ];
$self = [ 'general' => [], 'view' => [], 'edit' => [] ];
if ( $type == 'js' ) {
$self['general'][] = EAEL_PLUGIN_PATH . 'assets/front-end/js/view/general.min.js';
$self['edit'][] = EAEL_PLUGIN_PATH . 'assets/front-end/js/edit/promotion.min.js';
} else if ( $type == 'css' && ! $this->is_edit_mode() ) {
$self['view'][] = EAEL_PLUGIN_PATH . "assets/front-end/css/view/general.min.css";
}
foreach ( $elements as $element ) {
if ( isset( $this->registered_elements[ $element ] ) ) {
if ( ! empty( $this->registered_elements[ $element ]['dependency'][ $type ] ) ) {
foreach ( $this->registered_elements[ $element ]['dependency'][ $type ] as $file ) {
if ( ! empty( $file['type'] ) && ! empty( $file['context'] ) && ! empty( $file['file'] ) ) {
${$file['type']}[ $file['context'] ][] = $file['file'];
}
}
}
} elseif ( isset( $this->registered_extensions[ $element ] ) ) {
if ( ! empty( $this->registered_extensions[ $element ]['dependency'][ $type ] ) ) {
foreach ( $this->registered_extensions[ $element ]['dependency'][ $type ] as $file ) {
if ( ! empty( $file['type'] ) && ! empty( $file['context'] ) && ! empty( $file['file'] ) ) {
${$file['type']}[ $file['context'] ][] = $file['file'];
}
}
}
}
}
if ( $context == 'view' ) {
return array_unique( array_merge( $lib['view'], $self['view'] ) );
}
return array_unique( array_merge( $lib['view'], $lib['edit'], $self['edit'], $self['view'] ) );
}
/**
* has_exist
* @param $post_id
* check widget list already saved in option table weather load or not
* @return bool
*/
public function has_exist( $post_id ) {
$status = get_post_meta( $post_id, self::ELEMENT_KEY, true );
return ! empty( $status );
}
/**
* update_asset
* @param int $post_id
* @param $elements
*/
public function update_asset( $post_id, $elements ) {
if ( $this->css_print_method != 'internal' ) {
$this->generate_script( $post_id, $elements, 'view', 'css' );
}
if ( $this->js_print_method != 'internal' ) {
$this->generate_script( $post_id, $elements, 'view', 'js' );
}
}
/**
* excluded_template_type
* @return string[]
*/
public function excluded_template_type() {
return [
'kit',
];
}
}

View File

@@ -0,0 +1,108 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
class Migration
{
use \Essential_Addons_Elementor\Traits\Core;
use \Essential_Addons_Elementor\Traits\Library;
/**
* Plugin activation hook
*
* @since 3.0.0
*/
public function plugin_activation_hook()
{
// remove old cache files
$this->empty_dir(EAEL_ASSET_PATH);
//check setup wizard condition
$this->enable_setup_wizard();
// save default values
$this->set_default_values();
}
/**
* Plugin deactivation hook
*
* @since 3.0.0
*/
public function plugin_deactivation_hook()
{
$this->empty_dir(EAEL_ASSET_PATH);
}
/**
* Plugin upgrade hook
*
* @since 3.0.0
*/
public function plugin_upgrade_hook( $upgrader_object, $options ) {
if ( isset( $options['action'], $options['type'] ) && $options['action'] === 'update' && $options['type'] === 'plugin' ) {
if ( ( isset( $options['plugins'] ) &&
( in_array( EAEL_PLUGIN_BASENAME, $options['plugins'] ) ||
in_array( 'essential-addons-elementor/essential_adons_elementor.php', $options['plugins'] )
)
) || ( isset( $options['plugin'] ) &&
in_array( $options['plugin'], [ EAEL_PLUGIN_BASENAME, 'essential-addons-elementor/essential_adons_elementor.php' ] )
)
) {
// remove old cache files
$this->empty_dir( EAEL_ASSET_PATH );
}
}
}
/**
* Plugin migrator
*
* @since 3.0.0
*/
public function migrator() {
// set current version to db
if ( get_option( 'eael_version' ) != EAEL_PLUGIN_VERSION ) {
// update plugin version
update_option( 'eael_version', EAEL_PLUGIN_VERSION );
}
add_action( 'eael_after_clear_cache_files', [ $this, 'reduce_options_data' ] );
}
public function reduce_options_data() {
$status = get_transient( 'eael_reduce_op_table_data' );
if ( $status ) {
return false;
}
global $wpdb;
$sql = "from {$wpdb->options} as options_tb
inner join (SELECT option_id FROM {$wpdb->options}
WHERE ((option_name like '%\_eael_elements' and LENGTH(option_name) = 23 )
or (option_name like '%\_eael_custom_js' and LENGTH(option_name) = 24)
or (option_name like '%\_eael_updated_at' and LENGTH(option_name) = 25)
or (option_name = 'eael_reduce_op_table_data')
or (option_name = 'eael_remove_old_cache')
or (option_name = 'eael_editor_updated_at')
or (option_name like 'eael_login_error_%'))
) AS options_tb2
ON options_tb2.option_id = options_tb.option_id";
$selection_sql = "select count(options_tb.option_id) as total " . $sql;
$results = $wpdb->get_var( $selection_sql );
if ( $results > 0 ) {
$deletiation_sql = "delete options_tb " . $sql;
$wpdb->query( $deletiation_sql );
}
set_transient( 'eael_reduce_op_table_data', 1, DAY_IN_SECONDS );
wp_clear_scheduled_hook( 'eael_remove_unused_options_data' );
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly.
/**
* WPDeveloper Core Install
*/
class WPDeveloper_Core_Installer {
/**
* Plugin Base Name
*
* @var string
*/
private $plugin_basename;
/**
* Instantiate the class
*
* @param string $affiliate
*/
function __construct( $plugin_basename = '' ) {
$this->plugin_basename = $plugin_basename;
add_action( 'init', array( $this, 'init_hooks' ) );
}
/**
* Initialize the hooks
*
* @return void
*/
public function init_hooks() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
add_action( 'wp_ajax_wpdeveloper_upsale_core_install_' . $this->plugin_basename, array( $this, 'core_install' ) );
}
/**
* Fail if plugin installtion/activation fails
*
* @param Object $thing
*
* @return void
*/
public function fail_on_error( $thing ) {
if ( is_wp_error( $thing ) ) {
wp_send_json_error( $thing->get_error_message() );
}
}
/**
* Install Upsale Plugin
*
* @return void
*/
public function core_install() {
check_ajax_referer( 'wpdeveloper_upsale_core_install_' . $this->plugin_basename );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'You don\'t have permission to install the plugins', 'essential-addons-for-elementor-lite' ) );
}
$plugin_slug = ( isset( $_POST['slug'] ) ) ? sanitize_text_field( $_POST['slug'] ) : '';
$plugin_file = ( isset( $_POST['file'] ) ) ? sanitize_text_field( $_POST['file'] ) : '';
if( empty( $plugin_file ) || empty( $plugin_slug ) ) {
wp_send_json_error( __( 'You don\'t have set any slug and file name to install the plugins', 'essential-addons-for-elementor-lite' ) );
}
$plugin_status = $this->install_plugin( $plugin_slug, $plugin_file );
$this->fail_on_error( $plugin_status );
wp_send_json_success();
}
/**
* Install and activate a plugin
*
* @param string $slug
* @param string $file
*
* @return WP_Error|null
*/
public function install_plugin( $slug, $file ) {
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$plugin_basename = $slug . '/' . $file;
// if exists and not activated
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_basename ) ) {
return activate_plugin( $plugin_basename );
}
// seems like the plugin doesn't exists. Download and activate it
$upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin() );
$api = plugins_api( 'plugin_information', array( 'slug' => $slug, 'fields' => array( 'sections' => false ) ) );
$result = $upgrader->install( $api->download_link );
if ( is_wp_error( $result ) ) {
return $result;
}
return activate_plugin( $plugin_basename );
}
}

View File

@@ -0,0 +1,934 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly.
use Essential_Addons_Elementor\Classes\Helper;
use Essential_Addons_Elementor\Classes\WPDeveloper_Core_Installer;
class WPDeveloper_Notice {
/**
* Admin Notice Key
*
* @var array
*/
const ADMIN_UPDATE_NOTICE_KEY = 'wpdeveloper_notices_seen';
/**
* All Data
* @var array
*/
private $data = array();
private $properties = array(
'links', 'message', 'thumbnail',
);
private $methods = array(
'message', 'thumbnail', 'classes'
);
/**
* cne_day == current_notice_end_day
*
* @var integer
*/
public $cne_time = '2 day';
public $maybe_later_time = '7 day';
public $finish_time = [];
/**
* Plugin Name
*
* @var string
*/
private $plugin_name;
/**
* Plugin File Name
* @var string
*/
private $plugin_file;
/**
* First Install Version Of The Plugin
*
* @var string
*/
private $version;
/**
* Saved Data in DB
* @var array
*/
private $options_data;
/**
* Current Timestamp
* @var integer
*/
public $timestamp;
/**
* Primary Notice Action
*
* @var string
*/
private $do_notice_action;
/**
* Default Options Set
*
* @var array
*/
public $options_args = array(
);
/**
* Notice ID for users.
* @var string
*/
private $notice_id;
/**
* Upsale Notice Arguments
* @var array
*/
public $upsale_args;
/**
* Revoke this function when the object is created.
*
* @param string $plugin_name
* @param string $version
*/
public function __construct( $plugin_file = '', $version = '' ) {
$this->plugin_file = $plugin_file;
$this->plugin_name = basename( $plugin_file, '.php' );
$this->version = $version;
$this->timestamp = intval( current_time( 'timestamp' ) );
$this->notice_id = 'wpdeveloper_notice_' . str_replace( '.', '_', $this->version );
$this->do_notice_action = 'wpdeveloper_notices_for_' . $this->plugin_name;
new WPDeveloper_Core_Installer( $this->plugin_name );
}
/**
* Initiate The Plugin
* @return void
*/
public function init(){
$this->migration();
add_action( 'init', array( $this, 'first_install_track') );
add_action( 'deactivate_' . $this->plugin_file, array( $this, 'first_install_end' ) );
add_action( 'init', array( $this, 'hooks' ) );
}
public function migration(){
$user_notices = $this->get_user_notices();
if( \version_compare( get_option( 'eael_version', false ), '3.7.2', '==' ) && ! get_option( 'eael_notice_migration', false ) ) {
if( is_array( $user_notices ) ) {
array_walk( $user_notices, function( $value, $key ){
array_walk( $value, function( $v, $k ){
array_walk( $v, function( $vv, $kk ){
update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $vv, true );
} );
} );
} );
}
update_option( 'eael_notice_migration', true );
}
}
/**
* All Hooks
* @return void
*/
public function hooks(){
add_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name, array( $this, 'clicked' ) );
add_action( 'wp_ajax_wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'upsale_notice_dissmiss' ) );
add_action( 'wp_ajax_wpdeveloper_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'notice_dissmiss' ) );
add_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name, array( $this, 'before' ) );
add_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
add_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name, array( $this, 'before_upsale' ) );
add_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
add_action( $this->do_notice_action, array( $this, 'content' ) );
// if( current_user_can( 'install_plugins' ) ) {
if( isset( $_GET['plugin'] ) && $_GET['plugin'] == $this->plugin_name ) {
do_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name );
/**
* Redirect User To the Current URL, but without set query arguments.
*/
wp_safe_redirect( $this->redirect_to() );
}
$return_notice = $this->next_notice();
$current_notice = current( $return_notice );
$next_notice = next( $return_notice );
$deserve_notice = $this->deserve_notice( $current_notice );
$options_data = $this->get_options_data();
$user_notices = $this->get_user_notices();
$notice_time = isset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] )
? $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] : $this->timestamp;
$next_notice_time = $next_notice ? $options_data[ $this->plugin_name ]['notice_will_show'][ $next_notice ] : $this->timestamp;
$current_notice_end = $this->makeTime( $notice_time, $this->cne_time );
if( ! $deserve_notice ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
}
if( $deserve_notice ) {
/**
* TODO: automatic maybe later setup with time.
*/
if( ( $this->timestamp >= $current_notice_end ) || ( $this->timestamp > $next_notice_time ) ) {
$this->maybe_later( $current_notice );
$notice_time = false;
}
if( isset( $this->finish_time[ $current_notice ] ) ) {
if( $this->timestamp >= strtotime( $this->finish_time[ $current_notice ] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
$notice_time = false;
}
}
if( $notice_time != false ) {
if( $notice_time <= $this->timestamp ) {
if( $current_notice === 'upsale' ) {
$upsale_args = $this->get_upsale_args();
if( empty( $upsale_args ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
} else {
/**
* For Upsale Remove
* if the plugin is activated.
*/
if( isset( $upsale_args['condition'], $upsale_args['condition']['by'] ) ) {
switch( $upsale_args['condition']['by'] ) {
case 'class' :
if( isset( $upsale_args['condition']['class'] ) && class_exists( $upsale_args['condition']['class'] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
return;
}
break;
case 'function' :
if( isset( $upsale_args['condition']['function'] ) && function_exists( $upsale_args['condition']['function'] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
return;
}
break;
}
}
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
$pkey = $upsale_args['slug'] . '/' . $upsale_args['file'];
if( isset( $plugins[ $pkey ] ) ) {
$this->update( $current_notice );
return;
}
add_action( 'admin_notices', array( $this, 'upsale_notice' ) );
add_action( 'eael_admin_notices', array( $this, 'upsale_notice' ) );
}
} else {
if( $this->is_ok( 'message', $current_notice ) || $current_notice === 'opt_in' ) {
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
add_action( 'eael_admin_notices', array( $this, 'admin_notices' ) );
}
}
}
}
}
// }
}
/**
* Make time using timestamp and a string like 2 Hour, 2 Day, 30 Minutes, 1 Week, 1 year
* @param integer $current
* @param string $time
* @return integer
*/
public function makeTime( $current, $time ) {
return intval( strtotime( date( 'Y-m-d h:i:s', intval( $current ) ) . " +$time" ) );
}
/**
* Automatice Maybe Later.
* @param string $notice
* @return void
*/
private function maybe_later( $notice ){
if( empty( $notice ) ) {
return;
}
$options_data = $this->get_options_data();
$options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$this->update_options_data( $options_data[ $this->plugin_name ] );
}
/**
* When links are clicked, this function will invoked.
* @return void
*/
public function clicked(){
if( isset( $_GET['plugin'] ) ) {
$plugin = sanitize_text_field( $_GET['plugin'] );
if( $plugin === $this->plugin_name ) {
$options_data = $this->get_options_data();
$clicked_from = current( $this->next_notice() );
if( isset( $_GET['plugin_action'] ) ) {
$plugin_action = sanitize_text_field( $_GET['plugin_action'] );
}
if( isset( $_GET['dismiss'] ) ) {
$dismiss = sanitize_text_field( $_GET['dismiss'] );
}
if( isset( $_GET['later'] ) ) {
$later = sanitize_text_field( $_GET['later'] );
}
$later_time = '';
switch( $clicked_from ) {
case 'opt_in' :
$dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
break;
case 'first_install' :
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
break;
case 'update' :
$dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
break;
// case 'update_400k' :
// $dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
// $later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
// break;
case 'review' :
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
break;
case 'upsale' :
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
break;
}
if( isset( $later ) && $later == true ) {
$options_data[ $this->plugin_name ]['notice_will_show'][ $clicked_from ] = $later_time;
}
if( isset( $dismiss ) && $dismiss == true ) {
update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $clicked_from, true );
$this->update( $clicked_from );
}
$this->update_options_data( $options_data[ $this->plugin_name ] );
}
}
}
/**
* For Redirecting Current Page without Arguments!
*
* @return void
*/
private function redirect_to(){
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$query_string = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY );
wp_parse_str( $query_string, $current_url );
$unset_array = array( 'dismiss', 'plugin', '_wpnonce', 'later', 'plugin_action', 'marketing_optin' );
foreach( $unset_array as $value ) {
if( isset( $current_url[ $value ] ) ) {
unset( $current_url[ $value ] );
}
}
$current_url = http_build_query($current_url);
$redirect_url = $request_uri . '?' . $current_url;
return $redirect_url;
}
/**
* Before Notice
* @return void
*/
public function before(){
$current_notice = current( $this->next_notice() );
$classes = 'notice notice-info put-dismiss-notice';
if( isset( $this->data['classes'] ) ) {
if( isset( $this->data['classes'][ $current_notice ] ) ) {
$classes = $this->data['classes'][ $current_notice ];
}
}
if( $this->has_thumbnail( $current_notice ) ) {
$classes .= 'notice-has-thumbnail';
}
echo '<div class="'. $classes .' wpdeveloper-'. $current_notice .'-notice" data-notice="'. $current_notice .'">';
}
/**
* After Notice
* @return void
*/
public function after(){
echo '</div>';
}
/**
* Content generation & Hooks Funciton.
* @return void
*/
public function content(){
$options_data = $this->get_options_data();
$notice = current( $this->next_notice() );
switch( $notice ) {
case 'opt_in' :
do_action('wpdeveloper_optin_notice_for_' . $this->plugin_name );
break;
case 'first_install' :
if( $options_data[ $this->plugin_name ]['first_install'] !== 'deactivated' ) {
do_action( 'wpdeveloper_first_install_notice_for_' . $this->plugin_name );
$this->get_thumbnail( 'first_install' );
$this->get_message( 'first_install' );
}
break;
case 'update' :
do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
$this->dismiss_button_scripts();
$this->get_thumbnail( 'update' );
$this->get_message( 'update' );
break;
// case 'update_400k' :
// do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
// $this->dismiss_button_scripts();
// $this->get_thumbnail( 'update_400k' );
// $this->get_message( 'update_400k' );
// break;
case 'review' :
do_action( 'wpdeveloper_review_notice_for_' . $this->plugin_name );
$this->get_thumbnail( 'review' );
$this->get_message( 'review' );
break;
}
}
/**
* Before Upsale Notice
* @return void
*/
public function before_upsale(){
$classes = '';
if( $this->has_thumbnail('upsale') ) {
$classes = 'notice-has-thumbnail';
}
echo '<div class="error notice is-dismissible wpdeveloper-upsale-notice '. $classes .'">';
}
/**
* Upsale Notice
*/
public function upsale_notice(){
do_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name );
do_action('wpdeveloper_upsale_notice_for_' . $this->plugin_name);
$this->get_thumbnail( 'upsale' );
$this->get_message( 'upsale' );
do_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name );
$this->upsale_button_script();
}
/**
* Get upsale arguments.
* @return void
*/
private function get_upsale_args(){
return ( empty( $this->upsale_args ) ) ? array() : $this->upsale_args;
}
/**
* This function is responsible for making the button visible to the upsale notice.
*/
private function upsale_button(){
$upsale_args = $this->get_upsale_args();
$plugin_slug = ( isset( $upsale_args['slug'] )) ? $upsale_args['slug'] : '' ;
$btn_text = ( isset( $upsale_args['btn_text'] )) ? $upsale_args['btn_text'] : __( 'Install Now!', 'essential-addons-for-elementor-lite' ) ;
if( empty( $plugin_slug ) ) {
return;
}
echo '<button data-slug="'. esc_attr( $plugin_slug ) .'" id="plugin-install-core-'. $this->plugin_name .'" class="button button-primary">'. Helper::eael_wp_kses( $btn_text ) .'</button>';
}
/**
* This methods is responsible for get notice image.
*
* @param string $msg_for
* @return void
*/
protected function get_thumbnail( $msg_for ){
$output = '';
if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
$output = '<div class="wpdeveloper-notice-thumbnail">';
$output .= '<img src="'. esc_url( $this->data['thumbnail'][ $msg_for ] ) .'" alt="">';
$output .= '</div>';
}
echo wp_kses_post( $output );
}
/**
* Has Thumbnail Check
*
* @param string $msg_for
* @return boolean
*/
protected function has_thumbnail( $msg_for = '' ){
if( empty( $msg_for ) ) {
return false;
}
if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
return true;
}
return false;
}
/**
* This method is responsible for get messages.
*
* @param string $msg_for
* @return void
*/
protected function get_message( $msg_for ){
if( isset( $this->data['message'] ) && isset( $this->data['message'][ $msg_for ] ) ) {
echo '<div class="wpdeveloper-notice-message">';
echo Helper::eael_wp_kses( $this->data['message'][ $msg_for ] );
if( $msg_for === 'upsale' ) {
$this->upsale_button();
}
$this->dismissible_notice( $msg_for );
echo '</div>';
}
}
/**
* Detect which notice will show @ next.
* @return array
*/
protected function next_notice() {
$options_data = $this->get_options_data();
if ( ! $options_data ) {
$args = $this->get_args();
$return_notice = $args['notice_will_show'];
} else {
$return_notice = $options_data[ $this->plugin_name ]['notice_will_show'];
}
if ( is_array( $return_notice ) ) {
$return_notice = array_flip( $return_notice );
ksort( $return_notice );
}
return (array) $return_notice;
}
/**
* Which notice is deserve to show in next slot.
* @param string $notice
* @return boolean
*/
private function deserve_notice( $notice ) {
$notices = $this->get_user_notices();
if( $notice === false ) {
return false;
}
if( empty( $notices ) ) {
return true;
} else {
if( isset( $notices[ $this->notice_id ] ) && isset( $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
if( in_array( $notice, $notices[ $this->notice_id ][ $this->plugin_name ] ) ) {
return false;
} else {
return true;
}
} else {
return true;
}
}
}
/**
* This is the main methods for generate the notice.
* @return void
*/
public function admin_notices(){
$current_notice = current( $this->next_notice() );
if( get_user_meta( get_current_user_id(), $this->plugin_name . '_' . $current_notice, true ) ) {
return;
}
if( $current_notice == 'opt_in' ) {
do_action( $this->do_notice_action );
return;
}
do_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name );
do_action( $this->do_notice_action );
do_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name );
}
/**
* This method is responsible for all dismissible links generation.
* @param string $links_for
* @return void
*/
public function dismissible_notice( $links_for = '' ){
if( empty( $links_for ) ) {
return;
}
$links = isset( $this->data['links'][ $links_for ] ) ? $this->data['links'][ $links_for ] : false;
if( $links ) :
$output = '<ul class="wpdeveloper-notice-link">';
foreach( $links as $key => $link_value ) {
if( ! empty( $link_value['label'] ) ) {
$output .= '<li>';
if( isset( $link_value['link'] ) ) {
$link = $link_value['link'];
$target = isset( $link_value['target'] ) ? 'target="'. esc_attr( $link_value['target'] ) .'"' : '';
if( isset( $link_value['data_args'] ) && is_array( $link_value['data_args'] ) ) {
$data_args = [];
foreach( $link_value['data_args'] as $key => $args_value ) {
$data_args[ $key ] = $args_value;
}
$data_args[ 'plugin' ] = $this->plugin_name;
$normal_link = add_query_arg( $data_args, $link );
$link = wp_nonce_url( $normal_link, 'wpdeveloper-nonce' );
}
$class = '';
if( isset( $link_value['link_class'] ) ) {
$class = 'class="' . sanitize_html_class( implode( ' ', $link_value['link_class'] ) ) . '"';
}
$output .= '<a '. $class .' href="'. esc_url( $link ) .'" '. $target .'>';
}
if( isset( $link_value['icon_class'] ) ) {
$output .= '<span class="'. esc_attr( $link_value['icon_class'] ) .'"></span>';
}
if( isset( $link_value['icon_img'] ) ) {
$output .= '<img src="'. esc_url( $link_value['icon_img'] ) .'" alt="" />';
}
$output .= $link_value['label'];
if( isset( $link_value['link'] ) ) {
$output .= '</a>';
}
$output .= '</li>';
}
}
$output .= '</ul>';
printf( '%1$s', $output );
endif;
}
/**
* First Installation Track
* @return void
*/
public function first_install_track( $args = array() ){
if( ! current_user_can( 'manage_options' ) ) {
return;
}
if( empty( $args ) ) {
$args = array(
'time' => $this->timestamp,
'version' => $this->version,
);
}
$options_data = $this->get_options_data();
$args = wp_parse_args( $args, $this->get_args() );
if( ! isset( $options_data[ $this->plugin_name ] )
|| ( isset( $options_data[ $this->plugin_name ]['version'] ) && version_compare( $options_data[ $this->plugin_name ]['version'], $this->version, '!=' ) ) ) {
$this->update_options_data( $args );
}
}
/**
* First Installation Deactive Track
*
* @return void
*/
public function first_install_end(){
// $args = array(
// 'first_install' => 'deactivated'
// );
// $options_data = $this->get_options_data();
// if( isset( $options_data[ $this->plugin_name ] ) ) {
// $args = wp_parse_args( $args, $options_data[ $this->plugin_name ] );
// $this->update_options_data( $args );
// }
delete_option( 'wpdeveloper_plugins_data' );
}
/**
* Get all options from database!
* @return void
*/
protected function get_options_data( $key = '' ) {
$options_data = get_option( 'wpdeveloper_plugins_data', [] );
if ( empty( $key ) ) {
return $options_data;
}
if ( isset( $options_data[ $this->plugin_name ][ $key ] ) ) {
return $options_data[ $this->plugin_name ][ $key ];
}
return [];
}
/**
* This will update the options table for plugins.
*
* @param mixed $new_data
* @param array $args
* @return void
*/
protected function update_options_data( $args = array() ){
$options_data = $this->get_options_data();
$options_data[ $this->plugin_name ] = $args;
update_option( 'wpdeveloper_plugins_data', $options_data );
}
/**
* Set properties data, for some selected properties.
*
* @param string $name
* @param mixed $value
*/
public function __set( $name, $value ){
if( in_array( $name, $this->properties ) ) {
$this->data[ $name ] = $value;
}
}
/**
* Invoked when some selected methods are called
*
* @param string $name
* @param array $values
* @return void
*/
public function __call( $name, $values ){
if( in_array( $name, $this->methods ) ) {
$this->data[ $name ][ $values[0] ] = $values[1];
}
}
protected function is_ok( $name, $notice ){
if( isset( $this->data[ $name ], $this->data[ $name ][ $notice ] ) ) {
return true;
}
return false;
}
/**
* Get all option arguments.
* @param string $key
* @return array
*/
private function get_args( $key = '' ){
if( empty( $key ) ) {
return $this->options_args;
}
if( isset( $this->options_args[ $key ] ) ) {
return $this->options_args[ $key ];
}
return false;
}
/**
* Resetting data on update.
* @return void
*/
private function set_args_on_update(){
$args = $this->get_args();
$options_data = $this->get_options_data();
$set_data = $options_data[ $this->plugin_name ];
$args = wp_parse_args( $set_data, $args );
$this->update_options_data( $args );
}
/**
* When upgrade is complete. it will fired.
* @param WP_Upgrader $upgrader_object
* @param array $options
* @return void
*/
public function upgrade_completed( $upgrader_object, $options ) {
// If an update has taken place and the updated type is plugins and the plugins element exists
if( isset( $options['action'] ) && $options['action'] == 'update' && $options['type'] == 'plugin' ) {
if( ! isset( $options['plugin'] ) && isset( $options['plugins'] ) ) {
foreach( $options['plugins'] as $plugin ) {
if( $plugin == $this->plugin_name ) {
$this->set_args_on_update();
}
}
}
if( isset( $options['plugin'] ) && $options['plugin'] == $this->plugin_name ) {
$this->set_args_on_update();
}
}
}
/**
* This function is responsible for get_user_notices
* @return void
*/
private function get_user_notices() {
$notices = get_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, true );
return ! $notices ? array() : $notices;
}
/**
* This function is responsible for update meta information.
*
* @param string $notice
* @return void
*/
private function update( $notice ){
if( empty( $notice ) ) {
return;
}
$options_data = $this->get_options_data();
$user_notices = $this->get_user_notices();
$user_notices[ $this->notice_id ][ $this->plugin_name ][] = $notice;
// Remove the upsale from notice_will_show field in options DB.
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
// Set users meta, not to show again current_version notice.
update_user_meta( get_current_user_id(), self::ADMIN_UPDATE_NOTICE_KEY, $user_notices);
}
public function notice_dissmiss(){
if( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpdeveloper_notice_dissmiss' ) ) {
return;
}
if( ! isset( $_POST['action'] ) || ( $_POST['action'] !== 'wpdeveloper_notice_dissmiss_for_' . $this->plugin_name ) ) {
return;
}
$dismiss = isset( $_POST['dismiss'] ) ? sanitize_text_field( $_POST['dismiss'] ) : false;
$notice = isset( $_POST['notice'] ) ? sanitize_text_field( $_POST['notice'] ) : false;
if( $dismiss ) {
$this->update( $notice );
update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $notice, true );
echo 'success';
} else {
echo 'failed';
}
die();
}
/**
* This function is responsible for do action when
* the dismiss button clicked in upsale notice.
*/
public function upsale_notice_dissmiss(){
if( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wpdeveloper_upsale_notice_dissmiss' ) ) {
return;
}
if( ! isset( $_POST['action'] ) || ( $_POST['action'] !== 'wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name ) ) {
return;
}
$dismiss = isset( $_POST['dismiss'] ) ? sanitize_text_field( $_POST['dismiss'] ) : false;
if( $dismiss ) {
$this->update( 'upsale' );
echo 'success';
} else {
echo 'failed';
}
die();
}
public function dismiss_button_scripts(){
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
var wpdevNotice = $('.notice.is-dismissible');
if( wpdevNotice.length > 0 ) {
$('body').on('click', 'button.notice-dismiss', function (e) {
e.preventDefault();
$.ajax({
url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
type: 'post',
data: {
action: 'wpdeveloper_notice_dissmiss_for_<?php echo esc_html( $this->plugin_name ); ?>',
_wpnonce: '<?php echo wp_create_nonce('wpdeveloper_notice_dissmiss'); ?>',
dismiss: true,
notice: wpdevNotice.data('notice'),
},
success: function(response) {
$('.notice').hide();
console.log('Successfully saved!');
},
error: function(error) {
console.log('Something went wrong!');
},
complete: function() {
console.log('Its Complete.');
}
});
});
}
} );
</script>
<?php
}
/**
* Upsale Button Script.
* When install button is clicked, it will do its own things.
* also for dismiss button JS.
* @return void
*/
public function upsale_button_script(){
$upsale_args = $this->get_upsale_args();
$plugin_slug = ( isset( $upsale_args['slug'] ) ) ? $upsale_args['slug'] : '';
$plugin_file = ( isset( $upsale_args['file'] ) ) ? $upsale_args['file'] : '';
$page_slug = ( isset( $upsale_args['page_slug'] ) ) ? $upsale_args['page_slug'] : '';
?>
<script type="text/javascript">
jQuery(document).ready( function($) {
<?php if( ! empty( $plugin_slug ) && ! empty( $plugin_file ) ) : ?>
$('#plugin-install-core-<?php echo esc_html( $this->plugin_name ); ?>').on('click', function (e) {
var self = $(this);
e.preventDefault();
self.addClass('install-now updating-message');
self.text('<?php echo esc_js( 'Installing...' ); ?>');
$.ajax({
url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
type: 'POST',
data: {
action: 'wpdeveloper_upsale_core_install_<?php echo esc_html( $this->plugin_name ); ?>',
_wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_core_install_' . esc_html( $this->plugin_name )); ?>',
slug : '<?php echo esc_html( $plugin_slug ); ?>',
file : '<?php echo esc_html( $plugin_file ); ?>'
},
success: function(response) {
self.text('<?php echo esc_js( 'Installed' ); ?>');
<?php if( ! empty( $page_slug ) ) : ?>
window.location.href = '<?php echo esc_url( admin_url( "admin.php?page={$page_slug}" ) ); ?>';
<?php endif; ?>
},
error: function(error) {
self.removeClass('install-now updating-message');
},
complete: function() {
self.attr('disabled', 'disabled');
self.removeClass('install-now updating-message');
}
});
});
<?php endif; ?>
$('.wpdeveloper-upsale-notice').on('click', 'button.notice-dismiss', function (e) {
e.preventDefault();
$.ajax({
url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>',
type: 'post',
data: {
action: 'wpdeveloper_upsale_notice_dissmiss_for_<?php echo esc_html( $this->plugin_name ); ?>',
_wpnonce: '<?php echo wp_create_nonce('wpdeveloper_upsale_notice_dissmiss'); ?>',
dismiss: true
},
success: function(response) {
console.log('Successfully saved!');
},
error: function(error) {
console.log('Something went wrong!');
},
complete: function() {
console.log('Its Complete.');
}
});
});
} );
</script>
<?php
}
}

View File

@@ -0,0 +1,228 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly.
use \WP_Error;
class WPDeveloper_Plugin_Installer
{
public function __construct() {
add_action( 'wp_ajax_wpdeveloper_auto_active_even_not_installed', [ $this, 'ajax_auto_active_even_not_installed' ] );
add_action( 'wp_ajax_wpdeveloper_install_plugin', [ $this, 'ajax_install_plugin' ] );
add_action( 'wp_ajax_wpdeveloper_upgrade_plugin', [ $this, 'ajax_upgrade_plugin' ] );
add_action( 'wp_ajax_wpdeveloper_activate_plugin', [ $this, 'ajax_activate_plugin' ] );
add_action( 'wp_ajax_wpdeveloper_deactivate_plugin', [ $this, 'ajax_deactivate_plugin' ] );
}
/**
* get_local_plugin_data
*
* @param mixed $basename
* @return array|false
*/
public function get_local_plugin_data($basename = '')
{
if (empty($basename)) {
return false;
}
if (!function_exists('get_plugins')) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
if (!isset($plugins[$basename])) {
return false;
}
return $plugins[$basename];
}
/**
* get_remote_plugin_data
*
* @param mixed $slug
* @return mixed array|WP_Error
*/
public function get_remote_plugin_data($slug = '')
{
if (empty($slug)) {
return new WP_Error('empty_arg', __('Argument should not be empty.'));
}
$response = wp_remote_post(
'http://api.wordpress.org/plugins/info/1.0/',
[
'body' => [
'action' => 'plugin_information',
'request' => serialize((object) [
'slug' => $slug,
'fields' => [
'version' => false,
],
]),
],
]
);
if (is_wp_error($response)) {
return $response;
}
return unserialize(wp_remote_retrieve_body($response));
}
/**
* install_plugin
*
* @param mixed $slug
* @param bool $active
* @return mixed bool|WP_Error
*/
public function install_plugin($slug = '', $active = true)
{
if (empty($slug)) {
return new WP_Error('empty_arg', __('Argument should not be empty.'));
}
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
$plugin_data = $this->get_remote_plugin_data($slug);
if (is_wp_error($plugin_data)) {
return $plugin_data;
}
$upgrader = new \Plugin_Upgrader(new \Automatic_Upgrader_Skin());
// install plugin
$install = $upgrader->install($plugin_data->download_link);
if (is_wp_error($install)) {
return $install;
}
// activate plugin
if ($install === true && $active) {
$active = activate_plugin($upgrader->plugin_info(), '', false, true);
if (is_wp_error($active)) {
return $active;
}
return $active === null;
}
return $install;
}
/**
* upgrade_plugin
*
* @param mixed $basename
* @return mixed bool|WP_Error
*/
public function upgrade_plugin($basename = '')
{
if (empty($slug)) {
return new WP_Error('empty_arg', __('Argument should not be empty.'));
}
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/class-automatic-upgrader-skin.php';
$upgrader = new \Plugin_Upgrader(new \Automatic_Upgrader_Skin());
// upgrade plugin
return $upgrader->upgrade($basename);
}
public function ajax_install_plugin()
{
check_ajax_referer('essential-addons-elementor', 'security');
if(!current_user_can( 'install_plugins' )) {
wp_send_json_error(__('you are not allowed to do this action', 'essential-addons-for-elementor-lite'));
}
$slug = isset( $_POST['slug'] ) ? sanitize_text_field( $_POST['slug'] ) : '';
$result = $this->install_plugin( $slug );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result->get_error_message() );
}
wp_send_json_success(__('Plugin is installed successfully!', 'essential-addons-for-elementor-lite'));
}
public function ajax_upgrade_plugin()
{
check_ajax_referer('essential-addons-elementor', 'security');
//check user capabilities
if(!current_user_can( 'update_plugins' )) {
wp_send_json_error(__('you are not allowed to do this action', 'essential-addons-for-elementor-lite'));
}
$basename = isset( $_POST['basename'] ) ? sanitize_text_field( $_POST['basename'] ) : '';
$result = $this->upgrade_plugin( $basename );
if (is_wp_error($result)) {
wp_send_json_error($result->get_error_message());
}
wp_send_json_success(__('Plugin is updated successfully!', 'essential-addons-for-elementor-lite'));
}
public function ajax_activate_plugin()
{
check_ajax_referer('essential-addons-elementor', 'security');
//check user capabilities
if(!current_user_can( 'activate_plugins' )) {
wp_send_json_error(__('you are not allowed to do this action', 'essential-addons-for-elementor-lite'));
}
$basename = isset( $_POST['basename'] ) ? sanitize_text_field( $_POST['basename'] ) : '';
$result = activate_plugin( $basename, '', false, true );
if ( is_wp_error( $result ) ) {
wp_send_json_error( $result->get_error_message() );
}
if ($result === false) {
wp_send_json_error(__('Plugin couldn\'t be activated.', 'essential-addons-for-elementor-lite'));
}
wp_send_json_success(__('Plugin is activated successfully!', 'essential-addons-for-elementor-lite'));
}
public function ajax_deactivate_plugin() {
check_ajax_referer( 'essential-addons-elementor', 'security' );
//check user capabilities
if ( ! current_user_can( 'activate_plugins' ) ) {
wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) );
}
$basename = isset( $_POST['basename'] ) ? sanitize_text_field( $_POST['basename'] ) : '';
deactivate_plugins( $basename, true );
wp_send_json_success( __( 'Plugin is deactivated successfully!', 'essential-addons-for-elementor-lite' ) );
}
public function ajax_auto_active_even_not_installed() {
check_ajax_referer( 'essential-addons-elementor', 'security' );
if ( $this->get_local_plugin_data( $_POST['basename'] ) === false ) {
$this->ajax_install_plugin();
} else {
$this->ajax_activate_plugin();
}
}
}

View File

@@ -0,0 +1,807 @@
<?php
namespace Essential_Addons_Elementor\Classes;
if ( !defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly.
class WPDeveloper_Setup_Wizard {
public $templately_status;
public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'setup_wizard_scripts' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'wp_ajax_save_setup_wizard_data', [ $this, 'save_setup_wizard_data' ] );
add_action( 'wp_ajax_enable_wpins_process', [ $this, 'enable_wpins_process' ] );
add_action( 'wp_ajax_save_eael_elements_data', [ $this, 'save_eael_elements_data' ] );
add_action( 'in_admin_header', [ $this, 'remove_notice' ], 1000 );
$this->templately_status = $this->templately_active_status();
}
/**
* templately_active_status
* @return bool
*/
public function templately_active_status() {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
return is_plugin_active( 'templately/templately.php' );
}
/**
* Remove all notice in setup wizard page
*/
public function remove_notice() {
if ( isset( $_GET[ 'page' ] ) && $_GET[ 'page' ] == 'eael-setup-wizard' ) {
remove_all_actions( 'admin_notices' );
remove_all_actions( 'all_admin_notices' );
}
}
/**
* setup_wizard_scripts
* @param $hook
* @return array
*/
public function setup_wizard_scripts( $hook ) {
if ( isset( $hook ) && $hook == 'admin_page_eael-setup-wizard' ) {
wp_enqueue_style( 'essential_addons_elementor-setup-wizard-css', EAEL_PLUGIN_URL . 'assets/admin/css/quick-setup.css', false, EAEL_PLUGIN_VERSION );
wp_enqueue_style( 'essential_addons_elementor-setup-wizard-fonts', EAEL_PLUGIN_URL . 'includes/templates/admin/icons/style.css', false, EAEL_PLUGIN_VERSION );
wp_enqueue_style( 'sweetalert2-css', EAEL_PLUGIN_URL . 'assets/admin/vendor/sweetalert2/css/sweetalert2.min.css', false, EAEL_PLUGIN_VERSION );
wp_enqueue_script( 'sweetalert2-js', EAEL_PLUGIN_URL . 'assets/admin/vendor/sweetalert2/js/sweetalert2.min.js', array( 'jquery', 'sweetalert2-core-js' ), EAEL_PLUGIN_VERSION, true );
wp_enqueue_script( 'sweetalert2-core-js', EAEL_PLUGIN_URL . 'assets/admin/vendor/sweetalert2/js/core.js', array( 'jquery' ), EAEL_PLUGIN_VERSION, true );
// wp_enqueue_script( 'essential_addons_elementor-setup-wizard-js', EAEL_PLUGIN_URL . 'assets/admin/js/admin.js', array( 'jquery' ), EAEL_PLUGIN_VERSION, true );
// wp_enqueue_script( 'essential_addons_elementor-setup-wizard-react-css', EAEL_PLUGIN_URL . 'includes/templates/admin/quick-setup/dist/quick-setup.min.css', array(), EAEL_PLUGIN_VERSION, true );
wp_enqueue_script( 'essential_addons_elementor-setup-wizard-react-js', EAEL_PLUGIN_URL . 'includes/templates/admin/quick-setup/dist/quick-setup.min.js', array(), EAEL_PLUGIN_VERSION, true );
wp_localize_script( 'essential_addons_elementor-setup-wizard-react-js', 'localize', array(
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
'nonce' => wp_create_nonce( 'essential-addons-elementor' ),
'success_image' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/success.gif',
'eael_quick_setup_data' => $this->eael_quick_setup_data(),
) );
}
return [];
}
/**
* Create admin menu for setup wizard
*/
public function admin_menu() {
add_submenu_page(
'',
__( 'Essential Addons ', 'essential-addons-for-elementor-lite' ),
__( 'Essential Addons ', 'essential-addons-for-elementor-lite' ),
'manage_options',
'eael-setup-wizard',
[ $this, 'render_wizard' ]
);
}
/**
* render_wizard
*/
public function render_wizard() {
?>
<section id="eael-onboard--wrapper" class="eael-onboard--wrapper">
</section>
<?php
}
public function eael_quick_setup_data() {
$eael_quick_setup_data = [
'is_quick_setup' => 1,
'menu_items' => $this->data_menu_items(),
'getting_started_content' => $this->data_getting_started_content(),
'configuration_content' => $this->data_configuration_content(),
'elements_content' => $this->data_elements_content(),
'go_pro_content' => $this->data_go_pro_content(),
'templately_content' => $this->data_templately_content(),
'integrations_content' => $this->data_integrations_content(),
'modal_content' => $this->data_modal_content(),
];
return $eael_quick_setup_data;
}
public function data_menu_items(){
$items = [
__( 'Getting Started', 'essential-addons-for-elementor-lite' ),
__( 'Configuration', 'essential-addons-for-elementor-lite' ),
__( 'Elements', 'essential-addons-for-elementor-lite' ),
__( 'Go PRO', 'essential-addons-for-elementor-lite' ),
__( 'Templately', 'essential-addons-for-elementor-lite' ),
__( 'Integrations', 'essential-addons-for-elementor-lite' ),
];
$menu_items = [
'templately_status' => $this->templately_status,
'wizard_column' => !$this->templately_status ? 'five' : 'four',
'items' => $items,
'templately_local_plugin_data' => $this->get_local_plugin_data( 'templately/templately.php' ),
'ea_pro_local_plugin_data' => $this->get_local_plugin_data( 'essential-addons-elementor/essential_adons_elementor.php' ),
];
return $menu_items;
}
public function data_getting_started_content(){
$getting_started_content = [
'youtube_promo_src' => esc_url( EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/youtube-promo.png' ),
'is_tracking_allowed' => $this->get_is_tracking_allowed(),
];
return $getting_started_content;
}
public function data_configuration_content(){
$configuration_content = [
'ea_logo_src' => esc_url( EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/ea-new.png' ),
];
return $configuration_content;
}
public function data_elements_content(){
$elements_content = [
'elements_list' => $this->get_element_list(),
];
return $elements_content;
}
public function data_go_pro_content(){
$feature_items = [
[
'title' => 'Smart Post List',
'link' => 'https://essential-addons.com/post-list/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/smart-post-list.svg',
],
[
'title' => 'Dynamic Gallery',
'link' => 'https://essential-addons.com/dynamic-gallery/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/dynamic-gallery.svg',
],
[
'title' => 'Custom JS',
'link' => 'https://essential-addons.com/custom-js/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/custom-js.svg',
],
[
'title' => 'Protected Content',
'link' => 'https://essential-addons.com/protected-content/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/protected-content.svg',
],
[
'title' => 'Interactive Animations',
'link' => 'https://essential-addons.com/interactive-animations/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/lightbox-modal.svg',
],
[
'title' => 'Advanced Google Map',
'link' => 'https://essential-addons.com/advanced-google-map/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/advanced-google-map.svg',
],
[
'title' => 'Mailchimp',
'link' => 'https://essential-addons.com/mailchimp/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/mailchimp.svg',
],
[
'title' => 'Instagram Feed',
'link' => 'https://essential-addons.com/instagram-feed/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/instagram-feed.svg',
],
[
'title' => 'Woo Product Slider',
'link' => 'https://essential-addons.com/woo-product-slider/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/woo-product-slider.svg',
],
[
'title' => 'Parallax',
'link' => 'https://essential-addons.com/parallax-scrolling/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/parallax-scrolling.svg',
],
[
'title' => 'Post Carousel',
'link' => 'https://essential-addons.com/post-carousel/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/post-carousel.svg',
],
[
'title' => 'LearnDash Course List',
'link' => 'https://essential-addons.com/learndash-course-list/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/learndash-course-list.svg',
],
[
'title' => 'Particle Effect',
'link' => 'https://essential-addons.com/particle-effect/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/particle-effect.svg',
],
[
'title' => 'Logo Carousel',
'link' => 'https://essential-addons.com/logo-carousel/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/logo-carousel.svg',
],
[
'title' => 'Image Hotspots',
'link' => 'https://essential-addons.com/image-hotspots/',
'img_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/image-hotspots.svg',
]
];
$go_pro_content = [
'feature_items' => $feature_items,
];
return $go_pro_content;
}
public function data_templately_content(){
$templately_content = [
'templately_icon_1_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/templately-icon-1.svg',
'templately_icon_2_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/templately-icon-2.svg',
'templately_icon_3_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/templately-icon-3.svg',
'templately_icon_4_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/templately-icon-4.svg',
'templately_promo_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/templately-qs-img.png'
];
return $templately_content;
}
public function data_integrations_content(){
$integrations_content = [
'plugin_list' => $this->get_plugin_list(),
];
return $integrations_content;
}
public function data_modal_content(){
$modal_content = [
'success_2_src' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/success-2.png',
];
return $modal_content;
}
/**
* get_plugin_list
* @return array
*/
public function get_plugin_list() {
return [
[
'slug' => 'betterdocs',
'basename' => 'betterdocs/betterdocs.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/bd-new.svg',
'title' => __( 'BetterDocs', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Create and organize your knowledge base, FAQ & documentation page efficiently, making it easy for visitors to find any helpful article quickly and effortlessly.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'betterdocs/betterdocs.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'betterdocs/betterdocs.php' ),
],
[
'slug' => 'betterlinks',
'basename' => 'betterlinks/betterlinks.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/btl.svg',
'title' => __( 'BetterLinks', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Link Shortening tool to create, shorten & manage any URL. It helps to cross promote brands & products and gather analytics reports while running marketing campaigns.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'betterlinks/betterlinks.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'betterlinks/betterlinks.php' ),
],
[
'slug' => 'better-payment',
'basename' => 'better-payment/better-payment.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/bp.svg',
'title' => __( 'Better Payment', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Streamline transactions in Elementor by integrating PayPal & Stripe. Experience advanced analytics, validation, and Elementor forms for secure & efficient payments.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'better-payment/better-payment.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'better-payment/better-payment.php' ),
],
[
'slug' => 'notificationx',
'basename' => 'notificationx/notificationx.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/nx-logo.svg',
'title' => __( 'NotificationX', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Best FOMO & social proof plugin to boost sales conversion by creating stunning sales popups, growth & discount alerts, flashing tabs, notification bars & more.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'notificationx/notificationx.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'notificationx/notificationx.php' ),
],
[
'slug' => 'wp-scheduled-posts',
'basename' => 'wp-scheduled-posts/wp-scheduled-posts.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/wscp.svg',
'title' => __( 'SchedulePress', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Advanced content marketing tool for WordPress to schedule posts & pages with Schedule Calendar, Auto & Manual Scheduler, etc. It also allows auto-social sharing.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'wp-scheduled-posts/wp-scheduled-posts.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'wp-scheduled-posts/wp-scheduled-posts.php' ),
],
[
'slug' => 'easyjobs',
'basename' => 'easyjobs/easyjobs.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/easy-jobs-logo.svg',
'title' => __( 'easy.jobs', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Job recruitment tool to attract, manage, and hire the right talent faster. This talent recruitment solution lets you manage jobs and career pages in Elementor.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'easyjobs/easyjobs.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'easyjobs/easyjobs.php' ),
],
[
'slug' => 'embedpress',
'basename' => 'embedpress/embedpress.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/ep-logo.png',
'title' => __( 'EmbedPress', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Embed videos, images, gifs, charts, docs, maps, audio, live streams, pdf & more from 150+ sources into your WordPress site and get seamless customization options.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'embedpress/embedpress.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'embedpress/embedpress.php' ),
],
[
'slug' => 'essential-blocks',
'basename' => 'essential-blocks/essential-blocks.php',
'logo' => EAEL_PLUGIN_URL . 'assets/admin/images/quick-setup/eb-new.svg',
'title' => __( 'Essential Blocks', 'essential-addons-for-elementor-lite' ),
'desc' => __( 'Enhance Gutenberg experience with 50+ unique blocks (more coming soon). Boost your block editor with easy-to-use blocks for a simpler WordPress page or post design.', 'essential-addons-for-elementor-lite' ),
'is_active' => is_plugin_active( 'essential-blocks/essential-blocks.php' ),
'local_plugin_data' => $this->get_local_plugin_data( 'essential-blocks/essential-blocks.php' ),
],
];
}
/**
* get_local_plugin_data
*
* @param mixed $basename
* @return array|false
*/
public function get_local_plugin_data( $basename = '' ) {
if ( empty( $basename ) ) {
return false;
}
if ( !function_exists( 'get_plugins' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
$plugins = get_plugins();
if ( !isset( $plugins[ $basename ] ) ) {
return false;
}
return $plugins[ $basename ];
}
/**
* Save setup wizard data
*/
public function save_setup_wizard_data() {
check_ajax_referer( 'essential-addons-elementor', 'security' );
if ( !current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) );
}
if ( !isset( $_POST[ 'fields' ] ) ) {
return;
}
wp_parse_str( $_POST[ 'fields' ], $fields );
if ( isset( $fields[ 'eael_user_email_address' ] ) && intval( $fields[ 'eael_user_email_address' ] ) == 1 ) {
$this->wpins_process();
}
update_option( 'eael_setup_wizard', 'complete' );
if ( $this->save_element_list( $fields ) ) {
wp_send_json_success( [ 'redirect_url' => esc_url( admin_url( 'admin.php?page=eael-settings' ) ) ] );
}
wp_send_json_error();
}
public function enable_wpins_process() {
check_ajax_referer( 'essential-addons-elementor', 'security' );
if ( !current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) );
}
if ( !isset( $_POST[ 'fields' ] ) ) {
return;
}
wp_parse_str( $_POST[ 'fields' ], $fields );
$this->wpins_process();
wp_send_json_success();
}
/**
* save_eael_elements_data
*/
public function save_eael_elements_data() {
check_ajax_referer( 'essential-addons-elementor', 'security' );
if ( !current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'you are not allowed to do this action', 'essential-addons-for-elementor-lite' ) );
}
if ( !isset( $_POST[ 'fields' ] ) ) {
return;
}
wp_parse_str( $_POST[ 'fields' ], $fields );
if ( $this->save_element_list( $fields ) ) {
wp_send_json_success();
}
wp_send_json_error();
}
/**
* save_element_list
* @param $fields
* @return bool
*/
public function save_element_list( $fields ) {
if ( !empty( $fields ) ) {
$el_list = $fields[ 'eael_element' ];
$save_element = [];
foreach ( $GLOBALS[ 'eael_config' ][ 'elements' ] as $key => $item ) {
$save_element[ $key ] = ( isset( $el_list[ $key ] ) ) ? 1 : '';
}
$save_element = array_merge( $save_element, $this->get_dummy_widget() );
update_option( 'eael_save_settings', $save_element );
return true;
}
return false;
}
/**
* get_element_list
* @return array[]
*/
public function get_element_list() {
return [
'content-elements' => [
'title' => __( 'Content Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'creative-btn',
'title' => __( 'Creative Button', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'team-members',
'title' => __( 'Team Member', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'testimonials',
'title' => __( 'Testimonial', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'flip-box',
'title' => __( 'Flip Box', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'info-box',
'title' => __( 'Info Box', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'dual-header',
'title' => __( 'Dual Color Heading', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'tooltip',
'title' => __( 'Tooltip', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'adv-accordion',
'title' => __( 'Advanced Accordion', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'adv-tabs',
'title' => __( 'Advanced Tabs', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'feature-list',
'title' => __( 'Feature List', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'sticky-video',
'title' => __( 'Sticky Video', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'event-calendar',
'title' => __( 'Event Calendar', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'simple-menu',
'title' => __( 'Simple Menu', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
]
],
'dynamic-content-elements' => [
'title' => __( 'Dynamic Content Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'post-grid',
'title' => __( 'Post Grid', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'post-timeline',
'title' => __( 'Post Timeline', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'data-table',
'title' => __( 'Data Table', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'advanced-data-table',
'title' => __( 'Advanced Data Table', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'content-ticker',
'title' => __( 'Content Ticker', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'nft-gallery',
'title' => __( 'NFT Gallery', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'business-reviews',
'title' => __( 'Business Reviews', 'essential-addons-for-elementor-lite' ),
],
]
],
'creative-elements' => [
'title' => __( 'Creative Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'count-down',
'title' => __( 'Countdown', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'fancy-text',
'title' => __( 'Fancy Text', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'filter-gallery',
'title' => __( 'Filterable Gallery', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'image-accordion',
'title' => __( 'Image Accordion', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'progress-bar',
'title' => __( 'Progress Bar', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'interactive-circle',
'title' => __( 'Interactive Circle', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'svg-draw',
'title' => __( 'SVG Draw', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'fancy-chart',
'title' => __( 'Fancy Chart', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
]
],
'marketing-elements' => [
'title' => __( 'Marketing & Social Feed Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'call-to-action',
'title' => __( 'Call To Action', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'price-table',
'title' => __( 'Pricing Table', 'essential-addons-for-elementor-lite' ),
'preferences' => 'basic',
],
[
'key' => 'twitter-feed',
'title' => __( 'Twitter Feed', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'facebook-feed',
'title' => __( 'Facebook Feed', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
]
],
'form-styler-elements' => [
'title' => __( 'Form Styler Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'contact-form-7',
'title' => __( 'Contact Form 7', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'weforms',
'title' => __( 'weForms', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'ninja-form',
'title' => __( 'Ninja Form', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'gravity-form',
'title' => __( 'Gravity Form', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'caldera-form',
'title' => __( 'Caldera Form', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'wpforms',
'title' => __( 'WPForms', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'fluentform',
'title' => __( 'Fluent Forms', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'formstack',
'title' => __( 'Formstack', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'typeform',
'title' => __( 'Typeform', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'login-register',
'title' => __( 'Login Register Form', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
]
],
'documentation-elements' => [
'title' => __( 'Documentation Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'betterdocs-category-grid',
'title' => __( 'BetterDocs Category Grid', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'betterdocs-category-box',
'title' => __( 'BetterDocs Category Box', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'betterdocs-search-form',
'title' => __( 'BetterDocs Search Form', 'essential-addons-for-elementor-lite' ),
]
]
],
'woocommerce-elements' => [
'title' => __( 'WooCommerce Elements', 'essential-addons-for-elementor-lite' ),
'elements' => [
[
'key' => 'product-grid',
'title' => __( 'Woo Product Grid', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'woo-product-list',
'title' => __( 'Woo Product List', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'woo-product-carousel',
'title' => __( 'Woo Product Carousel', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'woo-checkout',
'title' => __( 'Woo Checkout', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'woo-cart',
'title' => __( 'Woo Cart', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'woo-cross-sells',
'title' => __( 'Woo Cross Sells', 'essential-addons-for-elementor-lite' ),
],
[
'key' => 'woo-product-compare',
'title' => __( 'Woo Product Compare', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
],
[
'key' => 'woo-product-gallery',
'title' => __( 'Woo Product Gallery', 'essential-addons-for-elementor-lite' ),
'preferences' => 'advance',
]
]
]
];
}
public static function redirect() {
update_option( 'eael_setup_wizard', 'init' );
wp_redirect( admin_url( 'admin.php?page=eael-setup-wizard' ) );
}
public function change_site_title() {
?>
<script>
document.title = "<?php _e( 'Quick Setup Wizard- Essential Addons', 'essential-addons-for-elementor-lite' ); ?>"
</script>
<?php
}
public function wpins_process() {
$plugin_name = basename( EAEL_PLUGIN_FILE, '.php' );
if ( class_exists( '\Essential_Addons_Elementor\Classes\Plugin_Usage_Tracker' ) ) {
$tracker = \Essential_Addons_Elementor\Classes\Plugin_Usage_Tracker::get_instance( EAEL_PLUGIN_FILE, [
'opt_in' => true,
'goodbye_form' => true,
'item_id' => '760e8569757fa16992d8'
] );
$tracker->set_is_tracking_allowed( true );
$tracker->do_tracking( true );
}
}
public function get_is_tracking_allowed( $plugin = 'essential_adons_elementor' ){
/**
* Get All Tracked Plugin List using this Tracker.
*/
$allow_tracking = get_option( 'wpins_allow_tracking' );
/**
* Check user is opted out for tracking or not.
*/
return intval( isset( $allow_tracking[$plugin] ) );
}
public function get_dummy_widget() {
return [
'embedpress' => 1,
'woocommerce-review' => 1,
'career-page' => 1,
'crowdfundly-single-campaign' => 1,
'crowdfundly-organization' => 1,
'crowdfundly-all-campaign' => 1,
'better-payment' => 1,
];
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden