WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

wp_insert_site() WP 5.1.0

Inserts a new site into the database.

Хуки из функции
Возвращает

Число/WP_Error. The new site's ID on success, or error object on failure.

Использование

wp_insert_site( $data );
$data(массив) (обязательный)

Data for the new site that should be inserted.

  • $domain (строка)
    Site domain.
    По умолчанию: empty string

  • $path (строка)
    Site path.
    По умолчанию: '/'

  • $network_id (число)
    The site's network ID.
    По умолчанию: current network ID

  • $registered (строка)
    When the site was registered, in SQL datetime format.
    По умолчанию: current time

  • $last_updated (строка)
    When the site was last updated, in SQL datetime format.
    По умолчанию: value of $registered

  • $public (число)
    Whether the site is public.
    По умолчанию: 1

  • $archived (число)
    Whether the site is archived.

  • $mature (число)
    Whether the site is mature.

  • $spam (число)
    Whether the site is spam.

  • $deleted (число)
    Whether the site is deleted.

  • $lang_id (число)
    The site's language ID. Currently unused.

  • $user_id (число)
    User ID for the site administrator. Passed to the wp_initialize_site hook.

  • $title (строка)
    Site title. where %d is the site ID. Passed to the wp_initialize_site hook.
    По умолчанию: 'Site %d'

  • $options (массив)
    Custom option $key => $value pairs to use. Passed to the wp_initialize_site hook.
    По умолчанию: empty array

  • $meta (массив)
    Custom site metadata $key => $value pairs to use. Passed to the wp_initialize_site hook.
    По умолчанию: empty array

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.

Список изменений

С версии 5.1.0 Введена.

Код wp insert site: wp-includes/ms-site.php WP 5.2.3

<?php
function wp_insert_site( array $data ) {
	global $wpdb;

	$now = current_time( 'mysql', true );

	$defaults = array(
		'domain'       => '',
		'path'         => '/',
		'network_id'   => get_current_network_id(),
		'registered'   => $now,
		'last_updated' => $now,
		'public'       => 1,
		'archived'     => 0,
		'mature'       => 0,
		'spam'         => 0,
		'deleted'      => 0,
		'lang_id'      => 0,
	);

	$prepared_data = wp_prepare_site_data( $data, $defaults );
	if ( is_wp_error( $prepared_data ) ) {
		return $prepared_data;
	}

	if ( false === $wpdb->insert( $wpdb->blogs, $prepared_data ) ) {
		return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error );
	}

	$new_site = get_site( $wpdb->insert_id );

	if ( ! $new_site ) {
		return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) );
	}

	clean_blog_cache( $new_site );

	/**
	 * Fires once a site has been inserted into the database.
	 *
	 * @since 5.1.0
	 *
	 * @param WP_Site $new_site New site object.
	 */
	do_action( 'wp_insert_site', $new_site );

	// Extract the passed arguments that may be relevant for site initialization.
	$args = array_diff_key( $data, $defaults );
	if ( isset( $args['site_id'] ) ) {
		unset( $args['site_id'] );
	}

	/**
	 * Fires when a site's initialization routine should be executed.
	 *
	 * @since 5.1.0
	 *
	 * @param WP_Site $new_site New site object.
	 * @param array   $args     Arguments for the initialization.
	 */
	do_action( 'wp_initialize_site', $new_site, $args );

	// Only compute extra hook parameters if the deprecated hook is actually in use.
	if ( has_action( 'wpmu_new_blog' ) ) {
		$user_id = ! empty( $args['user_id'] ) ? $args['user_id'] : 0;
		$meta    = ! empty( $args['options'] ) ? $args['options'] : array();

		// WPLANG was passed with `$meta` to the `wpmu_new_blog` hook prior to 5.1.0.
		if ( ! array_key_exists( 'WPLANG', $meta ) ) {
			$meta['WPLANG'] = get_network_option( $new_site->network_id, 'WPLANG' );
		}

		// Rebuild the data expected by the `wpmu_new_blog` hook prior to 5.1.0 using whitelisted keys.
		// The `$site_data_whitelist` matches the one used in `wpmu_create_blog()`.
		$site_data_whitelist = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' );
		$meta                = array_merge( array_intersect_key( $data, array_flip( $site_data_whitelist ) ), $meta );

		/**
		 * Fires immediately after a new site is created.
		 *
		 * @since MU (3.0.0)
		 * @deprecated 5.1.0 Use wp_insert_site
		 *
		 * @param int    $site_id    Site ID.
		 * @param int    $user_id    User ID.
		 * @param string $domain     Site domain.
		 * @param string $path       Site path.
		 * @param int    $network_id Network ID. Only relevant on multi-network installations.
		 * @param array  $meta       Meta data. Used to set initial site options.
		 */
		do_action_deprecated( 'wpmu_new_blog', array( $new_site->id, $user_id, $new_site->domain, $new_site->path, $new_site->network_id, $meta ), '5.1.0', 'wp_insert_site' );
	}

	return (int) $new_site->id;
}