The display_site_states WordPress PHP filter allows you to modify the default site display states for items in the Sites list table.
Usage
add_filter('display_site_states', 'custom_site_states', 10, 2); function custom_site_states($site_states, $site) { // your custom code here return $site_states; }
Parameters
$site_states
(string[]): An array of site states. Default values are ‘Main’, ‘Archived’, ‘Mature’, ‘Spam’, and ‘Deleted’.$site
(WP_Site): The current site object.
More information
See WordPress Developer Resources: display_site_states
Examples
Add a custom site state
Add a new custom site state called ‘Under Construction’:
add_filter('display_site_states', 'add_under_construction_state', 10, 2); function add_under_construction_state($site_states, $site) { if (get_blog_option($site->blog_id, 'under_construction') == '1') { $site_states[] = 'Under Construction'; } return $site_states; }
Remove the ‘Mature’ site state
Remove the ‘Mature’ site state from the list of site states:
add_filter('display_site_states', 'remove_mature_site_state', 10, 2); function remove_mature_site_state($site_states, $site) { $key = array_search('Mature', $site_states); if ($key !== false) { unset($site_states[$key]); } return $site_states; }
Rename the ‘Main’ site state
Change the name of the ‘Main’ site state to ‘Primary’:
add_filter('display_site_states', 'rename_main_site_state', 10, 2); function rename_main_site_state($site_states, $site) { $key = array_search('Main', $site_states); if ($key !== false) { $site_states[$key] = 'Primary'; } return $site_states; }
Add a custom site state based on a post count
Add a custom site state called ‘Low Content’ for sites with less than 10 published posts:
add_filter('display_site_states', 'add_low_content_state', 10, 2); function add_low_content_state($site_states, $site) { switch_to_blog($site->blog_id); $post_count = wp_count_posts()->publish; restore_current_blog(); if ($post_count < 10) { $site_states[] = 'Low Content'; } return $site_states; }
Modify site states based on custom conditions
Change the ‘Archived’ state to ‘On Hold’ if the site is less than 30 days old:
add_filter('display_site_states', 'modify_site_states_based_on_age', 10, 2); function modify_site_states_based_on_age($site_states, $site) { $site_age = (time() - strtotime($site->registered)) / DAY_IN_SECONDS; if ($site_age < 30 && in_array('Archived', $site_states)) { $key = array_search('Archived', $site_states); $site_states[$key] = 'On Hold'; } return $site_states; }