Last active
December 14, 2020 19:51
-
-
Save iamgaby7521/3245511233c32511df91ad333252432f to your computer and use it in GitHub Desktop.
Disable notices in WordPress dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Disable admin notices for all. | |
*/ | |
function _action_disable_admin_notices() { | |
global $wp_filter; | |
if ( is_user_admin() ) { | |
if ( isset( $wp_filter['user_admin_notices'] ) ) { | |
unset( $wp_filter['user_admin_notices'] ); | |
} | |
} elseif ( isset( $wp_filter['admin_notices'] ) ) { | |
unset( $wp_filter['admin_notices'] ); | |
} // end if is_user_admin() | |
if ( isset( $wp_filter['all_admin_notices'] ) ) { | |
unset( $wp_filter['all_admin_notices'] ); | |
} | |
} | |
add_action( 'admin_print_scripts', '_action_disable_admin_notices' ); | |
/** | |
* Disable update notices for all users with exceptions. | |
*/ | |
function _action_disable_update_notices() { | |
$current_user = wp_get_current_user(); | |
$current_user_login = $current_user->user_login; | |
if ( $current_user_login != 'adminusername' ) { | |
remove_action( 'load-update-core.php', 'wp_update_plugins' ); | |
add_filter( 'pre_site_transient_update_plugins', '__return_null' ); | |
} | |
} | |
add_action( 'admin_head', '_action_disable_update_notices' ); | |
/** | |
* Disable update notices for all. | |
*/ | |
remove_action( 'load-update-core.php', 'wp_update_plugins' ); | |
add_filter( 'pre_site_transient_update_plugins', '__return_null' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment