'; } /** * Remove any known actions which conflict with ANM. * * @since 1.0.0 */ public static function remove_unwanted_actions() { if ( function_exists( 'asenha_suppress_generic_notices' ) ) { \remove_action( 'all_admin_notices', 'asenha_suppress_generic_notices', 5 ); } } /** * Prints the beginning of wrapper element after all notices. * * @since 1.0.0 */ public static function finish_output_capturing() { echo ''; } /** * Adds menu item showing number of notifications. * * @param \WP_Admin_Bar $admin_bar WordPress admin bar. * * @since 1.0.0 */ public static function add_item_in_admin_bar( $admin_bar ) { $admin_bar->add_menu( array( 'id' => 'anm_notification_count', 'title' => esc_html__( 'No admin notices', 'admin-notices-manager' ), 'href' => '#', 'parent' => 'top-secondary', ) ); } /** * Handles AJAX requests for logging the notices. * * @return false|void * * @since 1.0.0 */ public static function log_notices() { $post_array = filter_input_array( INPUT_POST ); // If we have a nonce posted, check it. if ( \wp_doing_ajax() && isset( $post_array['_nonce'] ) ) { $nonce_check = \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $post_array['_nonce'] ) ), 'anm-ajax-nonce' ); if ( ! $nonce_check ) { return false; } } if ( isset( $post_array['notices'] ) && ( ! empty( $post_array['notices'] && is_array( $post_array['notices'] ) ) ) ) { $currently_held_options = \get_option( 'anm-notices', array() ); $hidden_forever = \get_option( 'anm-hidden-notices', array() ); $displayed_forever = \get_option( 'anm-displayed-notices', array() ); $hashed_notices = array(); $details = array(); $format = \get_option( 'date_format' ) . ' ' . \get_option( 'time_format' ); foreach ( $post_array['notices'] as $index => $notice ) { $hash = \wp_hash( $notice ); $current_time = \current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested $hashed_notices[ $hash ] = $current_time; $details[ $index ] = array( $hash, date_i18n( $format, $current_time ) ); // Do we already know about this notice? if ( isset( $currently_held_options[ $hash ] ) ) { $hashed_notices[ $hash ] = $currently_held_options[ $hash ]; $details[ $index ] = array( $hash, date_i18n( $format, $currently_held_options[ $hash ] ) ); } if ( in_array( $hash, $hidden_forever, true ) ) { $details[ $index ] = 'do-not-display'; } elseif ( in_array( $hash, $displayed_forever, true ) ) { $details[ $index ] = array( 'display-notice', $hash, date_i18n( $format, $hash ) ); } } \update_option( 'anm-notices', $hashed_notices ); \wp_send_json_success( $details ); } } /** * Handles AJAX requests for hiding a notice forever. * * @return false|void * * @since 1.0.0 */ public static function hide_notice_forever() { // If we have a nonce posted, check it. if ( \wp_doing_ajax() && isset( $_POST['_nonce'] ) ) { $nonce_check = \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['_nonce'] ) ), 'anm-ajax-nonce' ); if ( ! $nonce_check ) { return false; } } if ( isset( $_POST['notice_hash'] ) ) { $currently_held_options = \get_option( 'anm-hidden-notices', array() ); array_push( $currently_held_options, sanitize_text_field( wp_unslash( $_POST['notice_hash'] ) ) ); \update_option( 'anm-hidden-notices', $currently_held_options ); \wp_send_json_success(); } } /** * Handles AJAX requests for showing a notice as usual. * * @return false|void * * @since 1.6.0 */ public static function display_notice() { // If we have a nonce posted, check it. if ( \wp_doing_ajax() && isset( $_POST['_nonce'] ) ) { $nonce_check = \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['_nonce'] ) ), 'anm-ajax-nonce' ); if ( ! $nonce_check ) { return false; } } if ( isset( $_POST['notice_hash'] ) ) { $currently_held_options = \get_option( 'anm-displayed-notices', array() ); array_push( $currently_held_options, sanitize_text_field( wp_unslash( $_POST['notice_hash'] ) ) ); \update_option( 'anm-displayed-notices', $currently_held_options ); \wp_send_json_success(); } } /** * Handles AJAX requests for hiding a notice. * * @return false|void * * @since 1.6.0 */ public static function hide_notice() { // If we have a nonce posted, check it. if ( \wp_doing_ajax() && isset( $_POST['_nonce'] ) ) { $nonce_check = \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_POST['_nonce'] ) ), 'anm-ajax-nonce' ); if ( ! $nonce_check ) { return false; } } if ( isset( $_POST['notice_hash'] ) ) { $currently_held_options = \get_option( 'anm-displayed-notices', array() ); foreach ( $currently_held_options as $index => $notice ) { if ( sanitize_text_field( wp_unslash( $_POST['notice_hash'] ) ) === $notice ) { unset( $currently_held_options[ $index ] ); } } \update_option( 'anm-displayed-notices', $currently_held_options ); \wp_send_json_success(); } } } }