Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a weird issue. My post thumbnails aren't working with a custom role. Images can be uploaded, and when viewing the media uploader they show as attached to the relevant post. However, when calling the thumbnail is returns nothing.

I am running some PHP to filter what posts the author can see, could this be the issue?

Here's the role;

add_role(
    'dealer',//name of role
    'Dealer',//display name of role
    array(//array of capabilities 
        'read' => TRUE,
        'edit_posts' => TRUE,
        'publish_posts' => TRUE,
        'upload_files' => TRUE,
        'edit_published_posts' => TRUE,
        'delete_posts' => TRUE //to allow media to be deleted 
    )
);

This is one of the filters, picked up from this forum I believe;

//filter posts for dealer user
function ik_eyes_only( $wp_query ) 
{ 
    if(strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false || strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) 
    { //user level 5 converts to Editor 
        if ( !current_user_can( 'level_5' ) ) 
            { //restrict the query to current user 
                global $current_user; 
                $wp_query->set( 'author', $current_user->ID ); 
            } 
        } 
} 
add_filter('parse_query', 'ik_eyes_only' );

..and this should be the other one that might be the issue..

function ml_restrict_media_library( $wp_query_obj ) 
{
    global $current_user, $pagenow;
    if( !is_a( $current_user, 'WP_User') )
    return;
    if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
    return;
    if( !current_user_can('manage_media_library') )
    $wp_query_obj->set('author', $current_user->ID );
    return;
}
add_action('pre_get_posts','ml_restrict_media_library');

Any ideas? This one is driving me nuts!!!

share|improve this question
    
What do you mean by "calling the thumbnail"? Where is that code? –  s_ha_dum Sep 13 '13 at 18:10
    
has_post_thumbnail() The rest of the code works when the author is admin level, but this role does not work as it should. –  Dan Sep 13 '13 at 18:17
    
has_post_thumbnail() doesn't echo anything. What do you mean by "Images can be uploaded"? Do you see the "Featured Image" meta box? –  s_ha_dum Sep 13 '13 at 19:10
    
Yeah, I'm not new to this, only the permissions of a custom user role. I regularly work with featured images and the type of query I'm using. –  Dan Sep 13 '13 at 21:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.