I have my plugin all set-up using the Settings API and working but what I have is two manual functions in my plugin that can be run by the admin user by visiting the following URL’s
<?php echo admin_url(); ?>options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=1&sc_wpfmp_scan=1
<?php echo admin_url(); ?>options-general.php?page=wordpress-file-monitor-plus&sc_wpfmp_action=1&sc_wpfmp_reset_settings=1
I’m using the admin_init
hook to lookout for these GET parameters and do those functions.
The functions run fine and the user is back on my plugin settings page but the GET parameters are still in the URL. Not a big issue but if the user then goes ahead and save the settings those GET parameters are sent again and thus running those functions again.
Why does the Settings API send those parameters when submitting the settings form? The action of the form is to submit to options.php
.
The only way around my issue I can think of is that after those manual functions have run its code in admin_init
is to run a redirect to the settings page without the GET parameters, but if I do this I will lose my admin notices I’m trying to show to the user.
Anyway got any suggestions on how I can get around this problem. Maybe you think there is a better way to run these manual functions?
EDIT: full settings code: http://pastebin.com/Gk5RF5Lc
Quite frankly, it doesn’t. As you already mentioned, your form simply POST’s to
options.php
, which in turn handles the request, updates the database, and then redirects back to the referer.How the referer is fetched is down to the function
wp_get_referer()
;That’s why you’re getting sent back to your options page with the action parameters still there – because they were present in
$_SERVER['HTTP_REFERER']
.But you’ll also see that you can override this behaviour, by placing a hidden input inside your form like so;
Now
options.php
will always redirect back to……regardless of whatever was in the query string previously.