wppaste
WordPress

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

Since
5.1.0
Source
wp-includes/ms-site.php:159
Updates a site in the database.

Compatibility

WordPress
since 5.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$site_idint
ID of the site that should be updated.
$dataarray
Site data to update. See wp_insert_site() for the list of supported keys.

Return value

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

Performance profile

How much work a call to wp_update_site() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via ->update().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
13–63

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 91.

Plugin surface
1 hook

Third-party callbacks on 'wp_update_site' run inside this call, and their cost is not bounded by anything here.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • sqldatabase query->update()called directly
  • optionoption read or writeget_option()one call below wp_update_site()
  • cacheobject cachewp_cache_delete()one call below wp_update_site()

Further down the call graph this can also reach serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_update_site() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($site_id)13__()
!empty($site_id)18get_site(), __()
!empty($site_id) && is_wp_error()36get_site(), ->to_array(), current_time(), wp_prepare_site_data(), is_wp_error()
!empty($site_id) && !is_wp_error()57get_site(), ->to_array(), current_time(), wp_prepare_site_data(), is_wp_error(), blog_id(), __(), ->update()
!empty($site_id) && !is_wp_error()63get_site(), ->to_array(), current_time(), wp_prepare_site_data(), is_wp_error(), blog_id(), clean_blog_cache(), get_site(), do_action()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 91 instructions, 13–63 executed per call, 4 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while wp_update_site() runs, in this order:

  1. do_action( wp_update_site )actionline 197 (+38 into the body)

    Fires once a site has been updated in the database.

Uses · 8

Used by · 2

Source code

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;}

Changelog

Introduced in 5.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/ms-site.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.