Media Tags 2.0 Beta

July 8th, 2009 @ 3pm : 16 comments : Socialize This
Filed Under: Tags: , ,

Today I’d like to release the first public beta of the Media Tags plugin. This is an exciting change and almost complete rewrite to the core plugin code.

For anyone downloading this beta please be aware this is a beta version and subject to change in the near future. Also since this is a beta it is recommended NOT to use this on a production system. User beware! If you do download the plugin and test if please using the comment form below to mention any issue you have with the new plugin. I can only test thing to a certain level with my own client sites.

This new beta has been tested on WordPress versions 2.7.1 and 2.8 only! At this time I’ve not tested the new Media-Tags Management interface on any lower version of WordPress.

Some highlighted features:

  1. Moved the media tag storage to the WordPress Taxonomy system. The original version of the plugin used the WordPress media_meta data structure to store the comma separated list of Media Tags. The media_meta information is associated with the actual attachment. The problem is in order to access this information you need to have the post parent key. Since the serialized media_meta information is stored in such a way the search for items based on media tag value was mainly impossible. By using the built-in WordPress Taxonomy system queries against the media-tags is now much more flexible. When upgrading from a previous version of the media-tags plugin please deactivate then activate the plugin. During this activation step the existing media-tags are converted into the new Taxonomy. Note the old media tags are not removed from the postmeta table. This is in case something goes wrong and you need to downgrade the plugin.
  2. New Media Tags Management interface. Because the storage of the media tags is now more integrated with the WordPress core Taxonomy system the next logic development step was to provide an interface where users could manage the media tags. I give you the Media Tags Management panel. When the plugin is activated there is a new menu option added to the Media section sub-menu.
  3. New media-tags URL rewrite functionality. Again as a benefit of using the WordPress Taxonomy system I’ve setup a new /media-tags/ rewrite functionality. This means you can do something like http://www.somesite.com/media-tags/tagname. Or if the site is not using permalinks the URL will appears something like this http://www.somesite.com/?media-tag=tagname. This functionality is automatic.
  4. Media-Tag templates. Now in your theme you can define a template file ‘mediatag.php’ to be called when displaying a media-tag archive. This works much like the WordPress category.php template. You can also define a media tag specific template file like mediatag-xx.php when ‘xx’ is the media tag term id
  5. Replace legacy template function. In the original version of the media-tags plugin I provided the single hook into the plugin, get_media_by_tag(). This function is still supported. I’ve also added a new template function, get_attachments_by_media_tags().

    This new function accepts any more parameters like:

    • media_tags – comma seperated list of media_tag values.
    • media_types – comma seperated list of media_types values.
    • post_parent – This is now an optional parameter and will limit the selection of attachments to those from the post_parent Id. Possible future enhancement to this will be allowing a comma separated list of post ids.
    • numberposts, orderby, order offset – Standard list of WordPress options. See the get_posts() template function for details.
    • return_type
    • tags_compare – Possible values are: ‘OR’ (default) or ‘AND’. Used only when requests with more than one media_tag value. With the ‘OR’ option you want attachments associated with either media_tag. With ‘AND’ you want only attachments associate with both.
    • display_item_callback – This is a user defined callback function. If provided it let’s you control the display of the individual attachment item. This is handy for example when using the shortcode feature. More on shortcodes below.
  6. Shortcodes for drop into content easy of use. This is a little something extra and requested by many as the need to have feature in the next version of the plugins. Quite simply I added the new shortcode ability to the plugin. How do you use it? Simply add the shortcode code [media-tags] to your page content. Just as with the new template function, get_attachments_by_media_tags() it can take many parameters like the following which will filter the display.
    [media-tags media_tags="alt-views,page-full,thumb" tags_compare="AND" orderby="menu_order" display_item_callback="some_function"]

    When using shortcode the return type will always be an unordered list. you will need to supply the <ul></ul> or <ol></ol> elements before and after the shortcode call. My reasoning here is to allow the user the ability to ID or CLASS the top-level list wrapper as needed. But I’m torn. Thoughts?

    Notice the last parameter ‘display_item_callback’. This is a user defined function that will be called for each element of the returned list. It is important to note that per the WordPress use of shortcodes the user defined function needs to return the value not echo it from within the function. I’ve provided an example of a callback function in the file mediatags_shortcode.php. This default function is actually used by the plugin when displaying shortcode items.

  7. Event more template functions. In addition to the new get_attachments_by_media_tags() function I’ve also added a number of other template functions to be used in your theme.
    • is_mediatag() – Simpler to the WordPress is_category() or is_tag() template functions. If you are viewing a media-tags archive this will return true.
    • in_mediatag() – Similar to the WordPress in_category() function. Pass in a media-tag term id to check. If matching will return true.
    • mediatags_get_list() – Similar to the wp_list_categories() function will list all media-tags. Nice for the sidebar.
    • mediatags_get_link() – Pass in a media-tag term id and the link for that media-tag will be returned.
  8. media-tag tag cloud. This is still under development and probably will not make it into the initial 2.0 release. This is to be template function and/or widget that will display the weighted media-tags used in your site.

Download media-tags 2.0 Beta A now!
Media-tags plugin version 2.0 Beta A

Both comments and pings are currently closed.

