register_taxonomy_for_object_type('post_tag', 'attachment');
should do the trick. I think you could even do this from your themes functions.php .
Edit: ok, try this (save as attachmenttags/attachmenttags.php in your plugins folder and make sure WP can read it, then activate in plugin manager):
/*
Plugin Name: AttachmentTags
Description: enables tagging attachments
Author: Wyrfel <[email protected]>
Version: 0.1
*/
if (!class_exists('AttachmentTags') {
class AttachmentTags {
function AttachmentTags() {
add_action('admin_init', (&$this, 'admin_init'));
add_filter('wp_get_attachment_image_attributes', (&$this, 'add_tag_classes'), 10, 2);
}
function admin_init() {
register_taxonomy_for_object_type('post_tag', 'attachment');
}
function add_tag_classes($attr, $attachment) {
$tags = wp_get_object_terms($attachment->ID, 'post_tag', 'names');
if (!empty($tags)) foreach ($tags as $tag) {
$attr['class'] .= ' '.$tag; //wp sanitizes afterwards, so we don't need to
}
return $attr;
}
}
$AttachmentTags = new AttachmentTags();
}
BTW: This also creates the post tags field in the add/edit image popup when editing the actual post/page.
Edited again, should now also inject the classes whenever you use get_the_post_thumbnail() in your theme.