Using WordPress ‘ms_network_not_found’ PHP action

The ms_network_not_found WordPress action fires when a network cannot be found based on the requested domain and path.

Usage

add_action('ms_network_not_found', 'your_custom_function', 10, 2);

function your_custom_function($domain, $path) {
    // your custom code here
}

Parameters

  • $domain (string) – The domain used to search for a network.
  • $path (string) – The path used to search for a network.

More information

See WordPress Developer Resources: ms_network_not_found

Examples

Redirect to the main site

Redirect the user to the main site when the network is not found.

add_action('ms_network_not_found', 'redirect_to_main_site', 10, 2);

function redirect_to_main_site($domain, $path) {
    wp_redirect('https://www.example.com/');
    exit;
}

Log network not found errors

Log the domain and path when a network is not found.

add_action('ms_network_not_found', 'log_network_not_found', 10, 2);

function log_network_not_found($domain, $path) {
    error_log("Network not found for domain: $domain and path: $path");
}

Redirect to a custom error page

Redirect the user to a custom error page when a network is not found.

add_action('ms_network_not_found', 'redirect_to_custom_error_page', 10, 2);

function redirect_to_custom_error_page($domain, $path) {
    wp_redirect('https://www.example.com/network-error/');
    exit;
}

Send an email notification

Send an email notification to the site admin when a network is not found.

add_action('ms_network_not_found', 'email_network_not_found', 10, 2);

function email_network_not_found($domain, $path) {
    $to = '[email protected]';
    $subject = 'Network Not Found';
    $message = "Network not found for domain: $domain and path: $path";
    wp_mail($to, $subject, $message);
}

Display a custom message

Display a custom message to the user when a network is not found.

add_action('ms_network_not_found', 'display_custom_message', 10, 2);

function display_custom_message($domain, $path) {
    echo "We're sorry, but the network you're looking for cannot be found.";
    exit;
}