• Joseph

    (@fullstack1995)



    site: localhost
    theme: wordpress default theme (twentytwentyone)

    custom role and capability doesn’t work with woocommerce.

    im trying to open the option page(localhost/wp-admin/admin.php?page=product_manager) but it redirect to localhost/my-account/

    add_action( 'admin_menu', function()
    {
        remove_role( 'custom_role' );
    
        add_role(
            'custom_role',
            'custom role',
            array(
                'custom_capability' => true,
            )
        );
    
        add_menu_page(
            'title'                     ,   // page title
            'custom title'              ,   // menu title
            'custom_capability'         ,   // capability
            "product_manager"           ,   // slug
            'option_template'           ,   // page content
        );  
    });
    
    function option_template()
    {
        echo "string";
    }

    and if i use one of wordpress role capability like ‘edit_posts’ . it works fine

    add_action( 'admin_menu', function()
    {
        remove_role( 'custom_role' );
    
        add_role(
            'custom_role',
            'custom role',
            array(
                'custom_capability' => true,
                'edit_posts' => true
            )
        );
    
        add_menu_page(
            'title'                     ,   // page title
            'custom title'              ,   // menu title
            'edit_posts'                ,   // capability
            "product_manager"           ,   // slug
            'option_template'           ,   // page content
        );  
    });
    
    function option_template()
    {
        echo "string";
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Joy

    (@joyously)

    That sounds like it is working fine. Adding a role is only one step, though. There has to be a user with that role or capability. Since your user didn’t have the capability, it seems like the menu item would not be shown. You are saying that the item is shown, but redirects. Could it be that’s because your user doesn’t have the capability?

    Thread Starter Joseph

    (@fullstack1995)

    hi @joyously
    thanks for reply

    ofc my user have the capability.
    and no, the menu doesnt show…

    when i try to open open the menu slug (localhost/wp-admin/admin.php?page=product_manager that i have created, it redirect to localhost/my-account/

    as i said before, this progress will work fine, until woocoommerce get active

    i have tried any possible way, and still have this problem

    • This reply was modified 3 years ago by Joseph.
    • This reply was modified 3 years ago by Joseph.
    Joy

    (@joyously)

    Well, then you are saying that the plugin is the problem. You should ask at the plugin’s support forum.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘capability doesn’t work with woocommerce plugin’ is closed to new replies.