populate_site_meta

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

WordPress Version: 5.2

/**
 * Creates WordPress site meta and sets the default values.
 *
 * @since 5.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $site_id Site ID to populate meta for.
 * @param array $meta    Optional. Custom meta $key => $value pairs to use. Default empty array.
 */
function populate_site_meta($site_id, array $meta = array())
{
    global $wpdb;
    $site_id = (int) $site_id;
    if (!is_site_meta_supported()) {
        return;
    }
    if (empty($meta)) {
        return;
    }
    /**
     * Filters meta for a site on creation.
     *
     * @since 5.2.0
     *
     * @param array $meta    Associative array of site meta keys and values to be inserted.
     * @param int   $site_id ID of site to populate.
     */
    $site_meta = apply_filters('populate_site_meta', $meta, $site_id);
    $insert = '';
    foreach ($site_meta as $meta_key => $meta_value) {
        if (is_array($meta_value)) {
            $meta_value = serialize($meta_value);
        }
        if (!empty($insert)) {
            $insert .= ', ';
        }
        $insert .= $wpdb->prepare('( %d, %s, %s)', $site_id, $meta_key, $meta_value);
    }
    $wpdb->query("INSERT INTO {$wpdb->blogmeta} ( blog_id, meta_key, meta_value ) VALUES " . $insert);
    // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    wp_cache_delete($site_id, 'blog_meta');
    wp_cache_set_sites_last_changed();
}

WordPress Version: 5.1

/**
 * Creates WordPress site meta and sets the default values.
 *
 * @since 5.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int   $site_id Site ID to populate meta for.
 * @param array $meta    Optional. Custom meta $key => $value pairs to use. Default empty array.
 */
function populate_site_meta($site_id, array $meta = array())
{
    global $wpdb;
    $site_id = (int) $site_id;
    if (!is_site_meta_supported()) {
        return;
    }
    if (empty($meta)) {
        return;
    }
    $insert = '';
    foreach ($meta as $meta_key => $meta_value) {
        if (is_array($meta_value)) {
            $meta_value = serialize($meta_value);
        }
        if (!empty($insert)) {
            $insert .= ', ';
        }
        $insert .= $wpdb->prepare('( %d, %s, %s)', $site_id, $meta_key, $meta_value);
    }
    $wpdb->query("INSERT INTO {$wpdb->blogmeta} ( blog_id, meta_key, meta_value ) VALUES " . $insert);
    // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
    wp_cache_delete($site_id, 'blog_meta');
    wp_cache_set_sites_last_changed();
}