update_site_cache

The timeline below displays how wordpress function update_site_cache has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Updates sites in cache.
 *
 * @since 4.6.0
 * @since 5.1.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param array $sites             Array of site objects.
 * @param bool  $update_meta_cache Whether to update site meta cache. Default true.
 */
function update_site_cache($sites, $update_meta_cache = true)
{
    if (!$sites) {
        return;
    }
    $site_ids = array();
    $site_data = array();
    $blog_details_data = array();
    foreach ($sites as $site) {
        $site_ids[] = $site->blog_id;
        $site_data[$site->blog_id] = $site;
        $blog_details_data[$site->blog_id . 'short'] = $site;
    }
    wp_cache_add_multiple($site_data, 'sites');
    wp_cache_add_multiple($blog_details_data, 'blog-details');
    if ($update_meta_cache) {
        update_sitemeta_cache($site_ids);
    }
}

WordPress Version: 5.1

/**
 * Updates sites in cache.
 *
 * @since 4.6.0
 * @since 5.1.0 Introduced the `$update_meta_cache` parameter.
 *
 * @param array $sites             Array of site objects.
 * @param bool  $update_meta_cache Whether to update site meta cache. Default true.
 */
function update_site_cache($sites, $update_meta_cache = true)
{
    if (!$sites) {
        return;
    }
    $site_ids = array();
    foreach ($sites as $site) {
        $site_ids[] = $site->blog_id;
        wp_cache_add($site->blog_id, $site, 'sites');
        wp_cache_add($site->blog_id . 'short', $site, 'blog-details');
    }
    if ($update_meta_cache) {
        update_sitemeta_cache($site_ids);
    }
}

WordPress Version: 4.6

/**
 * Updates sites in cache.
 *
 * @since 4.6.0
 *
 * @param array $sites Array of site objects.
 */
function update_site_cache($sites)
{
    if (!$sites) {
        return;
    }
    foreach ($sites as $site) {
        wp_cache_add($site->blog_id, $site, 'sites');
        wp_cache_add($site->blog_id . 'short', $site, 'blog-details');
    }
}