setup-wizard
9 months ago
templates
9 months ago
admin-bar.php
9 months ago
admin-helper.php
9 months ago
admin-notices.php
9 months ago
beta-testers.php
9 months ago
duplicator.php
9 months ago
elements.php
9 months ago
feedback.php
9 months ago
keys.php
9 months ago
pa-rollback.php
9 months ago
admin-helper.php
1738 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Admin Helper |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Admin\Includes; |
| 7 | |
| 8 | use PremiumAddons\Includes\Helper_Functions; |
| 9 | use Elementor\Modules\Usage\Module; |
| 10 | use Elementor\Plugin; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Class Admin_Helper |
| 18 | */ |
| 19 | class Admin_Helper { |
| 20 | |
| 21 | /** |
| 22 | * Admin settings tabs |
| 23 | * |
| 24 | * @var tabs |
| 25 | */ |
| 26 | private static $tabs = null; |
| 27 | |
| 28 | /** |
| 29 | * Class instance |
| 30 | * |
| 31 | * @var instance |
| 32 | */ |
| 33 | private static $instance = null; |
| 34 | |
| 35 | /** |
| 36 | * Premium Addons Settings Page Slug |
| 37 | * |
| 38 | * @var page_slug |
| 39 | */ |
| 40 | public static $page_slug = 'premium-addons'; |
| 41 | |
| 42 | /** |
| 43 | * Elements List |
| 44 | * |
| 45 | * @var elements_list |
| 46 | */ |
| 47 | public static $elements_list = null; |
| 48 | |
| 49 | /** |
| 50 | * Elements Keys |
| 51 | * |
| 52 | * @var elements_list |
| 53 | */ |
| 54 | public static $elements_keys = null; |
| 55 | |
| 56 | /** |
| 57 | * Enabled Elements |
| 58 | * |
| 59 | * @var enabled_elements |
| 60 | */ |
| 61 | public static $enabled_elements = null; |
| 62 | |
| 63 | /** |
| 64 | * Integrations Settings |
| 65 | * |
| 66 | * @var integrations_settings |
| 67 | */ |
| 68 | public static $integrations_settings = null; |
| 69 | |
| 70 | /** |
| 71 | * Elements Names |
| 72 | * |
| 73 | * @var elements_names |
| 74 | */ |
| 75 | public static $elements_names = null; |
| 76 | |
| 77 | /** |
| 78 | * Integrations List |
| 79 | * |
| 80 | * @var integrations_list |
| 81 | */ |
| 82 | public static $integrations_list = null; |
| 83 | |
| 84 | /** |
| 85 | * Constructor for the class |
| 86 | */ |
| 87 | public function __construct() { |
| 88 | |
| 89 | // Insert admin settings submenus. |
| 90 | add_action( 'admin_menu', array( $this, 'add_menu_tabs' ), 100 ); |
| 91 | |
| 92 | // Enqueue required admin scripts. |
| 93 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 94 | |
| 95 | // Plugin Action Links. |
| 96 | add_filter( 'plugin_action_links_' . PREMIUM_ADDONS_BASENAME, array( $this, 'insert_action_links' ) ); |
| 97 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| 98 | |
| 99 | // Register AJAX HOOKS. |
| 100 | add_action( 'wp_ajax_pa_save_global_btn', array( $this, 'save_global_btn_value' ) ); |
| 101 | add_action( 'wp_ajax_pa_elements_settings', array( $this, 'save_settings' ) ); |
| 102 | add_action( 'wp_ajax_pa_disable_elementor_mc_template', array( $this, 'disable_elementor_mc_template' ) ); |
| 103 | add_action( 'wp_ajax_pa_additional_settings', array( $this, 'save_additional_settings' ) ); |
| 104 | add_action( 'wp_ajax_pa_get_unused_widgets', array( $this, 'get_unused_widgets' ) ); |
| 105 | add_action( 'wp_ajax_get_pa_menu_item_settings', array( $this, 'get_pa_menu_item_settings' ) ); |
| 106 | add_action( 'wp_ajax_save_pa_menu_item_settings', array( $this, 'save_pa_menu_item_settings' ) ); |
| 107 | add_action( 'wp_ajax_save_pa_mega_item_content', array( $this, 'save_pa_mega_item_content' ) ); |
| 108 | |
| 109 | // Register AJAX Hooks for regenerate assets. |
| 110 | add_action( 'wp_ajax_pa_clear_cached_assets', array( $this, 'clear_cached_assets' ) ); |
| 111 | |
| 112 | // Register Deactivation hooks. |
| 113 | register_deactivation_hook( PREMIUM_ADDONS_FILE, array( $this, 'clear_dynamic_assets_data' ) ); |
| 114 | |
| 115 | // Register AJAX Hooks for clearing saved site cursor. |
| 116 | add_action( 'wp_ajax_pa_clear_site_cursor_settings', array( $this, 'clear_site_cursor_settings' ) ); |
| 117 | |
| 118 | // Register AJAX Hooks for Newsletter. |
| 119 | add_action( 'wp_ajax_subscribe_newsletter', array( $this, 'subscribe_newsletter' ) ); |
| 120 | |
| 121 | // Add action for PA dashboard tab header. |
| 122 | add_action( 'pa_before_render_admin_tabs', array( $this, 'render_dashboard_header' ) ); |
| 123 | |
| 124 | // Register Rollback hooks. |
| 125 | add_action( 'admin_post_premium_addons_rollback', array( $this, 'run_pa_rollback' ) ); |
| 126 | |
| 127 | if ( is_admin() ) { |
| 128 | |
| 129 | Admin_Notices::get_instance(); |
| 130 | |
| 131 | // Beta tester. |
| 132 | // Not currently needed. |
| 133 | // Beta_Testers::get_instance();. |
| 134 | |
| 135 | // PA Duplicator. |
| 136 | if ( self::check_duplicator() ) { |
| 137 | Duplicator::get_instance(); |
| 138 | } |
| 139 | |
| 140 | if ( self::check_user_can( 'install_plugins' ) ) { |
| 141 | Feedback::get_instance(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | // PA Dynamic Assets. |
| 146 | $row_meta = Helper_Functions::is_hide_row_meta(); |
| 147 | |
| 148 | if ( ! is_admin() && self::check_dynamic_assets() && ! $row_meta ) { |
| 149 | Admin_Bar::get_instance(); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Checks user credentials for specific action |
| 155 | * |
| 156 | * @since 2.6.8 |
| 157 | * |
| 158 | * @param string $action action. |
| 159 | * |
| 160 | * @return boolean |
| 161 | */ |
| 162 | public static function check_user_can( $action ) { |
| 163 | return current_user_can( $action ); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Get Elements List |
| 168 | * |
| 169 | * Get a list of all the elements available in the plugin |
| 170 | * |
| 171 | * @since 3.20.9 |
| 172 | * @access private |
| 173 | * |
| 174 | * @return array elements_list |
| 175 | */ |
| 176 | public static function get_elements_list() { |
| 177 | |
| 178 | if ( null === self::$elements_list ) { |
| 179 | |
| 180 | self::$elements_list = require_once PREMIUM_ADDONS_PATH . 'admin/includes/elements.php'; |
| 181 | |
| 182 | } |
| 183 | |
| 184 | return self::$elements_list; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Get Elements Keys |
| 189 | * |
| 190 | * Get a list of all the keys available in the plugin |
| 191 | * |
| 192 | * @since 4.10.54 |
| 193 | * @access private |
| 194 | * |
| 195 | * @return array elements_keys |
| 196 | */ |
| 197 | public static function get_elements_keys() { |
| 198 | |
| 199 | if ( null === self::$elements_keys ) { |
| 200 | |
| 201 | self::$elements_keys = require_once PREMIUM_ADDONS_PATH . 'admin/includes/keys.php'; |
| 202 | |
| 203 | } |
| 204 | |
| 205 | return self::$elements_keys; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Get Integrations List |
| 210 | * |
| 211 | * Get a list of all the integrations available in the plugin |
| 212 | * |
| 213 | * @since 3.20.9 |
| 214 | * @access private |
| 215 | * |
| 216 | * @return array integrations_list |
| 217 | */ |
| 218 | private static function get_integrations_list() { |
| 219 | |
| 220 | if ( null === self::$integrations_list ) { |
| 221 | |
| 222 | self::$integrations_list = array( |
| 223 | 'premium-map-api', |
| 224 | 'premium-youtube-api', |
| 225 | 'premium-map-disable-api', |
| 226 | 'premium-map-cluster', |
| 227 | 'premium-wp-optimize-exclude', |
| 228 | 'premium-map-locale', |
| 229 | 'is-beta-tester', |
| 230 | ); |
| 231 | |
| 232 | } |
| 233 | |
| 234 | return self::$integrations_list; |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Admin Enqueue Scripts |
| 239 | * |
| 240 | * Enqueue the required assets on our admin pages |
| 241 | * |
| 242 | * @since 1.0.0 |
| 243 | * @access public |
| 244 | * |
| 245 | * @param string $hook The current admin page hook. |
| 246 | */ |
| 247 | public function admin_enqueue_scripts( $hook ) { |
| 248 | |
| 249 | $enabled_elements = self::get_enabled_elements(); |
| 250 | $action = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 251 | |
| 252 | wp_enqueue_style( |
| 253 | 'pa_admin_icon', |
| 254 | PREMIUM_ADDONS_URL . 'admin/assets/fonts/style.css', |
| 255 | array(), |
| 256 | PREMIUM_ADDONS_VERSION, |
| 257 | 'all' |
| 258 | ); |
| 259 | |
| 260 | wp_enqueue_style( |
| 261 | 'pa-notice', |
| 262 | PREMIUM_ADDONS_URL . 'admin/assets/css/notice.css', |
| 263 | array(), |
| 264 | PREMIUM_ADDONS_VERSION, |
| 265 | 'all' |
| 266 | ); |
| 267 | |
| 268 | wp_enqueue_style( |
| 269 | 'pa-admin', |
| 270 | PREMIUM_ADDONS_URL . 'admin/assets/css/admin.css', |
| 271 | array(), |
| 272 | PREMIUM_ADDONS_VERSION, |
| 273 | 'all' |
| 274 | ); |
| 275 | |
| 276 | if ( false !== strpos( $hook, 'premium-addons' ) ) { |
| 277 | |
| 278 | wp_enqueue_style( |
| 279 | 'pa-sweetalert-style', |
| 280 | PREMIUM_ADDONS_URL . 'admin/assets/js/sweetalert2/sweetalert2.min.css', |
| 281 | array(), |
| 282 | PREMIUM_ADDONS_VERSION, |
| 283 | 'all' |
| 284 | ); |
| 285 | |
| 286 | wp_enqueue_script( |
| 287 | 'pa-admin', |
| 288 | PREMIUM_ADDONS_URL . 'admin/assets/js/admin.js', |
| 289 | array( 'jquery' ), |
| 290 | PREMIUM_ADDONS_VERSION, |
| 291 | true |
| 292 | ); |
| 293 | |
| 294 | wp_enqueue_script( |
| 295 | 'pa-sweetalert-core', |
| 296 | PREMIUM_ADDONS_URL . 'admin/assets/js/sweetalert2/core.js', |
| 297 | array( 'jquery' ), |
| 298 | PREMIUM_ADDONS_VERSION, |
| 299 | true |
| 300 | ); |
| 301 | |
| 302 | wp_enqueue_script( |
| 303 | 'pa-sweetalert', |
| 304 | PREMIUM_ADDONS_URL . 'admin/assets/js/sweetalert2/sweetalert2.min.js', |
| 305 | array( 'jquery', 'pa-sweetalert-core' ), |
| 306 | PREMIUM_ADDONS_VERSION, |
| 307 | true |
| 308 | ); |
| 309 | |
| 310 | $theme_slug = Helper_Functions::get_installed_theme(); |
| 311 | |
| 312 | $is_second_run = get_option( 'pa_complete_wizard' ) ? false : true; |
| 313 | |
| 314 | $localized_data = array( |
| 315 | 'settings' => array( |
| 316 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 317 | 'nonce' => wp_create_nonce( 'pa-settings-tab' ), |
| 318 | 'unused_nonce' => wp_create_nonce( 'pa-disable-unused' ), |
| 319 | 'generate_nonce' => wp_create_nonce( 'pa-generate-nonce' ), |
| 320 | 'site_cursor_nonce' => wp_create_nonce( 'pa-site-cursor-nonce' ), |
| 321 | 'isSecondRun' => $is_second_run, |
| 322 | 'theme' => $theme_slug, |
| 323 | 'i18n' => array( |
| 324 | 'successMsg' => __( 'Your submission was successful.', 'premium-addons-for-elementor' ), |
| 325 | 'failMsg' => __( 'Your submission failed because of an error', 'premium-addons-for-elementor' ), |
| 326 | ), |
| 327 | ), |
| 328 | 'premiumRollBackConfirm' => array( |
| 329 | 'home_url' => home_url(), |
| 330 | 'i18n' => array( |
| 331 | 'rollback_to_previous_version' => __( 'Rollback to Previous Version', 'premium-addons-for-elementor' ), |
| 332 | /* translators: %s: PA stable version */ |
| 333 | 'rollback_confirm' => sprintf( __( 'Are you sure you want to reinstall version %s?', 'premium-addons-for-elementor' ), PREMIUM_ADDONS_STABLE_VERSION ), |
| 334 | 'yes' => __( 'Continue', 'premium-addons-for-elementor' ), |
| 335 | 'cancel' => __( 'Cancel', 'premium-addons-for-elementor' ), |
| 336 | ), |
| 337 | ), |
| 338 | ); |
| 339 | |
| 340 | // Only add savedFeatures if it's the second run. |
| 341 | if ( $is_second_run ) { |
| 342 | $localized_data['settings']['savedFeatures'] = get_option( 'pa_saved_features', array() ); |
| 343 | } |
| 344 | |
| 345 | // Add PAPRO Rollback Confirm message if PAPRO installed. |
| 346 | if ( Helper_Functions::check_papro_version() ) { |
| 347 | /* translators: %s: PA stable version */ |
| 348 | $localized_data['premiumRollBackConfirm']['i18n']['papro_rollback_confirm'] = sprintf( __( 'Are you sure you want to reinstall version %s?', 'premium-addons-for-elementor' ), PREMIUM_ADDONS_STABLE_VERSION ); |
| 349 | } |
| 350 | |
| 351 | wp_localize_script( 'pa-admin', 'premiumAddonsSettings', $localized_data ); |
| 352 | |
| 353 | } |
| 354 | |
| 355 | if ( false !== strpos( $action, 'page=pa-setup-wizard' ) ) { |
| 356 | wp_enqueue_style( |
| 357 | 'pa-wizard', |
| 358 | PREMIUM_ADDONS_URL . 'admin/assets/css/setup-wizard.css', |
| 359 | array(), |
| 360 | PREMIUM_ADDONS_VERSION, |
| 361 | 'all' |
| 362 | ); |
| 363 | |
| 364 | wp_enqueue_script( |
| 365 | 'pa-wizard', |
| 366 | PREMIUM_ADDONS_URL . 'admin/assets/js/setup-wizard.js', |
| 367 | array( 'jquery' ), |
| 368 | PREMIUM_ADDONS_VERSION, |
| 369 | true |
| 370 | ); |
| 371 | |
| 372 | wp_localize_script( |
| 373 | 'pa-wizard', |
| 374 | 'paWizardSettings', |
| 375 | array( |
| 376 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 377 | 'nonce' => wp_create_nonce( 'pa-wizard-nonce' ), |
| 378 | 'exitWizardURL' => admin_URL( 'plugins.php' ), |
| 379 | 'isSecondRun' => get_option( 'pa_complete_wizard' ) ? false : true, |
| 380 | 'dashboardURL' => admin_URL( 'admin.php' ) . '?page=premium-addons#tab=elements', |
| 381 | 'newPageURL' => Plugin::$instance->documents->get_create_new_post_url(), |
| 382 | ), |
| 383 | ); |
| 384 | |
| 385 | } |
| 386 | |
| 387 | if ( 'nav-menus.php' === $hook && $enabled_elements['premium-nav-menu'] ) { |
| 388 | |
| 389 | wp_enqueue_style( |
| 390 | 'pa-font-awesome', |
| 391 | ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/font-awesome.min.css', |
| 392 | array(), |
| 393 | '4.7.0', |
| 394 | 'all' |
| 395 | ); |
| 396 | |
| 397 | wp_enqueue_style( 'wp-color-picker' ); |
| 398 | |
| 399 | wp_enqueue_style( |
| 400 | 'jquery-fonticonpicker', |
| 401 | PREMIUM_ADDONS_URL . 'admin/assets/css/jquery-fonticonpicker.css', |
| 402 | array(), |
| 403 | PREMIUM_ADDONS_VERSION, |
| 404 | 'all' |
| 405 | ); |
| 406 | |
| 407 | wp_enqueue_script( |
| 408 | 'jquery-fonticonpicker', |
| 409 | PREMIUM_ADDONS_URL . 'admin/assets/js/jquery-fonticonpicker.js', |
| 410 | array( 'jquery' ), |
| 411 | PREMIUM_ADDONS_VERSION, |
| 412 | true |
| 413 | ); |
| 414 | |
| 415 | wp_enqueue_script( |
| 416 | 'pa-icon-list', |
| 417 | PREMIUM_ADDONS_URL . 'admin/assets/js/premium-icons-list.js', |
| 418 | array(), |
| 419 | PREMIUM_ADDONS_VERSION, |
| 420 | true |
| 421 | ); |
| 422 | |
| 423 | wp_enqueue_script( |
| 424 | 'mega-content-handler', |
| 425 | PREMIUM_ADDONS_URL . 'admin/assets/js/mega-content-handler.js', |
| 426 | array( 'jquery' ), |
| 427 | PREMIUM_ADDONS_VERSION, |
| 428 | true |
| 429 | ); |
| 430 | |
| 431 | wp_enqueue_script( |
| 432 | 'menu-editor', |
| 433 | PREMIUM_ADDONS_URL . 'admin/assets/js/menu-editor.js', |
| 434 | array( 'jquery', 'wp-color-picker' ), |
| 435 | PREMIUM_ADDONS_VERSION, |
| 436 | true |
| 437 | ); |
| 438 | |
| 439 | $pa_menu_localized = array( |
| 440 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 441 | 'nonce' => wp_create_nonce( 'pa-menu-nonce' ), |
| 442 | ); |
| 443 | |
| 444 | $menu_content_localized = array( |
| 445 | 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 446 | 'nonce' => wp_create_nonce( 'pa-live-editor' ), |
| 447 | ); |
| 448 | |
| 449 | wp_localize_script( 'mega-content-handler', 'paMegaContent', $menu_content_localized ); |
| 450 | wp_localize_script( 'menu-editor', 'paMenuSettings', $pa_menu_localized ); |
| 451 | |
| 452 | // menu screen popups. |
| 453 | include_once PREMIUM_ADDONS_PATH . 'admin/includes/templates/nav-menu-settings.php'; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Get PA menu item settings. |
| 459 | * Retrieve menu items settings from postmeta table. |
| 460 | * |
| 461 | * @access public |
| 462 | * @since 4.9.4 |
| 463 | */ |
| 464 | public function get_pa_menu_item_settings() { |
| 465 | |
| 466 | check_ajax_referer( 'pa-menu-nonce', 'security' ); |
| 467 | |
| 468 | if ( ! current_user_can( 'manage_options' ) ) { |
| 469 | wp_send_json_error( 'User is not authorized!' ); |
| 470 | } |
| 471 | |
| 472 | if ( ! isset( $_POST['item_id'] ) ) { |
| 473 | wp_send_json_error( 'Settings are not set!' ); |
| 474 | } |
| 475 | |
| 476 | $item_id = sanitize_text_field( wp_unslash( $_POST['item_id'] ) ); |
| 477 | $item_settings = json_decode( get_post_meta( $item_id, 'pa_megamenu_item_meta', true ) ); |
| 478 | |
| 479 | wp_send_json_success( $item_settings ); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Save PA menu item settings. |
| 484 | * Save/Update menu items settings in postmeta table. |
| 485 | * |
| 486 | * @access public |
| 487 | * @since 4.9.4 |
| 488 | */ |
| 489 | public function save_pa_menu_item_settings() { |
| 490 | |
| 491 | check_ajax_referer( 'pa-menu-nonce', 'security' ); |
| 492 | |
| 493 | if ( ! current_user_can( 'manage_options' ) ) { |
| 494 | wp_send_json_error( 'User is not authorized!' ); |
| 495 | } |
| 496 | |
| 497 | if ( ! isset( $_POST['settings'] ) ) { |
| 498 | wp_send_json_error( 'Settings are not set!' ); |
| 499 | } |
| 500 | |
| 501 | $settings = array_map( |
| 502 | function ( $setting ) { |
| 503 | return htmlspecialchars( $setting, ENT_QUOTES ); |
| 504 | }, |
| 505 | wp_unslash( $_POST['settings'] ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 506 | ); |
| 507 | |
| 508 | update_post_meta( $settings['item_id'], 'pa_megamenu_item_meta', wp_json_encode( $settings, JSON_UNESCAPED_UNICODE ) ); |
| 509 | |
| 510 | wp_send_json_success( $settings ); |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Save Pa Mega Item Content. |
| 515 | * Saves mega content's id in postmeta table. |
| 516 | * |
| 517 | * @access public |
| 518 | * @since 4.9.4 |
| 519 | */ |
| 520 | public function save_pa_mega_item_content() { |
| 521 | |
| 522 | check_ajax_referer( 'pa-live-editor', 'security' ); |
| 523 | |
| 524 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
| 525 | wp_send_json_error( 'Insufficient user permission' ); |
| 526 | } |
| 527 | |
| 528 | if ( ! isset( $_POST['template_id'] ) ) { |
| 529 | wp_send_json_error( 'template id is not set!' ); |
| 530 | } |
| 531 | |
| 532 | if ( ! isset( $_POST['menu_item_id'] ) ) { |
| 533 | wp_send_json_error( 'item id is not set!' ); |
| 534 | } |
| 535 | |
| 536 | $item_id = sanitize_text_field( wp_unslash( $_POST['menu_item_id'] ) ); |
| 537 | $temp_id = sanitize_text_field( wp_unslash( $_POST['template_id'] ) ); |
| 538 | |
| 539 | update_post_meta( $item_id, 'pa_mega_content_temp', $temp_id ); |
| 540 | |
| 541 | wp_send_json_success( 'Item Mega Content Saved' ); |
| 542 | } |
| 543 | |
| 544 | /** |
| 545 | * Insert action links. |
| 546 | * |
| 547 | * Adds action links to the plugin list table |
| 548 | * |
| 549 | * Fired by `plugin_action_links` filter. |
| 550 | * |
| 551 | * @param array $links plugin action links. |
| 552 | * |
| 553 | * @since 1.0.0 |
| 554 | * @access public |
| 555 | */ |
| 556 | public function insert_action_links( $links ) { |
| 557 | |
| 558 | $is_papro_active = apply_filters( 'papro_activated', false ); |
| 559 | |
| 560 | $settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=' . self::$page_slug . '#tab=elements' ), __( 'Settings', 'premium-addons-for-elementor' ) ); |
| 561 | |
| 562 | $rollback_link = sprintf( '<a href="%1$s">%2$s%3$s</a>', wp_nonce_url( admin_url( 'admin-post.php?action=premium_addons_rollback' ), 'premium_addons_rollback' ), __( 'Rollback to v', 'premium-addons-for-elementor' ), PREMIUM_ADDONS_STABLE_VERSION ); |
| 563 | |
| 564 | $new_links = array( $settings_link ); |
| 565 | |
| 566 | if ( ! $is_papro_active ) { |
| 567 | |
| 568 | $link = Helper_Functions::get_campaign_link( 'https://premiumaddons.com/pro', 'plugins-page', 'wp-dash', 'get-pro' ); |
| 569 | |
| 570 | $pro_link = sprintf( '<a href="%s" target="_blank" style="color: #FF6000; font-weight: bold;">%s</a>', $link, __( 'Go Pro (10% OFF)', 'premium-addons-for-elementor' ) ); |
| 571 | array_push( $new_links, $pro_link ); |
| 572 | } |
| 573 | |
| 574 | $new_links = array_merge( $links, $new_links ); |
| 575 | |
| 576 | return $new_links; |
| 577 | } |
| 578 | |
| 579 | /** |
| 580 | * Plugin row meta. |
| 581 | * |
| 582 | * Extends plugin row meta links |
| 583 | * |
| 584 | * Fired by `plugin_row_meta` filter. |
| 585 | * |
| 586 | * @since 3.8.4 |
| 587 | * @access public |
| 588 | * |
| 589 | * @param array $meta array of the plugin's metadata. |
| 590 | * @param string $file path to the plugin file. |
| 591 | * |
| 592 | * @return array An array of plugin row meta links. |
| 593 | */ |
| 594 | public function plugin_row_meta( $meta, $file ) { |
| 595 | |
| 596 | if ( Helper_Functions::is_hide_row_meta() ) { |
| 597 | return $meta; |
| 598 | } |
| 599 | |
| 600 | if ( PREMIUM_ADDONS_BASENAME === $file ) { |
| 601 | |
| 602 | $link = Helper_Functions::get_campaign_link( 'https://premiumaddons.com/support', 'plugins-page', 'wp-dash', 'get-support' ); |
| 603 | |
| 604 | $row_meta = array( |
| 605 | 'docs' => '<a href="' . esc_attr( $link ) . '" aria-label="' . esc_attr( __( 'View Premium Addons for Elementor Documentation', 'premium-addons-for-elementor' ) ) . '" target="_blank">' . __( 'Docs & FAQs', 'premium-addons-for-elementor' ) . '</a>', |
| 606 | 'videos' => '<a href="https://www.youtube.com/leap13" aria-label="' . esc_attr( __( 'View Premium Addons Video Tutorials', 'premium-addons-for-elementor' ) ) . '" target="_blank">' . __( 'Video Tutorials', 'premium-addons-for-elementor' ) . '</a>', |
| 607 | 'rate' => '<a href="https://wordpress.org/support/plugin/premium-addons-for-elementor/reviews/#new-post" aria-label="' . esc_attr( __( 'Rate plugin', 'premium-addons-for-elementor' ) ) . '" target="_blank">' . __( 'Rate the plugin � |
| 608 | � |
| 609 | � |
| 610 | � |
| 611 | � |
| 612 | ', 'premium-addons-for-elementor' ) . '</a>', |
| 613 | ); |
| 614 | |
| 615 | $meta = array_merge( $meta, $row_meta ); |
| 616 | } |
| 617 | |
| 618 | return $meta; |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * Set Admin Tabs |
| 623 | * |
| 624 | * @access private |
| 625 | * @since 3.20.8 |
| 626 | */ |
| 627 | private function set_admin_tabs() { |
| 628 | |
| 629 | $slug = self::$page_slug; |
| 630 | |
| 631 | self::$tabs = array( |
| 632 | 'general' => array( |
| 633 | 'id' => 'general', |
| 634 | 'slug' => $slug . '#tab=general', |
| 635 | 'title' => __( 'General', 'premium-addons-for-elementor' ), |
| 636 | 'href' => '#tab=general', |
| 637 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/general', |
| 638 | ), |
| 639 | 'elements' => array( |
| 640 | 'id' => 'elements', |
| 641 | 'slug' => $slug . '#tab=elements', |
| 642 | 'title' => __( 'Widgets & Add-ons', 'premium-addons-for-elementor' ), |
| 643 | 'href' => '#tab=elements', |
| 644 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/modules-settings', |
| 645 | ), |
| 646 | 'addons' => array( |
| 647 | 'id' => 'addons', |
| 648 | 'slug' => $slug . '#tab=addons', |
| 649 | 'title' => __( 'Global Addons', 'premium-addons-for-elementor' ), |
| 650 | 'href' => '#tab=addons', |
| 651 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/addons', |
| 652 | ), |
| 653 | 'integrations' => array( |
| 654 | 'id' => 'integrations', |
| 655 | 'slug' => $slug . '#tab=integrations', |
| 656 | 'title' => __( 'Integrations', 'premium-addons-for-elementor' ), |
| 657 | 'href' => '#tab=integrations', |
| 658 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/integrations', |
| 659 | ), |
| 660 | 'version-control' => array( |
| 661 | 'id' => 'vcontrol', |
| 662 | 'slug' => $slug . '#tab=vcontrol', |
| 663 | 'title' => __( 'Version Control', 'premium-addons-for-elementor' ), |
| 664 | 'href' => '#tab=vcontrol', |
| 665 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/version-control', |
| 666 | ), |
| 667 | 'white-label' => array( |
| 668 | 'id' => 'white-label', |
| 669 | 'slug' => $slug . '#tab=white-label', |
| 670 | 'title' => __( 'White Labeling', 'premium-addons-for-elementor' ), |
| 671 | 'href' => '#tab=white-label', |
| 672 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/white-label', |
| 673 | ), |
| 674 | 'info' => array( |
| 675 | 'id' => 'system-info', |
| 676 | 'slug' => $slug . '#tab=system-info', |
| 677 | 'title' => __( 'System Info', 'premium-addons-for-elementor' ), |
| 678 | 'href' => '#tab=system-info', |
| 679 | 'template' => PREMIUM_ADDONS_PATH . 'admin/includes/templates/info', |
| 680 | ), |
| 681 | ); |
| 682 | |
| 683 | self::$tabs = apply_filters( 'pa_admin_register_tabs', self::$tabs ); |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * Add Menu Tabs |
| 688 | * |
| 689 | * Create Submenu Page |
| 690 | * |
| 691 | * @since 3.20.9 |
| 692 | * @access public |
| 693 | * |
| 694 | * @return void |
| 695 | */ |
| 696 | public function add_menu_tabs() { |
| 697 | |
| 698 | $this->set_admin_tabs(); |
| 699 | |
| 700 | $plugin_name = Helper_Functions::name(); |
| 701 | |
| 702 | call_user_func( |
| 703 | 'add_menu_page', |
| 704 | $plugin_name, |
| 705 | $plugin_name, |
| 706 | 'manage_options', |
| 707 | self::$page_slug, |
| 708 | array( $this, 'render_setting_tabs' ), |
| 709 | '', |
| 710 | 100 |
| 711 | ); |
| 712 | |
| 713 | foreach ( self::$tabs as $tab ) { |
| 714 | |
| 715 | call_user_func( |
| 716 | 'add_submenu_page', |
| 717 | self::$page_slug, |
| 718 | $tab['title'], |
| 719 | $tab['title'], |
| 720 | 'manage_options', |
| 721 | $tab['slug'], |
| 722 | '__return_null' |
| 723 | ); |
| 724 | } |
| 725 | |
| 726 | if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 727 | call_user_func( |
| 728 | 'add_submenu_page', |
| 729 | self::$page_slug, |
| 730 | __( 'PA Setup Wizard', 'premium-addons-for-elementor' ), |
| 731 | __( 'Run Setup Wizard', 'premium-addons-for-elementor' ), |
| 732 | 'manage_options', |
| 733 | 'pa-setup-wizard', |
| 734 | array( $this, 'pa_init_setup_wizard' ) |
| 735 | ); |
| 736 | } |
| 737 | |
| 738 | $is_papro_active = apply_filters( 'papro_activated', false ); |
| 739 | |
| 740 | if ( ! $is_papro_active ) { |
| 741 | call_user_func( |
| 742 | 'add_submenu_page', |
| 743 | self::$page_slug, |
| 744 | '<span style="color: #FF6000;" class="pa_pro_upgrade">Upgrade To Pro!</span>', |
| 745 | '<span style="color: #FF6000;" class="pa_pro_upgrade">Upgrade To Pro!</span>', |
| 746 | 'manage_options', |
| 747 | 'https://premiumaddons.com/pro/', |
| 748 | '' |
| 749 | ); |
| 750 | } |
| 751 | |
| 752 | // To remove the main page link from the tabs. |
| 753 | remove_submenu_page( self::$page_slug, self::$page_slug ); |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Initializes the setup wizard Add the PRO popup template. |
| 758 | * |
| 759 | * @access public |
| 760 | * @since 3.20.8 |
| 761 | */ |
| 762 | public function pa_init_setup_wizard() { |
| 763 | |
| 764 | include_once PREMIUM_ADDONS_PATH . 'admin/includes/setup-wizard/main-view.php'; |
| 765 | // Add the PRO popup template. |
| 766 | include_once PREMIUM_ADDONS_PATH . 'admin/includes/templates/pro-popup.php'; |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * Render Setting Tabs. |
| 771 | * |
| 772 | * Render the final HTML content for admin setting tabs. |
| 773 | * |
| 774 | * @access public |
| 775 | * @since 3.20.8 |
| 776 | */ |
| 777 | public function render_setting_tabs() { |
| 778 | |
| 779 | // add the PRO popup template. |
| 780 | include_once PREMIUM_ADDONS_PATH . 'admin/includes/templates/pro-popup.php'; |
| 781 | |
| 782 | ?> |
| 783 | <div class="pa-settings-wrap"> |
| 784 | <?php do_action( 'pa_before_render_admin_tabs' ); ?> |
| 785 | <div class="pa-settings-tabs"> |
| 786 | <ul class="pa-settings-tabs-list"> |
| 787 | <?php |
| 788 | foreach ( self::$tabs as $key => $tab ) { |
| 789 | $link = '<li class="pa-settings-tab">'; |
| 790 | $link .= '<a id="pa-tab-link-' . esc_attr( $tab['id'] ) . '"'; |
| 791 | $link .= ' href="' . esc_url( $tab['href'] ) . '">'; |
| 792 | $link .= '<i class="pa-dash-' . esc_attr( $tab['id'] ) . '"></i>'; |
| 793 | $link .= '<span>' . esc_html( $tab['title'] ) . '</span>'; |
| 794 | $link .= '</a>'; |
| 795 | $link .= '</li>'; |
| 796 | |
| 797 | echo $link; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 798 | } |
| 799 | ?> |
| 800 | </ul> |
| 801 | </div> <!-- Settings Tabs --> |
| 802 | |
| 803 | <div class="pa-settings-sections"> |
| 804 | <?php |
| 805 | foreach ( self::$tabs as $key => $tab ) { |
| 806 | echo '<div id="pa-section-' . esc_attr( $tab['id'] ) . '" class="pa-section pa-section-' . esc_attr( $key ) . '">'; |
| 807 | include_once $tab['template'] . '.php'; |
| 808 | echo '</div>'; |
| 809 | } |
| 810 | ?> |
| 811 | </div> <!-- Settings Sections --> |
| 812 | <?php do_action( 'pa_after_render_admin_tabs' ); ?> |
| 813 | </div> <!-- Settings Wrap --> |
| 814 | <?php |
| 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Render Dashboard Header |
| 819 | * |
| 820 | * @since 4.0.0 |
| 821 | * @access public |
| 822 | */ |
| 823 | public function render_dashboard_header() { |
| 824 | |
| 825 | $show_logo = Helper_Functions::is_hide_logo(); |
| 826 | |
| 827 | ?> |
| 828 | |
| 829 | <div class="papro-admin-notice"> |
| 830 | <?php if ( ! $show_logo ) : ?> |
| 831 | <div class="papro-admin-notice-left"> |
| 832 | <div class="papro-admin-notice-logo"> |
| 833 | <img class="pa-notice-logo" src="<?php echo esc_attr( PREMIUM_ADDONS_URL . 'admin/images/papro-notice-logo.png' ); ?>"> |
| 834 | </div> |
| 835 | <a href="https://premiumaddons.com" target="_blank"></a> |
| 836 | </div> |
| 837 | <?php endif; ?> |
| 838 | |
| 839 | <?php |
| 840 | $banner_content = $this->get_banner_strings(); |
| 841 | |
| 842 | if ( is_array( $banner_content ) ) : |
| 843 | ?> |
| 844 | <div class="papro-admin-notice-right"> |
| 845 | <div class="papro-admin-notice-info"> |
| 846 | <h4> |
| 847 | <?php echo esc_html( $banner_content['title'] ); ?> |
| 848 | </h4> |
| 849 | <p> |
| 850 | <?php echo esc_html( $banner_content['desc'] ); ?> |
| 851 | <span class="papro-sale-notice"><?php echo wp_kses_post( __( 'save 10% on Lifetime!', 'premium-addons-for-elementor' ) ); ?></span> |
| 852 | </p> |
| 853 | </div> |
| 854 | <div class="papro-admin-notice-cta"> |
| 855 | <a class="papro-notice-btn" href="<?php echo esc_url( $banner_content['cta'] ); ?>" target="_blank"> |
| 856 | <?php echo esc_html( $banner_content['btn'] ); ?> |
| 857 | </a> |
| 858 | </div> |
| 859 | </div> |
| 860 | <?php endif; ?> |
| 861 | </div> |
| 862 | |
| 863 | <?php |
| 864 | } |
| 865 | |
| 866 | /** |
| 867 | * Retrieves banner strings. |
| 868 | * |
| 869 | * @access public |
| 870 | * @return array|null |
| 871 | */ |
| 872 | public function get_banner_strings() { |
| 873 | |
| 874 | if ( ! Helper_Functions::check_papro_version() ) { |
| 875 | return array( |
| 876 | 'title' => __( 'Get Premium Addons PRO', 'premium-addons-for-elementor' ), |
| 877 | 'desc' => __( 'Supercharge your Elementor with PRO Widgets & Addons that you won\'t find anywhere else.', 'premium-addons-for-elementor' ), |
| 878 | 'btn' => __( 'Get Pro', 'premium-addons-for-elementor' ), |
| 879 | 'cta' => 'https://premiumaddons.com/get/papro', |
| 880 | ); |
| 881 | } |
| 882 | |
| 883 | $papro_status = get_transient( 'pa_license_check' ); |
| 884 | |
| 885 | if ( ! $papro_status ) { |
| 886 | return; |
| 887 | } |
| 888 | |
| 889 | if ( 'invalid' === $papro_status ) { |
| 890 | |
| 891 | return array( |
| 892 | 'title' => __( 'You\'re Missing Out on the Official Pro Version!', 'premium-addons-for-elementor' ), |
| 893 | 'desc' => __( 'It looks like you\'re using Premium Addons Pro, but it was not purchased from our official website. Get official version to receive updates, support and use Premium Templates!', 'premium-addons-for-elementor' ), |
| 894 | 'btn' => __( 'Get Pro', 'premium-addons-for-elementor' ), |
| 895 | 'cta' => 'https://premiumaddons.com/validate/papro', |
| 896 | ); |
| 897 | |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * Save Settings. |
| 903 | * |
| 904 | * Save elements settings using AJAX. |
| 905 | * |
| 906 | * @access public |
| 907 | * @since 3.20.8 |
| 908 | */ |
| 909 | public function save_settings() { |
| 910 | |
| 911 | check_ajax_referer( 'pa-settings-tab', 'security' ); |
| 912 | |
| 913 | if ( ! isset( $_POST['fields'] ) ) { |
| 914 | return; |
| 915 | } |
| 916 | |
| 917 | parse_str( sanitize_text_field( wp_unslash( $_POST['fields'] ) ), $settings ); |
| 918 | |
| 919 | $defaults = self::get_default_keys(); |
| 920 | |
| 921 | $elements = array_fill_keys( array_keys( array_intersect_key( $settings, $defaults ) ), true ); |
| 922 | |
| 923 | update_option( 'pa_save_settings', $elements ); |
| 924 | |
| 925 | // Save the global addons only if it's the second run. |
| 926 | $is_second_run = get_option( 'pa_complete_wizard' ) ? false : true; |
| 927 | if ( $is_second_run ) { |
| 928 | self::update_global_addons_option( $settings ); |
| 929 | } else { |
| 930 | update_option( 'pa_complete_wizard', false ); |
| 931 | } |
| 932 | |
| 933 | wp_send_json_success(); |
| 934 | } |
| 935 | |
| 936 | private static function update_global_addons_option( $settings ) { |
| 937 | |
| 938 | $global_addons = array( |
| 939 | 'premium-mscroll', |
| 940 | 'premium-templates', |
| 941 | 'pa-display-conditions', |
| 942 | 'premium-equal-height', |
| 943 | 'premium-global-cursor', |
| 944 | 'premium-global-badge', |
| 945 | 'premium-shape-divider', |
| 946 | 'premium-global-tooltips', |
| 947 | 'premium-floating-effects', |
| 948 | 'premium-cross-domain', |
| 949 | 'premium-duplicator', |
| 950 | 'premium-wrapper-link', |
| 951 | 'premium-assets-generator' |
| 952 | ); |
| 953 | |
| 954 | $features = array(); |
| 955 | foreach ( $global_addons as $feature ) { |
| 956 | if ( isset( $settings[ $feature ] ) && 'on' === $settings[ $feature ] ) { |
| 957 | $features[] = $feature; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | update_option( 'pa_saved_features', $features ); |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Save Integrations Control Settings |
| 966 | * |
| 967 | * Stores integration and version control settings |
| 968 | * |
| 969 | * @since 3.20.8 |
| 970 | * @access public |
| 971 | */ |
| 972 | public function save_additional_settings() { |
| 973 | |
| 974 | check_ajax_referer( 'pa-settings-tab', 'security' ); |
| 975 | |
| 976 | if ( ! isset( $_POST['fields'] ) ) { |
| 977 | return; |
| 978 | } |
| 979 | |
| 980 | parse_str( sanitize_text_field( wp_unslash( $_POST['fields'] ) ), $settings ); |
| 981 | |
| 982 | $new_settings = array( |
| 983 | 'premium-map-api' => sanitize_text_field( $settings['premium-map-api'] ), |
| 984 | 'premium-youtube-api' => sanitize_text_field( $settings['premium-youtube-api'] ), |
| 985 | 'premium-map-disable-api' => intval( $settings['premium-map-disable-api'] ? 1 : 0 ), |
| 986 | 'premium-map-cluster' => intval( $settings['premium-map-cluster'] ? 1 : 0 ), |
| 987 | 'premium-wp-optimize-exclude' => intval( $settings['premium-wp-optimize-exclude'] ? 1 : 0 ), |
| 988 | 'premium-map-locale' => sanitize_text_field( $settings['premium-map-locale'] ), |
| 989 | 'is-beta-tester' => intval( $settings['is-beta-tester'] ? 1 : 0 ), |
| 990 | ); |
| 991 | |
| 992 | update_option( 'pa_maps_save_settings', $new_settings ); |
| 993 | |
| 994 | wp_send_json_success( $settings ); |
| 995 | } |
| 996 | |
| 997 | /** |
| 998 | * Save Global Button Value |
| 999 | * |
| 1000 | * Saves value for elements global switcher |
| 1001 | * |
| 1002 | * @since 4.0.0 |
| 1003 | * @access public |
| 1004 | */ |
| 1005 | public function save_global_btn_value() { |
| 1006 | |
| 1007 | check_ajax_referer( 'pa-settings-tab', 'security' ); |
| 1008 | |
| 1009 | if ( ! isset( $_POST['isGlobalOn'] ) ) { |
| 1010 | wp_send_json_error(); |
| 1011 | } |
| 1012 | |
| 1013 | $global_btn_value = sanitize_text_field( wp_unslash( $_POST['isGlobalOn'] ) ); |
| 1014 | |
| 1015 | update_option( 'pa_global_btn_value', $global_btn_value ); |
| 1016 | |
| 1017 | wp_send_json_success(); |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * Get default Elements |
| 1022 | * |
| 1023 | * @since 3.20.9 |
| 1024 | * @access private |
| 1025 | * |
| 1026 | * @return $default_keys array keys defaults |
| 1027 | */ |
| 1028 | private static function get_default_keys() { |
| 1029 | |
| 1030 | $elements = self::get_elements_keys(); |
| 1031 | |
| 1032 | $keys = array(); |
| 1033 | |
| 1034 | // Now, we need to fill our array with elements keys. |
| 1035 | |
| 1036 | foreach ( $elements as $elem ) { |
| 1037 | |
| 1038 | array_push( $keys, $elem['key'] ); |
| 1039 | |
| 1040 | if ( isset( $elem['draw_svg'] ) ) { |
| 1041 | array_push( $keys, 'svg_' . $elem['key'] ); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | $default_keys = array_fill_keys( $keys, true ); |
| 1046 | |
| 1047 | $default_keys['pa_mc_temp'] = false; |
| 1048 | |
| 1049 | return $default_keys; |
| 1050 | } |
| 1051 | |
| 1052 | /** |
| 1053 | * Get Pro Elements. |
| 1054 | * Return PAPRO Widgets. |
| 1055 | * |
| 1056 | * @since 4.5.3 |
| 1057 | * @access public |
| 1058 | * |
| 1059 | * @return array |
| 1060 | */ |
| 1061 | public static function get_pro_elements() { |
| 1062 | |
| 1063 | $elements = self::get_elements_list(); |
| 1064 | |
| 1065 | $pro_elements = array(); |
| 1066 | |
| 1067 | $all_elements = $elements['cat-1']; |
| 1068 | |
| 1069 | if ( count( $all_elements['elements'] ) ) { |
| 1070 | foreach ( $all_elements['elements'] as $elem ) { |
| 1071 | if ( isset( $elem['is_pro'] ) && ! isset( $elem['is_global'] ) ) { |
| 1072 | $elem['categories'] = '["premium-elements"]'; |
| 1073 | array_push( $pro_elements, $elem ); |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | return $pro_elements; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * Get PA Free Elements. |
| 1083 | * Return PA Widgets. |
| 1084 | * |
| 1085 | * @since 4.6.1 |
| 1086 | * @access public |
| 1087 | * |
| 1088 | * @return array |
| 1089 | */ |
| 1090 | public static function get_free_widgets_names() { |
| 1091 | |
| 1092 | $elements = self::get_elements_list()['cat-1']['elements']; |
| 1093 | |
| 1094 | $pa_elements = array(); |
| 1095 | |
| 1096 | if ( count( $elements ) ) { |
| 1097 | foreach ( $elements as $elem ) { |
| 1098 | if ( ! isset( $elem['is_pro'] ) && ! isset( $elem['is_global'] ) && isset( $elem['name'] ) ) { |
| 1099 | array_push( $pa_elements, $elem['name'] ); |
| 1100 | } |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | return $pa_elements; |
| 1105 | } |
| 1106 | |
| 1107 | /** |
| 1108 | * Get Info By Key. |
| 1109 | * |
| 1110 | * Returns elements by its key. |
| 1111 | * |
| 1112 | * @since 4.10.49 |
| 1113 | * @access public |
| 1114 | * |
| 1115 | * @param string $key element key. |
| 1116 | * |
| 1117 | * @return array |
| 1118 | */ |
| 1119 | public static function get_info_by_key( $key ) { |
| 1120 | |
| 1121 | $elements = self::get_elements_list()['cat-1']['elements']; |
| 1122 | |
| 1123 | $element = false; |
| 1124 | |
| 1125 | foreach ( $elements as $elem ) { |
| 1126 | |
| 1127 | if ( $key === $elem['name'] ) { |
| 1128 | $element = $elem; |
| 1129 | break; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | return $element; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
| 1137 | * Get Global Elements Switchers. |
| 1138 | * Construct an associative array of addon_switcher => 'yes' pairs |
| 1139 | * Example : |
| 1140 | * + array( 'premium_gradient_switcher' => yes'). |
| 1141 | * |
| 1142 | * @since 4.6.1 |
| 1143 | * @access public |
| 1144 | * |
| 1145 | * @return array |
| 1146 | */ |
| 1147 | public static function get_global_elements_switchers() { |
| 1148 | |
| 1149 | $elements = self::get_elements_list()['cat-4']; |
| 1150 | |
| 1151 | $global_elems = array(); |
| 1152 | |
| 1153 | if ( count( $elements['elements'] ) ) { |
| 1154 | foreach ( $elements['elements'] as $elem ) { |
| 1155 | if ( isset( $elem['is_pro'] ) && isset( $elem['is_global'] ) ) { |
| 1156 | $global_elems[ str_replace( '-', '_', $elem['key'] ) . '_switcher' ] = 'yes'; |
| 1157 | } |
| 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | return $global_elems; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * Get Default Integrations |
| 1166 | * |
| 1167 | * @since 3.20.9 |
| 1168 | * @access private |
| 1169 | * |
| 1170 | * @return $default_keys array default keys |
| 1171 | */ |
| 1172 | private static function get_default_integrations() { |
| 1173 | |
| 1174 | $settings = self::get_integrations_list(); |
| 1175 | |
| 1176 | $default_keys = array_fill_keys( $settings, true ); |
| 1177 | |
| 1178 | // Beta Tester should NOT be enabled by default. |
| 1179 | $default_keys['is-beta-tester'] = false; |
| 1180 | |
| 1181 | return $default_keys; |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * Get enabled widgets |
| 1186 | * |
| 1187 | * @since 3.20.9 |
| 1188 | * @access public |
| 1189 | * |
| 1190 | * @return array $enabled_keys enabled elements |
| 1191 | */ |
| 1192 | public static function get_enabled_elements() { |
| 1193 | |
| 1194 | if ( null === self::$enabled_elements ) { |
| 1195 | |
| 1196 | $defaults = self::get_default_keys(); |
| 1197 | |
| 1198 | $enabled_keys = get_option( 'pa_save_settings', $defaults ); |
| 1199 | |
| 1200 | foreach ( $defaults as $key => $value ) { |
| 1201 | |
| 1202 | if ( 'pa_mc_temp' !== $key && ! isset( $enabled_keys[ $key ] ) ) { |
| 1203 | $defaults[ $key ] = 0; |
| 1204 | } elseif ( 'pa_mc_temp' === $key && isset( $enabled_keys[ $key ] ) && $enabled_keys[ $key ] ) { |
| 1205 | $defaults[ $key ] = 1; |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | self::$enabled_elements = $defaults; |
| 1210 | |
| 1211 | } |
| 1212 | |
| 1213 | return self::$enabled_elements; |
| 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Check Elementor By Key |
| 1218 | * |
| 1219 | * @since 4.10.52 |
| 1220 | * @access public |
| 1221 | * |
| 1222 | * @return string $key element key. |
| 1223 | */ |
| 1224 | public static function check_element_by_key( $key ) { |
| 1225 | |
| 1226 | if ( ! $key ) { |
| 1227 | return; |
| 1228 | } |
| 1229 | |
| 1230 | $settings = self::get_enabled_elements(); |
| 1231 | |
| 1232 | if ( ! isset( $settings[ $key ] ) ) { |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
| 1236 | return $settings[ $key ]; |
| 1237 | } |
| 1238 | |
| 1239 | /** |
| 1240 | * Check SVG Draw. |
| 1241 | * |
| 1242 | * @since 4.9.26 |
| 1243 | * @access public |
| 1244 | * |
| 1245 | * @param string $key element key. |
| 1246 | * |
| 1247 | * @return boolean $is_enabled is option enabled. |
| 1248 | */ |
| 1249 | public static function check_svg_draw( $key ) { |
| 1250 | |
| 1251 | $is_enabled = self::check_element_by_key( 'svg_' . $key ); |
| 1252 | |
| 1253 | return $is_enabled; |
| 1254 | } |
| 1255 | |
| 1256 | /** |
| 1257 | * Check If Premium Templates is enabled |
| 1258 | * |
| 1259 | * @since 3.6.0 |
| 1260 | * @access public |
| 1261 | * |
| 1262 | * @return boolean |
| 1263 | */ |
| 1264 | public static function check_premium_templates() { |
| 1265 | |
| 1266 | $settings = self::get_enabled_elements(); |
| 1267 | |
| 1268 | if ( ! isset( $settings['premium-templates'] ) ) { |
| 1269 | return true; |
| 1270 | } |
| 1271 | |
| 1272 | $is_enabled = $settings['premium-templates']; |
| 1273 | |
| 1274 | return $is_enabled; |
| 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | /** |
| 1279 | * Check If Premium Duplicator is enabled |
| 1280 | * |
| 1281 | * @since 3.20.9 |
| 1282 | * @access public |
| 1283 | * |
| 1284 | * @return boolean |
| 1285 | */ |
| 1286 | public static function check_duplicator() { |
| 1287 | |
| 1288 | $settings = self::get_enabled_elements(); |
| 1289 | |
| 1290 | if ( ! isset( $settings['premium-duplicator'] ) ) { |
| 1291 | return true; |
| 1292 | } |
| 1293 | |
| 1294 | $is_enabled = $settings['premium-duplicator']; |
| 1295 | |
| 1296 | return $is_enabled; |
| 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Check If Premium Duplicator is enabled |
| 1301 | * |
| 1302 | * @since 4.9.4 |
| 1303 | * @access public |
| 1304 | * |
| 1305 | * @return boolean |
| 1306 | */ |
| 1307 | public static function check_dynamic_assets() { |
| 1308 | |
| 1309 | $settings = self::get_enabled_elements(); |
| 1310 | |
| 1311 | if ( ! isset( $settings['premium-assets-generator'] ) ) { |
| 1312 | return false; |
| 1313 | } |
| 1314 | |
| 1315 | $is_enabled = $settings['premium-assets-generator']; |
| 1316 | |
| 1317 | return $is_enabled; |
| 1318 | } |
| 1319 | |
| 1320 | /** |
| 1321 | * Get Integrations Settings. |
| 1322 | * |
| 1323 | * Get plugin integrations settings. |
| 1324 | * |
| 1325 | * @since 3.20.9 |
| 1326 | * @access public |
| 1327 | * |
| 1328 | * @return array $settings integrations settings. |
| 1329 | */ |
| 1330 | public static function get_integrations_settings() { |
| 1331 | |
| 1332 | if ( null === self::$integrations_settings ) { |
| 1333 | |
| 1334 | $defaults = self::get_default_integrations(); |
| 1335 | |
| 1336 | $enabled_keys = get_option( 'pa_maps_save_settings', $defaults ); |
| 1337 | |
| 1338 | foreach ( $defaults as $key => $value ) { |
| 1339 | |
| 1340 | if ( isset( $enabled_keys[ $key ] ) ) { |
| 1341 | |
| 1342 | $defaults[ $key ] = $enabled_keys[ $key ]; |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | self::$integrations_settings = $defaults; |
| 1347 | |
| 1348 | } |
| 1349 | |
| 1350 | return self::$integrations_settings; |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * Run PA Rollback |
| 1355 | * |
| 1356 | * Trigger PA Rollback actions |
| 1357 | * |
| 1358 | * @since 4.2.5 |
| 1359 | * @access public |
| 1360 | */ |
| 1361 | public function run_pa_rollback() { |
| 1362 | |
| 1363 | check_admin_referer( 'premium_addons_rollback' ); |
| 1364 | |
| 1365 | $plugin_slug = basename( PREMIUM_ADDONS_FILE, '.php' ); |
| 1366 | |
| 1367 | $pa_rollback = new PA_Rollback( |
| 1368 | array( |
| 1369 | 'version' => PREMIUM_ADDONS_STABLE_VERSION, |
| 1370 | 'plugin_name' => PREMIUM_ADDONS_BASENAME, |
| 1371 | 'plugin_slug' => $plugin_slug, |
| 1372 | 'package_url' => sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $plugin_slug, PREMIUM_ADDONS_STABLE_VERSION ), |
| 1373 | ) |
| 1374 | ); |
| 1375 | |
| 1376 | $pa_rollback->run(); |
| 1377 | |
| 1378 | wp_die( |
| 1379 | '', |
| 1380 | esc_html( __( 'Rollback to Previous Version', 'premium-addons-for-elementor' ) ), |
| 1381 | array( |
| 1382 | 'response' => 200, |
| 1383 | ) |
| 1384 | ); |
| 1385 | } |
| 1386 | |
| 1387 | /** |
| 1388 | * Disable unused widgets. |
| 1389 | * |
| 1390 | * @access public |
| 1391 | * @since 4.5.8 |
| 1392 | */ |
| 1393 | public function get_unused_widgets() { |
| 1394 | |
| 1395 | check_ajax_referer( 'pa-disable-unused', 'security' ); |
| 1396 | |
| 1397 | if ( ! current_user_can( 'install_plugins' ) ) { |
| 1398 | wp_send_json_error(); |
| 1399 | } |
| 1400 | |
| 1401 | $pa_elements = self::get_pa_elements_names(); |
| 1402 | |
| 1403 | $used_widgets = self::get_used_widgets(); |
| 1404 | |
| 1405 | $unused_widgets = array_diff( $pa_elements, array_keys( $used_widgets ) ); |
| 1406 | |
| 1407 | wp_send_json_success( $unused_widgets ); |
| 1408 | } |
| 1409 | |
| 1410 | /** |
| 1411 | * Disables Elementor Custom Mini Cart Template. |
| 1412 | * |
| 1413 | * @access public |
| 1414 | * @since 4.11.6 |
| 1415 | * @see ElementorPro\Modules\Woocommerce\Module [elementor-pro\modules\woocommerce\module.php]. |
| 1416 | */ |
| 1417 | public function disable_elementor_mc_template() { |
| 1418 | |
| 1419 | check_ajax_referer( 'pa-settings-tab', 'security' ); |
| 1420 | |
| 1421 | update_option( 'elementor_use_mini_cart_template', 'no' ); |
| 1422 | |
| 1423 | wp_send_json_success( 'Elementor Mini Cart Template Disabled.' ); |
| 1424 | } |
| 1425 | |
| 1426 | /** |
| 1427 | * Clear Cached Assets. |
| 1428 | * |
| 1429 | * Deletes assets options from DB And |
| 1430 | * deletes assets files from uploads/premium-addons-for-elementor via AJAX |
| 1431 | * diretory. |
| 1432 | * |
| 1433 | * @access public |
| 1434 | * @since 4.9.3 |
| 1435 | */ |
| 1436 | public function clear_cached_assets() { |
| 1437 | |
| 1438 | check_ajax_referer( 'pa-generate-nonce', 'security' ); |
| 1439 | |
| 1440 | $post_id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : ''; |
| 1441 | |
| 1442 | $this->clear_dynamic_assets_data( $post_id ); |
| 1443 | |
| 1444 | wp_send_json_success( 'Cached Assets Cleared' ); |
| 1445 | } |
| 1446 | |
| 1447 | /** |
| 1448 | * Clear Dynamic Assets Data. |
| 1449 | * |
| 1450 | * Deletes assets options from DB And |
| 1451 | * deletes assets files from uploads/premium-addons-for-elementor |
| 1452 | * diretory. |
| 1453 | * |
| 1454 | * @access public |
| 1455 | * @since 4.10.51 |
| 1456 | * |
| 1457 | * @param string $id post ID. |
| 1458 | */ |
| 1459 | public function clear_dynamic_assets_data( $id = '' ) { |
| 1460 | |
| 1461 | if ( ! current_user_can( 'manage_options' ) ) { |
| 1462 | wp_send_json_error( __( 'You are not allowed to do this action', 'premium-addons-for-elementor' ) ); |
| 1463 | } |
| 1464 | |
| 1465 | if ( empty( $id ) ) { |
| 1466 | $this->delete_assets_options(); |
| 1467 | } |
| 1468 | |
| 1469 | $this->delete_assets_files( $id ); |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * Clear Cached Assets. |
| 1474 | * |
| 1475 | * Deletes assets options from DB And |
| 1476 | * deletes assets files from uploads/premium-addons-for-elementor |
| 1477 | * diretory. |
| 1478 | * |
| 1479 | * @access public |
| 1480 | * @since 4.9.3 |
| 1481 | */ |
| 1482 | public function clear_site_cursor_settings() { |
| 1483 | |
| 1484 | check_ajax_referer( 'pa-site-cursor-nonce', 'security' ); |
| 1485 | |
| 1486 | if ( ! current_user_can( 'manage_options' ) ) { |
| 1487 | wp_send_json_error( __( 'You are not allowed to do this action', 'premium-addons-for-elementor' ) ); |
| 1488 | } |
| 1489 | |
| 1490 | delete_option( 'pa_site_custom_cursor' ); |
| 1491 | |
| 1492 | wp_send_json_success( 'Site Cursor Settings Cleared' ); |
| 1493 | } |
| 1494 | |
| 1495 | /** |
| 1496 | * Delete Assets Options. |
| 1497 | * |
| 1498 | * @access public |
| 1499 | * @since 4.9.3 |
| 1500 | */ |
| 1501 | public function delete_assets_options() { |
| 1502 | |
| 1503 | global $wpdb; |
| 1504 | |
| 1505 | $query = $wpdb->prepare( |
| 1506 | "DELETE FROM $wpdb->options |
| 1507 | WHERE (option_name LIKE %s OR option_name LIKE %s) |
| 1508 | AND autoload = %s", |
| 1509 | '%pa_elements_%', |
| 1510 | '%pa_edit_%', |
| 1511 | 'no' |
| 1512 | ); |
| 1513 | |
| 1514 | $wpdb->query( $query ); // phpcs:ignore |
| 1515 | } |
| 1516 | |
| 1517 | /** |
| 1518 | * Delete Assets Files. |
| 1519 | * |
| 1520 | * @access public |
| 1521 | * @since 4.6.1 |
| 1522 | * |
| 1523 | * @param string $id post id. |
| 1524 | */ |
| 1525 | public function delete_assets_files( $id ) { |
| 1526 | |
| 1527 | $path = PREMIUM_ASSETS_PATH; |
| 1528 | |
| 1529 | if ( ! is_dir( $path ) || ! file_exists( $path ) ) { |
| 1530 | return; |
| 1531 | } |
| 1532 | |
| 1533 | if ( empty( $id ) ) { |
| 1534 | foreach ( scandir( $path ) as $file ) { |
| 1535 | if ( '.' === $file || '..' === $file ) { |
| 1536 | continue; |
| 1537 | } |
| 1538 | |
| 1539 | wp_delete_file( Helper_Functions::get_safe_path( $path . DIRECTORY_SEPARATOR . $file ) ); |
| 1540 | } |
| 1541 | } else { |
| 1542 | |
| 1543 | $id = Helper_Functions::generate_unique_id( 'pa_assets_' . $id ); |
| 1544 | |
| 1545 | $arr = array(); |
| 1546 | foreach ( glob( PREMIUM_ASSETS_PATH . '/*' . $id . '*' ) as $file ) { |
| 1547 | wp_delete_file( Helper_Functions::get_safe_path( $file ) ); |
| 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | /** |
| 1553 | * Get PA widget names. |
| 1554 | * |
| 1555 | * @access public |
| 1556 | * @since 4.5.8 |
| 1557 | * |
| 1558 | * @return array |
| 1559 | */ |
| 1560 | public static function get_pa_elements_names() { |
| 1561 | |
| 1562 | $names = self::$elements_names; |
| 1563 | |
| 1564 | if ( null === $names ) { |
| 1565 | |
| 1566 | $names = array_map( |
| 1567 | function ( $item ) { |
| 1568 | return isset( $item['name'] ) ? $item['name'] : 'global'; |
| 1569 | }, |
| 1570 | self::get_elements_list()['cat-1']['elements'] |
| 1571 | ); |
| 1572 | |
| 1573 | $names = array_filter( |
| 1574 | $names, |
| 1575 | function ( $name ) { |
| 1576 | return 'global' !== $name; |
| 1577 | } |
| 1578 | ); |
| 1579 | |
| 1580 | } |
| 1581 | |
| 1582 | return $names; |
| 1583 | } |
| 1584 | |
| 1585 | /** |
| 1586 | * Get used widgets. |
| 1587 | * |
| 1588 | * @access public |
| 1589 | * @since 4.5.8 |
| 1590 | * |
| 1591 | * @return array |
| 1592 | */ |
| 1593 | public static function get_used_widgets() { |
| 1594 | |
| 1595 | $used_widgets = array(); |
| 1596 | |
| 1597 | if ( class_exists( 'Elementor\Modules\Usage\Module' ) ) { |
| 1598 | |
| 1599 | $module = Module::instance(); |
| 1600 | |
| 1601 | $module->recalc_usage(); |
| 1602 | |
| 1603 | $elements = $module->get_formatted_usage( 'raw' ); |
| 1604 | |
| 1605 | $pa_elements = self::get_pa_elements_names(); |
| 1606 | |
| 1607 | if ( is_array( $elements ) || is_object( $elements ) ) { |
| 1608 | |
| 1609 | foreach ( $elements as $post_type => $data ) { |
| 1610 | |
| 1611 | foreach ( $data['elements'] as $element => $count ) { |
| 1612 | |
| 1613 | if ( in_array( $element, $pa_elements, true ) ) { |
| 1614 | |
| 1615 | if ( isset( $used_widgets[ $element ] ) ) { |
| 1616 | $used_widgets[ $element ] += $count; |
| 1617 | } else { |
| 1618 | $used_widgets[ $element ] = $count; |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | return $used_widgets; |
| 1627 | } |
| 1628 | |
| 1629 | /** |
| 1630 | * Subscribe Newsletter |
| 1631 | * |
| 1632 | * Adds an email to Premium Addons subscribers list |
| 1633 | * |
| 1634 | * @since 4.7.0 |
| 1635 | * |
| 1636 | * @access public |
| 1637 | */ |
| 1638 | public function subscribe_newsletter() { |
| 1639 | |
| 1640 | check_ajax_referer( 'pa-settings-tab', 'security' ); |
| 1641 | |
| 1642 | if ( ! self::check_user_can( 'manage_options' ) ) { |
| 1643 | wp_send_json_error(); |
| 1644 | } |
| 1645 | |
| 1646 | $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; |
| 1647 | |
| 1648 | $api_url = 'https://premiumaddons.com/wp-json/mailchimp/v2/add'; |
| 1649 | |
| 1650 | $request = add_query_arg( |
| 1651 | array( |
| 1652 | 'email' => $email, |
| 1653 | ), |
| 1654 | $api_url |
| 1655 | ); |
| 1656 | |
| 1657 | $response = wp_remote_get( |
| 1658 | $request, |
| 1659 | array( |
| 1660 | 'timeout' => 15, |
| 1661 | 'sslverify' => true, |
| 1662 | ) |
| 1663 | ); |
| 1664 | |
| 1665 | $body = wp_remote_retrieve_body( $response ); |
| 1666 | $body = json_decode( $body, true ); |
| 1667 | |
| 1668 | wp_send_json_success( $body ); |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * Get PA News |
| 1673 | * |
| 1674 | * Gets a list of the latest three blog posts |
| 1675 | * |
| 1676 | * @since 4.7.0 |
| 1677 | * |
| 1678 | * @access public |
| 1679 | */ |
| 1680 | public function get_pa_news() { |
| 1681 | |
| 1682 | $posts = get_transient( 'pa_news' ); |
| 1683 | |
| 1684 | if ( empty( $posts ) ) { |
| 1685 | |
| 1686 | $api_url = 'https://premiumaddons.com/wp-json/wp/v2/posts'; |
| 1687 | |
| 1688 | $request = add_query_arg( |
| 1689 | array( |
| 1690 | 'per_page' => 3, |
| 1691 | 'categories' => 32, |
| 1692 | ), |
| 1693 | $api_url |
| 1694 | ); |
| 1695 | |
| 1696 | $response = wp_remote_get( |
| 1697 | $request, |
| 1698 | array( |
| 1699 | 'timeout' => 15, |
| 1700 | 'sslverify' => true, |
| 1701 | ) |
| 1702 | ); |
| 1703 | |
| 1704 | if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { |
| 1705 | set_transient( 'pa_news', true, WEEK_IN_SECONDS ); |
| 1706 | return; |
| 1707 | } |
| 1708 | |
| 1709 | $body = wp_remote_retrieve_body( $response ); |
| 1710 | $posts = json_decode( $body, true ); |
| 1711 | |
| 1712 | set_transient( 'pa_news', $posts, WEEK_IN_SECONDS ); |
| 1713 | |
| 1714 | } |
| 1715 | |
| 1716 | return $posts; |
| 1717 | } |
| 1718 | |
| 1719 | /** |
| 1720 | * Creates and returns an instance of the class |
| 1721 | * |
| 1722 | * @since 1.0.0 |
| 1723 | * @access public |
| 1724 | * |
| 1725 | * @return object |
| 1726 | */ |
| 1727 | public static function get_instance() { |
| 1728 | |
| 1729 | if ( ! isset( self::$instance ) ) { |
| 1730 | |
| 1731 | self::$instance = new self(); |
| 1732 | |
| 1733 | } |
| 1734 | |
| 1735 | return self::$instance; |
| 1736 | } |
| 1737 | } |
| 1738 |