← Back
Editing: class-notices.php
<?php /** * Responsible for notices showing. * * @package wsal * @subpackage helpers * @copyright 2026 Melapress * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License, version 3 or higher * @link https://wordpress.org/plugins/wp-security-audit-log/ * @since 4.6.0 */ declare(strict_types=1); namespace WSAL\Helpers; use WSAL\Helpers\Settings_Helper; use WSAL\Utils\Abstract_Migration; // Exit if accessed directly. if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! class_exists( '\WSAL\Helpers\Notices' ) ) { /** * Holds the notices of the plugin * * @since 4.6.0 */ class Notices { /** * That is a global constant used for showing the ebook notice. */ public const EBOOK_NOTICE = 'ebook-notice-show'; /** * Constant used for showing the LearnDash update notice. * * @since 5.6.0 */ public const LEARNDASH_UPDATE_NOTICE = 'learndash-update-notice-dismissed'; /** * Option holding the date (Y-m-d) the BF notice was last dismissed. * * @since 5.7.0 */ public const BF_NOTICE_DISMISSED_ON = 'bf-notice-dismissed-on'; /** * First day (Y-m-d) of the BF notice period. * * @since 5.7.0 */ private const BF_NOTICE_START_DATE = '2026-11-17'; /** * Day (Y-m-d) * * @since 5.7.0 */ private const BF_NOTICE_REMINDER_DATE = '2026-11-26'; /** * Last day (Y-m-d) of the BF notice period. * * @since 5.7.0 */ private const BF_NOTICE_END_DATE = '2026-12-01'; /** * Holds the number of notices we have to show in the admin menu bubble. * * @var integer * * @since 5.2.2 */ private static $number_of_notices = 0; /** * Checks if LearnDash plugin is active. * * ! We use this local function instead of LearnDash_Helper::is_learndash_active() to avoid a * ! hard dependency on the LearnDash_Helper class, which can cause a fatal error in some edge cases. * * @return bool * * @since 5.6.1 */ private static function is_learndash_active(): bool { return \function_exists( 'learndash_get_post_type_slug' ); } /** * Sets the class hooks. * * @return void * * @since 4.6.0 */ public static function init() { global $current_screen; if ( ! isset( $current_screen ) ) { return; } if ( in_array( $current_screen->base, \WpSecurityAuditLog::get_plugin_screens_array(), true ) ) { $notice_upgrade = Settings_Helper::get_boolean_option_value( Abstract_Migration::UPGRADE_NOTICE, false ); if ( $notice_upgrade ) { Settings_Helper::delete_option_value( self::EBOOK_NOTICE ); self::display_notice_upgrade(); } // @free:start $notice_feature_highlight = Settings_Helper::get_boolean_option_value( Abstract_Migration::FEATURE_HIGHLIGHT_NOTICE, false ); if ( $notice_feature_highlight ) { self::display_feature_highlight_notice(); } // @free:end // if ( 'free' === \WpSecurityAuditLog::get_plugin_version() ) { // $ebook = Settings_Helper::get_boolean_option_value( self::EBOOK_NOTICE, false ); // if ( ! $ebook ) { // self::display_ebook_notice(); // } // } // $survey_2025 = Settings_Helper::get_boolean_option_value( 'survey-2025', false ); // if ( ! $survey_2025 ) { // self::display_yearly_security_survey(); // } $learndash_update_notice = Settings_Helper::get_boolean_option_value( self::LEARNDASH_UPDATE_NOTICE, false ); if ( ! $learndash_update_notice && self::is_learndash_active() ) { self::display_learndash_update_notice(); } elseif ( self::should_show_melapress_survey() ) { self::display_melapress_product_survey(); } } } /** * Displays the in-plugin banners at the top of the plugin pages, above the page title. * * @return void * * @since 5.7.0 */ public static function display_in_plugin_banners() { global $current_screen; if ( ! Settings_Helper::current_user_can( 'view' ) || ! isset( $current_screen ) ) { return; } // If the current admin screen is not one of the plugin's screens. if ( ! in_array( $current_screen->base, \WpSecurityAuditLog::get_plugin_screens_array(), true ) ) { return; } // @free:start if ( self::should_show_bf_notice() ) { self::display_bf_notice(); } // @free:end } /** * Responsible for initializing the AJAX hooks for the notifications * * @return void * * @since 4.6.0 */ public static function init_ajax_hooks() { $notice_upgrade = Settings_Helper::get_boolean_option_value( Abstract_Migration::UPGRADE_NOTICE, false ); if ( $notice_upgrade ) { \add_action( 'wp_ajax_wsal_dismiss_upgrade_notice', array( __CLASS__, 'dismiss_upgrade_notice' ) ); ++self::$number_of_notices; } // @free:start $notice_feature_highlight = Settings_Helper::get_boolean_option_value( Abstract_Migration::FEATURE_HIGHLIGHT_NOTICE, false ); if ( $notice_feature_highlight ) { \add_action( 'wp_ajax_wsal_dismiss_feature_highlight_notice', array( __CLASS__, 'dismiss_feature_highlight_notice' ) ); ++self::$number_of_notices; } // @free:end // ! \WpSecurityAuditLog::get_plugin_version() does not work in this hook action, do not use it. // if ( 'free' === \WpSecurityAuditLog::get_plugin_version() ) { // $ebook = Settings_Helper::get_boolean_option_value( self::EBOOK_NOTICE, false ); // if ( ! $ebook ) { // ++self::$number_of_notices; // \add_action( 'wp_ajax_wsal_dismiss_ebook_notice', array( __CLASS__, 'dismiss_ebook_notice' ) ); // } // } // $survey_2025 = Settings_Helper::get_boolean_option_value( 'survey-2025', false ); // if ( ! $survey_2025 ) { // \add_action( 'wp_ajax_dismiss_yearly_survey', array( __CLASS__, 'dismiss_yearly_survey' ) ); // ++self::$number_of_notices; // } $learndash_update_notice = Settings_Helper::get_boolean_option_value( self::LEARNDASH_UPDATE_NOTICE, false ); if ( ! $learndash_update_notice && self::is_learndash_active() ) { \add_action( 'wp_ajax_dismiss_learndash_update_notice', array( __CLASS__, 'dismiss_learndash_update_notice' ) ); ++self::$number_of_notices; } elseif ( self::should_show_melapress_survey() ) { \add_action( 'wp_ajax_dismiss_melapress_survey', array( __CLASS__, 'dismiss_melapress_survey' ) ); \add_action( 'wp_ajax_take_melapress_survey', array( __CLASS__, 'take_melapress_survey' ) ); ++self::$number_of_notices; } // @free:start if ( self::should_show_bf_notice() ) { \add_action( 'wp_ajax_dismiss_bf_notice', array( __CLASS__, 'dismiss_bf_notice' ) ); ++self::$number_of_notices; } // @free:end } /** * Display upgrade notice. * * @since 5.1.0 * @since 5.6.5 Replaced the large update banner with a minimal notice. */ public static function display_notice_upgrade() { $message = sprintf( /* translators: 1: Plugin name. 2: Plugin version number. */ \__( '%1$s has been updated to version %2$s', 'wp-security-audit-log' ), '<strong>WP Activity Log</strong>', '<strong>' . WSAL_VERSION . '</strong>' ); ?> <style> .wsal-update-notice { position: relative; background-color: #fff; border: 1px solid #c3c4c7; border-left: 4px solid #009344; margin: 64px 20px 16px 0; padding: 0 40px 0 12px; font-size: 0.8125rem; } .wsal-update-notice p { margin: 0.5em 0; } .wsal-update-notice a { color: #009344; } .wsal-update-notice strong { color: #009344; } .wsal-update-notice-close { position: absolute; top: 0; right: 1px; padding: 9px; border: none; margin: 0; background: none; color: #787c82; cursor: pointer; } .wsal-update-notice-close::before { content: "\f153"; font-family: dashicons; font-style: normal; font-weight: normal; font-size: 1rem; line-height: 1.25; -webkit-font-smoothing: antialiased; } .wsal-update-notice-close:hover, .wsal-update-notice-close:focus { color: #d63638; } </style> <div class="wsal-update-notice wsal-notice" data-dismiss-action="wsal_dismiss_upgrade_notice" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_upgrade_notice' ) ); ?>"> <p> <?php echo \wp_kses( $message, Plugin_Settings_Helper::get_allowed_html_tags() ); ?> – <a href="https://melapress.com/support/kb/wp-activity-log-plugin-changelog/?utm_source=plugin&utm_medium=wsal&utm_campaign=update-notice-changelog" target="_blank" rel="noopener"><?php \esc_html_e( 'view changelog', 'wp-security-audit-log' ); ?></a> </p> <button type="button" class="wsal-update-notice-close wsal-plugin-notice-close" aria-label="<?php \esc_attr_e( 'Dismiss this notice', 'wp-security-audit-log' ); ?>"></button> </div> <?php } // @free:start /** * Display the feature highlight notice shown after a plugin upgrade. * * @return void * * @since 5.6.5 */ public static function display_feature_highlight_notice() { ?> <style> .wsal-feature-highlight-notice { position: relative; display: flex; gap: 16px; background: #fafbf3; border-radius: 5px; box-shadow: 0 3px 6px rgba(0, 0, 0, 0.06); margin: 64px 20px 16px 0; padding: 16px 48px 16px 16px; color: #3c434a; } .wsal-update-notice ~ .wsal-feature-highlight-notice { margin-top: 16px; } .wsal-feature-highlight-notice::before { content: ''; background: url('<?php echo \esc_url( WSAL_BASE_URL ); ?>classes/Free/assets/images/wp-activity-log-icon.svg') no-repeat center / contain; flex-shrink: 0; height: 44px; width: 44px; } .wsal-feature-highlight-notice h2 { color: #3c434a; font-size: 1.25rem; font-weight: 600; line-height: 1.3; margin: 0 0 8px; padding: 0; } .wsal-feature-highlight-notice p { font-size: 0.875rem; line-height: 1.6; margin: 0 0 16px; } .wsal-feature-highlight-notice-upgrade { background: #009344; border-radius: 5px; color: #fff; display: inline-block; font-size: 0.875rem; line-height: 1; padding: 8px 12px; text-decoration: none; } .wsal-feature-highlight-notice-upgrade:hover, .wsal-feature-highlight-notice-upgrade:focus { background: #007a39; color: #fff; } .wsal-feature-highlight-notice-close { position: absolute; top: 8px; right: 5px; padding: 6px; border: none; margin: 0; background: none; color: #787c82; cursor: pointer; } .wsal-feature-highlight-notice-close::before { content: "\f153"; font-family: dashicons; font-style: normal; font-weight: normal; font-size: 1rem; line-height: 1.25; -webkit-font-smoothing: antialiased; } .wsal-feature-highlight-notice-close:hover, .wsal-feature-highlight-notice-close:focus { color: #d63638; } </style> <div class="wsal-feature-highlight-notice wsal-notice" data-dismiss-action="wsal_dismiss_feature_highlight_notice" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_feature_highlight_notice' ) ); ?>"> <div> <h2><?php \esc_html_e( 'Know about important changes before they become problems', 'wp-security-audit-log' ); ?></h2> <p><?php \esc_html_e( 'Receive alerts for critical activity, monitor active user sessions, and keep a complete audit trail of everything happening on your site.', 'wp-security-audit-log' ); ?></p> <a class="wsal-feature-highlight-notice-upgrade" href="https://melapress.com/wordpress-activity-log/pricing/?utm_source=plugin&utm_medium=wsal&utm_campaign=update-feature-highlight-banner" target="_blank" rel="noopener"><?php \esc_html_e( 'Unlock Premium Features', 'wp-security-audit-log' ); ?></a> </div> <button type="button" class="wsal-feature-highlight-notice-close wsal-plugin-notice-close" aria-label="<?php \esc_attr_e( 'Dismiss this notice', 'wp-security-audit-log' ); ?>"></button> </div> <?php } // @free:end /** * Display upgrade notice. * * @since 5.1.1 */ public static function display_ebook_notice() { include_once WSAL_BASE_DIR . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'Free' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'wsal-ebook-card.php'; } /** * Method: Ajax request handler to dismiss upgrade notice. * * @since 5.1.0 */ public static function dismiss_upgrade_notice() { if ( ! Settings_Helper::current_user_can( 'edit' ) ) { \wp_send_json_error(); } if ( ! array_key_exists( 'nonce', $_POST ) || ! wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'dismiss_upgrade_notice' ) ) { \wp_send_json_error( \esc_html_e( 'nonce is not provided or incorrect', 'wp-security-audit-log' ) ); } Settings_Helper::delete_option_value( Abstract_Migration::UPGRADE_NOTICE ); \wp_send_json_success(); } // @free:start /** * Method: Ajax request handler to dismiss the feature highlight notice. * * @return void * * @since 5.6.5 */ public static function dismiss_feature_highlight_notice() { if ( ! Settings_Helper::current_user_can( 'edit' ) ) { \wp_send_json_error(); } if ( ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ?? '' ) ), 'dismiss_feature_highlight_notice' ) ) { \wp_send_json_error( \esc_html__( 'nonce is not provided or incorrect', 'wp-security-audit-log' ) ); } Settings_Helper::delete_option_value( Abstract_Migration::FEATURE_HIGHLIGHT_NOTICE ); \wp_send_json_success(); } // @free:end /** * Method: Ajax request handler to dismiss ebook notice. * * @since 5.1.1 */ public static function dismiss_ebook_notice() { if ( ! Settings_Helper::current_user_can( 'edit' ) ) { \wp_send_json_error(); } if ( ! array_key_exists( 'nonce', $_POST ) || ! wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ), 'dismiss_ebook_notice' ) ) { \wp_send_json_error( \esc_html_e( 'nonce is not provided or incorrect', 'wp-security-audit-log' ) ); } Settings_Helper::set_option_value( self::EBOOK_NOTICE, true ); \wp_send_json_success(); } /** * Returns the number of notifications we have to show. * * @return int * * @since 5.2.2 */ public static function get_number_of_notices(): int { return self::$number_of_notices; } /** * Ajax request handler to dismiss the yearly survey notice. * * @return void * * @since 5.5.1 */ public static function dismiss_yearly_survey() { if ( ! Settings_Helper::current_user_can( 'edit' ) || ! \current_user_can( 'manage_options' ) ) { \wp_send_json_error(); } $nonce_check = \check_ajax_referer( 'dismiss_yearly_survey', 'nonce' ); if ( ! $nonce_check ) { \wp_send_json_error( \esc_html_e( 'nonce is not provided or incorrect', 'wp-security-audit-log' ) ); } $update_yr_setting = Settings_Helper::set_option_value( 'survey-2025', true ); if ( ! $update_yr_setting ) { \wp_send_json_error( \esc_html__( 'Failed to dismiss the survey. Please try again.', 'wp-security-audit-log' ) ); } \wp_send_json_success(); } /** * Ajax request handler to dismiss the melapress survey notice (X button). * * @return void * * @since 5.5.3 * @since 5.6.1 - Changed to temporary dismissal that resets on plugin upgrade. */ public static function dismiss_melapress_survey() { if ( ! Settings_Helper::current_user_can( 'edit' ) || ! \current_user_can( 'manage_options' ) ) { \wp_send_json_error(); } \check_ajax_referer( 'dismiss_melapress_survey', 'nonce' ); $update_setting = Settings_Helper::set_boolean_option_value( 'melapress-survey-dismissed', true ); if ( ! $update_setting ) { \wp_send_json_error( \esc_html__( 'Failed to dismiss the survey. Please try again.', 'wp-security-audit-log' ) ); } \wp_send_json_success(); } /** * Ajax request handler when the user clicks "Take the survey". * Sets a permanent flag that persists across upgrades. * * @return void * * @since 5.6.1 */ public static function take_melapress_survey() { if ( ! Settings_Helper::current_user_can( 'edit' ) || ! \current_user_can( 'manage_options' ) ) { \wp_send_json_error(); } \check_ajax_referer( 'take_melapress_survey', 'nonce' ); $update_setting = Settings_Helper::set_boolean_option_value( 'melapress-survey-taken', true ); if ( ! $update_setting ) { \wp_send_json_error( \esc_html__( 'Failed to save the survey preference. Please try again.', 'wp-security-audit-log' ) ); } \wp_send_json_success(); } /** * Ajax request handler to dismiss the LearnDash update notice. * * @return void * * @since 5.6.0 */ public static function dismiss_learndash_update_notice() { if ( ! Settings_Helper::current_user_can( 'edit' ) || ! \current_user_can( 'manage_options' ) ) { \wp_send_json_error(); } \check_ajax_referer( 'dismiss_learndash_update_notice', 'nonce' ); $update_setting = Settings_Helper::set_option_value( self::LEARNDASH_UPDATE_NOTICE, true ); if ( ! $update_setting ) { \wp_send_json_error( \esc_html__( 'Failed to dismiss the notice. Please try again.', 'wp-security-audit-log' ) ); } \wp_send_json_success(); } /** * Display the 2025 MelaPress survey admin notice * * @since 5.5.1 */ public static function display_yearly_security_survey() { // Show only to admins. if ( ! \current_user_can( 'manage_options' ) ) { return; } $survey_url = \esc_url( \add_query_arg( array( 'utm_source' => 'plugin', 'utm_medium' => 'wsal', 'utm_campaign' => 'survey+promo+banner', ), 'https://melapress.com/wordpress-security-survey-2025/' ) ); ?> <div style="position: relative; padding-top: 8px; padding-bottom: 8px; border-left-color: #009344;" class="wsal-notice notice notice-info" id="wsal-survey-2025-notice" data-dismiss-action="dismiss_yearly_survey" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_yearly_survey' ) ); ?>"> <p style="font-weight:700; margin-top: 0;"><?php \esc_html_e( 'Want to know what the state of WordPress security is in 2025?', 'wp-security-audit-log' ); ?></p> <p> <?php \esc_html_e( 'Discover the latest insights in our 2025 WordPress Security Survey Report.', 'wp-security-audit-log' ); ?> </p> <a href="<?php echo \esc_url( $survey_url ); ?>" target="_blank" rel="noopener" style="background-color: #009344;" class="button button-primary"><?php \esc_html_e( 'Read the survey', 'wp-security-audit-log' ); ?></a> <button type="button" class="notice-dismiss wsal-plugin-notice-close"><span class="screen-reader-text"><?php \esc_html_e( 'Dismiss this notice.', 'wp-security-audit-log' ); ?></span></button> </div> <?php } /** * Display the Melapress product survey admin notice. * * @since 5.5.3 */ public static function display_melapress_product_survey() { // Show only to admins. if ( ! \current_user_can( 'manage_options' ) ) { return; } $melapress_survey_url = 'https://getformly.app/46gDbF'; ?> <div style="position: relative; padding: 16px; border-left-color: #009344;" class="wsal-notice notice notice-info" id="wsal-melapress-survey-notice" data-dismiss-action="dismiss_melapress_survey" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_melapress_survey' ) ); ?>" data-take-action="take_melapress_survey" data-take-nonce="<?php echo \esc_attr( \wp_create_nonce( 'take_melapress_survey' ) ); ?>"> <p style="font-weight:700; margin-top: 0;"><?php \esc_html_e( 'Got 2 minutes? Help us shape the future of WP Activity Log', 'wp-security-audit-log' ); ?></p> <a href="<?php echo \esc_url( $melapress_survey_url ); ?>" target="_blank" rel="noopener" style="background-color: #009344;" class="button button-primary wsal-survey-take-btn"><?php \esc_html_e( 'Take the survey', 'wp-security-audit-log' ); ?></a> <button type="button" class="notice-dismiss wsal-plugin-notice-close"><span class="screen-reader-text"><?php \esc_html_e( 'Dismiss this notice.', 'wp-security-audit-log' ); ?></span></button> </div> <?php } /** * Display the LearnDash update notice. * * @return void * * @since 5.6.0 */ public static function display_learndash_update_notice() { if ( ! \current_user_can( 'manage_options' ) ) { return; } $review_url = WP_Helper::get_admin_url( 'admin.php?page=wsal-togglealerts#cat-LearnDash-LMS' ); ?> <div style="position: relative; padding-top: 8px; padding-bottom: 8px; border-left-color: #009344;" class="wsal-notice notice notice-info" id="wsal-learndash-update-notice" data-dismiss-action="dismiss_learndash_update_notice" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_learndash_update_notice' ) ); ?>"> <p style="font-weight:700; margin-top: 0;"><?php \esc_html_e( 'Great news! We\'ve added support for LearnDash LMS.', 'wp-security-audit-log' ); ?></p> <p><?php \esc_html_e( 'You can now track course creation, lesson modifications, student enrollments, quiz completions, and more.', 'wp-security-audit-log' ); ?></p> <p><?php \esc_html_e( 'To help keep your activity log focused and efficient, we\'ve carefully selected which events are enabled by default. You can review and customize which LearnDash events you want to track at any time.', 'wp-security-audit-log' ); ?></p> <a href="<?php echo \esc_url( $review_url ); ?>" style="background-color: #009344;" class="button button-primary"><?php \esc_html_e( 'Review Settings', 'wp-security-audit-log' ); ?></a> <button type="button" class="button wsal-plugin-notice-close" style="margin-left: 8px;"><?php \esc_html_e( 'Not Now', 'wp-security-audit-log' ); ?></button> <button type="button" class="notice-dismiss wsal-plugin-notice-close"><span class="screen-reader-text"><?php \esc_html_e( 'Dismiss this notice.', 'wp-security-audit-log' ); ?></span></button> </div> <?php } /** * Get the current date in Y-m-d format (derived from DateTimeImmutable). * * @return string * * @since 5.5.4 */ private static function get_current_date(): string { $current_datetime = \current_datetime(); return $current_datetime->format( 'Y-m-d' ); } /** * Check if the BF notice period is currently active. * * @return bool * * @since 5.5.4 * @since 5.7.0 - Dates are read from the class constants. */ public static function is_bf_notice_period(): bool { $current_date = self::get_current_date(); return $current_date >= self::BF_NOTICE_START_DATE && $current_date <= self::BF_NOTICE_END_DATE; } /** * Check if the Melapress survey banner should be displayed. * * @return bool * * @since 5.6.1 */ public static function should_show_melapress_survey(): bool { // Permanent dismissal: user already took the survey. if ( Settings_Helper::get_boolean_option_value( 'melapress-survey-taken', false ) ) { return false; } // Temporary dismissal: user clicked X (resets on next upgrade). if ( Settings_Helper::get_boolean_option_value( 'melapress-survey-dismissed', false ) ) { return false; } // Don't show during the BF notice period. if ( self::is_bf_notice_period() ) { return false; } // On new installs, wait 15 days before showing. $installed_at = Settings_Helper::get_option_value( 'plugin-installed-at', false ); if ( false !== $installed_at && ( time() - (int) $installed_at ) < 15 * DAY_IN_SECONDS ) { return false; } return true; } /** * Check if the BF notice should be displayed. * * @return bool * * @since 5.5.4 * @since 5.7.0 - Dismissal is a single date compared against the current period dates. */ public static function should_show_bf_notice(): bool { if ( ! self::is_bf_notice_period() ) { return false; } $dismissed_on = (string) Settings_Helper::get_option_value( self::BF_NOTICE_DISMISSED_ON, '' ); // Not dismissed, or dismissed in an earlier year. if ( '' === $dismissed_on || $dismissed_on < self::BF_NOTICE_START_DATE ) { return true; } // Dismissed on or after the reminder date: hidden until the period ends. if ( $dismissed_on >= self::BF_NOTICE_REMINDER_DATE ) { return false; } // Dismissed before the reminder date: hidden until the reminder date. return self::get_current_date() >= self::BF_NOTICE_REMINDER_DATE; } /** * Ajax request handler to dismiss the BF notice. * * @return void * * @since 5.5.4 * @since 5.7.0 - Stores only the dismissal date. */ public static function dismiss_bf_notice() { if ( ! Settings_Helper::current_user_can( 'edit' ) || ! \current_user_can( 'manage_options' ) ) { \wp_send_json_error(); } // On multisite, only super admins can dismiss the banner. if ( WP_Helper::is_multisite() && ! \is_super_admin() ) { \wp_send_json_error(); } $nonce_check = \check_ajax_referer( 'dismiss_bf_notice', 'nonce' ); if ( ! $nonce_check ) { \wp_send_json_error( \esc_html__( 'nonce is not provided or incorrect', 'wp-security-audit-log' ) ); } $update_setting = Settings_Helper::set_option_value( self::BF_NOTICE_DISMISSED_ON, self::get_current_date() ); if ( ! $update_setting ) { \wp_send_json_error( \esc_html__( 'Failed to dismiss the notice. Please try again.', 'wp-security-audit-log' ) ); } \wp_send_json_success(); } /** * Display the BF admin notice. * * @return void * * @since 5.5.4 * @since 5.7.0 - Updated the BF notice design and campaign link. */ public static function display_bf_notice() { if ( ! \current_user_can( 'manage_options' ) ) { return; } // On multisite, only super admins can see the banner. if ( WP_Helper::is_multisite() && ! \is_super_admin() ) { return; } $mp_site_link = 'https://melapress.com/black-friday-cyber-monday/?utm_source=plugin&utm_medium=wsal&utm_campaign=BFCM'; $target_year = substr( self::BF_NOTICE_START_DATE, 0, 4 ); $offer_url = $mp_site_link . $target_year; ?> <div id="wsal-bf-notice" class="wsal-notice wsal-bf-notice" data-dismiss-action="dismiss_bf_notice" data-nonce="<?php echo \esc_attr( \wp_create_nonce( 'dismiss_bf_notice' ) ); ?>"> <div class="wsal-bf-icon"> <img src="<?php echo \esc_url( WSAL_BASE_URL ); ?>img/upgrade-plugin-icon.svg" alt="Black Friday Sale" /> </div> <div class="wsal-bf-content"> <div class="wsal-bf-title"> <?php \esc_html_e( 'Upgrade to premium', 'wp-security-audit-log' ); ?> </div> <div class="wsal-bf-subtitle"> <span class="wsal-bf-underline"><?php \esc_html_e( 'Black Friday', 'wp-security-audit-log' ); ?></span> <?php \esc_html_e( 'sale now live!', 'wp-security-audit-log' ); ?> </div> <a href="<?php echo \esc_url( $offer_url ); ?>" target="_blank" rel="noopener" class="button button-primary wsal-bf-button" id="wsal-bf-cta"><?php \esc_html_e( 'Get Offer Now', 'wp-security-audit-log' ); ?></a> </div> <button type="button" class="notice-dismiss wsal-plugin-notice-close"><img src="<?php echo \esc_url( WSAL_BASE_URL ); ?>img/bf-notice-close.svg" alt="" width="12" height="12" /><span class="screen-reader-text"><?php \esc_html_e( 'Dismiss this notice.', 'wp-security-audit-log' ); ?></span></button> </div> <style> @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&display=swap'); /* Hides the update notice while this banner is shown. */ .wsal-update-notice { display: none; } #wsal-bf-notice.wsal-bf-notice { background-color: #020E26; border-left: 4px solid #FF8977; box-shadow: 0 0 0 1px #C3C4C7; position: relative; font-family: 'Inter', sans-serif; display: flex; gap: 52px; clear: both; max-width: none; margin: 48px 0 16px; padding: 16px; justify-content: center; } #wsal-bf-notice .wsal-bf-icon { background-color: #B6C3F2; display: none; flex-shrink: 0; clip-path: polygon(0 0, 100% 0, calc(100% - 16px) 100%, 0 100%); } #wsal-bf-notice .wsal-bf-icon img { display: block; padding: 12px 29px 12px 20px; } #wsal-bf-notice .wsal-bf-content { color: #ffffff; margin-top: 13px; margin-bottom: 15px; } #wsal-bf-notice .wsal-bf-title, #wsal-bf-notice .wsal-bf-subtitle { font-weight: 900; text-transform: uppercase; } #wsal-bf-notice .wsal-bf-title { font-size: 32px; line-height: 1.2; color: #FF8977; } #wsal-bf-notice .wsal-bf-subtitle { color: #ffffff; font-size: 24px; line-height: 1.5; margin-bottom: 12px; } #wsal-bf-notice .wsal-bf-underline { position: relative; display: inline-block; text-decoration: none; } #wsal-bf-notice .wsal-bf-underline::after { content: ''; position: absolute; left: 0; bottom: -2px; width: 100%; height: 2px; background-color: currentColor; } #wsal-bf-notice #wsal-bf-cta.button.button-primary { background-color: #D9E4FD; border-color: #D9E4FD; color: #454BF7; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; padding: 7px 10px; line-height: 1; transition: background-color 0.3s ease, border-color 0.3s ease; } #wsal-bf-notice #wsal-bf-cta.button.button-primary:hover, #wsal-bf-notice #wsal-bf-cta.button.button-primary:focus { background-color: #B6C3F2; border-color: #B6C3F2; } #wsal-bf-notice .notice-dismiss { top: 12px; right: 12px; padding: 4px; } #wsal-bf-notice .notice-dismiss:before { content: none; } #wsal-bf-notice .notice-dismiss img { display: block; } #wsal-bf-notice .notice-dismiss .screen-reader-text { border: 0; clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } @media (min-width: 647px) { #wsal-bf-notice.wsal-bf-notice { padding: 0; justify-content: flex-start; } #wsal-bf-notice #wsal-bf-cta.button.button-primary { display: inline-flex; } #wsal-bf-notice .wsal-bf-icon { display: block; } #wsal-bf-notice .wsal-bf-title, #wsal-bf-notice .wsal-bf-subtitle { line-height: 1; } } </style> <script> document.addEventListener('DOMContentLoaded', function() { const wsalBlackFridayNotice = document.getElementById( 'wsal-bf-notice' ); const wsalUpgradeNotice = document.querySelector('.wsal-update-notice'); const wsalShowUpgradeNotice = () => { if (wsalUpgradeNotice) { wsalUpgradeNotice.style.display = 'block'; } }; if ( ! wsalBlackFridayNotice ) { // BF not present, show upgrade wsalShowUpgradeNotice(); } else { // BF present, listen for dismiss const wsalBlackFridayDismissButton = wsalBlackFridayNotice.querySelector( '.wsal-plugin-notice-close' ); if ( wsalBlackFridayDismissButton ) { wsalBlackFridayDismissButton.addEventListener( 'click', () => { // Delayed of 300ms, it looks slightly better as the BF notice "swaps" with the upgrade notice. setTimeout(wsalShowUpgradeNotice, 300); }); } } }); </script> <?php } } }
Save File
Cancel