Using WordPress ‘admin_post_send_email_notifications’ PHP action

The admin_post WordPress PHP action fires on an authenticated admin post request where no action is supplied.

Usage

add_action('admin_post', 'your_function_name');
function your_function_name() {
// your custom code here
}

Parameters

  • None.

More information

See WordPress Developer Resources: admin_post

Examples

Redirect after form submission

Handles form submission and redirects back to the previous page.

add_action('admin_post_your_form_submission', 'handle_form_submission');
function handle_form_submission() {
// Process your form data// Redirect back to the previous page
wp_redirect(wp_get_referer());
exit;
}

Saving custom settings

Save custom settings from an options page.

add_action('admin_post_save_custom_settings', 'save_custom_settings');
function save_custom_settings() {
// Save your custom settings here// Redirect back to the options page
wp_redirect(admin_url('options-general.php?page=your_options_page'));
exit;
}

Exporting data

Export data as a CSV file when a button is clicked.

add_action('admin_post_export_csv', 'export_data_to_csv');
function export_data_to_csv() {
// Generate CSV file with your data// Output CSV file for download
}

Deleting custom post type entries

Delete custom post type entries based on specific conditions.

add_action('admin_post_delete_custom_post_entries', 'delete_custom_post_entries');
function delete_custom_post_entries() {
// Delete custom post type entries based on conditions// Redirect back to the custom post type page
wp_redirect(admin_url('edit.php?post_type=your_custom_post_type'));
exit;
}

Send email notifications

Send email notifications to users after an admin action.

add_action('admin_post_send_email_notifications', 'send_email_notifications');
function send_email_notifications() {
// Send email notifications to users// Redirect back to the notifications page
wp_redirect(admin_url('admin.php?page=your_notifications_page'));
exit;
}