PluginProbe
Elementor Website Builder – more than just a page builder / 3.7.8
Elementor Website Builder – more than just a page builder v3.7.8
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / admin / admin-notices.php

admin-notices.php in Elementor Website Builder – more than just a page builder 3.7.8, at core/admin/admin-notices.php

679 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Admin;
3
4 use Elementor\Api;
5 use Elementor\Core\Admin\UI\Components\Button;
6 use Elementor\Core\Base\Module;
7 use Elementor\Plugin;
8 use Elementor\Tracker;
9 use Elementor\User;
10 use Elementor\Utils;
11 use Elementor\Core\Admin\Notices\Base_Notice;
12 use Elementor\Core\Admin\Notices\Elementor_Dev_Notice;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 class Admin_Notices extends Module {
19
20 const EXCLUDE_PAGES = [ 'plugins.php', 'plugin-install.php', 'plugin-editor.php' ];
21
22 private $plain_notices = [
23 'api_notice',
24 'api_upgrade_plugin',
25 'tracker',
26 'rate_us_feedback',
27 'woocommerce_promote',
28 'cf7_promote',
29 'mc4wp_promote',
30 'popup_maker_promote',
31 'role_manager_promote',
32 'experiment_promotion',
33 ];
34
35 private $elementor_pages_count = null;
36
37 private $install_time = null;
38
39 private $current_screen_id = null;
40
41 private function get_notices() {
42 $notices = [
43 new Elementor_Dev_Notice(),
44 ];
45
46 /**
47 * Admin notices.
48 *
49 * Filters Elementor admin notices.
50 *
51 * This hook can be used by external developers to manage existing
52 * admin notice or to add new notices for Elementor addons.
53 *
54 * @param array $notices A list of notice classes.
55 */
56 $notices = apply_filters( 'elementor/core/admin/notices', $notices );
57
58 return $notices;
59 }
60
61 private function get_install_time() {
62 if ( null === $this->install_time ) {
63 $this->install_time = Plugin::$instance->get_install_time();
64 }
65
66 return $this->install_time;
67 }
68
69 private function get_elementor_pages_count() {
70 if ( null === $this->elementor_pages_count ) {
71 $elementor_pages = new \WP_Query( [
72 'no_found_rows' => true,
73 'post_type' => 'any',
74 'post_status' => 'publish',
75 'fields' => 'ids',
76 'update_post_meta_cache' => false,
77 'update_post_term_cache' => false,
78 'meta_key' => '_elementor_edit_mode',
79 'meta_value' => 'builder',
80 ] );
81
82 $this->elementor_pages_count = $elementor_pages->post_count;
83 }
84
85 return $this->elementor_pages_count;
86 }
87
88 private function notice_api_upgrade_plugin() {
89 $upgrade_notice = Api::get_upgrade_notice();
90 if ( empty( $upgrade_notice ) ) {
91 return false;
92 }
93
94 if ( ! current_user_can( 'update_plugins' ) ) {
95 return false;
96 }
97
98 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_elementor', 'edit-elementor_library', 'elementor_page_elementor-system-info', 'dashboard' ], true ) ) {
99 return false;
100 }
101
102 // Check if have any upgrades.
103 $update_plugins = get_site_transient( 'update_plugins' );
104
105 $has_remote_update_package = ! ( empty( $update_plugins ) || empty( $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ] ) || empty( $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ]->package ) );
106
107 if ( ! $has_remote_update_package && empty( $upgrade_notice['update_link'] ) ) {
108 return false;
109 }
110
111 if ( $has_remote_update_package ) {
112 $product = $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ];
113
114 $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $product->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
115 $upgrade_url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . ELEMENTOR_PLUGIN_BASE ), 'upgrade-plugin_' . ELEMENTOR_PLUGIN_BASE );
116 $new_version = $product->new_version;
117 } else {
118 $upgrade_url = $upgrade_notice['update_link'];
119 $details_url = $upgrade_url;
120
121 $new_version = $upgrade_notice['version'];
122 }
123
124 // Check if have upgrade notices to show.
125 if ( version_compare( ELEMENTOR_VERSION, $upgrade_notice['version'], '>=' ) ) {
126 return false;
127 }
128
129 $notice_id = 'upgrade_notice_' . $upgrade_notice['version'];
130 if ( User::is_user_notice_viewed( $notice_id ) ) {
131 return false;
132 }
133
134 $message = sprintf(
135 /* translators: 1: Details URL, 2: Accessibility text, 3: Version number, 4: Update URL, 5: Accessibility text. */
136 __( 'There is a new version of Elementor Page Builder available. <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">View version %3$s details</a> or <a href="%4$s" class="update-link" aria-label="%5$s">update now</a>.', 'elementor' ),
137 esc_url( $details_url ),
138 esc_attr( sprintf(
139 /* translators: %s: Elementor version. */
140 __( 'View Elementor version %s details', 'elementor' ),
141 $new_version
142 ) ),
143 $new_version,
144 esc_url( $upgrade_url ),
145 esc_attr( esc_html__( 'Update Elementor Now', 'elementor' ) )
146 );
147
148 $options = [
149 'title' => esc_html__( 'Update Notification', 'elementor' ),
150 'description' => $message,
151 'button' => [
152 'icon_classes' => 'dashicons dashicons-update',
153 'text' => esc_html__( 'Update Now', 'elementor' ),
154 'url' => $upgrade_url,
155 ],
156 'id' => $notice_id,
157 ];
158
159 $this->print_admin_notice( $options );
160
161 return true;
162 }
163
164 private function notice_api_notice() {
165 $admin_notice = Api::get_admin_notice();
166 if ( empty( $admin_notice ) ) {
167 return false;
168 }
169
170 if ( ! current_user_can( 'manage_options' ) ) {
171 return false;
172 }
173
174 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_elementor', 'edit-elementor_library', 'elementor_page_elementor-system-info', 'dashboard' ], true ) ) {
175 return false;
176 }
177
178 $notice_id = 'admin_notice_api_' . $admin_notice['notice_id'];
179 if ( User::is_user_notice_viewed( $notice_id ) ) {
180 return false;
181 }
182
183 $options = [
184 'title' => esc_html__( 'Update Notification', 'elementor' ),
185 'description' => $admin_notice['notice_text'],
186 'id' => $notice_id,
187 ];
188
189 $this->print_admin_notice( $options );
190
191 return true;
192 }
193
194 private function notice_tracker() {
195 if ( ! current_user_can( 'manage_options' ) ) {
196 return false;
197 }
198
199 // Show tracker notice after 24 hours from installed time.
200 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
201 return false;
202 }
203
204 if ( '1' === get_option( 'elementor_tracker_notice' ) ) {
205 return false;
206 }
207
208 if ( Tracker::is_allow_track() ) {
209 return false;
210 }
211
212 if ( 2 > $this->get_elementor_pages_count() ) {
213 return false;
214 }
215
216 // TODO: Skip for development env.
217 $optin_url = wp_nonce_url( add_query_arg( 'elementor_tracker', 'opt_into' ), 'opt_into' );
218 $optout_url = wp_nonce_url( add_query_arg( 'elementor_tracker', 'opt_out' ), 'opt_out' );
219
220 $tracker_description_text = esc_html__( 'Become a super contributor by opting in to share non-sensitive plugin data and to receive periodic email updates from us.', 'elementor' );
221
222 /**
223 * Tracker admin description text.
224 *
225 * Filters the admin notice text for non-sensitive data collection.
226 *
227 * @since 1.0.0
228 *
229 * @param string $tracker_description_text Description text displayed in admin notice.
230 */
231 $tracker_description_text = apply_filters( 'elementor/tracker/admin_description_text', $tracker_description_text );
232
233 $message = esc_html( $tracker_description_text ) . ' <a href="https://go.elementor.com/usage-data-tracking/" target="_blank">' . esc_html__( 'Learn more.', 'elementor' ) . '</a>';
234
235 $options = [
236 'title' => esc_html__( 'Love using Elementor?', 'elementor' ),
237 'description' => $message,
238 'button' => [
239 'text' => esc_html__( 'Sure! I\'d love to help', 'elementor' ),
240 'url' => $optin_url,
241 'type' => 'cta',
242 ],
243 'button_secondary' => [
244 'text' => esc_html__( 'No thanks', 'elementor' ),
245 'url' => $optout_url,
246 'variant' => 'outline',
247 'type' => 'cta',
248 ],
249 ];
250
251 $this->print_admin_notice( $options );
252
253 return true;
254 }
255
256 private function notice_rate_us_feedback() {
257 $notice_id = 'rate_us_feedback';
258
259 if ( ! current_user_can( 'manage_options' ) ) {
260 return false;
261 }
262
263 if ( 'dashboard' !== $this->current_screen_id || User::is_user_notice_viewed( $notice_id ) ) {
264 return false;
265 }
266
267 if ( 10 >= $this->get_elementor_pages_count() ) {
268 return false;
269 }
270
271 $dismiss_url = add_query_arg( [
272 'action' => 'elementor_set_admin_notice_viewed',
273 'notice_id' => esc_attr( $notice_id ),
274 ], admin_url( 'admin-post.php' ) );
275
276 $options = [
277 'title' => esc_html__( 'Congrats!', 'elementor' ),
278 'description' => esc_html__( 'You created over 10 pages with Elementor. Great job! If you can spare a minute,
279 please help us by leaving a five star review on WordPress.org.', 'elementor' ),
280 'id' => $notice_id,
281 'button' => [
282 'text' => esc_html__( 'Happy To Help', 'elementor' ),
283 'url' => 'https://go.elementor.com/admin-review/',
284 'new_tab' => true,
285 'type' => 'cta',
286 ],
287 'button_secondary' => [
288 'text' => esc_html__( 'Hide Notification', 'elementor' ),
289 'classes' => [ 'e-notice-dismiss' ],
290 'url' => esc_url_raw( $dismiss_url ),
291 'new_tab' => true,
292 'type' => 'cta',
293 ],
294 ];
295
296 $this->print_admin_notice( $options );
297
298 return true;
299 }
300
301 private function notice_woocommerce_promote() {
302 $notice_id = 'woocommerce_promote';
303
304 if ( Utils::has_pro() || ! function_exists( 'WC' ) ) {
305 return false;
306 }
307
308 if ( ! current_user_can( 'install_plugins' ) ) {
309 return false;
310 }
311
312 if ( ! in_array( $this->current_screen_id, [ 'edit-product', 'woocommerce_page_wc-settings' ], true ) || User::is_user_notice_viewed( $notice_id ) ) {
313 return false;
314 }
315
316 if ( strtotime( '2019-08-01' ) > $this->get_install_time() ) {
317 return false;
318 }
319
320 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
321 return false;
322 }
323
324 $options = [
325 'title' => esc_html__( 'Using WooCommerce?', 'elementor' ),
326 'description' => esc_html__( 'With Elementor Pro’s WooCommerce Builder, you’ll be able to design your store without coding!', 'elementor' ),
327 'id' => $notice_id,
328
329 'button' => [
330 'text' => esc_html__( 'Learn More', 'elementor' ),
331 'url' => 'https://go.elementor.com/plugin-promotion-woocommerce/',
332 'new_tab' => true,
333 'type' => 'cta',
334 ],
335 ];
336
337 $this->print_admin_notice( $options );
338
339 return true;
340 }
341
342 private function notice_cf7_promote() {
343 $notice_id = 'cf7_promote';
344
345 if ( Utils::has_pro() || ! defined( 'WPCF7_VERSION' ) ) {
346 return false;
347 }
348
349 if ( ! current_user_can( 'install_plugins' ) ) {
350 return false;
351 }
352
353 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_wpcf7', 'contact_page_wpcf7-integration' ], true ) || User::is_user_notice_viewed( $notice_id ) ) {
354 return false;
355 }
356
357 if ( strtotime( '2019-08-01' ) > $this->get_install_time() ) {
358 return false;
359 }
360
361 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
362 return false;
363 }
364
365 $options = [
366 'title' => esc_html__( 'Using Elementor & Contact Form 7?', 'elementor' ),
367 'description' => esc_html__( 'Try out Elementor Pro and design your forms visually with one powerful tool.', 'elementor' ),
368
369 'id' => $notice_id,
370 'button' => [
371 'text' => esc_html__( 'Learn More', 'elementor' ),
372 'url' => 'https://go.elementor.com/plugin-promotion-contactform7/',
373 'new_tab' => true,
374 'type' => 'cta',
375 ],
376 ];
377
378 $this->print_admin_notice( $options );
379
380 return true;
381 }
382
383 private function notice_mc4wp_promote() {
384 $notice_id = 'mc4wp_promote';
385
386 if ( Utils::has_pro() || ! defined( 'MC4WP_VERSION' ) ) {
387 return false;
388 }
389
390 if ( ! current_user_can( 'install_plugins' ) ) {
391 return false;
392 }
393
394 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_mailchimp-for-wp', 'mc4wp_page_mailchimp-for-wp-forms', 'mc4wp_page_mailchimp-for-wp-integrations', 'mc4wp_page_mailchimp-for-wp-other', 'mc4wp_page_mailchimp-for-wp-extensions' ], true ) || User::is_user_notice_viewed( $notice_id ) ) {
395 return false;
396 }
397
398 if ( strtotime( '2019-08-01' ) > $this->get_install_time() ) {
399 return false;
400 }
401
402 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
403 return false;
404 }
405
406 $options = [
407 'title' => esc_html__( 'Want to design better MailChimp forms?', 'elementor' ),
408 'description' => esc_html__( 'Use Elementor Pro and enjoy unlimited integrations, visual design, templates and more.', 'elementor' ),
409 'dismissible' => true,
410 'id' => $notice_id,
411
412 'button' => [
413 'text' => esc_html__( 'Learn More', 'elementor' ),
414 'url' => 'https://go.elementor.com/plugin-promotion-mc4wp/',
415 'new_tab' => true,
416 'type' => 'cta',
417 ],
418 ];
419
420 $this->print_admin_notice( $options );
421
422 return true;
423 }
424
425 private function notice_popup_maker_promote() {
426 $notice_id = 'popup_maker_promote';
427
428 if ( Utils::has_pro() || ! class_exists( 'Popup_Maker' ) ) {
429 return false;
430 }
431
432 if ( ! current_user_can( 'install_plugins' ) ) {
433 return false;
434 }
435
436 if ( ! in_array( $this->current_screen_id, [ 'edit-popup', 'popup_page_pum-settings' ], true ) || User::is_user_notice_viewed( $notice_id ) ) {
437 return false;
438 }
439
440 if ( strtotime( '2019-08-01' ) > $this->get_install_time() ) {
441 return false;
442 }
443
444 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
445 return false;
446 }
447
448 $options = [
449 'title' => esc_html__( 'Using popups on your site?', 'elementor' ),
450 'description' => esc_html__( 'Build outstanding popups using Elementor Pro and get more leads, sales and subscribers.', 'elementor' ),
451 'dismissible' => true,
452 'id' => $notice_id,
453
454 'button' => [
455 'text' => esc_html__( 'Learn More', 'elementor' ),
456 'url' => 'https://go.elementor.com/plugin-promotion-popupmaker/',
457 'new_tab' => true,
458 'type' => 'cta',
459 ],
460 ];
461
462 $this->print_admin_notice( $options );
463
464 return true;
465 }
466
467 private function notice_role_manager_promote() {
468 $notice_id = 'role_manager_promote';
469
470 if ( Utils::has_pro() ) {
471 return false;
472 }
473
474 if ( ! current_user_can( 'manage_options' ) ) {
475 return false;
476 }
477
478 if ( 'elementor_page_elementor-role-manager' !== $this->current_screen_id || User::is_user_notice_viewed( $notice_id ) ) {
479 return false;
480 }
481
482 $users = new \WP_User_Query( [
483 'fields' => 'ID',
484 'number' => 10,
485 ] );
486
487 if ( 5 > $users->get_total() ) {
488 return false;
489 }
490
491 $options = [
492 'title' => esc_html__( 'Managing a multi-user site?', 'elementor' ),
493 'description' => esc_html__( 'With Elementor Pro, you can control user access and make sure no one messes up your design.', 'elementor' ),
494 'id' => $notice_id,
495
496 'button' => [
497 'text' => esc_html__( 'Learn More', 'elementor' ),
498 'url' => 'https://go.elementor.com/plugin-promotion-role-manager/',
499 'new_tab' => true,
500 'type' => 'cta',
501 ],
502 ];
503
504 $this->print_admin_notice( $options );
505
506 return true;
507 }
508
509 private function notice_experiment_promotion() {
510 $notice_id = 'experiment_promotion';
511
512 if ( ! current_user_can( 'manage_options' ) || User::is_user_notice_viewed( $notice_id ) ) {
513 return false;
514 }
515
516 $experiments = Plugin::$instance->experiments;
517 $is_all_performance_features_active = (
518 $experiments->is_feature_active( 'e_dom_optimization' ) &&
519 $experiments->is_feature_active( 'additional_custom_breakpoints' ) &&
520 $experiments->is_feature_active( 'e_optimized_css_loading' ) &&
521 $experiments->is_feature_active( 'e_optimized_assets_loading' )
522 );
523
524 if ( $is_all_performance_features_active ) {
525 return false;
526 }
527
528 $options = [
529 'title' => esc_html__( 'Improve your site’s performance score.', 'elementor' ),
530 'description' => esc_html__( 'With our experimental speed boosting features you can go faster than ever before. Look for the Performance label on our Experiments page and activate those experiments to improve your site loading speed.', 'elementor' ),
531 'id' => $notice_id,
532 'button' => [
533 'text' => esc_html__( 'Try it out', 'elementor' ),
534 'url' => admin_url( 'admin.php?page=elementor#tab-experiments' ),
535 'type' => 'cta',
536 ],
537 'button_secondary' => [
538 'text' => esc_html__( 'Learn more', 'elementor' ),
539 'url' => 'https://go.elementor.com/wp-dash-experiment-promotion/',
540 'new_tab' => true,
541 'type' => 'cta',
542 ],
543 ];
544
545 $this->print_admin_notice( $options );
546
547 return true;
548 }
549
550 public function print_admin_notice( array $options ) {
551 global $pagenow;
552
553 if ( in_array( $pagenow, self::EXCLUDE_PAGES ) ) {
554 return;
555 }
556
557 $default_options = [
558 'id' => null,
559 'title' => '',
560 'description' => '',
561 'classes' => [ 'notice', 'e-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
562 'type' => '',
563 'dismissible' => true,
564 'icon' => 'eicon-elementor',
565 'button' => [],
566 'button_secondary' => [],
567 ];
568
569 $options = array_replace_recursive( $default_options, $options );
570
571 $notice_classes = $options['classes'];
572 $dismiss_button = '';
573 $icon = '';
574
575 if ( $options['type'] ) {
576 $notice_classes[] = 'e-notice--' . $options['type'];
577 }
578
579 if ( $options['dismissible'] ) {
580 $label = esc_html__( 'Dismiss', 'elementor' );
581 $notice_classes[] = 'e-notice--dismissible';
582 $dismiss_button = '<i class="e-notice__dismiss" role="button" aria-label="' . $label . '" tabindex="0"></i>';
583 }
584
585 if ( $options['icon'] ) {
586 $notice_classes[] = 'e-notice--extended';
587 $icon = '<div class="e-notice__icon-wrapper"><i class="' . esc_attr( $options['icon'] ) . '" aria-hidden="true"></i></div>';
588 }
589
590 $wrapper_attributes = [
591 'class' => $notice_classes,
592 ];
593
594 if ( $options['id'] ) {
595 $wrapper_attributes['data-notice_id'] = $options['id'];
596 }
597 ?>
598 <div <?php Utils::print_html_attributes( $wrapper_attributes ); ?>>
599 <?php echo $dismiss_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
600 <div class="e-notice__aside">
601 <?php echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
602 </div>
603 <div class="e-notice__content">
604 <?php if ( $options['title'] ) { ?>
605 <h3><?php echo wp_kses_post( $options['title'] ); ?></h3>
606 <?php } ?>
607
608 <?php if ( $options['description'] ) { ?>
609 <p><?php echo wp_kses_post( $options['description'] ); ?></p>
610 <?php } ?>
611
612 <?php if ( ! empty( $options['button']['text'] ) || ! empty( $options['button_secondary']['text'] ) ) { ?>
613 <div class="e-notice__actions">
614 <?php
615 foreach ( [ $options['button'], $options['button_secondary'] ] as $index => $button_settings ) {
616 if ( empty( $button_settings['variant'] ) && $index ) {
617 $button_settings['variant'] = 'outline';
618 }
619
620 if ( empty( $button_settings['text'] ) ) {
621 continue;
622 }
623
624 $button = new Button( $button_settings );
625 $button->print_button();
626 } ?>
627 </div>
628 <?php } ?>
629 </div>
630 </div>
631 <?php }
632
633 public function admin_notices() {
634 $this->install_time = Plugin::$instance->get_install_time();
635 $this->current_screen_id = get_current_screen()->id;
636
637 foreach ( $this->plain_notices as $notice ) {
638 $method_callback = "notice_{$notice}";
639 if ( $this->$method_callback() ) {
640 return;
641 }
642 }
643
644 /** @var Base_Notice $notice_instance */
645 foreach ( $this->get_notices() as $notice_instance ) {
646 if ( ! $notice_instance->should_print() ) {
647 continue;
648 }
649
650 $this->print_admin_notice( $notice_instance->get_config() );
651
652 // It exits the method to make sure it prints only one notice.
653 return;
654 }
655 }
656
657 /**
658 * @since 2.9.0
659 * @access public
660 */
661 public function __construct() {
662 add_action( 'admin_notices', [ $this, 'admin_notices' ], 20 );
663 }
664
665 /**
666 * Get module name.
667 *
668 * Retrieve the module name.
669 *
670 * @since 2.9.0
671 * @access public
672 *
673 * @return string Module name.
674 */
675 public function get_name() {
676 return 'admin-notices';
677 }
678 }
679