Have you ever seen a WordPress plugin with action links in the plugins list and wondered how it was accomplished? It is actually quite simple to do. WordPress has a hook for that.
Deep within the bowels of WordPress you will find a filter named plugin_action_links. This filter accepts an array containing a list of links that will be placed in the plugin action. It can be used like so:
Setup the hook
add_filter('plugin_action_links', 'plugin_action_links', 10, 2);
The function takes the list of action and the name of the current plugin as parameters
function plugin_action_links($links, $file)
Now you want to check to ensure you are looking at the row only for your plugin
if ($file == plugin_basename(__FILE__))
Finally, add the link to the actions array
$link = 'Call to Action';
array_unshift($links, $link);
Do not forget to send back the updated set of actions
return $links;
You should now see something similar to the following on your plugin in the plugins page.
All together now!
add_filter('plugin_action_links', 'plugin_action_links', 10, 2);
function plugin_action_links($links, $file) {
if ($file == plugin_basename(__FILE__)) {
// The "page" query string value must be equal to the slug
// of the Settings admin page we defined earlier, which in
// this case equals "myplugin-settings".
$settings_link = 'Call to Action';
array_unshift($links, $settings_link);
}
return $links;
}