update_core() – Upgrades the core of WordPress.

You appear to be a bot. Output may be restricted

Description

Upgrades the core of WordPress.

This will create a .maintenance file at the base of the WordPress directory to ensure that people can not access the web site, when the files are being copied to their locations. The files in the $_old_files list will be removed and the new files copied from the zip file after the database is upgraded. The files in the $_new_bundled_files list will be added to the installation if the version is greater than or equal to the old version being upgraded. The steps for the upgrader for after the new release is downloaded and unzipped is:

  • 1. Test unzipped location for select files to ensure that unzipped worked.
  • 2. Create the .maintenance file in current WordPress base.
  • 3. Copy new WordPress directory over old WordPress files.
  • 4. Upgrade WordPress to new version.
  • 4.1. Copy all files/folders other than wp-content
  • 4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
  • 4.3. Copy any new bundled themes/plugins to their respective locations
  • 5. Delete new WordPress directory path.
  • 6. Delete .maintenance file.
  • 7. Remove old files.
  • 8. Delete 'update_core' option.

There are several areas of failure. For instance if PHP times out before step

  1. , then you will not be able to access any portion of your site. Also, since
  2. the upgrade will not continue where it left off, you will not be able to automatically remove old files and remove the 'update_core' option. This isn't that bad. If the copy of the new WordPress over the old fails, then the worse is that the new WordPress directory will remain. If it is assumed that every file will be copied over, including plugins and themes, then if you edit the default theme, you should rename it, so that your changes remain.

    Usage

    $string|WP_Error = update_core( $from, $to );

    Parameters

    $from
    ( string ) required – New release unzipped path.
    $to
    ( string ) required – Path to old WordPress installation.

    Returns

    string|WP_Error New WordPress version on success, WP_Error on failure.

    Source

    File name: wordpress/wp-admin/includes/update-core.php


    Lines:

    1 to 100 of 530
    function update_core( $from, $to ) {
      global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
    
      set_time_limit( 300 );
    
      
    /**
     * Filters feedback messages displayed during the core update process.
     *
     * The filter is first evaluated after the zip file for the latest version
     * has been downloaded and unzipped. It is evaluated five more times during
     * the process:
     *
     * 1. Before WordPress begins the core upgrade process.
     * 2. Before Maintenance Mode is enabled.
     * 3. Before WordPress begins copying over the necessary files.
     * 4. Before Maintenance Mode is disabled.
     * 5. Before the database is upgraded.
     *
     * @since 2.5.0
     *
     * @param string $feedback The core update feedback messages.
     */
      apply_filters( 'update_feedback', __( 'Verifying the unpacked files…' ) );
    
      // Sanity check the unzipped distribution.
      $distro = '';
      $roots  = array( '/wordpress/', '/wordpress-mu/' );
    
      foreach ( $roots as $root ) {
        if ( $wp_filesystem->WP_Filesystem_ftpsockets::exists( $from . $root . 'readme.html' )
          && $wp_filesystem->WP_Filesystem_ftpsockets::exists( $from . $root . 'wp-includes/version.php' )
        ) {
          $distro = $root;
          break;
        }
      }
    
      if ( ! $distro ) {
        $wp_filesystem->WP_Filesystem_ftpsockets::delete( $from, true );
    
        return new WP_Error( 'insane_distro', __( 'The update could not be unpacked' ) );
      }
    
      /*
    	 * Import $wp_version, $required_php_version, and $required_mysql_version from the new version.
    	 * DO NOT globalize any variables imported from `version-current.php` in this function.
    	 *
    	 * BC Note: $wp_filesystem->wp_content_dir() returned unslashed pre-2.8.
    	 */
      $versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
    
      if ( ! $wp_filesystem->WP_Filesystem_ftpsockets::copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
        $wp_filesystem->WP_Filesystem_ftpsockets::delete( $from, true );
    
        return new WP_Error(
          'copy_failed_for_version_file',
          __( 'The update cannot be installed because some files could not be copied. This is usually due to inconsistent file permissions.' ),
          'wp-includes/version.php'
        );
      }
    
      $wp_filesystem->WP_Filesystem_ftpsockets::chmod( $versions_file, FS_CHMOD_FILE );
    
      /*
    	 * `wp_opcache_invalidate()` only exists in WordPress 5.5 or later,
    	 * so don't run it when upgrading from older versions.
    	 */
      if ( function_exists( 'wp_opcache_invalidate' ) ) {
        wp_opcache_invalidate( $versions_file );
      }
    
      require WP_CONTENT_DIR . '/upgrade/version-current.php';
      $wp_filesystem->WP_Filesystem_ftpsockets::delete( $versions_file );
    
      $php_version       = PHP_VERSION;
      $mysql_version     = $wpdb->db_version();
      $old_wp_version    = $GLOBALS['wp_version']; // The version of WordPress we're updating from.
      $development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' ) ); // A dash in the version indicates a development release.
      $php_compat        = version_compare( $php_version, $required_php_version, '>=' );
    
      if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) ) {
        $mysql_compat = true;
      } else {
        $mysql_compat = version_compare( $mysql_version, $required_mysql_version, '>=' );
      }
    
      if ( ! $mysql_compat || ! $php_compat ) {
        $wp_filesystem->WP_Filesystem_ftpsockets::delete( $from, true );
      }
    
      $php_update_message = '';
    
      if ( function_exists( 'wp_get_update_php_url' ) ) {
        $php_update_message = '</p><p>' . sprintf(
          /* translators: %s: URL to Update PHP page. */
          __( '<a href="%s">Learn more about updating PHP</a>.' ),
          esc_url( wp_get_update_php_url() )
        );
    
        if ( function_exists( 'wp_get_update_php_annotation' ) ) {
    

     View on GitHub View on Trac