[wp-hackers] Best way to kick off actual work from plugin settings page?
Michael D Adams
mda at blogwaffe.com
Tue Jul 13 01:28:05 UTC 2010
On Mon, Jul 12, 2010 at 12:04 AM, Matt Jacob <matt at mattjacob.com> wrote:
> 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.
When does the $_POST array ever get "wiped out"?
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.
function my_plugin_admin_menu() {
$hook = add_options_page( 'Me', 'Me', 'manage_options', 'me',
'my_plugin_admin_page' );
add_action( "load-$hook", 'my_plugin_admin_page_load' );
}
function my_plugin_admin_page_load() {
if ( 'post' != strtolower( $_SERVER['REQUEST_METHOD'] ) )
return;
// do stuff
}
Does that suit your needs?
More information about the wp-hackers
mailing list