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.
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”.
Note
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.
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:
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.