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