NO BUG: Remove admin bricks menu for no-administrator rule

Bricks Version: 1.5.4
Using Bricks Editor Access settings does not work. If I set that on “only the administrator can use Bricks” it still makes the Bricks menu item appear to the other user roles.
I tried to solve differently using a function in function.php

add_action('admin_init', 'my_remove_menu_pages');

function my_remove_menu_pages() {

    if (!current_user_can('manage_options')) {
        remove_menu_page('bricks'); 
    }       

}

it’s works but in this way the php log file is filled with warnings as reported also by a user on the pages of the wordpress codex (remove_menu_page() – Function | Developer.WordPress.org ) —(the last comment) who basically says that the function remove_menu_page (‘slug’); it must not be used in conjunction with the admin_init but with the admin_menu.

so i tried to modify my function with this one below

add_action('admin_menu', 'my_remove_menu_pages');

function my_remove_menu_pages() {   
    
    $user = wp_get_current_user();
    
        if ( !in_array( 'administrator', (array) $user->roles ) ) {     
            remove_menu_page('bricks'); 
        }   
}

even so, however, the bricks menu continues to be seen.

How can I solve the problem?

Hi Paolo,
Thank you very much for your report!

Please check the user settings that can be set individually per user (which overrides the general access rules):

Best regards,
timmse

the site in question is an online newspaper with hundreds of editors … I can’t do it manually for each of them

1 Like

Well, there’s nothing we can do about that. The Bricks settings are only available for users with the “manage_options” capability (Administrators). It is your responsibility if some of your user roles have different capabilities.

Hi @timmse I can see you have not gotten around to moving the rendering of the Bricks menu item to admin_menu instead of admin_init. Am I correct?

Hi @pascald,

Actually, we are using admin_menu for the Bricks menu items, which is the appropriate hook for this task, not admin_init.

Edit: check includes > admin.php (line 16).

I will check the file. Maybe my priority is off and should be lower than the default value (10, I believe) to override your rendering of the menu item. I was able to remove the item via admin_init, not via admin_menu.