There’s an action hook triggered in admin.php
called 'admin_action_'.$_REQUEST['action']
. Unfortunately, it’s a bit useless for plugins as it’s triggered at the very end of admin.php, after everything’s loaded on the page (even the footer).
Does anyone know why it’s there, why in that silly position and if anything is using it internally?
Via the “Annotate” function the the Trac, you can see that this was added three years ago, after the request for a generic POST handler that plugins can use.
Google code search tells me that at least Akismet uses this hook, and it appeared there at the time it was introduced in core. It works by calling
admin.php
directly (and not the plugin page). From there it can just do a redirect at the end. The trick is thus to calladmin.php?action=your_action
, other URLs are not guaranteed to work.Many (but not all) admin pages include
admin.php
, as a sort of initialization. In this case your action would be fired before any output is sent, because the admin page includesadmin-header.php
afteradmin.php
. This won’t work on every admin page: not all of them includeadmin.php
, and others have checks for “rogue”action
query variables, and give you a “Are you sure you want to do that?” warning (due to missing nonces?). For a plugin pageadmin.php
does everything: it displays the header (unless thenoheader
query variable is in the URL), calls your page, and displays the footer (unless you calledexit()
in your code!).admin.php
then callsexit()
itself, so theadmin_action_
hook is not even called there.