How to get an array of user roles with or without a specific capability?

Try with this: function get_roles_that_cant($capability) { global $wp_roles; if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $available_roles_names = $wp_roles->get_names();//we get all roles names $available_roles_capable = array(); foreach ($available_roles_names as $role_key => $role_name) { //we iterate all the names $role_object = get_role( $role_key );//we get the Role Object $array_of_capabilities = $role_object->capabilities;//we get the array … Read more

WordPress theme custom capabilities not works

add_action( ‘init’, ‘register_cpt_gallery’ ); function register_cpt_gallery() { $labels = array( ‘name’ => _x( ‘Galleries’, ‘gallery’ ), ‘singular_name’ => _x( ‘Gallery’, ‘gallery’ ), ‘add_new’ => _x( ‘Add New’, ‘gallery’ ), ‘add_new_item’ => _x( ‘Add New Gallery’, ‘gallery’ ), ‘edit_item’ => _x( ‘Edit Gallery’, ‘gallery’ ), ‘new_item’ => _x( ‘New Gallery’, ‘gallery’ ), ‘view_item’ => _x( ‘View … Read more

Custom Post Type Tag Capabilities Not Working

It seems that although WP core creates four capability mappings for the built-in post_tag taxonomy (manage_terms => manage_post_tags, edit_terms => edit_post_tags, delete_terms => delete_post_tags, assign_terms => assign_post_tags) when it is registered, it uses different values when checking if the user has one of those capabilities. If you look at the implementation of the map_meta_cap function … Read more

Allow Author on Site A capability to upload files on Site B in Multi Site

Look into switch_to_blog() and its required follow up, restore_current_blog() I left comments in code for basic idea to adapt into your function. It may need tweaking, and can probably be improved. //Site B add_action( ‘init’, ‘site_a_author_upload_site_b’ ); function site_a_author_upload_site_b() { if ( is_user_logged_in() ) { //get a WP_User object of current user $current_user = wp_get_current_user(); … Read more

Add condition of user capability in WP_query

#SOLVED# Issue is solved by defining the meta_query conditions with an if statement. So if current_user_can(‘subscriber’) the meta_query includes the conditions, otherwise the query includes all posts. This is the code in case this is helpful for anyone else: <?php //create variables $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1; … Read more