I wanted to share this quick WordPress tip that you can use when you need some custom processing or catching callbacks in admin.
There is a wonderful WordPress hook (that I only found recently) that enables user to do some custom action very easily – admin_action_YOUR_ACTION_NAME.
It is setup in three quick and easy steps:
First you need to initialize the action:
Then in your function (YOUR_FUNCTION_NAME), after you do all the processing, you need to redirect the user somewhere:
// For example we’ll redirect him to dashboard here wp_redirect(admin_url()); // good to exit after redirect exit;
And the last thing you need to do is call your function when you go to URL looking like this:
For multi-site installation, the hook is network_admin_YOUR_ACTION_NAME
This is very useful when you need a callback after oAuth action to return to your WordPress admin for example.
Do you know some useful usage of this wonderful hook? Share it in comments below…