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

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