Using WordPress ‘admin_post_{$action}’ PHP action

The admin_post_{$action} WordPress PHP action fires on an authenticated admin post request for the given action.

Usage

add_action('admin_post_your_action', 'your_custom_function');

function your_custom_function() {
    // your custom code here
}

Parameters

  • $action (string): The dynamic portion of the hook name that refers to the given request action.

More information

See WordPress Developer Resources: admin_post_{$action}

Examples

Creating a custom admin form handler

To handle a form submission from the admin area, create a custom function and hook it to the admin_post_{$action} action.

add_action('admin_post_handle_form', 'your_custom_form_handler');

function your_custom_form_handler() {
    // your custom code here to handle the form submission
}

Exporting data as a CSV file

Create a custom function to export data as a CSV file when the export action is called.

add_action('admin_post_export_csv', 'your_custom_export_csv_function');

function your_custom_export_csv_function() {
    // your custom code here to export data as a CSV file
}

Sending a newsletter

To send a newsletter to subscribers, create a custom function and hook it to the admin_post_{$action} action.

add_action('admin_post_send_newsletter', 'your_custom_send_newsletter_function');

function your_custom_send_newsletter_function() {
    // your custom code here to send the newsletter to subscribers
}

Updating plugin settings

To update plugin settings, create a custom function and hook it to the admin_post_{$action} action.

add_action('admin_post_update_plugin_settings', 'your_custom_update_plugin_settings_function');

function your_custom_update_plugin_settings_function() {
    // your custom code here to update plugin settings
}

Bulk deleting posts

To bulk delete posts, create a custom function and hook it to the admin_post_{$action} action.

add_action('admin_post_bulk_delete_posts', 'your_custom_bulk_delete_posts_function');

function your_custom_bulk_delete_posts_function() {
    // your custom code here to bulk delete posts
}