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

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