wp_maybe_update_network_site_counts()WP 3.7.0

Updates the count of sites for the current network.

If enabled through the enable_live_network_counts filter, update the sites count on a network when a site is created or its status is updated.

Hooks from the function

Return

null. Nothing (null).

Usage

wp_maybe_update_network_site_counts( $network_id );
$network_id(int|null)
ID of the network.
Default: current network

Changelog

Since 3.7.0 Introduced.
Since 4.8.0 The $network_id parameter has been added.

wp_maybe_update_network_site_counts() code WP 6.5.2

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 );
}