PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / plugin.php
royal-elementor-addons Last commit date
admin 5 days ago assets 5 days ago base 5 days ago classes 5 days ago extensions 5 days ago freemius 5 days ago includes 5 days ago languages 5 days ago modules 5 days ago LICENSE 5 days ago plugin.php 5 days ago readme.txt 5 days ago wpml-config.xml 5 days ago wpr-addons.php 5 days ago
plugin.php
1292 lines
1 <?php
2 namespace WprAddons;
3
4 use Elementor\Utils;
5 use Elementor\Controls_Manager;
6 use WprAddons\Includes\Controls\WprAjaxSelect2\WPR_Control_Ajax_Select2;
7 use WprAddons\Includes\Controls\WPR_Select2;
8 use WprAddons\Includes\Controls\WPR_Control_Animations;
9 use WprAddons\Includes\Controls\WPR_Control_Animations_Alt;
10 use WprAddons\Includes\Controls\WPR_Control_Button_Animations;
11 use WprAddons\Includes\Controls\WPR_Control_Arrow_Icons;
12 use WprAddons\Classes\Utilities;
13 use Elementor\Core\App\App;
14 use WP_REST_Response;
15
16 if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
17
18 /**
19 * Main class plugin
20 */
21 class Plugin {
22
23 /**
24 * @var Plugin
25 */
26 private static $_instance;
27
28 /**
29 * @var Manager
30 */
31 private $_modules_manager;
32
33 /**
34 * @var array
35 */
36 private $_localize_settings = [];
37
38 /**
39 * @return string
40 */
41 public function get_version() {
42 return WPR_ADDONS_VERSION;
43 }
44
45 /**
46 * Throw error on object clone
47 *
48 * The whole idea of the singleton design pattern is that there is a single
49 * object therefore, we don't want the object to be cloned.
50 *
51 * @since 1.0
52 * @return void
53 */
54 public function __clone() {
55 // Cloning instances of the class is forbidden
56 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin huh?', 'wpr-addons' ), '1.0' );
57 }
58
59 /**
60 * Disable unserializing of the class
61 *
62 * @since 1.0
63 * @return void
64 */
65 public function __wakeup() {
66 // Unserializing instances of the class is forbidden
67 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin huh?', 'wpr-addons' ), '1.0' );
68 }
69
70 /**
71 * @return Plugin
72 */
73 public static function instance() {
74 if ( is_null( self::$_instance ) ) {
75 self::$_instance = new self();
76 }
77
78 return self::$_instance;
79 }
80
81 /**
82 * Cached extension/option toggles (reduces get_option calls on every request).
83 */
84 private static $wpr_extension_options = null;
85
86 private function wpr_get_extension_option( $key, $default = 'on' ) {
87 if ( null === self::$wpr_extension_options ) {
88 self::$wpr_extension_options = [
89 'wpr-particles' => get_option( 'wpr-particles', 'on' ),
90 'wpr-parallax-background' => get_option( 'wpr-parallax-background', 'on' ),
91 'wpr-parallax-multi-layer' => get_option( 'wpr-parallax-multi-layer', 'on' ),
92 'wpr-sticky-section' => get_option( 'wpr-sticky-section', 'on' ),
93 'wpr-custom-css' => get_option( 'wpr-custom-css', 'on' ),
94 'wpr-display-conditions' => get_option( 'wpr-display-conditions', 'on' ),
95 'wpr_override_woo_templates'=> get_option( 'wpr_override_woo_templates', 'on' ),
96 'wpr-column-slider' => get_option( 'wpr-column-slider', 'on' ),
97 'wpr-equal-height' => get_option( 'wpr-equal-height', 'on' ),
98 ];
99 }
100 return isset( self::$wpr_extension_options[ $key ] ) ? self::$wpr_extension_options[ $key ] : $default;
101 }
102
103 private function _includes() {
104 // Modules Manager
105 require WPR_ADDONS_PATH . 'includes/modules-manager.php';
106
107 // Custom Controls
108 require WPR_ADDONS_PATH . 'includes/controls/wpr-ajax-select2/wpr-control-ajax-select2.php';
109 require WPR_ADDONS_PATH . 'includes/controls/wpr-ajax-select2/wpr-control-ajax-select2-api.php';
110 require WPR_ADDONS_PATH . 'includes/controls/wpr-control-animations.php';
111 require WPR_ADDONS_PATH . 'includes/controls/wpr-control-icons.php';
112 require WPR_ADDONS_PATH . 'includes/controls/wpr-select2.php';
113
114 // Templates Library
115 require WPR_ADDONS_PATH . 'admin/includes/wpr-templates-library.php';
116
117 // Post Likes
118 require WPR_ADDONS_PATH . 'classes/modules/wpr-post-likes.php';
119
120 // Ajax Search
121 require WPR_ADDONS_PATH . 'classes/modules/wpr-ajax-search.php';
122
123 // Instagram
124 require WPR_ADDONS_PATH . 'classes/modules/wpr-load-more-instagram-posts.php';
125
126 // Twitter
127 require WPR_ADDONS_PATH . 'classes/modules/wpr-load-more-tweets.php';
128
129 // Meta Keys
130 require WPR_ADDONS_PATH . 'classes/wpr-custom-meta-keys.php';
131
132 // Grid
133 require WPR_ADDONS_PATH . 'classes/modules/wpr-grid-helpers.php';
134
135 // Woo Grid
136 require WPR_ADDONS_PATH . 'classes/modules/wpr-woo-grid-helpers.php';
137
138 // Media Grid
139 require WPR_ADDONS_PATH . 'classes/modules/wpr-filter-grid-media.php';
140
141 // Extensions Base
142 require WPR_ADDONS_PATH . 'extensions/wpr-extensions-base.php';
143
144 // Particles
145 if ( 'on' === $this->wpr_get_extension_option( 'wpr-particles' ) ) {
146 require WPR_ADDONS_PATH . 'extensions/wpr-particles.php';
147 }
148
149 // Parallax
150 if ( 'on' === $this->wpr_get_extension_option( 'wpr-parallax-background' ) || 'on' === $this->wpr_get_extension_option( 'wpr-parallax-multi-layer' ) ) {
151 require WPR_ADDONS_PATH . 'extensions/wpr-parallax.php';
152 }
153
154 // Sticky Header
155 if ( 'on' === $this->wpr_get_extension_option( 'wpr-sticky-section' ) ) {
156 require WPR_ADDONS_PATH . 'extensions/wpr-sticky-section.php';
157 }
158
159 // Custom CSS
160 if ( 'on' === $this->wpr_get_extension_option( 'wpr-custom-css' ) ) {
161 require WPR_ADDONS_PATH . 'extensions/wpr-custom-css.php';
162 }
163
164 // Display Conditions (Visibility)
165 if ( 'on' === $this->wpr_get_extension_option( 'wpr-display-conditions' ) ) {
166 require WPR_ADDONS_PATH . 'extensions/wpr-display-conditions.php';
167 }
168
169 // Column Slider
170 if ( 'on' === $this->wpr_get_extension_option( 'wpr-column-slider' ) ) {
171 require WPR_ADDONS_PATH . 'extensions/wpr-column-slider.php';
172 }
173
174 // Equal Height
175 if ( 'on' === $this->wpr_get_extension_option( 'wpr-equal-height' ) ) {
176 require WPR_ADDONS_PATH . 'extensions/wpr-equal-height.php';
177 }
178
179 // Mega Menu
180 require WPR_ADDONS_PATH . 'admin/mega-menu.php';
181
182
183 // Form Builder
184 // TODO:: ommit if form builder turned off if possible
185 require WPR_ADDONS_PATH . 'classes/modules/wpr-form-handlers.php';
186
187 // Admin Files
188 if ( is_admin() ) {
189 // Plugin Options
190 require WPR_ADDONS_PATH . 'admin/plugin-options.php';
191
192 // Templates Kit
193 require WPR_ADDONS_PATH . 'admin/templates-kit.php';
194
195 // Theme Builder
196 require WPR_ADDONS_PATH . 'admin/theme-builder.php';
197
198 // Premade Blocks
199 require WPR_ADDONS_PATH . 'admin/premade-blocks.php';
200
201 // Theme Builder
202 require WPR_ADDONS_PATH . 'admin/popups.php';
203
204 // Secondary Image
205 require WPR_ADDONS_PATH . 'admin/metabox/wpr-secondary-image.php';
206
207 // Featured Video (Woo Grid)
208 require WPR_ADDONS_PATH . 'admin/metabox/wpr-featured-video.php';
209
210 // Dropdown Category Filter for Wpr Templates
211 require WPR_ADDONS_PATH . 'admin/includes/wpr-templates-category-filter.php';
212
213 // Editor Hooks
214 require WPR_ADDONS_PATH . 'admin/includes/wpr-editor-hooks.php';
215
216 // Hide Theme Notice
217 // TODO: Remove this and fix with Transients
218 add_action( 'admin_enqueue_scripts', [ $this, 'hide_theme_notice' ] );
219 }
220
221 if ( class_exists('WooCommerce') ) {
222 if ( 'on' === $this->wpr_get_extension_option( 'wpr_override_woo_templates' ) ) {
223 // add_filter( 'astra_enable_woocommerce_integration', '__return_false' );
224 require WPR_ADDONS_PATH . 'includes/woocommerce/woocommerce-config.php';
225 }
226
227 // Add Remove From Wishlist
228 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-add-remove-from-wishlist.php';
229
230 // Add Remove From Compare
231 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-add-remove-from-compare.php';
232
233 // Update Mini Wishlist
234 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-update-mini-wishlist.php';
235
236 // Compare Popup Action
237 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-compare-popup-action.php';
238
239 // Add Remove From Compare
240 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-update-mini-compare.php';
241
242 // Count Wishlist Items
243 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-count-wishlist-compare-items.php';
244 require WPR_ADDONS_PATH . 'classes/woocommerce/wpr-check-product-in-wc.php';
245 }
246 }
247
248 public function autoload( $class ) {
249 if ( 0 !== strpos( $class, __NAMESPACE__ ) ) {
250 return;
251 }
252
253 $filename = strtolower(
254 preg_replace(
255 [ '/^' . __NAMESPACE__ . '\\\/', '/([a-z])([A-Z])/', '/_/', '/\\\/' ],
256 [ '', '$1-$2', '-', DIRECTORY_SEPARATOR ],
257 $class
258 )
259 );
260 $filename = WPR_ADDONS_PATH . $filename . '.php';
261
262 if ( is_readable( $filename ) ) {
263 include( $filename );
264 }
265 }
266
267 public function get_localize_settings() {
268 return $this->_localize_settings;
269 }
270
271 public function add_localize_settings( $setting_key, $setting_value = null ) {
272 if ( is_array( $setting_key ) ) {
273 $this->_localize_settings = array_replace_recursive( $this->_localize_settings, $setting_key );
274
275 return;
276 }
277
278 if ( ! is_array( $setting_value ) || ! isset( $this->_localize_settings[ $setting_key ] ) || ! is_array( $this->_localize_settings[ $setting_key ] ) ) {
279 $this->_localize_settings[ $setting_key ] = $setting_value;
280
281 return;
282 }
283
284 $this->_localize_settings[ $setting_key ] = array_replace_recursive( $this->_localize_settings[ $setting_key ], $setting_value );
285 }
286
287 public function script_suffix() {
288 // $dir = is_rtl() ? '-rtl' : '';
289 return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
290 }
291
292 public function register_ajax_hooks() {
293 add_action( 'wp_ajax_mailchimp_subscribe', [new Utilities, 'ajax_mailchimp_subscribe'] );
294 add_action( 'wp_ajax_nopriv_mailchimp_subscribe', [new Utilities, 'ajax_mailchimp_subscribe'] );
295 add_action( 'wp_ajax_wpr_ppc_verify_password', [new Utilities, 'ajax_ppc_verify_password'] );
296 add_action( 'wp_ajax_nopriv_wpr_ppc_verify_password', [new Utilities, 'ajax_ppc_verify_password'] );
297 }
298
299 public function mega_menu_ajax_loading( \WP_REST_Request $request ) {
300 $item_id = $request->get_param( 'item_id' );
301 if ( $item_id === null || $item_id === '' ) {
302 return new \WP_REST_Response( '', 400 );
303 }
304 $item_id = absint( $item_id );
305 if ( $item_id === 0 ) {
306 return new \WP_REST_Response( '', 400 );
307 }
308 $item_post = get_post( $item_id );
309 if ( ! $item_post || $item_post->post_type !== 'nav_menu_item' ) {
310 return new \WP_REST_Response( '', 403 );
311 }
312 $item_status = get_post_status( $item_post );
313 if ( 'publish' !== $item_status && ! current_user_can( 'read_post', $item_id ) ) {
314 return new \WP_REST_Response( '', 403 );
315 }
316 $mega_id = get_post_meta( $item_id, 'wpr-mega-menu-item', true );
317 $mega_post = $mega_id ? get_post( $mega_id ) : false;
318 if ( ! $mega_post ) {
319 return new \WP_REST_Response( '', 404 );
320 }
321 $mega_status = get_post_status( $mega_post );
322 if ( 'publish' !== $mega_status && ! current_user_can( 'read_post', $mega_post->ID ) ) {
323 return new \WP_REST_Response( '', 403 );
324 }
325 $elementor = \Elementor\Plugin::instance();
326 $type = get_post_meta( get_the_ID(), '_wpr_template_type', true ) || get_post_meta( $mega_post->ID, '_elementor_template_type', true );
327 $has_css = 'internal' === get_option( 'elementor_css_print_method' ) || '' !== $type;
328 $content = $elementor->frontend->get_builder_content_for_display( (int) $mega_post->ID, $has_css );
329 return new \WP_REST_Response( $content, 200 );
330 }
331
332 public function register_megamenu_route() {
333 add_action( 'rest_api_init', function() {
334 register_rest_route(
335 'wpraddons/v1',
336 '/wprmegamenu/',
337 [
338 'methods' => 'GET',
339 'callback' => [$this, 'mega_menu_ajax_loading'],
340 'permission_callback' => '__return_true'
341 ]
342 );
343 } );
344 }
345
346 public function register_custom_controls() {
347
348 $controls_manager = \Elementor\Plugin::$instance->controls_manager;
349 $controls_manager->register( new WPR_Control_Ajax_Select2() );
350 $controls_manager->register( new WPR_Select2() );
351 $controls_manager->register( new WPR_Control_Animations() );
352 $controls_manager->register( new WPR_Control_Animations_Alt() );
353 $controls_manager->register( new WPR_Control_Button_Animations() );
354 $controls_manager->register( new WPR_Control_Arrow_Icons() );
355
356 }
357
358 public function register_elementor_document_type( $documents_manager ) {
359 // Theme Builder
360 require WPR_ADDONS_PATH . 'modules/theme-builder/wpr-theme-builder.php';
361 $documents_manager->register_document_type( 'wpr-theme-builder', 'Wpr_Theme_Builder' );
362
363 // Popups
364 require WPR_ADDONS_PATH . 'modules/popup/wpr-popup.php';
365
366 if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) {
367 require WPR_ADDONS_PRO_PATH . 'modules/popup-pro/wpr-popup-pro.php';
368 $documents_manager->register_document_type( 'wpr-popups', 'Wpr_Popup_Pro' );
369 } else {
370 $documents_manager->register_document_type( 'wpr-popups', 'Wpr_Popup' );
371 }
372 }
373
374 public function enqueue_styles() {
375
376 wp_register_style(
377 'wpr-animations-css',
378 WPR_ADDONS_URL . 'assets/css/lib/animations/wpr-animations'. $this->script_suffix() .'.css',
379 [],
380 Plugin::instance()->get_version()
381 );
382
383 wp_register_style(
384 'wpr-link-animations-css',
385 WPR_ADDONS_URL . 'assets/css/lib/animations/wpr-link-animations'. $this->script_suffix() .'.css',
386 [],
387 Plugin::instance()->get_version()
388 );
389
390 wp_register_style(
391 'wpr-loading-animations-css',
392 WPR_ADDONS_URL . 'assets/css/lib/animations/loading-animations'. $this->script_suffix() .'.css',
393 [],
394 Plugin::instance()->get_version()
395 );
396
397 wp_register_style(
398 'wpr-button-animations-css',
399 WPR_ADDONS_URL . 'assets/css/lib/animations/button-animations'. $this->script_suffix() .'.css',
400 [],
401 Plugin::instance()->get_version()
402 );
403
404 // GOGA - enqueue instead of register (because of animations)
405 wp_enqueue_style(
406 'wpr-text-animations-css',
407 WPR_ADDONS_URL . 'assets/css/lib/animations/text-animations'. $this->script_suffix() .'.css',
408 [],
409 Plugin::instance()->get_version()
410 );
411
412 wp_register_style(
413 'wpr-lightgallery-css',
414 WPR_ADDONS_URL . 'assets/css/lib/lightgallery/lightgallery'. $this->script_suffix() .'.css',
415 [],
416 Plugin::instance()->get_version()
417 );
418
419 // Posts Timeline
420 wp_register_style(
421 'wpr-aos-css',
422 WPR_ADDONS_URL . 'assets/css/lib/aos/aos.min.css',
423 []
424 );
425
426 wp_register_style(
427 'wpr-flipster-css',
428 WPR_ADDONS_URL . 'assets/css/lib/flipster/jquery.flipster.min.css',
429 [],
430 Plugin::instance()->get_version()
431 );
432
433 wp_register_style(
434 'wpr-date-picker-css',
435 WPR_ADDONS_URL . 'assets/css/lib/air-datepicker/air-datepicker.css',
436 [],
437 Plugin::instance()->get_version()
438 );
439
440 wp_enqueue_style(
441 'wpr-addons-css',
442 WPR_ADDONS_URL . 'assets/css/frontend'. $this->script_suffix() .'.css',
443 [],
444 Plugin::instance()->get_version()
445 );
446
447 // Load FontAwesome - TODO: Check if necessary (maybe elementor is already loading this)
448 wp_enqueue_style(
449 'font-awesome-5-all',
450 ELEMENTOR_ASSETS_URL . 'lib/font-awesome/css/all'. $this->script_suffix() .'.css',
451 false,
452 Plugin::instance()->get_version()
453 );
454
455 if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
456 wp_enqueue_style(
457 'wpr-addons-library-frontend-css',
458 WPR_ADDONS_URL . 'assets/css/admin/library-frontend'. $this->script_suffix() .'.css',
459 [],
460 Plugin::instance()->get_version()
461 );
462 }
463 }
464
465 public function enqueue_editor_styles() {
466
467 wp_enqueue_style(
468 'wpr-animations-css',
469 WPR_ADDONS_URL . 'assets/css/lib/animations/wpr-animations'. $this->script_suffix() .'.css',
470 [],
471 Plugin::instance()->get_version()
472 );
473
474 wp_enqueue_style(
475 'wpr-animations-link-css',
476 WPR_ADDONS_URL . 'assets/css/lib/animations/wpr-link-animations'. $this->script_suffix() .'.css',
477 [],
478 Plugin::instance()->get_version()
479 );
480
481 wp_enqueue_style(
482 'wpr-loading-animations-css',
483 WPR_ADDONS_URL . 'assets/css/lib/animations/loading-animations'. $this->script_suffix() .'.css',
484 [],
485 Plugin::instance()->get_version()
486 );
487
488 wp_enqueue_style(
489 'wpr-button-animations-css',
490 WPR_ADDONS_URL . 'assets/css/lib/animations/button-animations'. $this->script_suffix() .'.css',
491 [],
492 Plugin::instance()->get_version()
493 );
494
495 wp_enqueue_style(
496 'wpr-text-animations-css',
497 WPR_ADDONS_URL . 'assets/css/lib/animations/text-animations'. $this->script_suffix() .'.css',
498 [],
499 Plugin::instance()->get_version()
500 );
501
502 wp_enqueue_style(
503 'wpr-aos-css',
504 WPR_ADDONS_URL . 'assets/css/lib/aos/aos.min.css',
505 []
506 );
507
508 wp_enqueue_style(
509 'wpr-flipster-css',
510 WPR_ADDONS_URL . 'assets/css/lib/flipster/jquery.flipster.min.css',
511 [],
512 Plugin::instance()->get_version()
513 );
514 }
515
516 public function wpr_some_init_actions() {
517 load_plugin_textdomain('wpr-addons', false, dirname(plugin_basename(__FILE__)) . '/languages/');
518
519 // Notices only in admin to reduce frontend CPU (no file I/O on every page view).
520 if ( is_admin() ) {
521 if ( get_option('wpr_hide_banners') !== 'on' ) {
522 // Pro Features Notice
523 require WPR_ADDONS_PATH . 'admin/notices/pro-features-notice.php';
524
525 // Plugin Update Notice
526 require WPR_ADDONS_PATH . 'admin/notices/plugin-update-notice.php';
527
528 // Plugin Sale Notice
529 require WPR_ADDONS_PATH . 'admin/notices/plugin-sale-notice.php';
530 }
531 // Rating Notice
532 require WPR_ADDONS_PATH . 'admin/notices/rating-notice.php';
533 }
534
535 // if ( defined('REST_REQUEST') && REST_REQUEST ) {
536 // return;
537 // }
538
539 // if ( ! isset( $_COOKIE['wpr_guest_token'] ) && !headers_sent() ) {
540 // // Generate a unique token and store it in a cookie
541 // $guest_id = bin2hex(random_bytes(32)); // Secure random string as guest "session"
542 // $secure = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' );
543 // setcookie( 'wpr_guest_token', $guest_id, time() + 3600, '/', '', $secure, true ); // 1 hour expiration
544 // $_COOKIE['wpr_guest_token'] = $guest_id; // Ensure it's immediately available in PHP
545 // }
546 }
547
548 public function wpr_generate_custom_token() {
549 if ( is_user_logged_in() ) {
550 // For logged-in users, use their user ID to store a token
551 $user_id = get_current_user_id();
552 $token = bin2hex(\random_bytes(32)); // Secure token generation
553 set_transient( 'wpr_custom_token_' . $user_id, $token, HOUR_IN_SECONDS ); // Store token for 1 hour
554 return $token;
555 } else {
556 // For non-logged-in users, check if the guest token cookie exists
557 if ( isset( $_COOKIE['wpr_guest_token'] ) ) {
558 $guest_id = sanitize_text_field( $_COOKIE['wpr_guest_token'] );
559 } else {
560 // If somehow the cookie isn't set, handle appropriately
561 return null;
562 }
563
564 // Check if a token already exists for this guest
565 $existing_token = get_transient( 'wpr_custom_guest_token_' . $guest_id );
566 if ( $existing_token ) {
567 return $existing_token;
568 }
569
570 // Only create new token if one doesn't exist
571 $token = bin2hex(\random_bytes(32)); // Secure token generation
572 set_transient( 'wpr_custom_guest_token_' . $guest_id, $token, HOUR_IN_SECONDS ); // Store token for 1 hour
573
574 // Clean up old guest tokens periodically (1% chance)
575 if ( rand(1, 100) === 1 ) {
576 $this->cleanup_guest_tokens();
577 }
578
579 return $token;
580 }
581 }
582
583 private function cleanup_guest_tokens() {
584 global $wpdb;
585 $wpdb->query(
586 "DELETE FROM {$wpdb->options}
587 WHERE option_name LIKE '_transient_wpr_custom_guest_token_%'
588 AND option_value = ''
589 LIMIT 100"
590 );
591 }
592
593 public function hide_theme_notice() {
594 wp_enqueue_style( 'hide-theme-notice', WPR_ADDONS_URL .'assets/css/admin/wporg-theme-notice.css', [] );
595
596 wp_enqueue_script(
597 'wpr-plugin-notice-js',
598 WPR_ADDONS_URL . 'assets/js/admin/plugin-update-notice.js',
599 [
600 'jquery'
601 ]
602 );
603
604 // if ( ! wp_script_is( 'wpr-wrong-update-js', 'enqueued' ) ) {
605 // wp_enqueue_script(
606 // 'wpr-wrong-update-js',
607 // WPR_ADDONS_URL . 'assets/js/admin/wrong-update.js',
608 // [
609 // 'jquery'
610 // ]
611 // );
612 // }
613
614 wp_localize_script(
615 'wpr-plugin-notice-js',
616 'WprPluginNotice',
617 [
618 'ajaxurl' => admin_url( 'admin-ajax.php' ),
619 'nonce' => wp_create_nonce( 'wpr-plugin-notice-js' ),
620 ]
621 );
622 }
623
624 public function enqueue_scripts() {
625
626 wp_enqueue_script(
627 'wpr-addons-js',
628 WPR_ADDONS_URL . 'assets/js/frontend'. $this->script_suffix() .'.js',
629 [
630 'jquery',
631 'elementor-frontend',
632 ],
633 Plugin::instance()->get_version(),
634 true
635 );
636
637 wp_enqueue_script(
638 'wpr-modal-popups-js',
639 WPR_ADDONS_URL . 'assets/js/modal-popups'. $this->script_suffix() .'.js',
640 [
641 'jquery',
642 ],
643 Plugin::instance()->get_version(),
644 true
645 );
646
647 // $custom_token = $this->wpr_generate_custom_token();
648
649 wp_localize_script(
650 'wpr-addons-js',
651 'WprConfig', // This is used in the js file to group all of your scripts together
652 [
653 'ajaxurl' => admin_url( 'admin-ajax.php' ),
654 'resturl' => get_rest_url() . 'wpraddons/v1',
655 'nonce' => wp_create_nonce( 'wpr-addons-js' ),
656 'addedToCartText' => esc_html__('was added to cart', 'wpr-addons'),
657 'viewCart' => esc_html__('View Cart', 'wpr-addons'),
658 'comparePageID' => get_option('wpr_compare_page'),
659 'comparePageURL' => get_permalink(get_option('wpr_compare_page')),
660 'wishlistPageID' => get_option('wpr_wishlist_page'),
661 'wishlistPageURL' => get_permalink(get_option('wpr_wishlist_page')),
662 'chooseQuantityText' => esc_html__('Please select the required number of items.', 'wpr-addons'),
663 'site_key' => get_option('wpr_recaptcha_v3_site_key'),
664 'site_key_v2' => get_option('wpr_recaptcha_v2_site_key'),
665 'is_admin' => current_user_can('manage_options'),
666 'input_empty' => esc_html__('Please fill out this field', 'wpr-addons'),
667 'select_empty' => esc_html__('Nothing selected', 'wpr-addons'),
668 'file_empty' => esc_html__('Please upload a file', 'wpr-addons'),
669 'recaptcha_error' => esc_html__('Recaptcha Error', 'wpr-addons'),
670 'woo_shop_ppp' => get_option('wpr_woo_shop_ppp', 9),
671 'woo_shop_cat_ppp' => get_option('wpr_woo_shop_cat_ppp', 9),
672 'woo_shop_tag_ppp' => get_option('wpr_woo_shop_tag_ppp', 9),
673 'is_product_category' => function_exists('is_product_category') ? is_product_category() : false,
674 'is_product_tag' => function_exists('is_product_tag') ? is_product_tag() : false,
675 'sticky_section' => $this->wpr_get_extension_option( 'wpr-sticky-section' ),
676 // 'token' => $custom_token
677 ]
678 );
679 }
680
681 public function register_scripts() {
682
683 // Register DOMPurify
684 wp_register_script(
685 'wpr-dompurify',
686 WPR_ADDONS_URL . 'assets/js/lib/dompurify/dompurify.min.js',
687 ['jquery'],
688 '3.0.6',
689 );
690
691 wp_register_script(
692 'wpr-infinite-scroll',
693 WPR_ADDONS_URL . 'assets/js/lib/infinite-scroll/infinite-scroll.min.js',
694 [
695 'jquery',
696 ],
697 '3.0.5',
698 true
699 );
700
701 wp_register_script(
702 'imagesloaded',
703 WPR_ADDONS_URL . 'assets/js/lib/isotope/imagesloaded'. $this->script_suffix() .'.js',
704 [
705 'jquery'
706 ],
707 '5.0.0',
708 true
709 );
710
711 wp_register_script(
712 'wpr-isotope',
713 WPR_ADDONS_URL . 'assets/js/lib/isotope/isotope'. $this->script_suffix() .'.js',
714 [
715 'jquery',
716 'imagesloaded'
717 ],
718 '3.0.8',
719 true
720 );
721
722 wp_register_script(
723 'wpr-date-picker-js',
724 WPR_ADDONS_URL . 'assets/js/lib/air-datepicker/air-datepicker.js',
725 [
726 'jquery',
727 ],
728 '',
729 true
730 );
731
732 wp_register_script(
733 'wpr-slick',
734 WPR_ADDONS_URL . 'assets/js/lib/slick/slick'. $this->script_suffix() .'.js',
735 [
736 'jquery',
737 ],
738 '1.8.1',
739 true
740 );
741
742 wp_register_script(
743 'wpr-lightgallery',
744 WPR_ADDONS_URL . 'assets/js/lib/lightgallery/lightgallery'. $this->script_suffix() .'.js',
745 [
746 'jquery',
747 ],
748 '1.6.12',
749 true
750 );
751
752 wp_register_script(
753 'wpr-marquee',
754 WPR_ADDONS_URL . 'assets/js/lib/marquee/marquee'. $this->script_suffix() .'.js',
755 [
756 'jquery',
757 ],
758 '1.0',
759 true
760 );
761
762 wp_register_script(
763 'wpr-google-maps',
764 'https://maps.googleapis.com/maps/api/js?key='. esc_attr(get_option('wpr_google_map_api_key')) . '&language='. esc_attr(get_option('wpr_google_map_language')),
765 [],
766 '',
767 true
768 );
769
770 wp_register_script(
771 'wpr-google-maps-clusters',
772 WPR_ADDONS_URL . 'assets/js/lib/gmap/markerclusterer'. $this->script_suffix() .'.js',
773 [],
774 '1.0.3',
775 true
776 );
777
778 wp_register_script(
779 'jquery-event-move',
780 WPR_ADDONS_URL . 'assets/js/lib/jquery-event-move/jquery.event.move'. $this->script_suffix() .'.js',
781 [],
782 '2.0',
783 true
784 );
785
786 wp_register_script(
787 'wpr-lottie-animations',
788 WPR_ADDONS_URL . 'assets/js/lib/lottie/lottie.min.js',
789 [],
790 '5.8.0',
791 true
792 );
793
794 wp_register_script(
795 'wpr-table-to-excel-js',
796 WPR_ADDONS_URL . 'assets/js/lib/tableToExcel/tableToExcel.js',
797 [],
798 null,
799 true
800 );
801
802 wp_register_script(
803 'wpr-aos-js',
804 WPR_ADDONS_URL . 'assets/js/lib/aos/aos.min.js',
805 [],
806 null,
807 true
808 );
809
810 wp_register_script(
811 'wpr-charts',
812 WPR_ADDONS_URL . 'assets/js/lib/charts/charts.min.js',
813 [],
814 '3.7.0',
815 true
816 );
817
818 wp_register_script(
819 'wpr-flipster',
820 WPR_ADDONS_URL . 'assets/js/lib/flipster/jquery.flipster.min.js',
821 [],
822 '2.0',
823 true
824 );
825
826 wp_register_script(
827 'wpr-circle-menu',
828 WPR_ADDONS_URL . 'assets/js/lib/circle-menu/circle-menu.min.js',
829 [ 'jquery' ],
830 '2.0.0',
831 true
832 );
833
834 wp_register_script(
835 'wpr-perfect-scroll-js',
836 WPR_ADDONS_URL .'assets/js/lib/perfect-scrollbar/perfect-scrollbar.min.js',
837 [ 'jquery' ],
838 '0.4.9'
839 );
840
841 wp_register_script(
842 'wpr-universal-tilt',
843 WPR_ADDONS_URL . 'assets/js/lib/universal-tilt/universal-tilt'. $this->script_suffix() .'.js',
844 [
845 'jquery',
846 ],
847 '6.0.3',
848 true
849 );
850 }
851
852 public function enqueue_panel_scripts() {
853
854 wp_enqueue_script(
855 'wpr-addons-editor-js',
856 WPR_ADDONS_URL . 'assets/js/admin/editor'. $this->script_suffix() .'.js',
857 [ 'jquery', 'wp-i18n' ],
858 Plugin::instance()->get_version(),
859 true
860 );
861
862 $args = ['nonce' => wp_create_nonce( 'wpr-addons-editor-js' ), 'adminURL' => admin_url(), 'isWooCommerceActive' => class_exists('WooCommerce') ? true : false];
863
864 $args = array_merge($args, Utilities::get_registered_modules());
865
866 wp_localize_script(
867 'wpr-addons-editor-js',
868 'registered_modules',
869 $args
870 );
871 }
872
873 public function enqueue_inner_panel_scripts() {
874
875 wp_enqueue_script(
876 'wpr-macy-js',
877 WPR_ADDONS_URL . 'assets/js/lib/macy/macy.js',
878 [],
879 '3.0.6',
880 true
881 );
882
883 wp_enqueue_script(
884 'wpr-addons-library-frontend-js',
885 WPR_ADDONS_URL . 'assets/js/admin/library-frontend'. $this->script_suffix() .'.js',
886 [ 'jquery', 'wpr-macy-js' ],
887 Plugin::instance()->get_version(),
888 true
889 );
890
891 wp_localize_script(
892 'wpr-addons-library-frontend-js',
893 'white_label',
894 [
895 'logo_url' => !empty(get_option('wpr_wl_plugin_logo')) ? esc_url(wp_get_attachment_image_src(get_option('wpr_wl_plugin_logo'), 'full')[0]) : WPR_ADDONS_ASSETS_URL .'img/logo-40x40.png'
896 ]
897 );
898
899 wp_localize_script(
900 'wpr-addons-library-frontend-js',
901 'WprLibFrontLoc',
902 [
903 'nonce' => wp_create_nonce('wpr-addons-library-frontend-js')
904 ]
905 );
906
907 wp_enqueue_script(
908 'wpr-addons-library-editor-js',
909 WPR_ADDONS_URL . 'assets/js/admin/library-editor'. $this->script_suffix() .'.js',
910 [ 'jquery' ],
911 Plugin::instance()->get_version(),
912 true
913 );
914 }
915
916 public function enqueue_panel_styles() {
917 wp_enqueue_style(
918 'wpr-addons-library-editor-css',
919 WPR_ADDONS_URL . 'assets/css/admin/editor'. $this->script_suffix() .'.css',
920 [],
921 Plugin::instance()->get_version()
922 );
923
924 $custom_css = "
925 .wpr-pro-notice {
926 background: #404349 !important;
927 border-color: #323232 !important;
928 }
929 .elementor-control select option[value*=pro-] {
930 background: #60646e !important;
931 }
932 .elementor-panel .wpr-icon:after {
933 box-shadow: 0 0 2px 2px #6985ee !important;
934 }
935 .wpr-pro-notice > span {
936 color: #fff !important;
937 font-weight: bold;
938 }
939 ";
940
941 $ui_theme = isset(get_user_meta(get_current_user_id(), 'elementor_preferences')[0]['ui_theme']) ? get_user_meta(get_current_user_id(), 'elementor_preferences')[0]['ui_theme'] : '';
942
943 if ( $ui_theme && $ui_theme === 'dark' ) {
944 wp_add_inline_style( 'elementor-editor-dark-mode', $custom_css );
945 }
946 }
947
948 // Lightbox Styles
949 public function lightbox_styles() {
950 echo '<style id="wpr_lightbox_styles">
951 .lg-backdrop {
952 background-color: '. esc_html(get_option('wpr_lb_bg_color','rgba(0,0,0,0.6)')) .' !important;
953 }
954 .lg-toolbar,
955 .lg-dropdown {
956 background-color: '. esc_html(get_option('wpr_lb_toolbar_color','rgba(0,0,0,0.8)')) .' !important;
957 }
958 .lg-dropdown:after {
959 border-bottom-color: '. esc_html(get_option('wpr_lb_toolbar_color','rgba(0,0,0,0.8)')) .' !important;
960 }
961 .lg-sub-html {
962 background-color: '. esc_html(get_option('wpr_lb_caption_color','rgba(0,0,0,0.8)')) .' !important;
963 }
964 .lg-thumb-outer,
965 .lg-progress-bar {
966 background-color: '. esc_html(get_option('wpr_lb_gallery_color','#444444')) .' !important;
967 }
968 .lg-progress {
969 background-color: '. esc_html(get_option('wpr_lb_pb_color','#a90707')) .' !important;
970 }
971 .lg-icon {
972 color: '. esc_html(get_option('wpr_lb_ui_color','#efefef')) .' !important;
973 font-size: '. esc_html(get_option('wpr_lb_icon_size',20)) .'px !important;
974 }
975 .lg-icon.lg-toogle-thumb {
976 font-size: '. esc_html((get_option('wpr_lb_icon_size',20) + 4)) .'px !important;
977 }
978 .lg-icon:hover,
979 .lg-dropdown-text:hover {
980 color: '. esc_html(get_option('wpr_lb_ui_hr_color','#ffffff')) .' !important;
981 }
982 .lg-sub-html,
983 .lg-dropdown-text {
984 color: '. esc_html(get_option('wpr_lb_text_color','#efefef')) .' !important;
985 font-size: '. esc_html(get_option('wpr_lb_text_size',14)) .'px !important;
986 }
987 #lg-counter {
988 color: '. esc_html(get_option('wpr_lb_text_color','#efefef')) .' !important;
989 font-size: '. esc_html(get_option('wpr_lb_text_size',14)) .'px !important;
990 }
991 .lg-prev,
992 .lg-next {
993 font-size: '. esc_html(get_option('wpr_lb_arrow_size',35)) .'px !important;
994 }
995
996 /* Defaults */
997 .lg-icon {
998 background-color: transparent !important;
999 }
1000
1001 #lg-counter {
1002 opacity: 0.9;
1003 }
1004
1005 .lg-thumb-outer {
1006 padding: 0 10px;
1007 }
1008
1009 .lg-thumb-item {
1010 border-radius: 0 !important;
1011 border: none !important;
1012 opacity: 0.5;
1013 }
1014
1015 .lg-thumb-item.active {
1016 opacity: 1;
1017 }
1018 </style>';
1019 }
1020
1021 public function elementor_init() {
1022 $this->_modules_manager = new Manager();
1023 }
1024
1025 public function register_widget_categories() {
1026 // Add element category in panel
1027 \Elementor\Plugin::instance()->elements_manager->add_category(
1028 'wpr-widgets',
1029 [
1030 'title' => Utilities::get_plugin_name(true),
1031 'icon' => 'font',
1032 ]
1033 );
1034
1035 // Add Woo element category in panel
1036 if ( Utilities::is_theme_builder_template() ) {
1037 \Elementor\Plugin::instance()->elements_manager->add_category(
1038 'wpr-theme-builder-widgets',
1039 [
1040 'title' => sprintf(esc_html__( '%s Theme Builder', 'wpr-addons' ), Utilities::get_plugin_name()),
1041 'icon' => 'font',
1042 ]
1043 );
1044 }
1045
1046 // Add Woocommerce Builder category in panel
1047 if ( Utilities::is_theme_builder_template() ) {
1048 \Elementor\Plugin::instance()->elements_manager->add_category(
1049 'wpr-woocommerce-builder-widgets',
1050 [
1051 'title' => sprintf(esc_html__( '%s Woocommerce Builder', 'wpr-addons' ), Utilities::get_plugin_name()),
1052 'icon' => 'font',
1053 ]
1054 );
1055 }
1056
1057 // Add Premium Widtgets category in panel
1058 \Elementor\Plugin::instance()->elements_manager->add_category(
1059 'wpr-premium-widgets',
1060 [
1061 'title' => sprintf(esc_html__( '%s Premium Widgets', 'wpr-addons' ), Utilities::get_plugin_name()),
1062 'icon' => 'font',
1063 ]
1064 );
1065 }
1066
1067 public function promote_premium_widgets($config) {
1068
1069 // if ( is_plugin_active('elementor-pro/elementor-pro.php') || is_plugin_active('pro-elements/pro-elements.php') ) {
1070 // }
1071 $config['promotionWidgets'] = [];
1072
1073 $category = Utilities::is_theme_builder_template() ? 'wpr-woocommerce-builder-widgets' : 'wpr-premium-widgets';
1074
1075 if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) {
1076 $promotion_widgets = [
1077 [
1078 'name' => 'wpr-woo-category-grid',
1079 'title' => __('Woo Category Grid', 'wpr-addons'),
1080 'icon' => 'wpr-icon eicon-gallery-grid',
1081 'categories' => '["'. $category .'"]',
1082 ],
1083 [
1084 'name' => 'wpr-my-account',
1085 'title' => __('My Account', 'wpr-addons'),
1086 'icon' => 'wpr-icon eicon-my-account',
1087 'categories' => '["'. $category .'"]',
1088 ],
1089 [
1090 'name' => 'wpr-product-filters',
1091 'title' => __('Product Filters', 'wpr-addons'),
1092 'icon' => 'wpr-icon eicon-filter',
1093 'categories' => '["'. $category .'"]',
1094 ],
1095 [
1096 'name' => 'wpr-product-breadcrumbs',
1097 'title' => __('Product Breadcrumbs', 'wpr-addons'),
1098 'icon' => 'wpr-icon eicon-product-breadcrumbs',
1099 'categories' => '["'. $category .'"]',
1100 ],
1101 [
1102 'name' => 'wpr-breadcrumbs',
1103 'title' => __('Post Breadcrumbs', 'wpr-addons'),
1104 'icon' => 'wpr-icon eicon-product-breadcrumbs',
1105 'categories' => '["'. $category .'"]',
1106 ],
1107 [
1108 'name' => 'wpr-weather',
1109 'title' => __('Weather', 'wpr-addons'),
1110 'icon' => 'wpr-icon eicon-cloud-check',
1111 'categories' => '["'. $category .'"]',
1112 ],
1113 [
1114 'name' => 'wpr-google-reviews',
1115 'title' => __('Google Reviews', 'wpr-addons'),
1116 'icon' => 'wpr-icon eicon-star',
1117 'categories' => '["'. $category .'"]',
1118 ],
1119 ];
1120
1121 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $promotion_widgets );
1122 }
1123
1124 if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->is_plan( 'expert' ) ) {
1125 $expert_widgets = [
1126 [
1127 'name' => 'wpr-category-grid',
1128 'title' => __('Category Grid', 'wpr-addons'),
1129 'icon' => 'wpr-icon eicon-gallery-grid',
1130 'categories' => '["'. $category .'"]',
1131 ],
1132 [
1133 'name' => 'wpr-wishlist-button',
1134 'title' => __('Wishlist Button', 'wpr-addons'),
1135 'icon' => 'wpr-icon eicon-heart',
1136 'categories' => '["'. $category .'"]',
1137 ],
1138 [
1139 'name' => 'wpr-mini-wishlist',
1140 'title' => __('Mini Wishlist', 'wpr-addons'),
1141 'icon' => 'wpr-icon eicon-heart',
1142 'categories' => '["'. $category .'"]',
1143 ],
1144 [
1145 'name' => 'wpr-wishlist',
1146 'title' => __('Wishlist Table', 'wpr-addons'),
1147 'icon' => 'wpr-icon eicon-heart',
1148 'categories' => '["'. $category .'"]',
1149 ],
1150 [
1151 'name' => 'wpr-compare-button',
1152 'title' => __('Compare Button', 'wpr-addons'),
1153 'icon' => 'wpr-icon eicon-exchange', // GOGA - new icon needed for compare
1154 'categories' => '["'. $category .'"]',
1155 ],
1156 [
1157 'name' => 'wpr-mini-compare',
1158 'title' => __('Mini Compare', 'wpr-addons'),
1159 'icon' => 'wpr-icon eicon-exchange',
1160 'categories' => '["'. $category .'"]',
1161 ],
1162 [
1163 'name' => 'wpr-compare',
1164 'title' => __('Compare Table', 'wpr-addons'),
1165 'icon' => 'wpr-icon eicon-exchange',
1166 'categories' => '["'. $category .'"]',
1167 ],
1168 [
1169 'name' => 'wpr-custom-field',
1170 'title' => __('Custom Field', 'wpr-addons'),
1171 'icon' => 'wpr-icon eicon-database',
1172 'categories' => '["'. $category .'"]',
1173 ],
1174 [
1175 'name' => 'wpr-advanced-filters',
1176 'title' => __('Advanced Filters', 'wpr-addons'),
1177 'icon' => 'wpr-icon eicon-filter',
1178 'categories' => '["'. $category .'"]',
1179 ],
1180 ];
1181
1182 $config['promotionWidgets'] = array_merge( $config['promotionWidgets'], $expert_widgets );
1183 }
1184
1185 return $config;
1186 }
1187
1188 protected function add_actions() {
1189
1190 // Widget Builder
1191 new \WprAddons\Modules\WidgetBuilder\Init();
1192
1193 // User Cookie
1194 add_action( 'init', [$this, 'wpr_some_init_actions' ]);
1195
1196 // Register Widgets
1197 add_action( 'elementor/init', [ $this, 'elementor_init' ] );
1198
1199 // Register Categories
1200 add_action( 'elementor/elements/categories_registered', [ $this, 'register_widget_categories' ] );
1201
1202 // Register Ajax Hooks
1203 $this->register_ajax_hooks();
1204
1205 // Register Mega Menu Route
1206 $this->register_megamenu_route();
1207
1208 // $this->register_compare_custom_routes();
1209
1210 // Register Custom Controls
1211 add_action( 'elementor/controls/controls_registered', [ $this, 'register_custom_controls' ] );
1212
1213 // Register Document Type
1214 add_action( 'elementor/documents/register', [ $this, 'register_elementor_document_type' ] );
1215
1216 // Frontend CSS
1217 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ], 998 );
1218
1219 // Editor CSS
1220 add_action( 'elementor/preview/enqueue_styles', [ $this, 'enqueue_editor_styles' ], 998 );
1221
1222 // Register Scripts
1223 add_action( 'elementor/frontend/before_register_scripts', [ $this, 'register_scripts' ], 998 );
1224
1225 // Frontend JS
1226 add_action( 'elementor/frontend/before_enqueue_scripts', [ $this, 'enqueue_scripts' ], 998 );
1227
1228 // Editor CSS/JS
1229 add_action( 'elementor/editor/after_enqueue_styles', [ $this, 'enqueue_panel_styles' ], 988 );
1230 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_inner_panel_scripts' ], 988 );
1231 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_panel_scripts' ], 988 );
1232
1233 // Lightbox Styles
1234 add_action( 'wp_head', [ $this, 'lightbox_styles' ], 988 );
1235
1236 // Promote Premium Widgets
1237 if ( current_user_can('administrator') ) {
1238 add_filter('elementor/editor/localize_settings', [$this, 'promote_premium_widgets'], 999);
1239 }
1240
1241 add_filter( 'pre_get_posts', [$this, 'wpr_custom_posts_per_page'] );
1242 add_filter('excerpt_more', [$this, 'wpr_custom_excerpt_more']);
1243 add_filter('excerpt_length', [$this, 'wpr_custom_excerpt_length']);
1244 }
1245
1246 /*
1247 ** Custom function to modify excerpt more text
1248 */
1249 function wpr_custom_excerpt_more($more) { // TODO: check
1250 return ''; // Change to '...' or any other text if desired
1251 }
1252
1253 /*
1254 ** Custom function to modify excerpt more length
1255 */
1256 function wpr_custom_excerpt_length($length) {
1257 return 999;
1258 }
1259
1260 public function wpr_custom_posts_per_page( $query ) {
1261 if ( $query->is_main_query() && isset($query->query['post_type']) ) {
1262 if (is_admin() ) {
1263 if (\Elementor\Plugin::$instance->editor && !\Elementor\Plugin::$instance->editor->is_edit_mode()) {
1264 return;
1265 }
1266 }
1267 $query_post_type = $query->query['post_type'];
1268 if ( is_string($query_post_type) && is_post_type_archive($query_post_type) && get_option('wpr_cpt_ppp_'. $query_post_type ) ) {
1269 $query->set( 'posts_per_page', get_option('wpr_cpt_ppp_'. $query_post_type ) );
1270 }
1271 }
1272
1273 return $query;
1274 }
1275
1276 /**
1277 * Plugin constructor.
1278 */
1279 private function __construct() {
1280 spl_autoload_register( [ $this, 'autoload' ] );
1281
1282 $this->_includes();
1283 $this->add_actions();
1284 }
1285
1286 }
1287
1288 if ( ! defined( 'WPR_ADDONS_TESTS' ) ) {
1289 // In tests we run the instance manually.
1290 Plugin::instance();
1291 }
1292