Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_insert_site ›

Seit5.0.0
Veraltetn/v
wp_insert_site ( $data )
Parameter:
  • (array) $data { Data for the new site that should be inserted.
    Erforderlich: Ja
Gibt zurück:
  • (int|WP_Error) The new site's ID on success, or error object on failure.
Definiert in:
Codex:

Inserts a new site into the database.



Quellcode

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

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

	if ( false === $wpdb->insert( $wpdb->blogs, $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 );

	clean_blog_cache( $new_site );

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

	return (int) $new_site->id;
}