Media Tags 2.0 Beta

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

About Paul Menard

Mis-placed Texas Geek now living on North Carolina. Lover of all things coding especially WordPress, Node.js, Objective-C and Swift. Love to work on interesting projects and come away with some new knowledge. Trying to keep my head on while I try to staying abreast of all the latest technologies. Lover of books and cats.