Page submenu is not shown for custom user role on Wordpress admin page (WooCommerce)

Viewed 263

I retitled and moved the WooCommerce Products top-level menu to underneath the main WooCommerce tab with the following code:

 $products = recursive_array_search_php_91365( 'Products', $menu );
 unset ($menu[$products]);
 add_submenu_page('woocommerce', 'Donation Options', 'Donation Options', 'manage_options, products', '/edit.php?post_type=product');

The recursive array search function is pulled from this page.

My custom user roles are created and managed through the User Role Editor plugin. The desired menu shows up for an administrator, but not for my custom user role. I checked and this user can access the page that is called back, so I'm not sure why it isn't be displayed in the menu.

Any ideas?

1 Answers

As $capability of the add_submenu_page function you are passing manage_options. So only a super admin or an administrator can view it. See here for more information.

So to have it also displayed to users with the custom role you will need to replace manage_options with the capability of your custom user role.

Here is a complete list:

There is a syntax error in the capability field, it should look like this:

add_submenu_page( 'woocommerce', 'Donation Options', 'Donation Options', 'manage_options', 'products', '/edit.php?post_type=product' );

Also you have to replace /edit.php?post_type=product with the name of a callback function otherwise you will get the following warning:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function '/edit.php?post_type=product' not found or invalid function name
Related