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

777 lines 22.6 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' );
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 return (bool) wp_rand( 0, 1 );
507 }
508
509 private function is_elementor_page(): bool {
510 return 0 === strpos( $this->current_screen_id, 'elementor_page' );
511 }
512
513 private function get_plugin_cta_data( $plugin_slug, $plugin_file_path ) {
514 if ( is_plugin_active( $plugin_file_path ) ) {
515 return false;
516 }
517
518 if ( $this->is_plugin_installed( $plugin_file_path ) ) {
519 $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 );
520 $cta_text = esc_html__( 'Activate Plugin', 'elementor' );
521 } else {
522 $url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $plugin_slug ), 'install-plugin_' . $plugin_slug );
523 $cta_text = esc_html__( 'Install Plugin', 'elementor' );
524 }
525
526 return [
527 'url' => $url,
528 'text' => $cta_text,
529 ];
530 }
531
532 /**
533 * For testing purposes
534 */
535 public function get_elementor_version() {
536 return ELEMENTOR_VERSION;
537 }
538
539 private function notice_plugin_image_optimization() {
540 $notice_id = 'plugin_image_optimization';
541
542 if ( 'upload' !== $this->current_screen_id ) {
543 return false;
544 }
545
546 if ( ! current_user_can( 'manage_options' ) || User::is_user_notice_viewed( $notice_id ) ) {
547 return false;
548 }
549
550 $attachments = new \WP_Query( [
551 'post_type' => 'attachment',
552 'post_status' => 'any',
553 'fields' => 'ids',
554 ] );
555
556 if ( 1 > $attachments->found_posts ) {
557 return false;
558 }
559
560 $plugin_file_path = 'image-optimization/image-optimization.php';
561 $plugin_slug = 'image-optimization';
562
563 $cta_data = $this->get_plugin_cta_data( $plugin_slug, $plugin_file_path );
564
565 if ( empty( $cta_data ) ) {
566 return false;
567 }
568
569 $options = [
570 'title' => esc_html__( 'Speed up your website with Image Optimizer by Elementor', 'elementor' ),
571 'description' => esc_html__( 'Automatically compress and optimize images, resize larger files, or convert to WebP. Optimize images individually, in bulk, or on upload.', 'elementor' ),
572 'id' => $notice_id,
573 'type' => 'cta',
574 'button_secondary' => [
575 'text' => $cta_data['text'],
576 'url' => $cta_data['url'],
577 'type' => 'cta',
578 ],
579 ];
580
581 $this->print_admin_notice( $options );
582
583 return true;
584 }
585
586 private function is_plugin_installed( $file_path ): bool {
587 $installed_plugins = get_plugins();
588
589 return isset( $installed_plugins[ $file_path ] );
590 }
591
592 public function print_admin_notice( array $options, $exclude_pages = self::DEFAULT_EXCLUDED_PAGES ) {
593 global $pagenow;
594
595 if ( in_array( $pagenow, $exclude_pages, true ) ) {
596 return;
597 }
598
599 $default_options = [
600 'id' => null,
601 'title' => '',
602 'description' => '',
603 'classes' => [ 'notice', 'e-notice' ], // We include WP's default notice class so it will be properly handled by WP's js handler
604 'type' => '',
605 'dismissible' => true,
606 'icon' => 'eicon-elementor',
607 'button' => [],
608 'button_secondary' => [],
609 ];
610
611 $options = array_replace_recursive( $default_options, $options );
612
613 $notice_classes = $options['classes'];
614 $dismiss_button = '';
615 $icon = '';
616
617 if ( $options['type'] ) {
618 $notice_classes[] = 'e-notice--' . $options['type'];
619 }
620
621 $wrapper_attributes = [];
622
623 if ( $options['dismissible'] ) {
624 $label = esc_html__( 'Dismiss this notice.', 'elementor' );
625 $notice_classes[] = 'e-notice--dismissible';
626 $dismiss_button = '<i class="e-notice__dismiss" role="button" aria-label="' . $label . '" tabindex="0"></i>';
627
628 $wrapper_attributes['data-nonce'] = wp_create_nonce( 'elementor_set_admin_notice_viewed' );
629 }
630
631 if ( $options['icon'] ) {
632 $notice_classes[] = 'e-notice--extended';
633 $icon = '<div class="e-notice__icon-wrapper"><i class="' . esc_attr( $options['icon'] ) . '" aria-hidden="true"></i></div>';
634 }
635
636 $wrapper_attributes['class'] = $notice_classes;
637
638 if ( $options['id'] ) {
639 $wrapper_attributes['data-notice_id'] = $options['id'];
640 }
641 ?>
642 <div <?php Utils::print_html_attributes( $wrapper_attributes ); ?>>
643 <?php echo $dismiss_button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
644 <div class="e-notice__aside">
645 <?php echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
646 </div>
647 <div class="e-notice__content">
648 <?php if ( $options['title'] ) { ?>
649 <h3><?php echo wp_kses_post( $options['title'] ); ?></h3>
650 <?php } ?>
651
652 <?php if ( $options['description'] ) { ?>
653 <p><?php echo wp_kses_post( $options['description'] ); ?></p>
654 <?php } ?>
655
656 <?php if ( ! empty( $options['button']['text'] ) || ! empty( $options['button_secondary']['text'] ) ) { ?>
657 <div class="e-notice__actions">
658 <?php
659 foreach ( [ $options['button'], $options['button_secondary'] ] as $index => $button_settings ) {
660 if ( empty( $button_settings['variant'] ) && $index ) {
661 $button_settings['variant'] = 'outline';
662 }
663
664 if ( empty( $button_settings['text'] ) ) {
665 continue;
666 }
667
668 $button = new Button( $button_settings );
669 $button->print_button();
670 } ?>
671 </div>
672 <?php } ?>
673 </div>
674 </div>
675 <?php }
676
677 public function admin_notices() {
678 $this->install_time = Plugin::$instance->get_install_time();
679 $this->current_screen_id = get_current_screen()->id;
680
681 foreach ( $this->plain_notices as $notice ) {
682 $method_callback = "notice_{$notice}";
683 if ( $this->$method_callback() ) {
684 return;
685 }
686 }
687
688 /** @var Base_Notice $notice_instance */
689 foreach ( $this->get_notices() as $notice_instance ) {
690 if ( ! $notice_instance->should_print() ) {
691 continue;
692 }
693
694 $this->print_admin_notice( $notice_instance->get_config() );
695
696 // It exits the method to make sure it prints only one notice.
697 return;
698 }
699 }
700
701 public function maybe_log_campaign() {
702 if ( empty( $_GET['plg_campaign'] ) || empty( $_GET['plg_campaign_name'] ) ) {
703 return;
704 }
705
706 $allowed_plgs = [
707 'elementor_image_optimization_campaign',
708 'elementor_ea11y_campaign',
709 'elementor_site_mailer_campaign',
710 ];
711
712 if ( ! in_array( $_GET['plg_campaign_name'], $allowed_plgs, true ) ) {
713 return;
714 }
715
716 if ( ! isset( $_GET['plg_campaign_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['plg_campaign_nonce'] ), sanitize_key( $_GET['plg_campaign_name'] ) ) ) {
717 return;
718 }
719
720 if ( ! current_user_can( 'manage_options' ) ) {
721 return;
722 }
723
724 if ( empty( $_GET['plg_source'] ) || empty( $_GET['plg_medium'] ) ) {
725 return;
726 }
727
728 $campaign_data = [
729 'source' => sanitize_key( $_GET['plg_source'] ),
730 'campaign' => sanitize_key( $_GET['plg_campaign'] ),
731 'medium' => sanitize_key( $_GET['plg_medium'] ),
732 ];
733
734 set_transient( sanitize_key( $_GET['plg_campaign_name'] ), $campaign_data, 30 * DAY_IN_SECONDS );
735 }
736
737 private static function add_plg_campaign_data( $url, $campaign_data ) {
738
739 foreach ( [ 'name', 'campaign' ] as $key ) {
740 if ( empty( $campaign_data[ $key ] ) ) {
741 return $url;
742 }
743 }
744
745 return add_query_arg( [
746 'plg_campaign_name' => $campaign_data['name'],
747 'plg_campaign' => $campaign_data['campaign'],
748 'plg_source' => empty( $campaign_data['source'] ) ? '' : $campaign_data['source'],
749 'plg_medium' => empty( $campaign_data['medium'] ) ? '' : $campaign_data['medium'],
750 'plg_campaign_nonce' => wp_create_nonce( $campaign_data['name'] ),
751 ], $url );
752 }
753
754 /**
755 * @since 2.9.0
756 * @access public
757 */
758 public function __construct() {
759 add_action( 'admin_notices', [ $this, 'admin_notices' ], 20 );
760 add_action( 'admin_action_install-plugin', [ $this, 'maybe_log_campaign' ] );
761 }
762
763 /**
764 * Get module name.
765 *
766 * Retrieve the module name.
767 *
768 * @since 2.9.0
769 * @access public
770 *
771 * @return string Module name.
772 */
773 public function get_name() {
774 return 'admin-notices';
775 }
776 }
777