I've created a custom role "Expert" and added a custom capability to this role: "manage_zoom_meetings".
If I try to check if the current user has the capability, the function current_user_can('manage_zoom_meetings')
returns false
.
I've tested this code to check if the role is maybe not existing for the function current_user_can.
add_filter( 'user_has_cap', function ( $allcaps, $caps, $args, $user ) {
wp_die( var_export( get_role( 'expert' )->capabilities, true ) );
return $allcaps;
}, PHP_INT_MAX, 4 );
The output looks like this:
array ( 'level_0' => true, 'manage_zoom_meetings' => true, 'read' => true, )
I don't understand what is wrong here.
The problem is, that I'm not able to add this capability to an admin menu item (add_menu_page()
) or to a custom post type.
This is how I add custom roles and custom caps via
function.php
using add action init...Doing this should in theory make the below code return
true
when used anywhere on your site if their current user role is expert or if the current user has this capability...Hope this helps :-)