'; } /** * 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() { // 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['notices'] ) && ( ! empty( $_POST['notices'] && is_array( $_POST['notices'] ) ) ) ) { $currently_held_options = \get_option( 'anm-notices', array() ); $hidden_forever = \get_option( 'anm-hidden-notices', array() ); $hashed_notices = array(); $details = array(); $format = \get_option( 'date_format' ) . ' ' . \get_option( 'time_format' ); foreach ( $_POST['notices'] as $index => $notice ) { $hash = \wp_hash( $notice ); $current_time = \current_time( 'timestamp' ); $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'; } } \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, $_POST['notice_hash'] ); \update_option( 'anm-hidden-notices', $currently_held_options ); \wp_send_json_success(); } } } }