do_core_upgrade( bool $reinstall = false )
- Since
- 2.7.0
- Source
wp-admin/update-core.php:845
Compatibility
- WordPress
- since 2.7.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
$reinstallbooloptional- Whether to reinstall WordPress. Default false.Default:
false
Performance profile
How much work a call to do_core_upgrade() 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
- Scales with input
- Instructions
- 27–138
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 184.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- transienttransient
get_site_transient()one call below do_core_upgrade() - hookthird-party callbacks
apply_filters()one call below do_core_upgrade() - optionoption read or write
get_option()one call below do_core_upgrade()
Further down the call graph this can also reach cache, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost do_core_upgrade() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 27–30 | wp_nonce_url(), find_core_update() |
$credentials === false | 48–55 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials() |
$credentials !== false && !WP_Filesystem() | 64–71 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), request_filesystem_credentials() |
$credentials !== false && WP_Filesystem() && ->has_errors() | 64–72 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), ->get_error_messages() |
$credentials !== false && WP_Filesystem() && !->has_errors() && is_wp_error() | 84–93 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), add_filter(), allow_relaxed_file_ownership(), is_wp_error(), show_message(), ->get_error_code() |
$credentials !== false && WP_Filesystem() && !->has_errors() && is_wp_error() | 88–97 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), add_filter(), allow_relaxed_file_ownership(), is_wp_error(), show_message(), ->get_error_code(), ->get_error_code() |
$credentials !== false && WP_Filesystem() && !->has_errors() && is_wp_error() | 94–103 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), add_filter(), allow_relaxed_file_ownership(), is_wp_error(), show_message(), ->get_error_code(), ->get_error_code(), __(), show_message() |
$credentials !== false && WP_Filesystem() && !->has_errors() && !is_wp_error() | 129–138 | wp_nonce_url(), find_core_update(), _e(), request_filesystem_credentials(), WP_Filesystem(), ->has_errors(), add_filter(), allow_relaxed_file_ownership(), is_wp_error(), __(), show_message(), __(), self_admin_url(), esc_url(), sprintf(), show_message(), __(), self_admin_url(), esc_url(), sprintf(), show_message(), self_admin_url(), esc_url() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 184 instructions, 27–138 executed per call, 15 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.
Uses · 12
- wp_nonce_url()Retrieves URL with nonce added to URL query.
- find_core_update()Finds the available update for WordPress core.
- _e()Displays translated text.
- request_filesystem_credentials()Displays a form to the user to request for their FTP/SSH details in order to connect to the filesystem.
- WP_Filesystem()Initializes and connects the WordPress Filesystem Abstraction classes.
- show_message()Displays the given administration message.
- add_filter()Adds a callback function to a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- self_admin_url()Retrieves the URL to the admin area for either the current site or the network depending on context.
- Core_Upgrader::__construct()
Source code
function do_core_upgrade( $reinstall = false ) { global $wp_filesystem; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; if ( $reinstall ) { $url = 'update-core.php?action=do-core-reinstall'; } else { $url = 'update-core.php?action=do-core-upgrade'; } $url = wp_nonce_url( $url, 'upgrade-core' ); $version = $_POST['version'] ?? false; $locale = $_POST['locale'] ?? 'en_US'; $update = find_core_update( $version, $locale ); if ( ! $update ) { return; } /* * Allow relaxed file ownership writes for User-initiated upgrades when the API specifies * that it's safe to do so. This only happens when there are no new files to create. */ $allow_relaxed_file_ownership = ! $reinstall && isset( $update->new_files ) && ! $update->new_files; ?> <div class="wrap"> <h1><?php _e( 'Update WordPress' ); ?></h1> <?php $credentials = request_filesystem_credentials( $url, '', false, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ); if ( false === $credentials ) { echo '</div>'; return; } if ( ! WP_Filesystem( $credentials, ABSPATH, $allow_relaxed_file_ownership ) ) { // Failed to connect. Error and request again. request_filesystem_credentials( $url, '', true, ABSPATH, array( 'version', 'locale' ), $allow_relaxed_file_ownership ); echo '</div>'; return; } if ( $wp_filesystem->errors->has_errors() ) { foreach ( $wp_filesystem->errors->get_error_messages() as $message ) { show_message( $message ); } echo '</div>'; return; } if ( $reinstall ) { $update->response = 'reinstall'; } add_filter( 'update_feedback', 'show_message' ); $upgrader = new Core_Upgrader(); $result = $upgrader->upgrade( $update, array( 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership, ) ); if ( is_wp_error( $result ) ) { show_message( $result ); if ( 'up_to_date' !== $result->get_error_code() && 'locked' !== $result->get_error_code() ) { show_message( __( 'Installation failed.' ) ); } echo '</div>'; return; } show_message( __( 'WordPress updated successfully.' ) ); show_message( '<span class="hide-if-no-js">' . sprintf( /* translators: 1: WordPress version, 2: URL to About screen. */ __( 'Welcome to WordPress %1$s. You will be redirected to the About WordPress screen. If not, click <a href="%2$s">here</a>.' ), $result,Changelog
Introduced in 2.7.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.1.0 tag, from
src/wp-admin/update-core.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.