admin管理员组

文章数量:1304098

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?

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?

Share Improve this question edited Feb 4, 2021 at 13:33 Rup 4,4004 gold badges29 silver badges29 bronze badges asked Feb 4, 2021 at 10:02 Akash SinghAkash Singh 113 bronze badges 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 Commented Feb 4, 2021 at 10:28
Add a comment  | 

1 Answer 1

Reset to default 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,
    );

}

本文标签: user rolesHow I can change the required capability for an admin menu without editing the plugin file