[wp-trac] [WordPress Trac] #14769: API for "Settings" action link on plugins.php
WordPress Trac
wp-trac at lists.automattic.com
Thu Sep 23 21:25:27 UTC 2010
#14769: API for "Settings" action link on plugins.php
----------------------------+-----------------------------------------------
Reporter: nacin | Owner:
Type: task (blessed) | Status: new
Priority: normal | Milestone: 3.1
Component: Plugins | Version:
Severity: normal | Keywords:
----------------------------+-----------------------------------------------
Comment(by joelhardi):
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14769#comment:1>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list