Set Meta Links For WordPress Plugins

In the past I explained in the article „How To Improve WordPress Plugins“ , how you can expand Plugins with useful functions and therefore optimize their usage. One of the suggestions was a simple link to the options page of your Plugin.
With WordPress 2.8 the Plugin page will be a little bit different and now there will be a hook, which you can use to enter a link, which is even more convenient.

This tutorial works only in Version 2.8 or higher. For 2.7 you have to use the tutorial of „How To Improve WordPress Plugins“ or without further explanation this short snippet.

/**
 * @version WP 2.7
 * Add action link(s) to plugins page
 */
function set_plugin_meta27($links) {
	
	$plugin = plugin_basename(__FILE__);
	
	$settings_link = sprintf( '<a href="options-general.php?page=%s">%s</a>', $plugin, __('Settings') );
	array_unshift( $links, $settings_link );
	
	return $links;
}

add_filter( 'plugin_action_links_' . $plugin, 'set_plugin_meta27' );

Since version 2.8 the backend is a little bit different, also the meta links to Plugins are displayed differently from now on, which you can use as you can see on this screenshot.

28_plugin_meta_link

You can use following code to set the link to your options page. You can use the term „Settings“ , so you don't have to take care about other languages, since it is already in the respective language package included. The word will be adjust automatically to the according language.

function set_plugin_meta($links, $file) {
	
	$plugin = plugin_basename(__FILE__);

	// create link
	if ($file == $plugin) {
		return array_merge(
			$links,
			array( sprintf( '<a href="options-general.php?page=%s">%s</a>', $plugin, __('Settings') ) )
		);
	}

	return $links;
}

add_filter( 'plugin_row_meta', 'set_plugin_meta', 10, 2 );

Alternativ you can use the follow functions to link before other links on the plugin page.

// plugin definitions
define( 'FB_BASENAME', plugin_basename( __FILE__ ) );
define( 'FB_BASEFOLDER', plugin_basename( dirname( __FILE__ ) ) );
define( 'FB_FILENAME', str_replace( FB_BASEFOLDER.'/', '', plugin_basename(__FILE__) ) );

function filter_plugin_meta($links, $file) {
	
	/* create link */
	if ( $file == FB_BASENAME ) {
		array_unshift(
			$links,
			sprintf( '<a href="options-general.php?page=%s">%s</a>', FB_FILENAME, __('Settings') )
		);
	}
	
	return $links;
}

global $wp_version;
if ( version_compare( $wp_version, '2.8alpha', '>' ) )
	add_filter( 'plugin_row_meta', 'filter_plugin_meta', 10, 2 ); // only 2.8 and higher
add_filter( 'plugin_action_links', 'filter_plugin_meta', 10, 2 );

This little hack is easy to do but has a significant value for the user, since it's easy to get to the options page. It's just sad, that the developer of WordPress always changing the hook, so you have to adjust it after every new version. Hope that won't happen again in the near future.

Comments are closed.

6 comments

  1. Epic Alex

    Sweet, thanks for the tips on WordPress 2.8. I've updated my own post on the topic to reflect the new version of WP.

    I've also put some if statements to see which version is being run, and then the right code is executed accordingly.

    Also, in RC1, the settings link is added to the left of the deactivate button using your code above, I'm not sure which version you tested in? And its worth noting too that the link only shows up when the plugin is active.

    Alex

  2. Frank

    @Epic Alex: I have also updated this post with a better solution for hook in 2.7 and 2.8; also now is the Settings-Link before the other links of WordPress default.
    Thanks for your comment and backlink!

  3. Mukesh Dak

    Thank you so much for this very useful code

  4. Michael Pedzotti

    Thanks Frank. I will include this feature in my plugins from now on.

2 pingbacks

  1. Set Meta Links For WordPress Plugins - WordPress … | Bloggers Tools
  2. WordPress & Blogging Articles for june 10 2009 | WPStart.org - WordPress themes, plugins and news