WC_Admin_Notices::hide_notices()public staticWC 1.0

Hide a notice if the GET variable is set.

Method of the class: WC_Admin_Notices{}

Return

null. Nothing (null).

Usage

$result = WC_Admin_Notices::hide_notices();

WC_Admin_Notices::hide_notices() code WC 9.6.1

public static function hide_notices() {
	if ( isset( $_GET['wc-hide-notice'] ) && isset( $_GET['_wc_notice_nonce'] ) ) {
		if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wc_notice_nonce'] ) ), 'woocommerce_hide_notices_nonce' ) ) {
			wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
		}

		$notice_name = sanitize_text_field( wp_unslash( $_GET['wc-hide-notice'] ) );

		/**
		 * Filter the capability required to dismiss a given notice.
		 *
		 * @since 6.7.0
		 *
		 * @param string $default_capability The default required capability.
		 * @param string $notice_name The notice name.
		 */
		$required_capability = apply_filters( 'woocommerce_dismiss_admin_notice_capability', 'manage_woocommerce', $notice_name );

		if ( ! current_user_can( $required_capability ) ) {
			wp_die( esc_html__( 'You don’t have permission to do this.', 'woocommerce' ) );
		}

		self::hide_notice( $notice_name );
	}
}