Add Custom Column To Media Page

written by Arief Bayu Purwanto on February 4, 2010 in Tutorial with one Comment

How do you get full image URL in Media Library? I bet you will go through this step:

  1. Go to Media » Library
  2. On Media Library list, click file name.
  3. Form Edit Media appeared. Select File URL and use it.

For single image operation, this should be enough. But, if you did have a lot of pictures, this operation would be very annoying. For this, I have a simple solution. With a few lines of code that later summarized into a plugin. Then you will have a way to access the images directly from the Media Library.

For these needs, we need to implement 2 filters, manage_media_columns and manage_media_custom_column. Here is his code:

add_filter ('manage_media_columns', 'beenSeenAttachmentDetail_columns');
function beenSeenAttachmentDetail_columns ($defaults ) {
    $defaults['media_url'] = __('Media URL');
    return $defaults;
}
add_action('manage_media_custom_column', 'beenSeenAttachmentDetail_custom_column', 10, 2);
function beenSeenAttachmentDetail_custom_column($cname, $id)
{
   if("media_url" == $cname)
   {
      $image = wp_get_attachment_image_src( $id, 'full' );
      echo "<input type='text' size='25' value='$image[0]' name='attachmentURL[$id]' onclick='javascript:this.select()'/>";
   }
}

Save it with file name ‘direct_image_url_access_from_media_list.php‘. But, before saving it to the /wp-content/plugins/, do not forget to add ‘file header‘. This is mandatory, if not, the plugin will not be recognized by wordpress. This is an example, please be creative:

/*
Plugin Name: Been Seen Manager
Description: Exclusive plugin for beenseen
Version: 0.1
Author: Arief Bayu Purwanto
Author URI: http://bayu.freelancer.web.id/
*/

Oh, ‘file header’ MUST be placed early in the script. Can’t follow this tutorial? don’t worry, I’ve prepared the files that’s already done so you can upload directly to server.

Let’s see how this plugin in action. Figure One is Media Library before the plugin is active and the second one is Media Library after the plugin is active. See the difference?

Free Image Hosting at www.ImageShack.us
Free Image Hosting at www.ImageShack.us