Finding a Lost Site in a Massive Multisite

In WordPress Multisite there are some scenarios where a site with a custom domain can get lost. There is the central place in network admin where you can assign custom domains but you can also do it at the site level. If it’s done at the site level, it’s possible for that site to become lost. You just can’t find it in the network admin for some reason. Maybe the search just sucks. Maybe something else weird happened but the site just wasn’t coming up.

The easiest way I had to deal with this was to add the site ID to our custom JSON endpoint data. This technique is a really handy way to add the information you need to the endpoint. Some day, I’ll build a nice dashboard based on this for multisite.

Now I can always easily find the ID of the site (and the other useful information) on any site. With the site ID, I can just go there directly through a URL like https://mainsiteurl.com/wp-admin/network/site-info.php?id=11803

/*---------------------------------JSON MOD FOR ADDITIONAL SITE INFO----------------------------------*/

function extraJsonData($response){
    $blog_id = get_current_blog_id();
    $blog_details = get_blog_details($blog_id);
    $data = $response->data;
    $data['blogid'] = $blog_id;//add the blog ID in case it gets lost
    $data['created'] =$blog_details->registered;
    $data['last_updated'] =$blog_details->last_updated;
    $data['post_count'] =$blog_details->post_count;
    $data['page_count'] = wp_count_posts('page','publish');
    $response->set_data($data);
    return $response;
}

add_filter('rest_index', 'extraJsonData');