views:

184

answers:

2

I developed a plugin with Settings link that was working fine in WordPress 2.7. Version 2.8 brings some additional security features that cause Settings link displaying message: You do not have sufficient permissions to access this page.

This is the API hook I use to create link:

function folksr_plugin_action($links, $file) {
    if (strstr($file, 'folksr/folksr.php')) {
        $fl = "<a href=\"options-general.php?page=folksr/settings.php\">Settings</a>";
        return array_merge(array($fl), $links);
    }
    return $links;
}

add_filter('plugin_action_links', 'folksr_plugin_action', 10, 2);

Full source code available at plugin page.

Settings screen does not contain any additional logic, just a couple of options and HTML echoed to the screen.

Suprisingly enough, Codex does not return anything for search phrase "plugin_action_links". Can you provide example or point me to working code for Settings link in Plugins menu?

A: 

I have working admin menu links on my plugins working in 2.8+. My function looks like this:

  function plugin_action_links( $links, $file ) {
    if ( $file == plugin_basename(__FILE__) )
      $links[] = '<a href="' . admin_url( 'options-general.php?page=lj-longtail-seo/lj-longtail-seo.php' ) . '">Settings</a>';

    return $links;
  }

My add_filter line is mostly identical. I think the first thing to try is adding the use of the admin_url function.

Hope that helps.

Littlejon
Adding admin_url didn't help. I suspect it could have something to the fact that my settings screen is in separate file.
Michał Rudnicki
A: 

I found the solution to my own problem by analyzing sources of some random plugins. I must say - what an unpleasurable experience that was! But hey, here's the solution.

It turns out that in order to build Settings link, it needs to be registered first. The following code is a stub that does the trick:

class MyPlugin {

    public function __construct() {
        add_filter('plugin_action_links', array($this, 'renderPluginMenu'), 10, 2);
        add_action('admin_menu', array($this, 'setupConfigScreen'));
    }

    public function renderPluginMenu() {
        $thisFile = basename(__FILE__);
        if (basename($file) == $thisFile) {
            $l = '<a href="' . admin_url("options-general.php?page=MyPlugin.php") . '">Settings</a>';
            array_unshift($links, $l);
        }
        return $links;
    }

    public function setupConfigScreen() {
        if (function_exists('add_options_page')) {
            add_options_page('MyPlugin settings', 'MyPlugin', 8, basename(__FILE__), array($this, 'renderConfigScreen'));
        }
    }

    public function renderConfigScreen() {
        include dirname(__FILE__) . '/MyPluginSettings.php';
    }

}
Michał Rudnicki