| 1 |
<?php |
| 2 |
/** |
| 3 |
* Remove the admin notices from global options settings |
| 4 |
* |
| 5 |
* @since 2015-12-09 |
| 6 |
*/ |
| 7 |
if ( ! function_exists( 'add_action' ) ) { |
| 8 |
die( "Hi there! I'm just a part of plugin, not much I can do when called directly." ); |
| 9 |
} |
| 10 |
|
| 11 |
// Need only on admin area |
| 12 |
if ( ! is_admin() ) { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
// If is AJAX Call. |
| 17 |
if ( defined('DOING_AJAX') && DOING_AJAX ) { |
| 18 |
return; |
| 19 |
} |
| 20 |
|
| 21 |
// If is AJAX Call. |
| 22 |
if ( defined('DOING_AJAX') && DOING_AJAX ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
add_action( 'admin_init', '_mw_adminimize_init_to_remove_admin_notices' ); |
| 27 |
/** |
| 28 |
* Fire all hooks to remove admin notices. |
| 29 |
*/ |
| 30 |
function _mw_adminimize_init_to_remove_admin_notices() { |
| 31 |
|
| 32 |
if ( _mw_adminimize_check_to_remove_admin_notices() ) { |
| 33 |
add_action( 'admin_head', '_mw_adminimize_remove_admin_notices' ); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Remove Admin Notices. |
| 39 |
* |
| 40 |
* @return string|void |
| 41 |
*/ |
| 42 |
function _mw_adminimize_check_to_remove_admin_notices() { |
| 43 |
|
| 44 |
// Exclude super admin. |
| 45 |
if ( _mw_adminimize_exclude_super_admin() ) { |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
$user_roles = _mw_adminimize_get_all_user_roles(); |
| 50 |
|
| 51 |
foreach ( $user_roles as $role ) { |
| 52 |
$disabled_global_option_[ $role ] = _mw_adminimize_get_option_value( |
| 53 |
'mw_adminimize_disabled_global_option_' . $role . '_items' |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
foreach ( $user_roles as $role ) { |
| 58 |
if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) { |
| 59 |
$disabled_global_option_[ $role ][ '0' ] = ''; |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
$remove_admin_notices = FALSE; |
| 64 |
foreach ( $user_roles as $role ) { |
| 65 |
|
| 66 |
$user = wp_get_current_user(); |
| 67 |
|
| 68 |
if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) { |
| 69 |
if ( _mw_adminimize_current_user_has_role( $role ) |
| 70 |
&& isset( $disabled_global_option_[ $role ] ) |
| 71 |
&& is_array( $disabled_global_option_[ $role ] ) |
| 72 |
) { |
| 73 |
$remove_admin_notices = _mw_adminimize_recursive_in_array( |
| 74 |
'.admin-notices', $disabled_global_option_[ $role ] |
| 75 |
); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
return $remove_admin_notices; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Remove different admin notices. |
| 85 |
*/ |
| 86 |
function _mw_adminimize_remove_admin_notices() { |
| 87 |
|
| 88 |
remove_action( 'admin_notices', 'update_nag', 3 ); |
| 89 |
remove_action( 'admin_notices', 'maintenance_nag', 10 ); |
| 90 |
remove_action( 'admin_notices', 'new_user_email_admin_notice' ); |
| 91 |
remove_action( 'admin_notices', 'site_admin_notice' ); |
| 92 |
} |