Custom user role cannot see or modify featured image

Users that are only assigned to your event_admin role, don’t have the upload_files capability, needed to display the featured image meta box. Here’s the relevant code from the core: if ( $thumbnail_support && current_user_can( ‘upload_files’ ) ) // <– Notice this check add_meta_box( ‘postimagediv’, esc_html( $post_type_object->labels->featured_image ), ‘post_thumbnail_meta_box’, null, ‘side’, ‘low’ ); Note that if … Read more

Why does my custom WP role need edit_posts to edit images?

If I had to guess: because images are Attachments, and Attachments are a Post-Type. Thus, in order to edit an image, which is an attachment, which is a post, requires the edit_post capability. EDIT Don’t you have your capability mapping array keys/values reversed? e.g. you have ‘edit_posts’ => ‘edit_listings’. Shouldn’t it instead be ‘edit_listings’ => … Read more

Query users by custom taxonomy and user role

Apparently there is no core implementation of ‘tax_query’ in WP_User_Query yet. Check the ticket here for more info –> https://core.trac.wordpress.org/ticket/31383 Nevertheless there is an alternative way using get_objects_in_term $taxonomy = ‘shop-category’; $users = get_objects_in_term( $term_id, $taxonomy ); if(!empty($users)){ // WP_User_Query arguments $args = array ( ‘role’ => ‘shop_manager’, ‘order’ => ‘DESC’, ‘orderby’ => ‘user_registered’, ‘include’ … Read more

alphabetically order role drop-down selection in dashboard

Almost the same approach One Trick Pony has chosen, but I am using translated names and uasort() (to preserve the keys): add_filter( ‘editable_roles’, ‘t5_sort_editable_roles’ ); /** * Array of roles. * * @wp-hook editable_roles * @param array $roles * @return array */ function t5_sort_editable_roles( $roles ) { uasort( $roles, ‘t5_uasort_editable_roles’ ); return $roles; } /** … Read more

Restrict Contributors to view only their own custom post types?

You need to use the action hook pre_get_posts. See the comments for details and modify the Custom Post Type(s) to your own: add_action( ‘pre_get_posts’, ‘filter_cpt_listing_by_author_wpse_89233’ ); function filter_cpt_listing_by_author_wpse_89233( $wp_query_obj ) { // Front end, do nothing if( !is_admin() ) return; global $current_user, $pagenow; wp_get_current_user(); // http://php.net/manual/en/function.is-a.php if( !is_a( $current_user, ‘WP_User’) ) return; // Not the … Read more

wp_insert_user role not working

$WP_array = array ( ‘user_login’ => $username, ‘user_email’ => $email, ‘user_pass’ => $password, ‘user_url’ => $website, ‘first_name’ => $first_name, ‘last_name’ => $last_name, ‘nickname’ => $nickname, ‘description’ => $bio, ) ; $id = wp_insert_user( $WP_array ) ; wp_update_user( array (‘ID’ => $id, ‘role’ => ‘editor’) ) ; Since you are looking for working solutions, this one … Read more

Temporary capability for current_user_can()

Yes, just filter ‘user_has_cap’. You get an array with the current capabilities that you can change without touching the database. Sample Code add_filter( ‘user_has_cap’, ‘wpse_53230_catch_cap’, 10, 3 ); /** * See WP_User::has_cap() in wp-includes/capabilities.php * * @param array $allcaps Existing capabilities for the user * @param string $caps Capabilities provided by map_meta_cap() * @param array … Read more