WC_Settings_Payment_Gateways_React::suppress_admin_notices()
Suppress WP admin notices on the WooCommerce Payments settings page.
Метод класса: WC_Settings_Payment_Gateways_React{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$WC_Settings_Payment_Gateways_React = new WC_Settings_Payment_Gateways_React(); $WC_Settings_Payment_Gateways_React->suppress_admin_notices();
Код WC_Settings_Payment_Gateways_React::suppress_admin_notices() WC Settings Payment Gateways React::suppress admin notices WC 9.7.1
public function suppress_admin_notices() { global $wp_filter; $screen = get_current_screen(); if ( ! $screen instanceof WP_Screen || 'woocommerce_page_wc-settings' !== $screen->id ) { return; } global $current_tab; if ( 'checkout' !== $current_tab ) { return; } // Generic admin notices are definitely not needed. remove_all_actions( 'all_admin_notices' ); // WooCommerce uses the 'admin_notices' hook for its own notices. // We will only allow WooCommerce core notices to be displayed. $wp_admin_notices_hook = $wp_filter['admin_notices'] ?? null; if ( ! $wp_admin_notices_hook || ! $wp_admin_notices_hook->has_filters() ) { // Nothing to do if there are no actions hooked into `admin_notices`. return; } $wc_admin_notices = WC_Admin_Notices::get_notices(); if ( empty( $wc_admin_notices ) ) { // If there are no WooCommerce core notices, we can remove all actions hooked into `admin_notices`. remove_all_actions( 'admin_notices' ); return; } // Go through the callbacks hooked into `admin_notices` and // remove any that are NOT from the WooCommerce core (i.e. from the `WC_Admin_Notices` class). foreach ( $wp_admin_notices_hook->callbacks as $priority => $callbacks ) { if ( ! is_array( $callbacks ) ) { continue; } foreach ( $callbacks as $callback ) { // Ignore malformed callbacks. if ( ! is_array( $callback ) ) { continue; } // WooCommerce doesn't use closures to handle notices. // WooCommerce core notices are handled by `WC_Admin_Notices` class methods. // Remove plain functions or closures. if ( ! is_array( $callback['function'] ) ) { remove_action( 'admin_notices', $callback['function'], $priority ); continue; } $class_or_object = $callback['function'][0] ?? null; // We need to allow Automattic\WooCommerce\Internal\Admin\Loader methods callbacks // because they are used to wrap notices. // @see Automattic\WooCommerce\Internal\Admin\Loader::inject_before_notices(). // @see Automattic\WooCommerce\Internal\Admin\Loader::inject_after_notices(). if ( ( // We have a class name. is_string( $class_or_object ) && ! ( WC_Admin_Notices::class === $class_or_object || Loader::class === $class_or_object ) ) || ( // We have a class instance. is_object( $class_or_object ) && ! ( $class_or_object instanceof WC_Admin_Notices || $class_or_object instanceof Loader ) ) ) { remove_action( 'admin_notices', $callback['function'], $priority ); } } } }