WP Development

I always prefer it when plugins make it as easy as possible to find their configuration page. When I install a new plugin the last thing I want to do is hunt around for some hidden menu item, I want to play around with my new toy! And what better place to link to a plugin’s configuration than right from the admin Plugins page where the plugin is activated, deactivated or (the horror!) deleted. These are called ‘Action Links’ and it’s so easy to add a ‘Configure’ or ‘Manage’, or indeed any other link to your own plugin, that there’s no reason not to.

To add your very own action link, hook into the plugin_action_links_ filter like so, from your plugins constructor for instance:

if ( is_admin() ) {
  add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( &$this, 'plugin_manage_link' ), 10, 4 );
}

Then write a plugin_manage_link() function to add your own custom action links. Here’s an example to get you started:

/**
 * Return the plugin action links.  This will only be called if the plugin
 * is active.
 *
 * @param array $actions associative array of action names to anchor tags
 * @param string $plugin_file plugin file name, ie my-plugin/my-plugin.php
 * @param array $plugin_data associative array of plugin data from the plugin file headers
 * @param string $context plugin status context, ie 'all', 'active', 'inactive', 'recently_active'
 *
 * @return array associative array of plugin action links
 */
function plugin_manage_link( $actions, $plugin_file, $plugin_data, $context ) {

    // add a 'Configure' link to the front of the actions list for this plugin

    return array_merge( array( 'configure' => '' . __( 'Configure' ) . '' ), $actions );

}

Substitue the path to your plugin configuration for admin.php?page=myplugin, of course. Remember that this filter is only called when your plugin is active, so there’s no need to check for that. Easy, right?

Published by Nik McLaughlin

You can find Nik around the WP space, on LinkedIn, or on his personal blog.