Make WordPress Core

Opened 13 years ago

Closed 8 years ago

#14769 closed feature request (maybelater)

API for "Settings" action link on plugins.php

Reported by: nacin's profile nacin Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Plugins Keywords: needs-patch
Focuses: administration Cc:

Description

Plugins should be able to register a "Settings" actions link that will then take them to their plugin settings page.

We should try to hook into add_options_page() as well, just by taking the first one that the plugin registers. Probably not really doable to ascertain which plugin calls that function however, without running a backtrace. Maybe try matching the slug with the plugin basename.

Someone is encouraged to run with this before I get to it.

Change History (14)

#1 @joelhardi
13 years ago

A very simple way to implement this would just be to create a function analogous to register_activation_hook and register_deactivation_hook, that takes the plugin's filepath (i.e. __FILE__) and callback as args. i.e. the plugin author would do:

function my_settings_link(/* array */ $links) {
  $links[] = '<a href="options-general.php?page=your_plugin.php">'.__("Settings").'</a>';
  return $links;
}
register_plugins_link_filter(__FILE__, 'my_settings_link');

And then register_plugins_link_filter() would just register the plugin_action_links_ filter.

Or, if you want to plug into add_(options|media|posts|etc)_page, we could add an optional argument to add_submenu_page, i.e. a (bool) $settings_link that if set, would add the link.

Would be easy and efficient to implement because add_submenu_page is already doing the capability check to see if the link should appear, and already calling get_plugin_page_hookname() to generate the link URL, so would not have to do that twice. Would also need to add this optional argument to add_menu_page. And, to all of the one-line wrapper functions like add_options_page as well -- unless you want these to just always do it by default.

I think this second approach is more along the lines of what you're suggesting. If the plugin calls add_(sub)menu_page more than once to add multiple options pages, and sets the bool $settings_link more than once, it would be easy to check whether a filter for 'plugin_action_links_'.plugin_basename() has already been set before setting another one.

Or, we could not add this optional argument at all and just always register a settings link for whatever is the first page the plugin registers. I guess I don't necessarily love this degree of automagic (what if the plugin author doesn't want any settings link, or doesn't want to register their pages in a particular order?) but then I don't necessarily love adding an (eighth!) argument to these functions either, and making the API more complicated for people. Speaking as a plugin author I can't see why I wouldn't want to have the Settings link, so I guess I would lean toward the automagic and not complicating the API with an additional argument.

Alternately, could do only 50% automagic: Add the argument to add_menu_page and add_submenu_page, but just have add_(options|media|post|etc)_page call add_submenu_page with the flag always set to TRUE, so the API is magic for people who are using these simpler wrapper funcs, but anyone who needs the additional control can call add_submenu_page directly.

#2 @jane
13 years ago

  • Keywords needs-patch added
  • Version set to 3.0

#3 @jane
13 years ago

We have a few days before freeze to get a patch for this into consideration, if anyone wants to take a stab.

#4 follow-up: @edward mindreantre
13 years ago

  • Cc edward@… added

When would this settings link be clicked? And where?

Are you referring to them there quicklinks on the plugin page? Activate / Deactivate / Settings?

#5 in reply to: ↑ 4 @duck_
13 years ago

Replying to edward mindreantre:

Are you referring to them there quicklinks on the plugin page? Activate / Deactivate / Settings?

Yeah.

#6 @edward mindreantre
13 years ago

Doesn't the action "plugin_action_links" already do that?

See wp-admin/includes/class-wp-plugins-list-table.php, lines 388 and 389.

#7 @edward mindreantre
13 years ago

Or even: plugin_row_meta

#8 @markjaquith
13 years ago

  • Milestone changed from 3.1 to Future Release

We already have the ability to do this. Or did you want to abstract it even further?

#9 @nacin
13 years ago

  • Type changed from task (blessed) to feature request

Abstract it further so plugins have a standard. Then "Settings" can always in the same spot and always be called "Settings."

This came out of a dev chat at one point.

#11 @mordauk
10 years ago

  • Cc pippin@… added

#12 @nacin
9 years ago

  • Component changed from Plugins to Admin APIs
  • Focuses administration added

#13 @nacin
9 years ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

#14 @chriscct7
8 years ago

  • Milestone Future Release deleted
  • Resolution set to maybelater
  • Status changed from new to closed

Closing as maybelater. Complete lack of interest on the feature on the ticket over the last 5 years. Feel free to reopen when more interest re-emerges (particularly if there's a patch).

Note: See TracTickets for help on using tickets.