Using WordPress ‘do_core_upgrade()’ PHP function

The do_core_upgrade() WordPress PHP function is used to upgrade the WordPress core display.


The function is quite simple to use. You just call it and pass a boolean value indicating whether or not to reinstall. For instance:


This line will upgrade the WordPress core without reinstalling it.


  • $reinstall (bool) – Optional. This parameter controls whether the WordPress core is reinstalled or not. The default value is false.

More information

See WordPress Developer Resources: do_core_upgrade()

This function has been a part of WordPress core since version 2.7. It is not deprecated and continues to be actively maintained. You can find its source code in the file wp-admin/includes/update-core.php.

Related functions include update_core(), which automatically updates WordPress to the latest version.


Basic Usage

In this example, we’re updating WordPress without reinstalling it.


Reinstalling WordPress

If you’d like to reinstall WordPress while updating, pass true.


Conditional Reinstallation

In some scenarios, you might want to conditionally decide whether to reinstall or not. In this case, we’re using a variable $shouldReinstall.

$shouldReinstall = get_option('should_reinstall'); // Assume this option returns true or false

Using within a function

You might want to use do_core_upgrade() inside a function to encapsulate the upgrade logic.

function upgrade_my_site($reinstall = false) {

Tied with a WordPress action

This is a more practical example where the upgrade process is tied to a WordPress action, such as ‘init’.

add_action('init', function() {
    if (current_user_can('update_core')) {

In this example, we’re hooking into WordPress’s initialization process and, if the current user has the capability to update the core, we proceed with the upgrade.