admin管理员组

文章数量:1279238

When a user with Editor privileges logs in, they are bombarded with notices that they do not and should not care about.

How can I disable all nags for everyone except users with Administrator privileges?

When a user with Editor privileges logs in, they are bombarded with notices that they do not and should not care about.

How can I disable all nags for everyone except users with Administrator privileges?

Share Improve this question asked Sep 30, 2021 at 8:00 bobbob 2491 gold badge6 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

You could remove all actions from the admin_notices hook. The best way to do that might be from the earliest priority of the hook itself, that way you catch any notices registered late.

add_action(
    'admin_notices',
    function() {
        if ( ! current_user_can( 'manage_options' ) ) {
            remove_all_actions( 'admin_notices' );
        }
    },
    0
);

The problem is that there's very little standardisation around admin notices, and there could be plugins that are registering notices in the incorrect way or in the incorrect places. So if any notices aren't caught by that code, you'd need to address them on a case by case basis.

本文标签: dashboardHow can I programattically hide all admin notices for everyone except admin users