pigsound
pigsound

Reputation: 79

wordpress: remove plugin submenu item for specific user

On the backend of a WordPress site, the admin menu looks like this:

Dashboard
Media
Pages
Pluginname
–– Edit
–– Short Code
–– Settings
–– FAQs

I would like to hide Pluginname/Settings from one admin. Since hovering over Pluginname/Settings shows https://url.xy/wp-admin/edit.php?post_type=pluginname&page=plg_settings , i added these lines of code to the functions.php file:

add_action( 'admin_init', 'my_remove_menu_pages' );
    function my_remove_menu_pages() {
        global $user_ID;
        if ( $user_ID == 2 ) {
            remove_menu_page( 'pluginname.php' , 'plg_settings.php' );
        }
    }

But this does not do anything. Does anybody have advice for me?

Upvotes: 1

Views: 202

Answers (2)

pigsound
pigsound

Reputation: 79

Thanks to the hint from speshock I could find the solution. I had to use remove_submenu_page instead of remove_menu_page:

remove_submenu_page( 'edit.php?post_type=pluginname' , 'plg_settings' );

Upvotes: 1

speshock
speshock

Reputation: 140

If your not looking at functions code I really recommend just using the admin menu editor. https://wordpress.org/plugins/admin-menu-editor/ It will allow you to change the name of the links, the icons, the permissions and so many more options. Hope that it works out for you

Upvotes: 0

Related Questions