Using WordPress ‘can_edit_network’ PHP filter

The can_edit_network WordPress PHP filter allows you to modify whether a network can be edited from the current page.

Usage

add_filter('can_edit_network', 'my_custom_edit_network', 10, 2);

function my_custom_edit_network($result, $network_id) {
    // Your custom code here

    return $result;
}

Parameters

  • $result (bool) – Whether the network can be edited from this page.
  • $network_id (int) – The network ID to check.

More information

See WordPress Developer Resources: can_edit_network

Examples

Restrict network editing to a specific network ID

Prevent network editing except for a specific network ID (e.g., 3).

add_filter('can_edit_network', 'restrict_network_editing', 10, 2);

function restrict_network_editing($result, $network_id) {
    if ($network_id == 3) {
        return true;
    }
    return false;
}

Allow network editing only for a specific user role

Allow network editing only for users with the ‘administrator’ role.

add_filter('can_edit_network', 'allow_network_editing_for_admins', 10, 2);

function allow_network_editing_for_admins($result, $network_id) {
    if (current_user_can('administrator')) {
        return true;
    }
    return false;
}

Disable network editing for all users

Disable network editing for all users regardless of their roles.

add_filter('can_edit_network', 'disable_network_editing', 10, 2);

function disable_network_editing($result, $network_id) {
    return false;
}

Enable network editing based on custom user meta

Enable network editing for users who have a specific custom user meta value (e.g., ‘can_edit_networks’ set to ‘yes’).

add_filter('can_edit_network', 'enable_network_editing_based_on_meta', 10, 2);

function enable_network_editing_based_on_meta($result, $network_id) {
    $user_id = get_current_user_id();
    $can_edit = get_user_meta($user_id, 'can_edit_networks', true);

    if ($can_edit === 'yes') {
        return true;
    }
    return false;
}

Enable network editing only on a specific page

Enable network editing only when users are on a specific page (e.g., a page with ID 42).

add_filter('can_edit_network', 'enable_network_editing_on_specific_page', 10, 2);

function enable_network_editing_on_specific_page($result, $network_id) {
    if (is_page(42)) {
        return true;
    }
    return false;
}