Share this:

Technorati ReddIt Favorites

Expanding Plugins Panel with Links and Info

If you are plugin developer, it’s very important to give as much info about the plugin updates as you can before the blog admins update the plugin to a new version. Also, some of the plugin control panels go into different menus, and it’s a good idea to have direct links on the plugins panel also.

Examples bellow are for WordPress 2.9 or newer. This is re-revised version of last years tutorial, this time with added meta info links block. New method is used that doesn’t require for you to check if the filter is executed for your plugin only. New filters already include plugin name in the filter name.

Additional options

Each plugin row on the Plugins panel has several standard actions. You can add more actions like the link to the settings panel or anything else. You need to add filter function that will be used to add this action(s).

<?php
add_filter('plugin_action_links_$plugin_file', 'add_plugin_links');

function add_plugin_links($links) {
  $links[] = '<a href="index.php">Dashboard</a>';
  $links[] = '<a href="edit.php">Posts</a>';
  return $links;
}
?>

Lines 5 and 6 are adding new action to the plugin row. This example adds link to the dashboard and to post edit page, you can change it to whatever you need. Don’t forget to return $links because this is a filter not an action.

Very Important: On line 2 filter has $plugin_file. You need to replace this with the relative path/name of the main file of your plugin. For instance, my plugin GD Press Tools has a $plugin_name: gd-press-tools/gd-press-tools.php. It has folder name, slash, main plugin file name (with extension), and full filter name will be than: plugin_action_links_gd-press-tools/gd-press-tools.php. Same method will be used in the last expand examples.

Plugin Meta options

Description column in the plugins grid have also number of links. This can be expanded similar to additional options from previous block.

<?php
add_filter('plugin_row_meta', 'add_plugin_meta_links', 10, 2);

function add_plugin_meta_links($links, $file) {
  if ($file == "$plugin_name") {
    $links[] = '<a href="index.php">Dashboard</a>';
    $links[] = '<a href="edit.php">Posts</a>';
  }
  return $links;
}
?>

Lines 5 is there to ensure that you add settings only to your own plugin. Lines 6 and 7 are actually adding new action to the plugin row. This example adds same links as previous one, but, you can add whatever you want leading to your own plugin. In the case of this filter, you must check on your own if the filter is run for your plugin.You must $plugin_name on line 5 with the string as described in the first example above.

Additional plugin info

WordPress shows description from your plugin file. And when the new version is available for update, there is no detailed info about the the update. Adding that is not very hard.

<?php
add_action('after_plugin_row_$plugin_file', 'add_after_plugin_meta');

function add_after_plugin_meta($file) {
  $current = get_site_transient('update_plugins');
  if (!isset($current->response[$file])) return false;

  $url = "http://www.yoursite.com/info.txt";
  $update = wp_remote_fopen($url);
  echo '<tr><td colspan="3">'.$update.'</td></tr>';
}
?>

Function checks to see if you add row to your plugin as the previous function does. Lines 5 and 6 will check if there is an updated found for your plugin. If no update is found, additional row will not be added. You can remove this part, and added row will be always visible. My intention with this code is to display details about the plugin update, you can change it to anything else. You need to echo only TD part of the row, WordPress already echoes TR tag. Function will get contents of the file from $url variable and will echo that file in the row.

Example

Example

Example above shows both functions used in GD Press Tools plugin. First row is a standard plugin info, and you can see Settings action added by first function. Second row is WordPress info that plugin upgrade is available. Third row is info displayed by second function that has retrieved this changes notice from my website.

This example uses same $plugin_name method that is described in the first example.

8 Responses to “Expanding Plugins Panel with Links and Info”

  1. Kim | October 11, 2010 at 21:42

    Thanks for this nice and clean explanation! I’m sure i’m using it in my next releases!!!

    Kim

  2. Frank P. Walentynowicz | December 27, 2010 at 22:55

    I’ve tried to follow instructions in Additional plugin info. No success. First of all this is a filter not an action. To check if plugin update is available you need to call `get_site_transient( ‘update_plugins’ )` function rather than `get_transient( ‘update_plugins’ )`. Below is what I came up with:

    `add_filter(‘plugin_row_meta’, ‘add_plugin_meta’, 10, 2);

    function add_plugin_meta($links, $file) {
    static $this_plugin;

    if (!$this_plugin)
    $this_plugin = plugin_basename(__FILE__);

    if ($file == $this_plugin ){
    $current = get_site_transient(‘update_plugins’);
    if (!isset($current->response[$file]))
    return $links;
    $url = “http://fw2s.com/update.txt”;
    $update = wp_remote_fopen($url);
    $links[] = ”.$update;
    }
    return $links;
    }`

    • MillaN | December 27, 2010 at 23:21

      This is not the same for every version of WordPress. It was an action in some older versions. Also, there is a simpler way now that doesn’t require check for the plugin. I will update this in a day or two.

  3. Frank P. Walentynowicz | December 28, 2010 at 00:50

    Thanks Milan.

    • MillaN | December 28, 2010 at 12:02

      Tutorial is updated now.

      • Frank P. Walentynowicz | December 29, 2010 at 20:50

        RE: Additional plugin info

        Finally I got it working, however some changes to the function were necessary. First parameter MUST be $file. Second parameter can be removed. Also to check if update is available we have to use get_site_transient(‘update_plugins’) not get_transient(‘update_plugins’).

        • MillaN | December 29, 2010 at 20:56

          Thanks! You are right, I missed that yesterday. I have made a change to the post.

Trackbacks/Pingbacks

  1. Graphic Tuts | Dev4Press | WordPress Tips: Expanding Plugins Panel with Links and Info - January 11, 2011

    [...] via Dev4Press | WordPress Tips: Expanding Plugins Panel with Links and Info. [...]

Leave a Reply

Follow us on Twitter

Date Archives

Social Networks

Google Plus Profile Subscribe to RSS feed LinkedIn Profile Follow me on Pinterest Watch our Youtube Videos Find us on Flickr

Feedburner Feedburner updates

Sign up to receive news from this website to your email.

Recent Blog Posts

Dev4Press on YouTube

Share This

Technorati ReddIt Favorites