0

I need to change the capability required for an added admin menu page. By default the plugin added the capability manage_options which I need to change. How can I change this without editing the plugin file?

1
  • Even if there is a hook for that, I'd guess you'd need to change the permission check on the page it links to which I doubt you could do with a hook. – Rup Feb 4 at 10:28
1

The functioning of the code below depends a lot on how the plugin in question was built.

add_action( 'admin_menu', 'change_capability' );

function change_capability() {

    remove_menu_page(
        $menu_slug,
    );

    add_menu_page(
        $page_title,
        $menu_title,
        $new_capability,
        $menu_slug,
    );

}
2
  • Is that the only way, to remove the menu option and re-add it? How does that put the replacement menu option back in the same place? – Rup Feb 4 at 23:23
  • add_menu_page function has a parameter called $position. It determines the page position on menu. So to put it in the same place you need to know the position number in the original declaration. – Talita Mota Feb 5 at 12:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.