I've developed a few plugin for Wordpress. Currently I've not been able to replicate the way wp save settings. I've a setting page which I learned from a tutorial. It POST to option.php, and wp take care of saving the data.

But I have some custom option page which require more complex handling. Basically I wanted to POST some data to my own php, then redirect back to the original page/url after handling. I can't find a "proper" way to redirect correctly, i.e. without load the whole page then redirect using javascript.

Currently I use GET with add_query_arg(), the url will display the data that I passed. Using POST will trigger a redirect prompt when refreshed.

Is there a built in wp function that does it automatically? OR If I were to POST to option.php, how should I access the data without it handling automatically?

EDIT: Example of one of the complex page would be like this:

I assign a usermeta to some users which we would call SU (SpecialUser). To ease the job of admin, I have a page to display the list of users with a column showing whether they are SU. The text in that column of each row is a link which if clicked, will toggle the state of SU for that user. Currently I use GET, to pass the id of the user and also action to be carried out. Then page itself will detect, if both action and id is valid, the state of the user is toggled. At the same time, the updated result is displayed. The GET query remain at the URL

What I would really like to do is to use POST, pass the id and action to the same page, then toggle the state but not displaying anything, then "redirect" back to the page displaying the updated user list. What I've tried earlier while implementing this is to use javascript to redirect the page, but this means it will have to load the whole page before the javascript can be executed. It's not resource friendly. I would like it to work much like how the Settings API would.

Sorry for the long explaination. I'm sure there's a term to what I wanted to do, but I'm not sure what it is.


EDIT: It's more or less like the Plugin page, when you activate/deactivate the plugin. The plugin page is using GET. The problem I have is actually redirecting, so GET or POST shouldn't matter.

2 Answers 2


if you are using the Settings API then you can use your own php inside the $sanitize_callback of your register_setting and return the value you want to save after doing your "more complex handling".

  • The WordPress Settings API is incredibly powerful and flexible, and is definitely the way to go here. May 25, 2011 at 14:51
  • Thanks, yes, you're right. I'm using Settings API for the "simple" setting page. As for the complex one, I'm creating something similar to the "Posts" (wp-admin/edit.php) but without ajax. Do you know any similar tutorial I can pickup from? The Settings API is already complicated enough for me.
    – faulty
    May 25, 2011 at 22:30
  • I think I can't use Settings API for the complex page, since the users who are going to use them doesn't have "manage_options" capability but it's required according to codex.wordpress.org/Settings_API
    – faulty
    May 25, 2011 at 22:37
  • can you explain the use case? what are you trying to do?
    – Bainternet
    May 26, 2011 at 5:41
  • Hi Bainternet, I've updated my question. Please take a look. Tq
    – faulty
    May 26, 2011 at 10:00

I've found a way to overcome what I needed by using wp_redirect(). I'm calling wp_redirect() after I've done processing. Also following advise from WordPress and wp_redirect() function problem, I added noheader=true to the form's action or link to prevent the error "header already sent" from php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.