PluginProbe
Elementor Website Builder – more than just a page builder / 3.5.0-beta1
Elementor Website Builder – more than just a page builder v3.5.0-beta1
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.5.0-beta1, at core/admin/admin-notices.php

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