[wp-hackers] Best way to kick off actual work from plugin settings page?
Michael D Adams
mda at blogwaffe.com
Tue Jul 13 03:40:49 UTC 2010
On Mon, Jul 12, 2010 at 7:58 PM, Matt Jacob <matt at mattjacob.com> wrote:
> On 7/12/10 6:28 PM, Michael D Adams wrote:
>> Does your plugin have its own settings page, or are you adding
>> settings to a core settings page? If you have your own page, I feel
>> like the tried and true method is to do something like the following.
> Maybe, but I'm posting back to options.php, not plugins.php. Are you
> suggesting a separate form with an action set to my plugin's settings page?
Ah. Yes - I forgot that the settings API is usually used by POSTing
to options.php. My bad.
You could replicate option.php's calls to check_admin_referer() and
update_option() in the load-function (my_plugin_admin_page_load() in
my earlier example) and change to action="" in the form.
If you don't want to change the action, then I agree that you're stuck
with the methods you mentioned: the register_setting() callback and
admin_init (or load-options.php).
If you're trying to intercept the entire POST before anything updates
in the DB, and you have multiple calls to register_setting(), then
you'll have to be careful where you put your interception code; make
sure you know which register_setting() callback gets called first or
put your interception code in all of the callbacks.
More information about the wp-hackers