wp/wp-admin/includes/class-core-upgrader.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    46 	 * @global WP_Filesystem_Base $wp_filesystem                WordPress filesystem subclass.
    46 	 * @global WP_Filesystem_Base $wp_filesystem                WordPress filesystem subclass.
    47 	 * @global callable           $_wp_filesystem_direct_method
    47 	 * @global callable           $_wp_filesystem_direct_method
    48 	 *
    48 	 *
    49 	 * @param object $current Response object for whether WordPress is current.
    49 	 * @param object $current Response object for whether WordPress is current.
    50 	 * @param array  $args {
    50 	 * @param array  $args {
    51 	 *        Optional. Arguments for upgrading WordPress core. Default empty array.
    51 	 *     Optional. Arguments for upgrading WordPress core. Default empty array.
    52 	 *
    52 	 *
    53 	 *        @type bool $pre_check_md5    Whether to check the file checksums before
    53 	 *     @type bool $pre_check_md5    Whether to check the file checksums before
    54 	 *                                     attempting the upgrade. Default true.
    54 	 *                                  attempting the upgrade. Default true.
    55 	 *        @type bool $attempt_rollback Whether to attempt to rollback the chances if
    55 	 *     @type bool $attempt_rollback Whether to attempt to rollback the chances if
    56 	 *                                     there is a problem. Default false.
    56 	 *                                  there is a problem. Default false.
    57 	 *        @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
    57 	 *     @type bool $do_rollback      Whether to perform this "upgrade" as a rollback.
    58 	 *                                     Default false.
    58 	 *                                  Default false.
    59 	 * }
    59 	 * }
    60 	 * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
    60 	 * @return string|false|WP_Error New WordPress version on success, false or WP_Error on failure.
    61 	 */
    61 	 */
    62 	public function upgrade( $current, $args = array() ) {
    62 	public function upgrade( $current, $args = array() ) {
    63 		global $wp_filesystem;
    63 		global $wp_filesystem;
   102 		 * the new_bundled zip. Don't though if the constant is set to skip bundled items.
   102 		 * the new_bundled zip. Don't though if the constant is set to skip bundled items.
   103 		 * If the API returns a no_content zip, go with it. Finally, default to the full zip.
   103 		 * If the API returns a no_content zip, go with it. Finally, default to the full zip.
   104 		 */
   104 		 */
   105 		if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
   105 		if ( $parsed_args['do_rollback'] && $current->packages->rollback ) {
   106 			$to_download = 'rollback';
   106 			$to_download = 'rollback';
   107 		} elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version == $current->partial_version && $partial ) {
   107 		} elseif ( $current->packages->partial && 'reinstall' !== $current->response && $wp_version === $current->partial_version && $partial ) {
   108 			$to_download = 'partial';
   108 			$to_download = 'partial';
   109 		} elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
   109 		} elseif ( $current->packages->new_bundled && version_compare( $wp_version, $current->new_bundled, '<' )
   110 			&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
   110 			&& ( ! defined( 'CORE_UPGRADE_SKIP_NEW_BUNDLED' ) || ! CORE_UPGRADE_SKIP_NEW_BUNDLED ) ) {
   111 			$to_download = 'new_bundled';
   111 			$to_download = 'new_bundled';
   112 		} elseif ( $current->packages->no_content ) {
   112 		} elseif ( $current->packages->no_content ) {
   277 		$new_branch     = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
   277 		$new_branch     = implode( '.', array_slice( preg_split( '/[.-]/', $offered_ver ), 0, 2 ) ); // x.y
   278 
   278 
   279 		$current_is_development_version = (bool) strpos( $wp_version, '-' );
   279 		$current_is_development_version = (bool) strpos( $wp_version, '-' );
   280 
   280 
   281 		// Defaults:
   281 		// Defaults:
   282 		$upgrade_dev   = true;
   282 		$upgrade_dev   = get_site_option( 'auto_update_core_dev', 'enabled' ) === 'enabled';
   283 		$upgrade_minor = true;
   283 		$upgrade_minor = get_site_option( 'auto_update_core_minor', 'enabled' ) === 'enabled';
   284 		$upgrade_major = false;
   284 		$upgrade_major = get_site_option( 'auto_update_core_major', 'unset' ) === 'enabled';
   285 
   285 
   286 		// WP_AUTO_UPDATE_CORE = true (all), 'minor', false.
   286 		// WP_AUTO_UPDATE_CORE = true (all), 'beta', 'rc', 'development', 'branch-development', 'minor', false.
   287 		if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
   287 		if ( defined( 'WP_AUTO_UPDATE_CORE' ) ) {
   288 			if ( false === WP_AUTO_UPDATE_CORE ) {
   288 			if ( false === WP_AUTO_UPDATE_CORE ) {
   289 				// Defaults to turned off, unless a filter allows it.
   289 				// Defaults to turned off, unless a filter allows it.
   290 				$upgrade_dev   = false;
   290 				$upgrade_dev   = false;
   291 				$upgrade_minor = false;
   291 				$upgrade_minor = false;
   292 				$upgrade_major = false;
   292 				$upgrade_major = false;
   293 			} elseif ( true === WP_AUTO_UPDATE_CORE ) {
   293 			} elseif ( true === WP_AUTO_UPDATE_CORE
       
   294 				|| in_array( WP_AUTO_UPDATE_CORE, array( 'beta', 'rc', 'development', 'branch-development' ), true )
       
   295 			) {
   294 				// ALL updates for core.
   296 				// ALL updates for core.
   295 				$upgrade_dev   = true;
   297 				$upgrade_dev   = true;
   296 				$upgrade_minor = true;
   298 				$upgrade_minor = true;
   297 				$upgrade_major = true;
   299 				$upgrade_major = true;
   298 			} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
   300 			} elseif ( 'minor' === WP_AUTO_UPDATE_CORE ) {
   302 				$upgrade_major = false;
   304 				$upgrade_major = false;
   303 			}
   305 			}
   304 		}
   306 		}
   305 
   307 
   306 		// 1: If we're already on that version, not much point in updating?
   308 		// 1: If we're already on that version, not much point in updating?
   307 		if ( $offered_ver == $wp_version ) {
   309 		if ( $offered_ver === $wp_version ) {
   308 			return false;
   310 			return false;
   309 		}
   311 		}
   310 
   312 
   311 		// 2: If we're running a newer version, that's a nope.
   313 		// 2: If we're running a newer version, that's a nope.
   312 		if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
   314 		if ( version_compare( $wp_version, $offered_ver, '>' ) ) {
   319 			if ( ! empty( $failure_data['critical'] ) ) {
   321 			if ( ! empty( $failure_data['critical'] ) ) {
   320 				return false;
   322 				return false;
   321 			}
   323 			}
   322 
   324 
   323 			// Don't claim we can update on update-core.php if we have a non-critical failure logged.
   325 			// Don't claim we can update on update-core.php if we have a non-critical failure logged.
   324 			if ( $wp_version == $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
   326 			if ( $wp_version === $failure_data['current'] && false !== strpos( $offered_ver, '.1.next.minor' ) ) {
   325 				return false;
   327 				return false;
   326 			}
   328 			}
   327 
   329 
   328 			/*
   330 			/*
   329 			 * Cannot update if we're retrying the same A to B update that caused a non-critical failure.
   331 			 * Cannot update if we're retrying the same A to B update that caused a non-critical failure.
   330 			 * Some non-critical failures do allow retries, like download_failed.
   332 			 * Some non-critical failures do allow retries, like download_failed.
   331 			 * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2.
   333 			 * 3.7.1 => 3.7.2 resulted in files_not_writable, if we are still on 3.7.1 and still trying to update to 3.7.2.
   332 			 */
   334 			 */
   333 			if ( empty( $failure_data['retry'] ) && $wp_version == $failure_data['current'] && $offered_ver == $failure_data['attempted'] ) {
   335 			if ( empty( $failure_data['retry'] ) && $wp_version === $failure_data['current'] && $offered_ver === $failure_data['attempted'] ) {
   334 				return false;
   336 				return false;
   335 			}
   337 			}
   336 		}
   338 		}
   337 
   339 
   338 		// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2.
   340 		// 3: 3.7-alpha-25000 -> 3.7-alpha-25678 -> 3.7-beta1 -> 3.7-beta2.
   351 			}
   353 			}
   352 			// Else fall through to minor + major branches below.
   354 			// Else fall through to minor + major branches below.
   353 		}
   355 		}
   354 
   356 
   355 		// 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4).
   357 		// 4: Minor in-branch updates (3.7.0 -> 3.7.1 -> 3.7.2 -> 3.7.4).
   356 		if ( $current_branch == $new_branch ) {
   358 		if ( $current_branch === $new_branch ) {
   357 
   359 
   358 			/**
   360 			/**
   359 			 * Filters whether to enable minor automatic core updates.
   361 			 * Filters whether to enable minor automatic core updates.
   360 			 *
   362 			 *
   361 			 * @since 3.7.0
   363 			 * @since 3.7.0