Merge pull request #19772 from woocommerce/update/notice-display
Only show notices on specific screens
This commit is contained in:
commit
9679e7be1f
|
@ -152,18 +152,32 @@ class WC_Admin_Notices {
|
|||
public static function add_notices() {
|
||||
$notices = self::get_notices();
|
||||
|
||||
if ( ! empty( $notices ) ) {
|
||||
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ), array(), WC_VERSION );
|
||||
if ( empty( $notices ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add RTL support.
|
||||
wp_style_add_data( 'woocommerce-activation', 'rtl', 'replace' );
|
||||
$screen = get_current_screen();
|
||||
$screen_id = $screen ? $screen->id : '';
|
||||
$show_on_screens = array(
|
||||
'dashboard',
|
||||
'plugins',
|
||||
);
|
||||
|
||||
foreach ( $notices as $notice ) {
|
||||
if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
|
||||
add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
|
||||
} else {
|
||||
add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
|
||||
}
|
||||
// Notices should only show on WooCommerce screens, the main dashboard, and on the plugins screen.
|
||||
if ( ! in_array( $screen_id, wc_get_screen_ids(), true ) && ! in_array( $screen_id, $show_on_screens, true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ), array(), WC_VERSION );
|
||||
|
||||
// Add RTL support.
|
||||
wp_style_add_data( 'woocommerce-activation', 'rtl', 'replace' );
|
||||
|
||||
foreach ( $notices as $notice ) {
|
||||
if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
|
||||
add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
|
||||
} else {
|
||||
add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue