The network_admin_edit_{$_GET[‘action’]} WordPress PHP action fires the requested handler action. The dynamic portion of the hook name, $_GET['action']
, refers to the name of the requested action.
Usage
add_action('network_admin_edit_my_custom_action', 'my_custom_function'); function my_custom_function() { // Your custom code here }
Parameters
- None
More information
See WordPress Developer Resources: network_admin_edit_{$_GET[‘action’]}
Examples
Delete a custom table
Delete a custom table when the action is triggered.
add_action('network_admin_edit_delete_custom_table', 'delete_custom_table_function'); function delete_custom_table_function() { global $wpdb; $table_name = $wpdb->prefix . 'my_custom_table'; $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); }
Update a custom option
Update a custom option value when the action is triggered.
add_action('network_admin_edit_update_custom_option', 'update_custom_option_function'); function update_custom_option_function() { update_option('my_custom_option', 'new_value'); }
Add a new user
Add a new user with a specific role when the action is triggered.
add_action('network_admin_edit_add_new_user', 'add_new_user_function'); function add_new_user_function() { $user_id = wp_create_user('new_user', 'password', '[email protected]'); wp_update_user(array('ID' => $user_id, 'role' => 'editor')); }
Send an email notification
Send an email notification to the site administrator when the action is triggered.
add_action('network_admin_edit_send_email_notification', 'send_email_notification_function'); function send_email_notification_function() { $to = get_option('admin_email'); $subject = 'Action Triggered'; $message = 'The custom action has been triggered.'; wp_mail($to, $subject, $message); }
Create a custom post
Create a custom post with specific details when the action is triggered.
add_action('network_admin_edit_create_custom_post', 'create_custom_post_function'); function create_custom_post_function() { $post_data = array( 'post_title' => 'My Custom Post', 'post_content' => 'This is a custom post created by the action.', 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'post', ); wp_insert_post($post_data); }