[wp-hackers] Best way to kick off actual work from plugin settings page?

Matt Jacob matt at mattjacob.com
Mon Jul 12 07:04:33 UTC 2010


I'm using the settings API for my plugin's custom settings page, and 
it's working pretty well. Sometimes, though, I want to perform an action 
based on a submitted value instead of just saving the value back to the 
DB. Where's the best place to intercept the form submission and do some 
actual work?

I have two possibilities in my mind:

1. Hook into the admin_init action, since this should come before the 
$_POST array gets wiped out. I can determine if a specific submit button 
was used, if a certain checkbox was checked, etc. and then do some work 
based on those criteria.

2. Use the validation callback in register_setting() to check the 
submitted fields for what I want, do some work, and then return only the 
options I actually want to be persistent. (I'm using a single array for 
all of my options, so it's easy to leave some options out.)

Option #2 seems more elegant, but it's kind of overloading the purpose 
of the callback.

Just for reference, the kind of "work" I'm talking about doing is 
regenerating a secret token or importing existing records to custom 
posts during an upgrade.

Matt


More information about the wp-hackers mailing list