controls
2 months ago
extras
1 month ago
helpers
1 week ago
pa-display-conditions
1 month ago
templates
1 month ago
addons-integration.php
1 week ago
assets-manager.php
3 weeks ago
class-pa-core.php
1 month ago
helper-functions.php
3 weeks ago
module-base.php
2 months ago
premium-template-tags.php
1 week ago
promotion-pointer.php
3 weeks ago
addons-integration.php
538 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Addons Integration. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes; |
| 7 | |
| 8 | use PremiumAddons\Admin\Includes\Admin_Helper; |
| 9 | use PremiumAddons\Includes\Helpers\AJAX_Helper; |
| 10 | use PremiumAddons\Modules\Woocommerce\Module as Woocommerce; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit(); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * Class Addons_Integration. |
| 18 | */ |
| 19 | class Addons_Integration { |
| 20 | |
| 21 | use AJAX_Helper; |
| 22 | |
| 23 | /** |
| 24 | * Class instance |
| 25 | * |
| 26 | * @var instance |
| 27 | */ |
| 28 | private static $instance = null; |
| 29 | |
| 30 | /** |
| 31 | * CSS Content |
| 32 | * |
| 33 | * @var css_content |
| 34 | */ |
| 35 | private static $css_content = null; |
| 36 | |
| 37 | /** |
| 38 | * Modules |
| 39 | * |
| 40 | * @var modules |
| 41 | */ |
| 42 | private static $modules = null; |
| 43 | |
| 44 | /** |
| 45 | * Integrations Keys |
| 46 | * |
| 47 | * @var integrations |
| 48 | */ |
| 49 | private static $integrations = null; |
| 50 | |
| 51 | /** |
| 52 | * Initialize integration hooks |
| 53 | * |
| 54 | * @return void |
| 55 | */ |
| 56 | public function __construct() { |
| 57 | |
| 58 | if ( ! Helper_Functions::check_elementor_version() ) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ( null === self::$modules ) { |
| 63 | self::$modules = Admin_Helper::get_enabled_elements(); |
| 64 | self::$integrations = Admin_Helper::get_integrations_settings(); |
| 65 | } |
| 66 | |
| 67 | $this->register_hooks(); |
| 68 | |
| 69 | $this->register_ajax_hooks(); |
| 70 | |
| 71 | $this->load_extensions(); |
| 72 | |
| 73 | // Promote PAPRO Elements. |
| 74 | add_filter( 'elementor/editor/localize_settings', array( $this, 'add_papro_elements' ) ); |
| 75 | |
| 76 | // Handle everything related to widgets assets. |
| 77 | Assets_Manager::get_instance( self::$modules, self::$integrations ); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Register Hooks |
| 82 | * |
| 83 | * @since 4.11.53 |
| 84 | * @access public |
| 85 | */ |
| 86 | public function register_hooks() { |
| 87 | |
| 88 | // Load Editor CSS Files. |
| 89 | add_action( 'elementor/preview/enqueue_styles', array( $this, 'enqueue_preview_styles' ) ); |
| 90 | add_action( 'elementor/editor/before_enqueue_styles', array( $this, 'enqueue_editor_styles' ) ); |
| 91 | |
| 92 | // Load Editor JS Files. |
| 93 | add_action( 'elementor/editor/before_enqueue_scripts', array( $this, 'before_enqueue_scripts' ) ); |
| 94 | add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'after_enqueue_scripts' ) ); |
| 95 | |
| 96 | // Register Controls and Widgets Area. |
| 97 | add_action( 'elementor/elements/categories_registered', array( $this, 'register_widgets_category' ), 9 ); |
| 98 | add_action( 'elementor/controls/register', array( $this, 'register_controls' ) ); |
| 99 | add_action( 'elementor/widgets/register', array( $this, 'register_widgets' ) ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * After Enqueue Scripts |
| 104 | * |
| 105 | * Loads editor scripts for our controls. |
| 106 | * |
| 107 | * @access public |
| 108 | * @return void |
| 109 | */ |
| 110 | public function after_enqueue_scripts() { |
| 111 | |
| 112 | wp_enqueue_script( |
| 113 | 'pa-controls-handlers', |
| 114 | PREMIUM_ADDONS_URL . 'assets/editor/js/controls-handlers.js', |
| 115 | array( 'elementor-editor', 'jquery' ), |
| 116 | PREMIUM_ADDONS_VERSION, |
| 117 | true |
| 118 | ); |
| 119 | |
| 120 | wp_localize_script( |
| 121 | 'pa-controls-handlers', |
| 122 | 'PremiumSettings', |
| 123 | array( |
| 124 | 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
| 125 | 'nonce' => wp_create_nonce( 'pa-blog-widget-nonce' ), |
| 126 | 'upgrade_link' => Helper_Functions::get_campaign_link( 'https://premiumaddons.com/pro/', '', 'wp-editor', 'get-pro' ), |
| 127 | ) |
| 128 | ); |
| 129 | |
| 130 | $data = array( |
| 131 | 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
| 132 | 'nonce' => wp_create_nonce( 'pa-editor' ), |
| 133 | ); |
| 134 | |
| 135 | wp_enqueue_script( |
| 136 | 'pa-editor-handler', |
| 137 | PREMIUM_ADDONS_URL . 'assets/editor/js/editor-handler.js', |
| 138 | array( 'elementor-editor' ), |
| 139 | PREMIUM_ADDONS_VERSION, |
| 140 | true |
| 141 | ); |
| 142 | |
| 143 | wp_localize_script( 'pa-editor-handler', 'paEditorSettings', $data ); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Loads plugin icons font |
| 148 | * |
| 149 | * @since 1.0.0 |
| 150 | * @access public |
| 151 | * @return void |
| 152 | */ |
| 153 | public function enqueue_editor_styles() { |
| 154 | |
| 155 | $theme = Helper_Functions::get_elementor_ui_theme(); |
| 156 | |
| 157 | wp_enqueue_style( |
| 158 | 'pa-editor', |
| 159 | PREMIUM_ADDONS_URL . 'assets/editor/css/style.css', |
| 160 | array(), |
| 161 | PREMIUM_ADDONS_VERSION |
| 162 | ); |
| 163 | |
| 164 | // Enqueue required style for Elementor dark UI Theme. |
| 165 | if ( 'dark' === $theme ) { |
| 166 | |
| 167 | wp_add_inline_style( |
| 168 | 'pa-editor', |
| 169 | '.elementor-panel .elementor-control-section_pa_docs .elementor-panel-heading-title.elementor-panel-heading-title, |
| 170 | .elementor-control-raw-html.editor-pa-doc a { |
| 171 | color: #e0e1e3 !important; |
| 172 | } |
| 173 | [class^="pa-"]::after, |
| 174 | [class*=" pa-"]::after { |
| 175 | color: #aaa; |
| 176 | opacity: 1 !important; |
| 177 | } |
| 178 | .premium-promotion-dialog .premium-promotion-btn { |
| 179 | background-color: #202124 !important |
| 180 | } |
| 181 | .premium-promote-ctas .elementor-button.premium-promote-upgrade:hover { |
| 182 | background-color: #999C9E !important; |
| 183 | } |
| 184 | .premium-promote-ctas .elementor-button.premium-promote-demo { |
| 185 | color: #BFC3C7 !important; |
| 186 | background-color: #373C41 !important; |
| 187 | border: 1px solid rgba(154, 157, 160, 0.5) !important; |
| 188 | } |
| 189 | |
| 190 | .premium-promote-ctas .elementor-button.premium-promote-demo:hover { |
| 191 | background-color: #2B2E32 !important; |
| 192 | }' |
| 193 | ); |
| 194 | |
| 195 | } |
| 196 | |
| 197 | $badge_text = Helper_Functions::get_badge(); |
| 198 | |
| 199 | $dynamic_css = sprintf( '.elementor-element-wrapper:not(.elementor-element--promotion) [class^="pa-"]::after, .elementor-element-wrapper:not(.elementor-element--promotion) [class*=" pa-"]::after { content: "%s"; }', $badge_text ); |
| 200 | |
| 201 | wp_add_inline_style( 'pa-editor', $dynamic_css ); |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Enqueue Preview CSS files |
| 206 | * |
| 207 | * @since 2.9.0 |
| 208 | * @access public |
| 209 | */ |
| 210 | public function enqueue_preview_styles() { |
| 211 | |
| 212 | wp_enqueue_style( |
| 213 | 'pa-preview', |
| 214 | PREMIUM_ADDONS_URL . 'assets/editor/templates/css/preview.css', |
| 215 | array(), |
| 216 | PREMIUM_ADDONS_VERSION, |
| 217 | 'all' |
| 218 | ); |
| 219 | |
| 220 | wp_enqueue_style( 'pa-prettyphoto' ); |
| 221 | |
| 222 | wp_enqueue_style( 'premium-addons' ); |
| 223 | |
| 224 | wp_enqueue_style( 'pa-slick' ); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Register Widgets Category |
| 229 | * |
| 230 | * Register a new category for Premium Addons widgets |
| 231 | * |
| 232 | * @since 4.0.0 |
| 233 | * @access public |
| 234 | * |
| 235 | * @param object $elements_manager elements manager. |
| 236 | */ |
| 237 | public function register_widgets_category( $elements_manager ) { |
| 238 | |
| 239 | $elements_manager->add_category( |
| 240 | 'premium-elements', |
| 241 | array( |
| 242 | 'title' => Helper_Functions::get_category(), |
| 243 | ), |
| 244 | 1 |
| 245 | ); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Load widgets require function |
| 250 | * |
| 251 | * @since 1.0.0 |
| 252 | * @access public |
| 253 | */ |
| 254 | public function register_widgets( $widgets_manager ) { |
| 255 | |
| 256 | $enabled_elements = Helper_Functions::get_enabled_widgets(); |
| 257 | |
| 258 | foreach ( $enabled_elements as $key ) { |
| 259 | |
| 260 | $class = Helper_Functions::get_widget_class_name( $key ); |
| 261 | |
| 262 | if ( ! $class ) { |
| 263 | continue; |
| 264 | } |
| 265 | |
| 266 | if ( 'PremiumAddons\Widgets\Premium_Contactform' === $class && ! function_exists( 'wpcf7' ) ) { |
| 267 | continue; |
| 268 | } |
| 269 | |
| 270 | $this->load_widget_files( $class ); |
| 271 | |
| 272 | $widgets_manager->register( new $class() ); |
| 273 | |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | public function load_widget_files( $class ) { |
| 278 | |
| 279 | // if ( 'PremiumAddons\Widgets\Premium_Videobox' === $class || 'PremiumAddons\Widgets\Premium_Weather' === $class ) { |
| 280 | // require_once PREMIUM_ADDONS_PATH . 'widgets/dep/urlopen.php'; |
| 281 | // } |
| 282 | |
| 283 | if ( 'PremiumAddons\Widgets\Premium_Weather' === $class ) { |
| 284 | require_once PREMIUM_ADDONS_PATH . 'widgets/dep/pa-weather-handler.php'; |
| 285 | } |
| 286 | |
| 287 | if ( in_array( $class, array( 'PremiumAddons\Widgets\Premium_Pinterest_Feed', 'PremiumAddons\Widgets\Premium_Tiktok_Feed' ), true ) ) { |
| 288 | |
| 289 | if ( 'PremiumAddons\Widgets\Premium_Pinterest_Feed' == $class ) { |
| 290 | require_once PREMIUM_ADDONS_PATH . 'widgets/dep/pa-pins-handler.php'; |
| 291 | } |
| 292 | |
| 293 | if ( 'PremiumAddons\Widgets\Premium_Tiktok_Feed' == $class ) { |
| 294 | require_once PREMIUM_ADDONS_PATH . 'widgets/dep/pa-tiktok-handler.php'; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Enqueue editor scripts |
| 301 | * |
| 302 | * @since 3.2.5 |
| 303 | * @access public |
| 304 | */ |
| 305 | public function before_enqueue_scripts() { |
| 306 | |
| 307 | wp_enqueue_script( |
| 308 | 'pa-editor-behavior', |
| 309 | PREMIUM_ADDONS_URL . 'assets/editor/js/pa-editor-behavior.min.js', |
| 310 | array( 'elementor-editor', 'jquery' ), |
| 311 | PREMIUM_ADDONS_VERSION, |
| 312 | true |
| 313 | ); |
| 314 | |
| 315 | $data = array( |
| 316 | 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
| 317 | 'nonce' => wp_create_nonce( 'pa-disable-unused' ), |
| 318 | 'disable_unused_link' => add_query_arg( |
| 319 | array( |
| 320 | 'page' => 'premium-addons', |
| 321 | 'pa-action' => 'unused', |
| 322 | '#tab' => 'elements', |
| 323 | ), |
| 324 | esc_url( admin_url( 'admin.php' ) ) |
| 325 | ), |
| 326 | |
| 327 | ); |
| 328 | |
| 329 | wp_localize_script( 'pa-editor-behavior', 'paEditorBehaviorSettings', $data ); |
| 330 | |
| 331 | $map_enabled = isset( self::$modules['premium-maps'] ) ? self::$modules['premium-maps'] : 1; |
| 332 | |
| 333 | if ( $map_enabled ) { |
| 334 | |
| 335 | $premium_maps_api = self::$integrations['premium-map-api']; |
| 336 | |
| 337 | $locale = self::$integrations['premium-map-locale'] ?? 'en'; |
| 338 | |
| 339 | $disable_api = self::$integrations['premium-map-disable-api']; |
| 340 | |
| 341 | if ( $disable_api && '1' !== $premium_maps_api ) { |
| 342 | |
| 343 | $api = sprintf( 'https://maps.googleapis.com/maps/api/js?key=%1$s&libraries=marker&language=%2$s&loading=async', $premium_maps_api, $locale ); |
| 344 | wp_enqueue_script( |
| 345 | 'pa-maps-api', |
| 346 | $api, |
| 347 | array(), |
| 348 | PREMIUM_ADDONS_VERSION, |
| 349 | false |
| 350 | ); |
| 351 | |
| 352 | } |
| 353 | |
| 354 | wp_enqueue_script( |
| 355 | 'pa-maps-finder', |
| 356 | PREMIUM_ADDONS_URL . 'assets/editor/js/pa-maps-finder.js', |
| 357 | array( 'jquery' ), |
| 358 | PREMIUM_ADDONS_VERSION, |
| 359 | true |
| 360 | ); |
| 361 | |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Registers Premium Addons Custom Controls. |
| 367 | * |
| 368 | * @since 4.2.5 |
| 369 | * @access public |
| 370 | * |
| 371 | * @return void |
| 372 | */ |
| 373 | public function register_controls() { |
| 374 | |
| 375 | $control_manager = \Elementor\Plugin::instance(); |
| 376 | |
| 377 | if ( self::$modules['premium-equal-height'] || self::$modules['premium-pinterest-feed'] ) { |
| 378 | |
| 379 | require_once PREMIUM_ADDONS_PATH . 'includes/controls/premium-select.php'; |
| 380 | $premium_select = __NAMESPACE__ . '\Controls\Premium_Select'; |
| 381 | $control_manager->controls_manager->register( new $premium_select() ); |
| 382 | |
| 383 | } |
| 384 | |
| 385 | require_once PREMIUM_ADDONS_PATH . 'includes/controls/premium-post-filter.php'; |
| 386 | |
| 387 | $premium_post_filter = __NAMESPACE__ . '\Controls\Premium_Post_Filter'; |
| 388 | |
| 389 | $control_manager->controls_manager->register( new $premium_post_filter() ); |
| 390 | |
| 391 | if ( self::$modules['premium-blog'] || self::$modules['premium-smart-post-listing'] || self::$modules['premium-tcloud'] ) { |
| 392 | |
| 393 | require_once PREMIUM_ADDONS_PATH . 'includes/controls/premium-tax-filter.php'; |
| 394 | |
| 395 | $premium_tax_filter = __NAMESPACE__ . '\Controls\Premium_Tax_Filter'; |
| 396 | |
| 397 | $control_manager->controls_manager->register( new $premium_tax_filter() ); |
| 398 | } |
| 399 | |
| 400 | if ( self::$modules['pa-display-conditions'] && class_exists( 'ACF' ) ) { |
| 401 | |
| 402 | require_once PREMIUM_ADDONS_PATH . 'includes/controls/premium-acf-selector.php'; |
| 403 | $premium_acf_selector = __NAMESPACE__ . '\Controls\Premium_Acf_Selector'; |
| 404 | $control_manager->controls_manager->register( new $premium_acf_selector() ); |
| 405 | |
| 406 | } |
| 407 | |
| 408 | if ( self::$modules['premium-shape-divider'] ) { |
| 409 | |
| 410 | require_once PREMIUM_ADDONS_PATH . 'includes/controls/pa-image-choose.php'; |
| 411 | $premium_image_choose = __NAMESPACE__ . '\Controls\Premium_Image_Choose'; |
| 412 | $control_manager->controls_manager->register( new $premium_image_choose() ); |
| 413 | |
| 414 | } |
| 415 | |
| 416 | $premium_background = __NAMESPACE__ . '\Controls\Premium_Background'; |
| 417 | |
| 418 | $control_manager->controls_manager->add_group_control( 'pa-background', new $premium_background() ); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Load PA Extensions |
| 423 | * |
| 424 | * @since 4.7.0 |
| 425 | * @access public |
| 426 | */ |
| 427 | public function load_extensions() { |
| 428 | |
| 429 | Extras\Live_Editor::get_instance(); |
| 430 | |
| 431 | if ( self::$modules['premium-equal-height'] ) { |
| 432 | \PremiumAddons\Addons\Equal_Height::get_instance(); |
| 433 | } |
| 434 | |
| 435 | if ( self::$modules['premium-glassmorphism'] ) { |
| 436 | \PremiumAddons\Addons\Liquid_Glass::get_instance(); |
| 437 | } |
| 438 | |
| 439 | if ( self::$modules['pa-display-conditions'] ) { |
| 440 | // require_once PREMIUM_ADDONS_PATH . 'widgets/dep/urlopen.php'; |
| 441 | require_once PREMIUM_ADDONS_PATH . 'includes/pa-display-conditions/pa-controls-handler.php'; |
| 442 | \PremiumAddons\Addons\Display_Conditions::get_instance(); |
| 443 | } |
| 444 | |
| 445 | if ( self::$modules['premium-floating-effects'] ) { |
| 446 | \PremiumAddons\Addons\Floating_Effects::get_instance(); |
| 447 | } |
| 448 | |
| 449 | if ( class_exists( 'woocommerce' ) && ( self::$modules['woo-products'] || self::$modules['woo-categories'] || self::$modules['mini-cart'] || self::$modules['woo-cta'] ) ) { |
| 450 | Woocommerce::get_instance(); |
| 451 | } |
| 452 | |
| 453 | if ( self::$modules['premium-global-tooltips'] ) { |
| 454 | \PremiumAddons\Addons\Tooltips::get_instance(); |
| 455 | } |
| 456 | |
| 457 | if ( self::$modules['premium-shape-divider'] ) { |
| 458 | \PremiumAddons\Addons\Shape_Divider::get_instance(); |
| 459 | } |
| 460 | |
| 461 | if ( self::$modules['premium-wrapper-link'] ) { |
| 462 | \PremiumAddons\Addons\Wrapper_Link::get_instance(); |
| 463 | } |
| 464 | |
| 465 | if ( self::$modules['premium-cross-domain'] ) { |
| 466 | Extras\Cross_Copy_Paste::get_instance(); |
| 467 | } |
| 468 | |
| 469 | if ( self::$modules['premium-contactform'] && function_exists( 'wpcf7' ) ) { |
| 470 | Extras\CF7_Inserter::get_instance(); |
| 471 | } |
| 472 | |
| 473 | if ( ! Helper_Functions::check_papro_version() ) { |
| 474 | Helpers\PAPRO_Promotion::get_instance(); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Add PAPRO Elements |
| 480 | * |
| 481 | * @since 4.10.90 |
| 482 | * @access public |
| 483 | * |
| 484 | * @param array $config Elementor Config |
| 485 | */ |
| 486 | public function add_papro_elements( $config ) { |
| 487 | |
| 488 | $is_papro_active = Helper_Functions::check_papro_version(); |
| 489 | |
| 490 | if ( $is_papro_active ) { |
| 491 | return $config; |
| 492 | } |
| 493 | |
| 494 | $promotion_widgets = array(); |
| 495 | |
| 496 | if ( isset( $config['promotionWidgets'] ) ) { |
| 497 | $promotion_widgets = $config['promotionWidgets']; |
| 498 | } |
| 499 | |
| 500 | $pro_elements = Admin_Helper::get_pro_elements(); |
| 501 | |
| 502 | $pro_elements = array_merge( $promotion_widgets, $pro_elements ); |
| 503 | |
| 504 | $config['promotionWidgets'] = $pro_elements; |
| 505 | |
| 506 | // Fix promotion box not showing when Elementor Pro is active. |
| 507 | if ( defined( 'ELEMENTOR_PRO_VERSION' ) ) { |
| 508 | $config['promotion']['elements']['action_button'] = array( |
| 509 | 'text' => 'Connect & Activate', |
| 510 | 'url' => 'https://go.elementor.com/', |
| 511 | ); |
| 512 | } |
| 513 | |
| 514 | return $config; |
| 515 | } |
| 516 | |
| 517 | |
| 518 | /** |
| 519 | * |
| 520 | * Creates and returns an instance of the class |
| 521 | * |
| 522 | * @since 1.0.0 |
| 523 | * @access public |
| 524 | * |
| 525 | * @return object |
| 526 | */ |
| 527 | public static function get_instance() { |
| 528 | |
| 529 | if ( ! isset( self::$instance ) ) { |
| 530 | |
| 531 | self::$instance = new self(); |
| 532 | |
| 533 | } |
| 534 | |
| 535 | return self::$instance; |
| 536 | } |
| 537 | } |
| 538 |