16 Responses to “Media Tags 2.0 Beta”

  1. Moth Menace Says:

    Fantastic work and it’s looking really good, congrats. I’ve been playing with it today, love the page template file & permalinking. One question, I want to have a list of media-tags, clicking on which takes you through to a list of the relevant attachments from different posts. I am assuming I need to use get_attachments_by_media_tags(‘media_tags=’.$slug)
    But this returns none? Is a post ID also required? But then how do I get attachments from any relevant post?

  2. Paul Menard Says:

    @Moth Menace: If you just want a list, something like a sidebar list of categories or then you can use the new template function ‘mediatags_get_list()’. It take similar arguments to the main get_attachments_by_media_tags() function. But this function, located in mediatags_template_functions.php also provide some filters you can set to control the display. Hope this helps. And Thanks!

  3. Moth Menace Says:

    The list is working fine, many thanks again. In your readme you give an example like this:
    $media_items = $mediatags->get_media_by_tag(‘media_tags=banner&post_parent=6′);
    Does this query work without post_parent specified? On my media-tag.php template, how do I list all the attachments? Is there something like: http://codex.wordpress.org/Template_Tags/query_posts#Tag_Parameters
    ?

  4. Paul Menard Says:

    Ah. Please ignore the readme.txt file for now. I’ve not updated the information in the readme for the new version of the plugin. I would follow this post for the most up to date information on the plugin changes. I will at some point take this post and update the readme.txt

    At this time I didn’t add any logic to control filtering via the template file itself like the Tag_Parameters you linked. It’s a good idea and well something to add to my list for some future release. In the meantime I might be able to provide some suggestions on how to do this manually. Let me look at things and I’ll comment back here. Thanks.

  5. Moth Menace Says:

    Hi Paul,
    Thanks and I certainly don’t want to give you any more work!

    In my mediatags.php template, I used this query to get all the attachments under a tag:

    $tag = mediatag_get_tags(‘slug=’.get_query_var(‘media-tag’));
    $tag = $tag[0];
    $tag_id = $tag->term_id;

    “SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts AS posts
    LEFT JOIN $wpdb->term_relationships AS term_rel ON (term_rel.object_id = posts.ID)
    LEFT JOIN $wpdb->term_taxonomy AS term_tax ON (term_tax.term_taxonomy_id = term_rel.term_taxonomy_id AND term_tax.taxonomy = ‘media-tags’ )
    WHERE post_type = ‘attachment’ AND term_tax.term_id = $tag_id
    GROUP BY ID
    ORDER BY posts.post_date DESC”

  6. Paul Menard Says:

    Moth, As always thanks for al the questions and feedback. So on this issue I’m unclear what you are attempting. Are you trying to display all attachments for all posts in the system? I do know the current and new get_attachments_by_media_tags() does require at least on media-tag value to filter on. Let me know. Thanks.

  7. Moth Menace Says:

    Hi Paul, many apologies, I didn’t look at the mediatags-template-sample.php properly, and realise that the post loop functions perfectly well! I’ve been testing since you launched & no problems at all, just needs some documentation and then it’s an amazing plugin, thanks again.

    If I had OCD, I’d ask that the tag-adding form under the attachment was a replica of the main Post tagging panel, but that’s far from essential.

  8. Paul Menard Says:

    @Moth Menace: Thanks man. As for your last comment I do need to leave some features for future. :) Seriously though when it comes to API hooks available inside wp-admin media section things are rather limited.

    Curious abut your testing setup. Did you install this as an upgrade to an existing site making heavy use of the media tagged items? Just trying to make sure the upgrade processing works flawlessly. It’s my biggest concern.

  9. Violeta Says:

    Hi Paul, I installed the new plugin (thanks!) and then tried the shortcode in a page, but it just gets displayed as text. What could I be doing wrong? Do I need to have anything else installed for the shortcode to work?

  10. Paul Menard Says:

    Hmm. This was working. I might have broken something with the shortcodes as I was moving files around. Give me a few to investigate. I’m actually working on final tests this evening along with new documentation on the changes.

  11. Paul Menard Says:

    Ah Violeta it appears I forgot to add the include statement at the top of the main media_tags.php file.

    include_once ( dirname(__FILE__) . “/mediatags_shortcodes.php”);

  12. Violeta Says:

    Paul, thanks for the quick reply! Hmm. Still not working for me. Here’s what I’m trying in a page:
    [media-tags media_tags="Activity"]
    where I have two Media Library documents tagged as “Activity”. I added the line above directly within WP. Should I maybe download the plugin again and re-install it? Also, are there any restrictions on the type of files I can tag and use in pages? The two files I’m trying to list are both PDF.
    Thanks again so much for developing this awesome plugin!

  13. Violeta Says:

    Oops. To clarify, I meant that I added the include_one line you gave above directly to the php file using the WP file editor. Then used the shortcode in the page editor. Actually, I used [media-tags ...].

  14. Violeta Says:

    Oh bummer. Darn browsers never know what I mean to say :D I enclosed the [media-tags ...] within an unordered list. :)

  15. Paul Menard Says:

    Violeta I just posted the official 2.0 release of the Media-Tags plugin. I would definitely download the official release from the WordPress plugin page http://wordpress.org/extend/plugins/media-tags/

    As for you shortcode code I would also try a lower-case ‘activity’. as this is the ‘slug’ for the media tag not the upper/lower-case name for the mediatag. Once you download the official release make comments to the new post on this site for issues http://www.codehooligans.com/2009/07/15/media-tags-20-released/ as I will be closing this beta post comments. Thanks!

  16. Paul Menard Says:

    Comments are now closed on this Post as this was only open for the Media-Tags beta version. Please refer to the official Media-Tags 2.0 Release post where you will be able to enter comments. http://www.codehooligans.com/2009/07/15/media-tags-20-released/