I'm creating a theme for a client and one of their requests is to allow users to upload images for their own use, but there may be an option to share the images.

Here are some of the caveats:

  • Each user has the ability to upload their own images to their own Media Library.
  • These images must be capable of being 'tagged' exactly similar to how we 'tag' 'posts' now.
  • The Admin can manage these images also.

Firstly is this possible and is it possible to create a 'tag' taxonomy for images?

Thanks for your help.

3 Answers 3


Built in features

The Media Library has major updates with the upcoming version. You can see the changes in the slides by Daryl Koopersmith here. You can read the announcement and discussion on "Make".

Your request for "tags/categories" is already built into 3.5.


The difference between themes and plugins is pretty easy: Display vs. Functionality. So I'd suggest to not build such functionality into a theme, but keep it separated as plugin. Your benefit from doing this: You/Your client wouldn't loose this functionality on update or theme change. It simply makes your life a lot easier. Imagine, that you got another client requesting this. Then you'd simply upload your already existing plugin instead of ripping this out of your theme and moving it into the next theme.

  • I like what Wordpress has coming but I don't see the 'tagging' ability, maybe it just isn't shown in those slides? The problem right now is I have an urgent deadline and can't really wait for a new release. As for the 'theme/plugin/ diff, this theme is a custom build for this client; I may use components from it but for the most part it won't be merged to another theme so this isn't an issue this instance.
    – Anthony
    Commented Nov 12, 2012 at 10:27
  • Ad slides) Yes, this isn't shown, but already available. In your case, I'd just use the Beta release instead of the current version. Ad client) It's less about the client, but mostly about yourself and future work you'll do. I myself have a vast number of some hundreds of plugins. Some are smaller, some are bigger, but it's extremely handy to have those not hidden in some themes, but separated and well organized, so I can 1) look those up for reference much easier and 2) pull them in (in case functionality stays the same) and 3) fork them out in case I need to change something minor.
    – kaiser
    Commented Nov 12, 2012 at 10:31
  • @Anthony Take a look at the roadmap of WP. It will be released in some days, so there won't be any major changes (at least it's "Beta", not "Alpha").
    – kaiser
    Commented Nov 12, 2012 at 10:32
  • Do I have to sign up to access the Beta? I suppose this will be better as it will let me get used to the new changes. The deadline is 2013 for this project so if the actual release is to be early December that would be fine.
    – Anthony
    Commented Nov 12, 2012 at 11:29

As Kaiser mentioned, in the next version of WordPress the Media Library uses a UI closer to the posts/pages interface.

Since the media library is basically a CPT called 'attachment', you can comment on, have post meta, and assign taxonomies to the 'attachment' post type.

3.4.2 supports all of this, but will not show the taxonomies UI for media types. 3.5 does.

So that's tagging done.

For showing all to admins, and giving individual users their own media libraries? You'll need to filter them out based on 'author', using a pre_get_posts filter that only runs in the backend, and if the user is not of role administrator or higher, and only if the query is looking for posts of type 'attachment'.


This Q&A shows how to limit the posts a user role is able to see in the dashboard. It was missing the attachments part, which is this:

add_filter( 'pre_get_posts', 'wpse_72278_current_author_media' );
add_filter( 'views_upload', 'wpse_72278_custom_view_count', 10, 1 );

function wpse_72278_current_author_media( $query ) 
    global $pagenow, $user_ID;

    if( 'upload.php' !== $pagenow )
        return $query;

    if ( $query->is_admin && current_user_can( 'editor' ) ) 
        $query->set( 'author', $user_ID );      

    return $query;

function wpse_72278_custom_view_count( $views ) 
    global $user_ID, $wpdb;

    if ( !current_user_can('editor') ) 
        return $views;

    $total = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts 
        WHERE post_author = '$user_ID'
        AND post_type = 'attachment' " );
    $image = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts 
        WHERE post_author = '$user_ID' 
        AND post_mime_type LIKE 'image/%' " );
    $video = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts 
        WHERE post_author = '$user_ID' 
        AND post_mime_type LIKE 'video/%' " );
    $detached = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts 
        WHERE post_author = '$user_ID' 
        AND post_type = 'attachment' AND post_parent = '0' " );

    $views['all'] = preg_replace( '/\(.+\)/U', '('.$total.')', $views['all'] ); 
    $views['image'] = preg_replace( '/\(.+\)/U', '('.$image.')', $views['image'] ); 
    $views['video'] = preg_replace( '/\(.+\)/U', '('.$video.')', $views['video'] ); 
    $views['detached'] = preg_replace( '/\(.+\)/U', '('.$detached.')', $views['detached'] ); 

    return $views;

This other takes care of the issue of a post owned by one author and the upload made by another.

And case you're not jumping into 3.5 yet, this last one handles Custom Fields for Attachments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.