0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
/**
* Dismiss admin notices for non-administrator users.
*
* This function checks the current user's capabilities and removes all admin notices
* from the dashboard if the user is not an administrator.
*/
function wpgriffino_dismiss_admin_notices() {
// Check if the current user does NOT have administrator capabilities.
if ( ! current_user_can( 'administrator' ) ) {
// Remove all actions hooked to the 'admin_notices' action.
// This effectively hides all plugin notifications from non-admin users.
remove_all_actions( 'admin_notices' );
}
}
// Hook the wpgriffino_dismiss_admin_notices function to the 'admin_init' action.
// This ensures the function runs early in the WordPress admin lifecycle,
// allowing the removal of notices before they are displayed.
add_action( 'admin_init', 'wpgriffino_dismiss_admin_notices' );
These comments enhance the code's readability and maintainability, making it easier for anyone reviewing the code to grasp its functionality and intention.