wp_update_site( int $site_id, array $data ): int|WP_Error
- Since
- 5.1.0
- Source
wp-includes/ms-site.php:159
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
- Scaling
- Constant
- Instructions
- 13–63
- Plugin surface
- 1 hook
- Called by
- 2
Reaches the database via ->update().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 91.
Third-party callbacks on 'wp_update_site' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly - sqldatabase query
->update()called directly - optionoption read or write
get_option()one call below wp_update_site() - cacheobject cache
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
empty($site_id) | 13 | __() |
!empty($site_id) | 18 | get_site(), __() |
!empty($site_id) && is_wp_error() | 36 | get_site(), ->to_array(), current_time(), wp_prepare_site_data(), is_wp_error() |
!empty($site_id) && !is_wp_error() | 57 | get_site(), ->to_array(), current_time(), wp_prepare_site_data(), is_wp_error(), blog_id(), __(), ->update() |
!empty($site_id) && !is_wp_error() | 63 | get_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:
- do_action( wp_update_site )actionline 197 (+38 into the body)
Fires once a site has been updated in the database.
Uses · 8
- __()Retrieves the translation of $text.
- get_site()Retrieves site data given a site ID or site object.
- current_time()Retrieves the current time based on specified type.
- wp_prepare_site_data()Prepares site data for insertion or update in the database.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- clean_blog_cache()Clean the blog cache
- do_action()Calls the callback functions that have been added to an action hook.
- WP_Error::__construct()Initializes the error.
Used by · 2
- update_blog_details()Updates the details for a blog and the blogs table for a given blog ID.
- update_blog_status()Updates a blog details field.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.