WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 months ago

#14769 new feature request

API for "Settings" action link on plugins.php

Reported by: nacin Owned by:
Milestone: Future Release 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 (13)

comment:1 joelhardi4 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.

comment:2 jane3 years ago

  • Keywords needs-patch added
  • Version set to 3.0

comment:3 jane3 years ago

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

comment:4 follow-up: edward mindreantre3 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?

comment:5 in reply to: ↑ 4 duck_3 years ago

Replying to edward mindreantre:

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

Yeah.

comment:6 edward mindreantre3 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.

comment:7 edward mindreantre3 years ago

Or even: plugin_row_meta

comment:8 markjaquith3 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?

comment:9 nacin3 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.

comment:11 mordauk8 months ago

  • Cc pippin@… added

comment:12 nacin2 months ago

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

comment:13 nacin2 months ago

  • Component changed from Admin APIs to Plugins

Sorry for the noise.

Note: See TracTickets for help on using tickets.