Title: wp_maybe_update_network_site_counts
Published: April 25, 2014
Last modified: April 28, 2025

---

# wp_maybe_update_network_site_counts( int|null $network_id = null )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#wp--skip-link--target)

Updates the count of sites for the current network.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#description)󠁿

If enabled through the [‘enable_live_network_counts’](https://developer.wordpress.org/reference/hooks/enable_live_network_counts/)
filter, update the sites count on a network when a site is created or its status
is updated.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#parameters)󠁿

 `$network_id`int|nulloptional

ID of the network. Default is the current network.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#source)󠁿

    ```php
    function wp_maybe_update_network_site_counts( $network_id = null ) {
    	$is_small_network = ! wp_is_large_network( 'sites', $network_id );

    	/**
    	 * Filters whether to update network site or user counts when a new site is created.
    	 *
    	 * @since 3.7.0
    	 *
    	 * @see wp_is_large_network()
    	 *
    	 * @param bool   $small_network Whether the network is considered small.
    	 * @param string $context       Context. Either 'users' or 'sites'.
    	 */
    	if ( ! apply_filters( 'enable_live_network_counts', $is_small_network, 'sites' ) ) {
    		return;
    	}

    	wp_update_network_site_counts( $network_id );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/ms-functions.php#L2499)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-functions.php#L2499-L2517)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#hooks)󠁿

 [apply_filters( ‘enable_live_network_counts’, bool $small_network, string $context )](https://developer.wordpress.org/reference/hooks/enable_live_network_counts/)

Filters whether to update network site or user counts when a new site is created.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_is_large_network()](https://developer.wordpress.org/reference/functions/wp_is_large_network/)`wp-includes/ms-functions.php` |

Determines whether or not we have a large network.

  | 
| [wp_update_network_site_counts()](https://developer.wordpress.org/reference/functions/wp_update_network_site_counts/)`wp-includes/ms-functions.php` |

Updates the network-wide site count.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#)

| Used by | Description | 
| [wp_maybe_update_network_site_counts_on_update()](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts_on_update/)`wp-includes/ms-site.php` |

Updates the count of sites for a network based on a changed site.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_maybe_update_network_site_counts/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | The `$network_id` parameter has been added. | 
| [3.7.0](https://developer.wordpress.org/reference/since/3.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_maybe_update_network_site_counts%2F)
before being able to contribute a note or feedback.