Add initial files and structure for Essential Addons for Elementor Lite plugin
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
<?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'));
|
||||
|
||||
// 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 ( 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'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,386 @@
|
||||
<?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';
|
||||
}
|
||||
|
||||
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',
|
||||
];
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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' );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,982 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin_Usage_Tracker
|
||||
* This class is responsible for data sending to insights.
|
||||
* @version 3.0.0
|
||||
*/
|
||||
namespace Essential_Addons_Elementor\Classes;
|
||||
/**
|
||||
* Exit if accessed directly
|
||||
*/
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main SDK for Plugin_Usage_Tracker.
|
||||
*/
|
||||
class Plugin_Usage_Tracker {
|
||||
/**
|
||||
* WP Insights Version
|
||||
*/
|
||||
const WPINS_VERSION = '3.0.3';
|
||||
/**
|
||||
* API URL
|
||||
*/
|
||||
const API_URL = 'https://send.wpinsight.com/process-plugin-data';
|
||||
/**
|
||||
* Installed Plugin File
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_file = null;
|
||||
/**
|
||||
* Installed Plugin Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_name = null;
|
||||
/**
|
||||
* How often the event should subsequently
|
||||
* @var string
|
||||
*/
|
||||
public $recurrence = 'daily';
|
||||
private $event_hook = null;
|
||||
/**
|
||||
* Instace of Plugin_Usage_Tracker
|
||||
* @var Plugin_Usage_Tracker
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
private $disabled_wp_cron;
|
||||
private $enable_self_cron;
|
||||
private $require_optin;
|
||||
private $include_goodbye_form;
|
||||
private $marketing;
|
||||
private $options;
|
||||
private $item_id;
|
||||
private $notice_options;
|
||||
|
||||
/**
|
||||
* Get Instance of Plugin_Usage_Tracker
|
||||
* @return Plugin_Usage_Tracker
|
||||
*/
|
||||
public static function get_instance( $plugin_file, $args = [] ){
|
||||
if( is_null( static::$_instance ) ) {
|
||||
static::$_instance = new static( $plugin_file, $args );
|
||||
}
|
||||
return static::$_instance;
|
||||
}
|
||||
/**
|
||||
* Automatically Invoked when initialized.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
public function __construct( $plugin_file, $args = [] ){
|
||||
$this->plugin_file = $plugin_file;
|
||||
$this->plugin_name = basename( $this->plugin_file, '.php' );
|
||||
$this->disabled_wp_cron = defined('DISABLE_WP_CRON') && DISABLE_WP_CRON == true;
|
||||
$this->enable_self_cron = $this->disabled_wp_cron == true ? true : false;
|
||||
|
||||
$this->event_hook = 'put_do_weekly_action';
|
||||
|
||||
$this->require_optin = isset( $args['opt_in'] ) ? $args['opt_in'] : true;
|
||||
$this->include_goodbye_form = isset( $args['goodbye_form'] ) ? $args['goodbye_form'] : true;
|
||||
$this->marketing = isset( $args['email_marketing'] ) ? $args['email_marketing'] : true;
|
||||
$this->options = isset( $args['options'] ) ? $args['options'] : [];
|
||||
$this->item_id = isset( $args['item_id'] ) ? $args['item_id'] : false;
|
||||
/**
|
||||
* Activation Hook
|
||||
*/
|
||||
register_activation_hook( $this->plugin_file, array( $this, 'activate_this_plugin' ) );
|
||||
/**
|
||||
* Deactivation Hook
|
||||
*/
|
||||
register_deactivation_hook( $this->plugin_file, array( $this, 'deactivate_this_plugin' ) );
|
||||
}
|
||||
/**
|
||||
* When user agreed to opt-in tracking schedule is enabled.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function schedule_tracking() {
|
||||
if( $this->disabled_wp_cron ) {
|
||||
return;
|
||||
}
|
||||
if ( ! wp_next_scheduled( $this->event_hook ) ) {
|
||||
wp_schedule_event( time(), $this->recurrence, $this->event_hook );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add the schedule event if the plugin is tracked.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function activate_this_plugin(){
|
||||
$allow_tracking = $this->is_tracking_allowed();
|
||||
if( ! $allow_tracking ) {
|
||||
return;
|
||||
}
|
||||
$this->schedule_tracking();
|
||||
}
|
||||
/**
|
||||
* Remove the schedule event when plugin is deactivated and send the deactivated reason to inishghts if user submitted.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function deactivate_this_plugin() {
|
||||
/**
|
||||
* Check tracking is allowed or not.
|
||||
*/
|
||||
$allow_tracking = $this->is_tracking_allowed();
|
||||
if( ! $allow_tracking ) {
|
||||
return;
|
||||
}
|
||||
$body = $this->get_data();
|
||||
$body['status'] = 'Deactivated';
|
||||
$body['deactivated_date'] = time();
|
||||
|
||||
// Check deactivation reason and add for insights data.
|
||||
if( false !== get_option( 'wpins_deactivation_reason_' . $this->plugin_name ) ) {
|
||||
$body['deactivation_reason'] = get_option( 'wpins_deactivation_reason_' . $this->plugin_name );
|
||||
}
|
||||
if( false !== get_option( 'wpins_deactivation_details_' . $this->plugin_name ) ) {
|
||||
$body['deactivation_details'] = get_option( 'wpins_deactivation_details_' . $this->plugin_name );
|
||||
}
|
||||
|
||||
$this->send_data( $body );
|
||||
delete_option( 'wpins_deactivation_reason_' . $this->plugin_name );
|
||||
delete_option( 'wpins_deactivation_details_' . $this->plugin_name );
|
||||
/**
|
||||
* Clear the event schedule.
|
||||
*/
|
||||
if( ! $this->disabled_wp_cron ) {
|
||||
wp_clear_scheduled_hook( $this->event_hook );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Initial Method to Hook Everything.
|
||||
* @return void
|
||||
*/
|
||||
public function init(){
|
||||
// $this->clicked();
|
||||
add_action('wpdeveloper_notice_clicked_for_' . $this->plugin_name, array($this, 'clicked'));
|
||||
add_action( $this->event_hook, array( $this, 'do_tracking' ) );
|
||||
// For Test
|
||||
// add_action( 'admin_init', array( $this, 'force_tracking' ) );
|
||||
// add_action( 'admin_notices', array( $this, 'notice' ) );
|
||||
add_action('wpdeveloper_optin_notice_for_' . $this->plugin_name, array($this, 'notice'));
|
||||
/**
|
||||
* Deactivation Reason Form and Submit Data to Insights.
|
||||
*/
|
||||
add_filter( 'plugin_action_links_' . plugin_basename( $this->plugin_file ), array( $this, 'deactivate_action_links' ) );
|
||||
add_action( 'admin_footer-plugins.php', array( $this, 'deactivate_reasons_form' ) );
|
||||
add_action( 'wp_ajax_deactivation_form_' . esc_attr( $this->plugin_name ), array( $this, 'deactivate_reasons_form_submit' ) );
|
||||
}
|
||||
/**
|
||||
* 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 );
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* This method forcing the do_tracking method to execute instant.
|
||||
* @return void
|
||||
*/
|
||||
public function force_tracking(){
|
||||
$this->do_tracking( true );
|
||||
}
|
||||
/**
|
||||
* This method is responsible for all the magic from the front of the plugin.
|
||||
* @since 3.0.0
|
||||
* @param $force Force tracking if it's not the correct time to track/
|
||||
*/
|
||||
public function do_tracking( $force = false ) {
|
||||
/**
|
||||
* Check URL is set or not.
|
||||
*/
|
||||
if ( empty( self::API_URL ) ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check is tracking allowed or not.
|
||||
*/
|
||||
if( ! $this->is_tracking_allowed() ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check is this the correct time to track or not.
|
||||
* or Force to track.
|
||||
*/
|
||||
if( ! $this->is_time_to_track() && ! $force ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Get All Data.
|
||||
*/
|
||||
$body = $this->get_data();
|
||||
/**
|
||||
* Send all data.
|
||||
*/
|
||||
return $this->send_data( $body );
|
||||
}
|
||||
/**
|
||||
* Is tracking allowed?
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function is_tracking_allowed() {
|
||||
// First, check if the user has changed their mind and opted out of tracking
|
||||
if( $this->has_user_opted_out() ) {
|
||||
$this->set_is_tracking_allowed( false, $this->plugin_name );
|
||||
return false;
|
||||
}
|
||||
// The wpins_allow_tracking option is an array of plugins that are being tracked
|
||||
$allow_tracking = get_option( 'wpins_allow_tracking' );
|
||||
// If this plugin is in the array, then tracking is allowed
|
||||
if( isset( $allow_tracking[$this->plugin_name] ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Set a flag in DB If tracking is allowed.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param $is_allowed Boolean true if is allowed.
|
||||
*/
|
||||
public function set_is_tracking_allowed( $is_allowed, $plugin = null ) {
|
||||
if( empty( $plugin ) ) {
|
||||
$plugin = $this->plugin_name;
|
||||
}
|
||||
/**
|
||||
* Get All Tracked Plugin List using this Tracker.
|
||||
*/
|
||||
$allow_tracking = get_option( 'wpins_allow_tracking' );
|
||||
/**
|
||||
* Check user is opted out for tracking or not.
|
||||
*/
|
||||
if( $this->has_user_opted_out() ) {
|
||||
if( isset( $allow_tracking[$plugin] ) ) {
|
||||
unset( $allow_tracking[$plugin] );
|
||||
}
|
||||
} else if( $is_allowed || ! $this->require_optin ) {
|
||||
/**
|
||||
* If user has agreed to allow tracking
|
||||
*/
|
||||
if( empty( $allow_tracking ) || ! is_array( $allow_tracking ) ) {
|
||||
$allow_tracking = array( $plugin => $plugin );
|
||||
} else {
|
||||
$allow_tracking[$plugin] = $plugin;
|
||||
}
|
||||
} else {
|
||||
if( isset( $allow_tracking[$plugin] ) ) {
|
||||
unset( $allow_tracking[$plugin] );
|
||||
}
|
||||
}
|
||||
update_option( 'wpins_allow_tracking', $allow_tracking );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the user has opted out or not.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @return Boolean
|
||||
*/
|
||||
protected function has_user_opted_out() {
|
||||
if( ! empty( $this->options ) ) {
|
||||
foreach( $this->options as $option_name ) {
|
||||
$options = get_option( $option_name );
|
||||
if( ! empty( $options['wpins_opt_out'] ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check if it's time to track
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function is_time_to_track() {
|
||||
$track_times = get_option( 'wpins_last_track_time', array() );
|
||||
return ! isset( $track_times[$this->plugin_name] ) ? true :
|
||||
( ( isset( $track_times[$this->plugin_name] ) && $track_times[$this->plugin_name] ) < strtotime( '-1 day' ) ? true : false );
|
||||
}
|
||||
/**
|
||||
* Set tracking time.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function set_track_time() {
|
||||
$track_times = get_option( 'wpins_last_track_time', array() );
|
||||
$track_times[ $this->plugin_name ] = time();
|
||||
update_option( 'wpins_last_track_time', $track_times );
|
||||
}
|
||||
/**
|
||||
* This method is responsible for collecting all data.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function get_data() {
|
||||
$body = array(
|
||||
'plugin_slug' => sanitize_text_field( $this->plugin_name ),
|
||||
'url' => get_bloginfo( 'url' ),
|
||||
'site_name' => get_bloginfo( 'name' ),
|
||||
'site_version' => get_bloginfo( 'version' ),
|
||||
'site_language' => get_bloginfo( 'language' ),
|
||||
'charset' => get_bloginfo( 'charset' ),
|
||||
'wpins_version' => self::WPINS_VERSION,
|
||||
'php_version' => phpversion(),
|
||||
'multisite' => is_multisite(),
|
||||
'file_location' => __FILE__
|
||||
);
|
||||
|
||||
// Collect the email if the correct option has been set
|
||||
if( $this->marketing ) {
|
||||
if( ! function_exists( 'wp_get_current_user' ) ) {
|
||||
include ABSPATH . 'wp-includes/pluggable.php';
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
$email = $current_user->user_email;
|
||||
if( is_email( $email ) ) {
|
||||
$body['email'] = $email;
|
||||
} else {
|
||||
$email = get_option( 'admin_email' );
|
||||
if( is_email($email) ) {
|
||||
$body['email'] = $email;
|
||||
}
|
||||
}
|
||||
}
|
||||
$body['marketing_method'] = $this->marketing;
|
||||
$body['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
|
||||
|
||||
/**
|
||||
* Collect all active and inactive plugins
|
||||
*/
|
||||
if( ! function_exists( 'get_plugins' ) ) {
|
||||
include ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
}
|
||||
$plugins = array_keys( get_plugins() );
|
||||
$active_plugins = is_network_admin() ? array_keys( get_site_option( 'active_sitewide_plugins', array() ) ) : get_option( 'active_plugins', array() );
|
||||
foreach ( $plugins as $key => $plugin ) {
|
||||
if ( in_array( $plugin, $active_plugins ) ) {
|
||||
unset( $plugins[$key] );
|
||||
}
|
||||
}
|
||||
$body['active_plugins'] = $active_plugins;
|
||||
$body['inactive_plugins'] = $plugins;
|
||||
|
||||
/**
|
||||
* Text Direction.
|
||||
*/
|
||||
$body['text_direction'] = ( function_exists( 'is_rtl' ) ? ( is_rtl() ? 'RTL' : 'LTR' ) : 'NOT SET' );
|
||||
/**
|
||||
* Get Our Plugin Data.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$plugin = $this->plugin_data();
|
||||
if( empty( $plugin ) ) {
|
||||
$body['message'] .= __( 'We can\'t detect any plugin information. This is most probably because you have not included the code in the plugin main file.', 'disable-comments' );
|
||||
$body['status'] = 'NOT FOUND';
|
||||
} else {
|
||||
if( isset( $plugin['Name'] ) ) {
|
||||
$body['plugin'] = sanitize_text_field( $plugin['Name'] );
|
||||
}
|
||||
if( isset( $plugin['Version'] ) ) {
|
||||
$body['version'] = sanitize_text_field( $plugin['Version'] );
|
||||
}
|
||||
$body['status'] = 'Active';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active theme name and version
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$theme = wp_get_theme();
|
||||
if( $theme->Name ) {
|
||||
$body['theme'] = sanitize_text_field( $theme->Name );
|
||||
}
|
||||
if( $theme->Version ) {
|
||||
$body['theme_version'] = sanitize_text_field( $theme->Version );
|
||||
}
|
||||
|
||||
if ( ! empty( $this->get_used_elements_count() ) ) {
|
||||
$body['optional_data'] = $this->get_used_elements_count();
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect plugin data,
|
||||
* Retrieve current plugin information
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function plugin_data() {
|
||||
if( ! function_exists( 'get_plugin_data' ) ) {
|
||||
include ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
}
|
||||
$plugin = get_plugin_data( $this->plugin_file );
|
||||
return $plugin;
|
||||
}
|
||||
/**
|
||||
* Send the data to insights.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function send_data( $body ) {
|
||||
/**
|
||||
* Get SITE ID
|
||||
*/
|
||||
$site_id_key = "wpins_{$this->plugin_name}_site_id";
|
||||
$site_id = get_option( $site_id_key, false );
|
||||
$failed_data = [];
|
||||
$site_url = get_bloginfo( 'url' );
|
||||
$original_site_url = get_option( "wpins_{$this->plugin_name}_original_url", false );
|
||||
|
||||
if( ( $original_site_url === false || $original_site_url != $site_url ) && version_compare( $body['wpins_version'], '3.0.1', '>=' ) ) {
|
||||
$site_id = false;
|
||||
}
|
||||
/**
|
||||
* Send Initial Data to API
|
||||
*/
|
||||
if( $site_id == false && $this->item_id !== false ) {
|
||||
if( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] && $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ) ) {
|
||||
$country_request = wp_remote_get( 'http://ip-api.com/json/'. $_SERVER['REMOTE_ADDR'] .'?fields=country');
|
||||
if( ! is_wp_error( $country_request ) && $country_request['response']['code'] == 200 ) {
|
||||
$ip_data = json_decode( $country_request["body"] );
|
||||
$body['country'] = isset( $ip_data->country ) ? $ip_data->country : 'NOT SET';
|
||||
}
|
||||
}
|
||||
|
||||
$body['plugin_slug'] = $this->plugin_name;
|
||||
$body['url'] = $site_url;
|
||||
$body['item_id'] = $this->item_id;
|
||||
|
||||
$request = $this->remote_post( $body );
|
||||
if( ! is_wp_error( $request ) && $request['response']['code'] == 200 ) {
|
||||
$retrieved_body = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
if( is_array( $retrieved_body ) && isset( $retrieved_body['siteId'] ) ) {
|
||||
update_option( $site_id_key, $retrieved_body['siteId'] );
|
||||
update_option( "wpins_{$this->plugin_name}_original_url", $site_url );
|
||||
update_option( "wpins_{$this->plugin_name}_{$retrieved_body['siteId']}", $body );
|
||||
}
|
||||
} else {
|
||||
$failed_data = $body;
|
||||
}
|
||||
}
|
||||
|
||||
$site_id_data_key = "wpins_{$this->plugin_name}_{$site_id}";
|
||||
$site_id_data_failed_key = "wpins_{$this->plugin_name}_{$site_id}_send_failed";
|
||||
|
||||
if( $site_id != false ) {
|
||||
$old_sent_data = get_option( $site_id_data_key, [] );
|
||||
$diff_data = $this->diff( $body, $old_sent_data );
|
||||
$failed_data = get_option( $site_id_data_failed_key, [] );
|
||||
if( ! empty( $failed_data ) && $diff_data != $failed_data ) {
|
||||
$failed_data = array_merge( $failed_data, $diff_data );
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty( $failed_data ) && $site_id != false ) {
|
||||
$failed_data['plugin_slug'] = $this->plugin_name;
|
||||
$failed_data['url'] = $site_url;
|
||||
$failed_data['site_id'] = $site_id;
|
||||
if( $original_site_url != false ) {
|
||||
$failed_data['original_url'] = $original_site_url;
|
||||
}
|
||||
|
||||
$request = $this->remote_post( $failed_data );
|
||||
if( ! is_wp_error( $request ) ) {
|
||||
delete_option( $site_id_data_failed_key );
|
||||
$replaced_data = array_merge( $old_sent_data, $failed_data );
|
||||
update_option( $site_id_data_key, $replaced_data );
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty( $diff_data ) && $site_id != false && empty( $failed_data ) ) {
|
||||
$diff_data['plugin_slug'] = $this->plugin_name;
|
||||
$diff_data['url'] = $site_url;
|
||||
$diff_data['site_id'] = $site_id;
|
||||
if( $original_site_url != false ) {
|
||||
$diff_data['original_url'] = $original_site_url;
|
||||
}
|
||||
|
||||
$request = $this->remote_post( $diff_data );
|
||||
if( is_wp_error( $request ) ) {
|
||||
update_option( $site_id_data_failed_key, $diff_data );
|
||||
} else {
|
||||
$replaced_data = array_merge( $old_sent_data, $diff_data );
|
||||
update_option( $site_id_data_key, $replaced_data );
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_track_time();
|
||||
|
||||
if( isset( $request ) && is_wp_error( $request ) ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
if( isset( $request ) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* WP_REMOTE_POST method responsible for send data to the API_URL
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $args
|
||||
* @return void
|
||||
*/
|
||||
protected function remote_post( $data = array(), $args = array() ){
|
||||
if( empty( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$args = wp_parse_args( $args, array(
|
||||
'method' => 'POST',
|
||||
'timeout' => 30,
|
||||
'redirection' => 5,
|
||||
'httpversion' => '1.1',
|
||||
'blocking' => true,
|
||||
'body' => $data,
|
||||
'user-agent' => 'PUT/1.0.0; ' . get_bloginfo( 'url' )
|
||||
));
|
||||
$request = wp_remote_post( esc_url( self::API_URL ), $args );
|
||||
if( is_wp_error( $request ) || ( isset( $request['response'], $request['response']['code'] ) && $request['response']['code'] != 200 ) ) {
|
||||
return new \WP_Error( 500, 'Something went wrong.' );
|
||||
}
|
||||
return $request;
|
||||
}
|
||||
/**
|
||||
* Difference between old and new data
|
||||
*
|
||||
* @param array $new_data
|
||||
* @param array $old_data
|
||||
* @return void
|
||||
*/
|
||||
protected function diff( $new_data, $old_data ){
|
||||
$data = [];
|
||||
if( ! empty( $new_data ) ) {
|
||||
foreach( $new_data as $key => $value ) {
|
||||
if( isset( $old_data[ $key ] ) ) {
|
||||
if( $old_data[ $key ] == $value ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$data[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Display the admin notice to users to allow them to opt in
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function notice() {
|
||||
/**
|
||||
* Return if notice is not set.
|
||||
*/
|
||||
if( ! isset( $this->notice_options['notice'] ) ) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Check is allowed or blocked for notice.
|
||||
*/
|
||||
$block_notice = get_option( 'wpins_block_notice' );
|
||||
if( isset( $block_notice[$this->plugin_name] ) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$url_yes = add_query_arg( [
|
||||
'plugin' => $this->plugin_name,
|
||||
'plugin_action' => 'yes',
|
||||
] );
|
||||
$url_no = add_query_arg( array(
|
||||
'plugin' => $this->plugin_name,
|
||||
'plugin_action' => 'no'
|
||||
) );
|
||||
|
||||
$url_yes = wp_nonce_url( $url_yes, '_wpnonce_optin_' . $this->plugin_name );
|
||||
$url_no = wp_nonce_url( $url_no, '_wpnonce_optin_' . $this->plugin_name );
|
||||
|
||||
// Decide on notice text
|
||||
$notice_text = $this->notice_options['notice'] . ' <a href="#" class="wpinsights-'. esc_attr( $this->plugin_name ) .'-collect">'. $this->notice_options['consent_button_text'] .'</a>';
|
||||
$extra_notice_text = $this->notice_options['extra_notice'];
|
||||
|
||||
$output = '';
|
||||
$output .= '<div class="notice notice-info updated put-dismiss-notice">';
|
||||
$output .= '<p>'. $notice_text .'</p>';
|
||||
$output .= '<div class="wpinsights-data" style="display: none;">';
|
||||
$output .= '<p>'. $extra_notice_text .'</p>';
|
||||
$output .= '</div>';
|
||||
$output .= '<p>';
|
||||
$output .= '<a href="'. esc_url( $url_yes ) .'" class="button-primary">'. $this->notice_options['yes'] .'</a> ';
|
||||
$output .= '<a href="'. esc_url( $url_no ) .'" class="button-secondary">'. $this->notice_options['no'] .'</a>';
|
||||
$output .= '</p>';
|
||||
$output .= "<script type='text/javascript'>jQuery('.wpinsights-". esc_attr( $this->plugin_name ) ."-collect').on('click', function(e) {e.preventDefault();jQuery('.wpinsights-data').slideToggle('fast');});</script>";
|
||||
$output .= '</div>';
|
||||
|
||||
printf( '%1$s', $output );
|
||||
}
|
||||
/**
|
||||
* Set all notice options to customized notice.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @param array $options
|
||||
* @return void
|
||||
*/
|
||||
public function set_notice_options( $options = [] ){
|
||||
$default_options = [
|
||||
'consent_button_text' => __( 'What we collect.', 'disable-comments' ),
|
||||
'yes' => __( 'Sure, I\'d like to help', 'disable-comments' ),
|
||||
'no' => __( 'No Thanks.', 'disable-comments' ),
|
||||
];
|
||||
$options = wp_parse_args( $options, $default_options );
|
||||
$this->notice_options = $options;
|
||||
}
|
||||
/**
|
||||
* Responsible for track the click from Notice.
|
||||
* @return void
|
||||
*/
|
||||
public function clicked(){
|
||||
if ( isset( $_GET['_wpnonce'] ) && isset( $_GET['plugin'] ) && trim( $_GET['plugin'] ) === $this->plugin_name && isset( $_GET['plugin_action'] ) ) {
|
||||
if ( ! wp_verify_nonce( $_GET['_wpnonce'], '_wpnonce_optin_' . $this->plugin_name ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( isset( $_GET['tab'] ) && $_GET['tab'] === 'plugin-information' ) {
|
||||
return;
|
||||
}
|
||||
$plugin = sanitize_text_field( $_GET['plugin'] );
|
||||
$action = sanitize_text_field( $_GET['plugin_action'] );
|
||||
if( $action == 'yes' ) {
|
||||
$this->schedule_tracking();
|
||||
$this->set_is_tracking_allowed( true, $plugin );
|
||||
if( $this->do_tracking( true ) ) {
|
||||
$this->update_block_notice( $plugin );
|
||||
}
|
||||
/**
|
||||
* Redirect User To the Current URL, but without set query arguments.
|
||||
*/
|
||||
wp_safe_redirect( $this->redirect_to() );
|
||||
} else {
|
||||
$this->set_is_tracking_allowed( false, $plugin );
|
||||
$this->update_block_notice( $plugin );
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set if we should block the opt-in notice for this plugin
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function update_block_notice( $plugin = null ) {
|
||||
if( empty( $plugin ) ) {
|
||||
$plugin = $this->plugin_name;
|
||||
}
|
||||
$block_notice = get_option( 'wpins_block_notice' );
|
||||
if( empty( $block_notice ) || ! is_array( $block_notice ) ) {
|
||||
$block_notice = array( $plugin => $plugin );
|
||||
} else {
|
||||
$block_notice[$plugin] = $plugin;
|
||||
}
|
||||
update_option( 'wpins_block_notice', $block_notice );
|
||||
}
|
||||
/**
|
||||
* AJAX callback when the deactivated form is submitted.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function deactivate_reasons_form_submit() {
|
||||
check_ajax_referer( 'wpins_deactivation_nonce', 'security' );
|
||||
if( isset( $_POST['values'] ) ) {
|
||||
$values = sanitize_text_field( $_POST['values'] );
|
||||
update_option( 'wpins_deactivation_reason_' . $this->plugin_name, $values );
|
||||
}
|
||||
if( isset( $_POST['details'] ) ) {
|
||||
$details = sanitize_text_field( $_POST['details'] );
|
||||
update_option( 'wpins_deactivation_details_' . $this->plugin_name, $details );
|
||||
}
|
||||
echo 'success';
|
||||
wp_die();
|
||||
}
|
||||
/**
|
||||
* Filter the deactivation link to allow us to present a form when the user deactivates the plugin
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function deactivate_action_links( $links ) {
|
||||
/**
|
||||
* Check is tracking allowed or not.
|
||||
*/
|
||||
if( ! $this->is_tracking_allowed() ) {
|
||||
return $links;
|
||||
}
|
||||
if( isset( $links['deactivate'] ) && $this->include_goodbye_form ) {
|
||||
$deactivation_link = $links['deactivate'];
|
||||
/**
|
||||
* Change the default deactivate button link.
|
||||
*/
|
||||
$deactivation_link = str_replace( '<a ', '<div class="wpinsights-goodbye-form-wrapper-'. esc_attr( $this->plugin_name ) .'"><div class="wpinsights-goodbye-form-bg"></div><span class="wpinsights-goodbye-form" id="wpinsights-goodbye-form"></span></div><a onclick="javascript:event.preventDefault();" id="wpinsights-goodbye-link-' . esc_attr( $this->plugin_name ) . '" ', $deactivation_link );
|
||||
$links['deactivate'] = $deactivation_link;
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
/**
|
||||
* ALL Deactivate Reasons.
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function deactivation_reasons() {
|
||||
$form = array();
|
||||
$form['heading'] = __( 'Sorry to see you go', 'disable-comments' );
|
||||
$form['body'] = __( 'Before you deactivate the plugin, would you quickly give us your reason for doing so?', 'disable-comments' );
|
||||
|
||||
$form['options'] = array(
|
||||
__( 'I no longer need the plugin', 'disable-comments' ),
|
||||
[
|
||||
'label' => __( 'I found a better plugin', 'disable-comments' ),
|
||||
'extra_field' => __( 'Please share which plugin', 'disable-comments' )
|
||||
],
|
||||
__( "I couldn't get the plugin to work", 'disable-comments' ),
|
||||
__( 'It\'s a temporary deactivation', 'disable-comments' ),
|
||||
[
|
||||
'label' => __( 'Other', 'disable-comments' ),
|
||||
'extra_field' => __( 'Please share the reason', 'disable-comments' ),
|
||||
'type' => 'textarea'
|
||||
]
|
||||
);
|
||||
return apply_filters( 'wpins_form_text_' . $this->plugin_name, $form );
|
||||
}
|
||||
/**
|
||||
* Deactivate Reasons Form.
|
||||
* This form will appears when user wants to deactivate the plugin to send you deactivated reasons.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function deactivate_reasons_form() {
|
||||
$form = $this->deactivation_reasons();
|
||||
$class_plugin_name = esc_attr( $this->plugin_name );
|
||||
$html = '<div class="wpinsights-goodbye-form-head"><strong>' . esc_html( $form['heading'] ) . '</strong></div>';
|
||||
$html .= '<div class="wpinsights-goodbye-form-body"><p class="wpinsights-goodbye-form-caption">' . esc_html( $form['body'] ) . '</p>';
|
||||
if( is_array( $form['options'] ) ) {
|
||||
$html .= '<div id="wpinsights-goodbye-options" class="wpinsights-goodbye-options"><ul>';
|
||||
foreach( $form['options'] as $option ) {
|
||||
if( is_array( $option ) ) {
|
||||
$id = strtolower( str_replace( " ", "_", esc_attr( $option['label'] ) ) );
|
||||
$id = $id . '_' . $class_plugin_name;
|
||||
$html .= '<li class="has-goodbye-extra">';
|
||||
$html .= '<input type="radio" name="wpinsights-'. esc_attr( $class_plugin_name ) .'-goodbye-options" id="' . esc_attr( $id ) . '" value="' . esc_attr( $option['label'] ) . '">';
|
||||
$html .= '<div><label for="' . $id . '">' . esc_attr( $option['label'] ) . '</label>';
|
||||
if( isset( $option[ 'extra_field' ] ) && ! isset( $option['type'] )) {
|
||||
$html .= '<input type="text" style="display: none" name="'. esc_attr( $id ) .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '">';
|
||||
}
|
||||
if( isset( $option[ 'extra_field' ] ) && isset( $option['type'] )) {
|
||||
$html .= '<'. $option['type'] .' style="display: none" type="text" name="'. esc_attr( $id ) .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '"></' . $option['type'] . '>';
|
||||
}
|
||||
$html .= '</div></li>';
|
||||
} else {
|
||||
$id = strtolower( str_replace( " ", "_", esc_attr( $option ) ) );
|
||||
$id = $id . '_' . $class_plugin_name;
|
||||
$html .= '<li><input type="radio" name="wpinsights-'. $class_plugin_name .'-goodbye-options" id="' . esc_attr( $id ) . '" value="' . esc_attr( $option ) . '"> <label for="' . $id . '">' . esc_attr( $option ) . '</label></li>';
|
||||
}
|
||||
}
|
||||
$html .= '</ul></div><!-- .wpinsights-'. $class_plugin_name .'-goodbye-options -->';
|
||||
}
|
||||
$html .= '</div><!-- .wpinsights-goodbye-form-body -->';
|
||||
$html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'disable-comments' ) . '</p>';
|
||||
|
||||
$wrapper_class = '.wpinsights-goodbye-form-wrapper-'. $class_plugin_name;
|
||||
|
||||
$styles = '';
|
||||
$styles .= '<style type="text/css">';
|
||||
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form-bg {';
|
||||
$styles .= 'background: rgba( 0, 0, 0, .8 );position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 9;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . '{';
|
||||
$styles .= 'position: relative; display: none;';
|
||||
$styles .= '}';
|
||||
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' ' . $wrapper_class . '{';
|
||||
$styles .= 'display: flex !important; position: fixed;top: 0;left: 0;width: 100%;height: 100%; justify-content: center; align-items: center;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form { display: none; }';
|
||||
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form {';
|
||||
$styles .= 'position: relative !important; width: 550px; max-width: 80%; background: #fff; box-shadow: 2px 8px 23px 3px rgba(0,0,0,.2); border-radius: 3px; white-space: normal; overflow: hidden; display: block; z-index: 999999;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-head {';
|
||||
$styles .= 'background: #fff; color: #495157; padding: 18px; box-shadow: 0 0 8px rgba(0,0,0,.1); font-size: 15px;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form .wpinsights-goodbye-form-head strong { font-size: 15px; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body { padding: 8px 18px; color: #333; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body label { padding-left: 5px; color: #6d7882; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body .wpinsights-goodbye-form-caption {';
|
||||
$styles .= 'font-weight: 500; font-size: 15px; color: #495157; line-height: 1.4;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options { padding-top: 5px; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li { margin-bottom: 15px; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div { display: inline; padding-left: 3px; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > input, '. $wrapper_class .' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > textarea {';
|
||||
$styles .= 'margin: 10px 18px; padding: 8px; width: 80%;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .deactivating-spinner { display: none; padding-bottom: 20px !important; }';
|
||||
$styles .= $wrapper_class . ' .deactivating-spinner .spinner { float: none; margin: 4px 4px 0 18px; vertical-align: bottom; visibility: visible; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer { padding: 8px 18px; margin-bottom: 15px; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer > .wpinsights-goodbye-form-buttons { display: flex; align-items: center; justify-content: space-between; }';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-submit-btn {';
|
||||
$styles .= 'background-color: #f3bafd; -webkit-border-radius: 3px; border-radius: 3px; color: #0c0d0e; line-height: 1; padding: 10px 20px; font-size: 13px; font-weight: 500; text-transform: uppercase; transition: .3s;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-submit-btn:hover {';
|
||||
$styles .= 'background-color: #f5d0fe;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-deactivate-btn {';
|
||||
$styles .= 'font-size: 13px; color: #a4afb7; background: none; float: right; padding-right: 10px; width: auto; text-decoration: underline;';
|
||||
$styles .= '}';
|
||||
$styles .= $wrapper_class . ' .test {';
|
||||
$styles .= '}';
|
||||
$styles .= '</style>';
|
||||
$styles .= '';
|
||||
|
||||
echo $styles;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
jQuery(document).ready(function($){
|
||||
$("#wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>").on("click",function(){
|
||||
// We'll send the user to this deactivation link when they've completed or dismissed the form
|
||||
var url = document.getElementById("wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>");
|
||||
$('body').toggleClass('wpinsights-form-active-<?php echo $class_plugin_name; ?>');
|
||||
$(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").fadeIn();
|
||||
$(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").html( '<?php echo $html; ?>' + '<div class="wpinsights-goodbye-form-footer"><div class="wpinsights-goodbye-form-buttons"><a id="wpinsights-submit-form-<?php echo $class_plugin_name; ?>" class="wpinsights-submit-btn" href="#"><?php _e( 'Submit and Deactivate', 'disable-comments' ); ?></a> <a class="wpsp-put-deactivate-btn" href="'+url+'"><?php _e( 'Just Deactivate', 'disable-comments' ); ?></a></div></div>');
|
||||
$('#wpinsights-submit-form-<?php echo $class_plugin_name; ?>').on('click', function(e){
|
||||
// As soon as we click, the body of the form should disappear
|
||||
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-body").fadeOut();
|
||||
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-footer").fadeOut();
|
||||
// Fade in spinner
|
||||
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .deactivating-spinner").fadeIn();
|
||||
e.preventDefault();
|
||||
var checkedInput = $("input[name='wpinsights-<?php echo esc_attr( $class_plugin_name ); ?>-goodbye-options']:checked"),
|
||||
checkedInputVal, details;
|
||||
if( checkedInput.length > 0 ) {
|
||||
checkedInputVal = checkedInput.val();
|
||||
details = $('input[name="'+ checkedInput[0].id +'"], textarea[name="'+ checkedInput[0].id +'"]').val();
|
||||
}
|
||||
|
||||
if( typeof details === 'undefined' ) {
|
||||
details = '';
|
||||
}
|
||||
if( typeof checkedInputVal === 'undefined' ) {
|
||||
checkedInputVal = 'No Reason';
|
||||
}
|
||||
|
||||
var data = {
|
||||
'action': 'deactivation_form_<?php echo esc_attr( $class_plugin_name ); ?>',
|
||||
'values': checkedInputVal,
|
||||
'details': details,
|
||||
'security': "<?php echo wp_create_nonce ( 'wpins_deactivation_nonce' ); ?>",
|
||||
'dataType': "json"
|
||||
}
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
data,
|
||||
function(response){
|
||||
// Redirect to original deactivation URL
|
||||
window.location.href = url;
|
||||
}
|
||||
);
|
||||
});
|
||||
$('#wpinsights-goodbye-options > ul ').on('click', 'li label, li > input', function( e ){
|
||||
var parent = $(this).parents('li');
|
||||
parent.siblings().find('label').next('input, textarea').css('display', 'none');
|
||||
parent.find('label').next('input, textarea').css('display', 'block');
|
||||
});
|
||||
// If we click outside the form, the form will close
|
||||
$('.wpinsights-goodbye-form-bg').on('click',function(){
|
||||
$("#wpinsights-goodbye-form").fadeOut();
|
||||
$('body').removeClass('wpinsights-form-active-<?php echo esc_attr( $class_plugin_name ); ?>');
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php }
|
||||
|
||||
/**
|
||||
* Get Used Elements Count
|
||||
* Get eael all used elements from all pages
|
||||
* @return array
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public static function get_used_elements_count() {
|
||||
global $wpdb;
|
||||
|
||||
$sql = "SELECT `post_id`
|
||||
FROM $wpdb->postmeta
|
||||
WHERE `meta_key` = '_eael_widget_elements'";
|
||||
$post_ids = $wpdb->get_col( $sql );
|
||||
$used_elements = [];
|
||||
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$ea_elements = get_post_meta( (int) $post_id, '_eael_widget_elements', true );
|
||||
$el_controls = get_post_meta( (int) $post_id, '_elementor_controls_usage', true );
|
||||
if ( empty( $ea_elements ) || empty( $el_controls ) || ! is_array( $ea_elements ) || ! is_array( $el_controls ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $ea_elements as $element ) {
|
||||
$element_name = "eael-{$element}";
|
||||
$replace_widget_name = array_flip( Elements_Manager::replace_widget_name() );
|
||||
$count = 0;
|
||||
|
||||
if ( isset( $replace_widget_name[ $element_name ] ) ) {
|
||||
$element_name = $replace_widget_name[ $element_name ];
|
||||
}
|
||||
|
||||
if ( ! empty( $el_controls[ $element_name ] ) && is_array( $el_controls[ $element_name ] ) ) {
|
||||
$count = $el_controls[ $element_name ]['count'];
|
||||
}
|
||||
|
||||
$used_elements[ $element_name ] = isset( $used_elements[ $element_name ] ) ? $used_elements[ $element_name ] + $count : $count;
|
||||
}
|
||||
|
||||
array_walk_recursive( $el_controls, function ( $value, $key ) use ( &$used_elements ) {
|
||||
$element_name = '';
|
||||
|
||||
if ( $key === 'eael_particle_switch' ) {
|
||||
$element_name = 'eael-section-particles';
|
||||
} elseif ( $key === 'eael_parallax_switcher' ) {
|
||||
$element_name = 'eael-section-parallax';
|
||||
} elseif ( $key === 'eael_tooltip_section_enable' ) {
|
||||
$element_name = 'eael-tooltip-section';
|
||||
} elseif ( $key === 'eael_ext_content_protection' ) {
|
||||
$element_name = 'eael-content-protection';
|
||||
} elseif ( $key === 'eael_cl_enable' ) {
|
||||
$element_name = 'eael-conditional-display';
|
||||
}
|
||||
|
||||
if ( ! empty( $element_name ) ) {
|
||||
$used_elements[ $element_name ] = isset( $used_elements[ $element_name ] ) ? $used_elements[ $element_name ] + $value : $value;
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
return $used_elements;
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?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_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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
||||
Reference in New Issue
Block a user