This function will add the notification * * @param array $args configuration for notification * *
* * @since 1.0.0 */ public static function add_notification( $args ) { $default = array( 'type' => 'success', 'content' => '', 'is_dismissible' => true, 'callback' => null, 'show_only' => false, ); self::$all_notifications[ key( $args ) ] = wp_parse_args( $args[ key( $args ) ], $default ); } /** * Hide notices to show under dashboard *
Its a handler function to any request come to hide the notice *
save the slug in Database so that it wont come again */ public static function hide_notices() { if ( isset( $_GET['woofunnels-hide-notice'] ) && isset( $_GET['_woofunnels_notice_nonce'] ) ) { if ( ! wp_verify_nonce( sanitize_text_field( $_GET['_woofunnels_notice_nonce'] ), 'woofunnels_hide_notices_nonce' ) ) { wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woofunnels' ) ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch } if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'Cheating huh?', 'woofunnels' ) ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch } $hide_notice = sanitize_text_field( $_GET['woofunnels-hide-notice'] ); self::remove_notice( $hide_notice ); do_action( 'woofunnels_hide_' . $hide_notice . '_notice' ); } } /** * Remove a notice from being displayed * * @param string $name */ public static function remove_notice( $name ) { $has_notice_removed = get_option( 'woofunnels_admin_notices' ); if ( $has_notice_removed && ! empty( $has_notice_removed ) ) { $array_to_push = array_push( $has_notice_removed, $name ); update_option( 'woofunnels_admin_notices', $array_to_push, false ); } else { update_option( 'woofunnels_admin_notices', array( $name ), false ); } } /** * Render all the notifications after filtering * @since 1.0.0 */ public static function render() { self::filter_before_render(); if ( ! is_null( self::$all_notifications ) && ! empty( self::$all_notifications ) ) { foreach ( self::$all_notifications as $slug => $notification ) { ?>
$notification ) { if ( in_array( $slug, self::get_all_removed(), true ) ) { unset( $clone[ $slug ] ); } } } self::$all_notifications = $clone; } /** * Get all removed notifications from database * So that we can filter the push notification with the removed ones * @return array */ public static function get_all_removed() { return get_option( 'woofunnels_admin_notices' ); } /** * Check whether has notification pushed? * @since 1.0.0 */ public static function has_notification( $slug ) { if ( is_null( self::$all_notifications ) ) : return false; endif; return array_key_exists( $slug, self::$all_notifications ); } } }