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

781 lines 22.8 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\Core\Utils\Promotions\Filtered_Promotions_Manager;
8 use Elementor\Plugin;
9 use Elementor\Settings;
10 use Elementor\Tracker;
11 use Elementor\User;
12 use Elementor\Utils;
13 use Elementor\Core\Admin\Notices\Base_Notice;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 class Admin_Notices extends Module {
20
21 const DEFAULT_EXCLUDED_PAGES = [ 'plugins.php', 'plugin-install.php', 'plugin-editor.php' ];
22
23 private $plain_notices = [
24 'api_notice',
25 'api_upgrade_plugin',
26 'tracker',
27 'rate_us_feedback',
28 'role_manager_promote',
29 'experiment_promotion',
30 'site_mailer_promotion',
31 'plugin_image_optimization',
32 'ally_pages_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 /**
43 * Admin notices.
44 *
45 * Filters Elementor admin notices.
46 *
47 * This hook can be used by external developers to manage existing
48 * admin notice or to add new notices for Elementor add-ons.
49 *
50 * @param array $notices A list of notice classes.
51 */
52 $notices = apply_filters( 'elementor/core/admin/notices', [] );
53
54 return $notices;
55 }
56
57 private function get_install_time() {
58 if ( null === $this->install_time ) {
59 $this->install_time = Plugin::$instance->get_install_time();
60 }
61
62 return $this->install_time;
63 }
64
65 private function get_elementor_pages_count() {
66 if ( null === $this->elementor_pages_count ) {
67 $elementor_pages = new \WP_Query( [
68 'no_found_rows' => true,
69 'post_type' => 'any',
70 'post_status' => 'publish',
71 'fields' => 'ids',
72 'update_post_meta_cache' => false,
73 'update_post_term_cache' => false,
74 'meta_key' => '_elementor_edit_mode',
75 'meta_value' => 'builder',
76 ] );
77
78 $this->elementor_pages_count = $elementor_pages->post_count;
79 }
80
81 return $this->elementor_pages_count;
82 }
83
84 private function notice_api_upgrade_plugin() {
85 $upgrade_notice = Api::get_upgrade_notice();
86 if ( empty( $upgrade_notice ) ) {
87 return false;
88 }
89
90 if ( ! current_user_can( 'update_plugins' ) ) {
91 return false;
92 }
93
94 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_elementor', 'edit-elementor_library', 'elementor_page_elementor-system-info', 'dashboard' ], true ) ) {
95 return false;
96 }
97
98 // Check for upgrades.
99 $update_plugins = get_site_transient( 'update_plugins' );
100
101 $has_remote_update_package = ! ( empty( $update_plugins ) || empty( $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ] ) || empty( $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ]->package ) );
102
103 if ( ! $has_remote_update_package && empty( $upgrade_notice['update_link'] ) ) {
104 return false;
105 }
106
107 if ( $has_remote_update_package ) {
108 $product = $update_plugins->response[ ELEMENTOR_PLUGIN_BASE ];
109
110 $details_url = self_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $product->slug . '&section=changelog&TB_iframe=true&width=600&height=800' );
111 $upgrade_url = wp_nonce_url( self_admin_url( 'update.php?action=upgrade-plugin&plugin=' . ELEMENTOR_PLUGIN_BASE ), 'upgrade-plugin_' . ELEMENTOR_PLUGIN_BASE );
112 $new_version = $product->new_version;
113 } else {
114 $upgrade_url = $upgrade_notice['update_link'];
115 $details_url = $upgrade_url;
116
117 $new_version = $upgrade_notice['version'];
118 }
119
120 // Check if upgrade messages should be shown.
121 if ( version_compare( ELEMENTOR_VERSION, $upgrade_notice['version'], '>=' ) ) {
122 return false;
123 }
124
125 $notice_id = 'upgrade_notice_' . $upgrade_notice['version'];
126 if ( User::is_user_notice_viewed( $notice_id ) ) {
127 return false;
128 }
129
130 $message = sprintf(
131 /* translators: 1: Details URL, 2: Accessibility text, 3: Version number, 4: Update URL, 5: Accessibility text. */
132 __( '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' ),
133 esc_url( $details_url ),
134 esc_attr( sprintf(
135 /* translators: %s: Elementor version. */
136 __( 'View Elementor version %s details', 'elementor' ),
137 $new_version
138 ) ),
139 $new_version,
140 esc_url( $upgrade_url ),
141 esc_attr( esc_html__( 'Update Now', 'elementor' ) )
142 );
143
144 $options = [
145 'title' => esc_html__( 'Update Notification', 'elementor' ),
146 'description' => $message,
147 'button' => [
148 'icon_classes' => 'dashicons dashicons-update',
149 'text' => esc_html__( 'Update Now', 'elementor' ),
150 'url' => $upgrade_url,
151 ],
152 'id' => $notice_id,
153 ];
154
155 $this->print_admin_notice( $options );
156
157 return true;
158 }
159
160 private function notice_api_notice() {
161 $admin_notice = Api::get_admin_notice();
162 if ( empty( $admin_notice ) ) {
163 return false;
164 }
165
166 if ( ! current_user_can( 'manage_options' ) ) {
167 return false;
168 }
169
170 if ( ! in_array( $this->current_screen_id, [ 'toplevel_page_elementor', 'edit-elementor_library', 'elementor_page_elementor-system-info', 'dashboard' ], true ) ) {
171 return false;
172 }
173
174 $notice_id = 'admin_notice_api_' . $admin_notice['notice_id'];
175 if ( User::is_user_notice_viewed( $notice_id ) ) {
176 return false;
177 }
178
179 $options = [
180 'title' => esc_html__( 'Update Notification', 'elementor' ),
181 'description' => $admin_notice['notice_text'],
182 'id' => $notice_id,
183 ];
184
185 $this->print_admin_notice( $options );
186
187 return true;
188 }
189
190 private function notice_tracker() {
191 if ( ! current_user_can( 'manage_options' ) ) {
192 return false;
193 }
194
195 // Show tracker notice after 24 hours from installed time.
196 if ( strtotime( '+24 hours', $this->get_install_time() ) > time() ) {
197 return false;
198 }
199
200 if ( '1' === get_option( 'elementor_tracker_notice' ) ) {
201 return false;
202 }
203
204 if ( Tracker::is_allow_track() ) {
205 return false;
206 }
207
208 if ( 2 > $this->get_elementor_pages_count() ) {
209 return false;
210 }
211
212 // TODO: Skip for development env.
213 $optin_url = wp_nonce_url( add_query_arg( 'elementor_tracker', 'opt_into' ), 'opt_into' );
214 $optout_url = wp_nonce_url( add_query_arg( 'elementor_tracker', 'opt_out' ), 'opt_out' );
215
216 $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' );
217
218 /**
219 * Tracker admin description text.
220 *
221 * Filters the admin notice text for non-sensitive data collection.
222 *
223 * @since 1.0.0
224 *
225 * @param string $tracker_description_text Description text displayed in admin notice.
226 */
227 $tracker_description_text = apply_filters( 'elementor/tracker/admin_description_text', $tracker_description_text );
228
229 $message = esc_html( $tracker_description_text ) . ' <a href="https://go.elementor.com/usage-data-tracking/" target="_blank">' . esc_html__( 'Learn more.', 'elementor' ) . '</a>';
230
231 $options = [
232 'title' => esc_html__( 'Love using Elementor?', 'elementor' ),
233 'description' => $message,
234 'dismissible' => false,
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 '_wpnonce' => wp_create_nonce( 'elementor_set_admin_notice_viewed' ),
272 ], admin_url( 'admin-post.php' ) );
273
274 $options = [
275 'title' => esc_html__( 'Congrats!', 'elementor' ),
276 'description' => esc_html__( 'You created over 10 pages with Elementor. Great job! If you can spare a minute, 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_role_manager_promote() {
299 $notice_id = 'role_manager_promote';
300
301 if ( Utils::has_pro() ) {
302 return false;
303 }
304
305 if ( ! current_user_can( 'manage_options' ) ) {
306 return false;
307 }
308
309 if ( 'elementor_page_elementor-role-manager' !== $this->current_screen_id || User::is_user_notice_viewed( $notice_id ) ) {
310 return false;
311 }
312
313 $users = new \WP_User_Query( [
314 'fields' => 'ID',
315 'number' => 10,
316 ] );
317
318 if ( 5 > $users->get_total() ) {
319 return false;
320 }
321
322 $options = [
323 'title' => esc_html__( 'Managing a multi-user site?', 'elementor' ),
324 'description' => esc_html__( 'With Elementor Pro, you can control user access and make sure no one messes up your design.', 'elementor' ),
325 'id' => $notice_id,
326
327 'button' => [
328 'text' => esc_html__( 'Learn More', 'elementor' ),
329 'url' => 'https://go.elementor.com/plugin-promotion-role-manager/',
330 'new_tab' => true,
331 'type' => 'cta',
332 ],
333 ];
334
335 $options = Filtered_Promotions_Manager::get_filtered_promotion_data( $options, 'core/admin/notice_role_manager_promote', 'button', 'url' );
336
337 $this->print_admin_notice( $options );
338
339 return true;
340 }
341
342 private function notice_experiment_promotion() {
343 $notice_id = 'experiment_promotion';
344
345 if ( ! current_user_can( 'manage_options' ) || User::is_user_notice_viewed( $notice_id ) ) {
346 return false;
347 }
348
349 $experiments = Plugin::$instance->experiments;
350 $is_all_performance_features_active = (
351 $experiments->is_feature_active( 'e_element_cache' ) &&
352 $experiments->is_feature_active( 'e_font_icon_svg' )
353 );
354
355 if ( $is_all_performance_features_active ) {
356 return false;
357 }
358
359 $options = [
360 'title' => esc_html__( 'Improve your site’s performance score.', 'elementor' ),
361 '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' ),
362 'id' => $notice_id,
363 'button' => [
364 'text' => esc_html__( 'Try it out', 'elementor' ),
365 'url' => Settings::get_settings_tab_url( 'experiments' ),
366 'type' => 'cta',
367 ],
368 'button_secondary' => [
369 'text' => esc_html__( 'Learn more', 'elementor' ),
370 'url' => 'https://go.elementor.com/wp-dash-experiment-promotion/',
371 'new_tab' => true,
372 'type' => 'cta',
373 ],
374 ];
375
376 $this->print_admin_notice( $options );
377
378 return true;
379 }
380
381 private function site_has_forms_plugins() {
382 return defined( 'WPFORMS_VERSION' ) || defined( 'WPCF7_VERSION' ) || defined( 'FLUENTFORM_VERSION' ) || class_exists( '\GFCommon' ) || class_exists( '\Ninja_Forms' ) || function_exists( 'load_formidable_forms' ) || did_action( 'metform/after_load' ) || defined( 'FORMINATOR_PLUGIN_BASENAME' );
383 }
384
385 private function site_has_woocommerce() {
386 return class_exists( 'WooCommerce' );
387 }
388
389 private function notice_ally_pages_promotion() {
390 global $pagenow;
391 $notice_id = 'ally_pages_promotion';
392
393 if ( 'edit.php' !== $pagenow || empty( $_GET['post_type'] ) || 'page' !== $_GET['post_type'] ) {
394 return false;
395 }
396
397 if ( ! current_user_can( 'manage_options' ) || User::is_user_notice_viewed( $notice_id ) ) {
398 return false;
399 }
400
401 $plugin_file_path = 'pojo-accessibility/pojo-accessibility.php';
402 $plugin_slug = 'pojo-accessibility';
403
404 $cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
405 if ( empty( $cta_data ) ) {
406 return false;
407 }
408
409 $options = [
410 'title' => esc_html__( 'Make sure your site has an accessibility statement page', 'elementor' ),
411 'description' => esc_html__( 'Create a more inclusive site experience for all your visitors. With Ally, it\'s easy to add your statement page in just a few clicks.', 'elementor' ),
412 'id' => $notice_id,
413 'type' => 'cta',
414 'button' => [
415 'text' => $cta_data['text'],
416 'url' => self::add_plg_campaign_data( $cta_data['url'], [
417 'name' => 'elementor_ea11y_campaign',
418 'campaign' => 'acc-statement-plg-pages',
419 'source' => 'wp-pages',
420 'medium' => 'wp-dash',
421 ] ),
422 'type' => 'cta',
423 ],
424 'button_secondary' => [
425 'text' => esc_html__( 'Learn more', 'elementor' ),
426 'url' => 'https://go.elementor.com/acc-plg-learn-more',
427 'new_tab' => true,
428 'type' => 'cta',
429 ],
430 ];
431
432 $this->print_admin_notice( $options );
433
434 return true;
435 }
436
437 private function notice_site_mailer_promotion() {
438 $notice_id = 'site_mailer_promotion';
439 $has_forms = $this->site_has_forms_plugins();
440 $has_woocommerce = $this->site_has_woocommerce();
441
442 if ( ! $has_forms && ! $has_woocommerce ) {
443 return false;
444 }
445
446 if ( ! $this->is_elementor_page() && ! in_array( $this->current_screen_id, [ 'toplevel_page_elementor', 'edit-elementor_library', 'dashboard' ], true ) ) {
447 return false;
448 }
449
450 if ( ( Utils::has_pro() && ! $has_woocommerce ) || ! current_user_can( 'install_plugins' ) || User::is_user_notice_viewed( $notice_id ) ) {
451 return false;
452 }
453
454 $plugin_file_path = 'site-mailer/site-mailer.php';
455 $plugin_slug = 'site-mailer';
456
457 $cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
458 if ( empty( $cta_data ) ) {
459 return false;
460 }
461
462 $options = [
463 'title' => esc_html__( 'Ensure your form emails avoid the spam folder!', 'elementor' ),
464 'description' => esc_html__( 'Use Site Mailer for improved email deliverability, detailed email logs, and an easy setup.', 'elementor' ),
465 'id' => $notice_id,
466 'type' => 'cta',
467 'button' => [
468 'text' => $cta_data['text'],
469 'url' => $cta_data['url'],
470 'type' => 'cta',
471 ],
472 'button_secondary' => [
473 'text' => esc_html__( 'Learn more', 'elementor' ),
474 'url' => 'https://go.elementor.com/sm-core-form/',
475 'new_tab' => true,
476 'type' => 'cta',
477 ],
478 ];
479
480 if ( $this->should_render_woocommerce_hint( $has_forms, $has_woocommerce ) ) {
481 // We include WP's default notice class so it will be properly handled by WP's js handler
482 // And add a new one to distinguish between the two types of notices
483 $options['classes'] = [ 'notice', 'e-notice', 'sm-notice-wc' ];
484 $options['title'] = esc_html__( 'Improve Transactional Email Deliverability', 'elementor' );
485 $options['description'] = esc_html__( 'Use Elementor\'s Site Mailer to ensure your store emails like purchase confirmations, shipping updates and more are reliably delivered.', 'elementor' );
486 }
487
488 $this->print_admin_notice( $options );
489
490 return true;
491 }
492
493 private function should_render_woocommerce_hint( $has_forms, $has_woocommerce ): bool {
494 if ( ! $has_forms && ! $has_woocommerce ) {
495 return false;
496 }
497
498 if ( ! $has_forms && $has_woocommerce ) {
499 return true;
500 }
501
502 if ( $has_forms && $has_woocommerce && Utils::has_pro() ) {
503 return true;
504 }
505
506 if ( ! $has_woocommerce ) {
507 return false;
508 }
509
510 return (bool) wp_rand( 0, 1 );
511 }
512
513 private function is_elementor_page(): bool {
514 return 0 === strpos( $this->current_screen_id, 'elementor_page' );
515 }
516
517 private function get_plugin_cta_data( $plugin_slug, $plugin_file_path ) {
518 if ( is_plugin_active( $plugin_file_path ) ) {
519 return false;
520 }
521
522 if ( $this->is_plugin_installed( $plugin_file_path ) ) {
523 $url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . $plugin_file_path . '&amp;plugin_status=all&amp;paged=1&amp;s', 'activate-plugin_' . $plugin_file_path );
524 $cta_text = esc_html__( 'Activate Plugin', 'elementor' );
525 } else {
526 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
527 $cta_text = esc_html__( 'Install Plugin', 'elementor' );
528 }
529
530 return [
531 'url' => $url,
532 'text' => $cta_text,
533 ];
534 }
535
536 /**
537 * For testing purposes
538 */
539 public function get_elementor_version() {
540 return ELEMENTOR_VERSION;
541 }
542
543 private function notice_plugin_image_optimization() {
544 $notice_id = 'plugin_image_optimization';
545
546 if ( 'upload' !== $this->current_screen_id ) {
547 return false;
548 }
549
550 if ( ! current_user_can( 'manage_options' ) || User::is_user_notice_viewed( $notice_id ) ) {
551 return false;
552 }
553
554 $attachments = new \WP_Query( [
555 'post_type' => 'attachment',
556 'post_status' => 'any',
557 'fields' => 'ids',
558 ] );
559
560 if ( 1 > $attachments->found_posts ) {
561 return false;
562 }
563
564 $plugin_file_path = 'image-optimization/image-optimization.php';
565 $plugin_slug = 'image-optimization';
566
567 $cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
568
569 if ( empty( $cta_data ) ) {
570 return false;
571 }
572
573 $options = [
574 'title' => esc_html__( 'Speed up your website with Image Optimizer by Elementor', 'elementor' ),
575 'description' => esc_html__( 'Automatically compress and optimize images, resize larger files, or convert to WebP. Optimize images individually, in bulk, or on upload.', 'elementor' ),
576 'id' => $notice_id,
577 'type' => 'cta',
578 'button_secondary' => [
579 'text' => $cta_data['text'],
580 'url' => $cta_data['url'],
581 'type' => 'cta',
582 ],
583 ];
584
585 $this->print_admin_notice( $options );
586
587 return true;
588 }
589
590 private function is_plugin_installed( $file_path ): bool {
591 $installed_plugins = get_plugins();
592
593 return isset( $installed_plugins[ $file_path ] );
594 }
595
596 public function print_admin_notice( array $options, $exclude_pages = self::DEFAULT_EXCLUDED_PAGES ) {
597 global $pagenow;
598
599 if ( in_array( $pagenow, $exclude_pages, true ) ) {
600 return;
601 }
602
603 $default_options = [
604 'id' => null,
605 'title' => '',
606 'description' => '',
607 'classes' => [ 'notice', 'e-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
608 'type' => '',
609 'dismissible' => true,
610 'icon' => 'eicon-elementor',
611 'button' => [],
612 'button_secondary' => [],
613 ];
614
615 $options = array_replace_recursive( $default_options, $options );
616
617 $notice_classes = $options['classes'];
618 $dismiss_button = '';
619 $icon = '';
620
621 if ( $options['type'] ) {
622 $notice_classes[] = 'e-notice--' . $options['type'];
623 }
624
625 $wrapper_attributes = [];
626
627 if ( $options['dismissible'] ) {
628 $label = esc_html__( 'Dismiss this notice.', 'elementor' );
629 $notice_classes[] = 'e-notice--dismissible';
630 $dismiss_button = '<i class="e-notice__dismiss" role="button" aria-label="' . $label . '" tabindex="0"></i>';
631
632 $wrapper_attributes['data-nonce'] = wp_create_nonce( 'elementor_set_admin_notice_viewed' );
633 }
634
635 if ( $options['icon'] ) {
636 $notice_classes[] = 'e-notice--extended';
637 $icon = '<div class="e-notice__icon-wrapper"><i class="' . esc_attr( $options['icon'] ) . '" aria-hidden="true"></i></div>';
638 }
639
640 $wrapper_attributes['class'] = $notice_classes;
641
642 if ( $options['id'] ) {
643 $wrapper_attributes['data-notice_id'] = $options['id'];
644 }
645 ?>
646 <div <?php Utils::print_html_attributes( $wrapper_attributes ); ?>>
647 <?php echo $dismiss_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
648 <div class="e-notice__aside">
649 <?php echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
650 </div>
651 <div class="e-notice__content">
652 <?php if ( $options['title'] ) { ?>
653 <h3><?php echo wp_kses_post( $options['title'] ); ?></h3>
654 <?php } ?>
655
656 <?php if ( $options['description'] ) { ?>
657 <p><?php echo wp_kses_post( $options['description'] ); ?></p>
658 <?php } ?>
659
660 <?php if ( ! empty( $options['button']['text'] ) || ! empty( $options['button_secondary']['text'] ) ) { ?>
661 <div class="e-notice__actions">
662 <?php
663 foreach ( [ $options['button'], $options['button_secondary'] ] as $index => $button_settings ) {
664 if ( empty( $button_settings['variant'] ) && $index ) {
665 $button_settings['variant'] = 'outline';
666 }
667
668 if ( empty( $button_settings['text'] ) ) {
669 continue;
670 }
671
672 $button = new Button( $button_settings );
673 $button->print_button();
674 } ?>
675 </div>
676 <?php } ?>
677 </div>
678 </div>
679 <?php }
680
681 public function admin_notices() {
682 $this->install_time = Plugin::$instance->get_install_time();
683 $this->current_screen_id = get_current_screen()->id;
684
685 foreach ( $this->plain_notices as $notice ) {
686 $method_callback = "notice_{$notice}";
687 if ( $this->$method_callback() ) {
688 return;
689 }
690 }
691
692 /** @var Base_Notice $notice_instance */
693 foreach ( $this->get_notices() as $notice_instance ) {
694 if ( ! $notice_instance->should_print() ) {
695 continue;
696 }
697
698 $this->print_admin_notice( $notice_instance->get_config() );
699
700 // It exits the method to make sure it prints only one notice.
701 return;
702 }
703 }
704
705 public function maybe_log_campaign() {
706 if ( empty( $_GET['plg_campaign'] ) || empty( $_GET['plg_campaign_name'] ) ) {
707 return;
708 }
709
710 $allowed_plgs = [
711 'elementor_image_optimization_campaign',
712 'elementor_ea11y_campaign',
713 'elementor_site_mailer_campaign',
714 ];
715
716 if ( ! in_array( $_GET['plg_campaign_name'], $allowed_plgs, true ) ) {
717 return;
718 }
719
720 if ( ! isset( $_GET['plg_campaign_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['plg_campaign_nonce'] ), sanitize_key( $_GET['plg_campaign_name'] ) ) ) {
721 return;
722 }
723
724 if ( ! current_user_can( 'manage_options' ) ) {
725 return;
726 }
727
728 if ( empty( $_GET['plg_source'] ) || empty( $_GET['plg_medium'] ) ) {
729 return;
730 }
731
732 $campaign_data = [
733 'source' => sanitize_key( $_GET['plg_source'] ),
734 'campaign' => sanitize_key( $_GET['plg_campaign'] ),
735 'medium' => sanitize_key( $_GET['plg_medium'] ),
736 ];
737
738 set_transient( sanitize_key( $_GET['plg_campaign_name'] ), $campaign_data, 30 * DAY_IN_SECONDS );
739 }
740
741 private static function add_plg_campaign_data( $url, $campaign_data ) {
742
743 foreach ( [ 'name', 'campaign' ] as $key ) {
744 if ( empty( $campaign_data[ $key ] ) ) {
745 return $url;
746 }
747 }
748
749 return add_query_arg( [
750 'plg_campaign_name' => $campaign_data['name'],
751 'plg_campaign' => $campaign_data['campaign'],
752 'plg_source' => empty( $campaign_data['source'] ) ? '' : $campaign_data['source'],
753 'plg_medium' => empty( $campaign_data['medium'] ) ? '' : $campaign_data['medium'],
754 'plg_campaign_nonce' => wp_create_nonce( $campaign_data['name'] ),
755 ], $url );
756 }
757
758 /**
759 * @since 2.9.0
760 * @access public
761 */
762 public function __construct() {
763 add_action( 'admin_notices', [ $this, 'admin_notices' ], 20 );
764 add_action( 'admin_action_install-plugin', [ $this, 'maybe_log_campaign' ] );
765 }
766
767 /**
768 * Get module name.
769 *
770 * Retrieve the module name.
771 *
772 * @since 2.9.0
773 * @access public
774 *
775 * @return string Module name.
776 */
777 public function get_name() {
778 return 'admin-notices';
779 }
780 }
781