wp_update_site( int $site_id, array $data ): int|WP_Error

Updates a site in the database.


Parameters

$site_id int Required
ID of the site that should be updated.
$data array Required
Site data to update. See wp_insert_site() for the list of supported keys.
More Arguments from wp_insert_site( ... $data ) Data for the new site that should be inserted.
  • domain string
    Site domain. Default empty string.
  • path string
    Site path. Default '/'.
  • network_id int
    The site's network ID. Default is the current network ID.
  • registered string
    When the site was registered, in SQL datetime format. Default is the current time.
  • last_updated string
    When the site was last updated, in SQL datetime format. Default is the value of $registered.
  • public int
    Whether the site is public. Default 1.
  • archived int
    Whether the site is archived. Default 0.
  • mature int
    Whether the site is mature. Default 0.
  • spam int
    Whether the site is spam. Default 0.
  • deleted int
    Whether the site is deleted. Default 0.
  • lang_id int
    The site's language ID. Currently unused. Default 0.
  • user_id int
    User ID for the site administrator. Passed to the wp_initialize_site hook.
  • title string
    Site title. Default is 'Site %d' where %d is the site ID. Passed to the wp_initialize_site hook.
  • options array
    Custom option $key => $value pairs to use. Default empty array. Passed to the wp_initialize_site hook.
  • meta array
    Custom site metadata $key => $value pairs to use. Default empty array.
    Passed to the wp_initialize_site hook.

Top ↑

Return

int|WP_Error The updated site's ID on success, or error object on failure.


Top ↑

Source

File: wp-includes/ms-site.php. View all references

function wp_update_site( $site_id, array $data ) {
	global $wpdb;

	if ( empty( $site_id ) ) {
		return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) );
	}

	$old_site = get_site( $site_id );
	if ( ! $old_site ) {
		return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) );
	}

	$defaults                 = $old_site->to_array();
	$defaults['network_id']   = (int) $defaults['site_id'];
	$defaults['last_updated'] = current_time( 'mysql', true );
	unset( $defaults['blog_id'], $defaults['site_id'] );

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

	if ( false === $wpdb->update( $wpdb->blogs, $data, array( 'blog_id' => $old_site->id ) ) ) {
		return new WP_Error( 'db_update_error', __( 'Could not update site in the database.' ), $wpdb->last_error );
	}

	clean_blog_cache( $old_site );

	$new_site = get_site( $old_site->id );

	/**
	 * Fires once a site has been updated in the database.
	 *
	 * @since 5.1.0
	 *
	 * @param WP_Site $new_site New site object.
	 * @param WP_Site $old_site Old site object.
	 */
	do_action( 'wp_update_site', $new_site, $old_site );

	return (int) $new_site->id;
}

Top ↑

Hooks



Top ↑

Changelog

Changelog
Version Description
5.1.0 Introduced.

Top ↑

User Contributed Notes

You must log in before being able to contribute a note or feedback.