network_admin_edit_(action) │ action-hook │ WP 3.1.0

Fires when a user action is handled through wp-admin/network/edit.php in the WordPress Multisite network admin.

Use it to save network plugin settings and perform other operations in the network admin.

The wpmuadminedit action fires before this one.

After the callback runs, WordPress redirects the user to the network admin dashboard. To return the user to another page, perform your own redirect and end the request with exit.

In the callback, check the capability for the operation with current_user_can(), the nonce with check_admin_referer(), and the input data yourself. The action does not perform these checks for your code.

Usage

add_action( 'network_admin_edit_(action)', 'wp_kama_network_admin_edit_action' );

/**
 * Function for `network_admin_edit_(action)` action-hook.
 * 
 * @return void
 */
function wp_kama_network_admin_edit_action(){
	// action...
}
$action(string)

Dynamic part of the hook name. It is taken from $_GET['action'] - the action parameter in the URL.

For example, network_admin_edit_my_action fires for edit.php?action=my_action.

This parameter is not passed to the callback. The action has no arguments.

Examples

#1 Save a network plugin setting

Add a "Plugin Settings" page to the "Settings" section of the network admin. The form sends a request to network/edit.php, and the callback saves the current network's option with update_site_option().

The code can be placed in a network-activated plugin or an MU plugin.

add_action( 'network_admin_menu', 'kama_add_network_settings_page' );
add_action( 'network_admin_edit_my_action', 'kama_save_network_settings' );

function kama_add_network_settings_page() {
	add_submenu_page(
		'settings.php',
		'Plugin Settings',
		'Plugin Settings',
		'manage_network_options',
		'kama-network-settings',
		'kama_render_network_settings_page'
	);
}

function kama_render_network_settings_page() {
	if ( ! current_user_can( 'manage_network_options' ) ) {
		wp_die( 'Insufficient permissions.' );
	}

	$enabled  = get_site_option( 'kama_feature_enabled', false );
	$form_url = network_admin_url( 'edit.php?action=my_action' );
	?>
	<div class="wrap">
		<h1>Plugin Settings</h1>

		<form method="post" action="<?php echo esc_url( $form_url ); ?>">
			<?php wp_nonce_field( 'kama_save_network_settings' ); ?>

			<label>
				<input type="checkbox" name="kama_feature_enabled" value="1"
					<?php checked( $enabled ); ?>>
				Enable feature for the network
			</label>

			<?php submit_button(); ?>
		</form>
	</div>
	<?php
}

function kama_save_network_settings() {
	if ( ! current_user_can( 'manage_network_options' ) ) {
		wp_die( 'Insufficient permissions.' );
	}

	if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
		wp_die( 'Only POST requests are allowed.', '', [ 'response' => 405 ] );
	}

	check_admin_referer( 'kama_save_network_settings' );

	$enabled = isset( $_POST['kama_feature_enabled'] )
		&& '1' === $_POST['kama_feature_enabled'];

	update_site_option( 'kama_feature_enabled', $enabled );

	wp_safe_redirect(
		network_admin_url( 'settings.php?page=kama-network-settings' )
	);
	exit;
}

The action must also be registered for requests to network/edit.php. Therefore, do not put add_action() inside a callback that only renders the settings page.

Changelog

Since 3.1.0 Introduced.

Where the hook is called

In file: /wp-admin/network/edit.php
network_admin_edit_(action)
wp-admin/network/edit.php 38
do_action( "network_admin_edit_{$action}" );

Where the hook is used in WordPress

Usage not found.