wp/wp-admin/includes/update-core.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * WordPress core upgrade functionality.
     3  * WordPress core upgrade functionality.
       
     4  *
       
     5  * Note: Newly introduced functions and methods cannot be used here.
       
     6  * All functions must be present in the previous version being upgraded from
       
     7  * as this file is used there too.
     4  *
     8  *
     5  * @package WordPress
     9  * @package WordPress
     6  * @subpackage Administration
    10  * @subpackage Administration
     7  * @since 2.7.0
    11  * @since 2.7.0
     8  */
    12  */
    12  *
    16  *
    13  * Bundled theme files should not be included in this list.
    17  * Bundled theme files should not be included in this list.
    14  *
    18  *
    15  * @since 2.7.0
    19  * @since 2.7.0
    16  *
    20  *
    17  * @global array $_old_files
    21  * @global string[] $_old_files
    18  * @var array
    22  * @var string[]
    19  * @name $_old_files
    23  * @name $_old_files
    20  */
    24  */
    21 global $_old_files;
    25 global $_old_files;
    22 
    26 
    23 $_old_files = array(
    27 $_old_files = array(
   735 	'wp-includes/blocks/heading/editor-rtl.min.css',
   739 	'wp-includes/blocks/heading/editor-rtl.min.css',
   736 	'wp-includes/blocks/query-title/editor.css',
   740 	'wp-includes/blocks/query-title/editor.css',
   737 	'wp-includes/blocks/query-title/editor.min.css',
   741 	'wp-includes/blocks/query-title/editor.min.css',
   738 	'wp-includes/blocks/query-title/editor-rtl.css',
   742 	'wp-includes/blocks/query-title/editor-rtl.css',
   739 	'wp-includes/blocks/query-title/editor-rtl.min.css',
   743 	'wp-includes/blocks/query-title/editor-rtl.min.css',
   740 	'wp-includes/blocks/tag-cloud/editor.css',
   744 	/*
   741 	'wp-includes/blocks/tag-cloud/editor.min.css',
   745 	 * Restored in WordPress 6.7
   742 	'wp-includes/blocks/tag-cloud/editor-rtl.css',
   746 	 *
   743 	'wp-includes/blocks/tag-cloud/editor-rtl.min.css',
   747 	 * 'wp-includes/blocks/tag-cloud/editor.css',
       
   748 	 * 'wp-includes/blocks/tag-cloud/editor.min.css',
       
   749 	 * 'wp-includes/blocks/tag-cloud/editor-rtl.css',
       
   750 	 * 'wp-includes/blocks/tag-cloud/editor-rtl.min.css',
       
   751 	 */
   744 	// 6.1
   752 	// 6.1
   745 	'wp-includes/blocks/post-comments.php',
   753 	'wp-includes/blocks/post-comments.php',
   746 	'wp-includes/blocks/post-comments',
   754 	'wp-includes/blocks/post-comments',
   747 	'wp-includes/blocks/comments-query-loop',
   755 	'wp-includes/blocks/comments-query-loop',
   748 	// 6.3
   756 	// 6.3
   768 	// 6.6
   776 	// 6.6
   769 	'wp-includes/blocks/block/editor.css',
   777 	'wp-includes/blocks/block/editor.css',
   770 	'wp-includes/blocks/block/editor.min.css',
   778 	'wp-includes/blocks/block/editor.min.css',
   771 	'wp-includes/blocks/block/editor-rtl.css',
   779 	'wp-includes/blocks/block/editor-rtl.css',
   772 	'wp-includes/blocks/block/editor-rtl.min.css',
   780 	'wp-includes/blocks/block/editor-rtl.min.css',
       
   781 	/*
       
   782 	 * 6.7
       
   783 	 *
       
   784 	 * WordPress 6.7 included a SimplePie upgrade that included a major
       
   785 	 * refactoring of the file structure and library. The old files are
       
   786 	 * split in to two sections to account for this: files and directories.
       
   787 	 *
       
   788 	 * See https://core.trac.wordpress.org/changeset/59141
       
   789 	 */
       
   790 	// 6.7 - files
       
   791 	'wp-includes/js/dist/interactivity-router.asset.php',
       
   792 	'wp-includes/js/dist/interactivity-router.js',
       
   793 	'wp-includes/js/dist/interactivity-router.min.js',
       
   794 	'wp-includes/js/dist/interactivity-router.min.asset.php',
       
   795 	'wp-includes/js/dist/interactivity.js',
       
   796 	'wp-includes/js/dist/interactivity.min.js',
       
   797 	'wp-includes/js/dist/vendor/react-dom.min.js.LICENSE.txt',
       
   798 	'wp-includes/js/dist/vendor/react.min.js.LICENSE.txt',
       
   799 	'wp-includes/js/dist/vendor/wp-polyfill-importmap.js',
       
   800 	'wp-includes/js/dist/vendor/wp-polyfill-importmap.min.js',
       
   801 	'wp-includes/sodium_compat/src/Core/Base64/Common.php',
       
   802 	'wp-includes/SimplePie/Author.php',
       
   803 	'wp-includes/SimplePie/Cache.php',
       
   804 	'wp-includes/SimplePie/Caption.php',
       
   805 	'wp-includes/SimplePie/Category.php',
       
   806 	'wp-includes/SimplePie/Copyright.php',
       
   807 	'wp-includes/SimplePie/Core.php',
       
   808 	'wp-includes/SimplePie/Credit.php',
       
   809 	'wp-includes/SimplePie/Enclosure.php',
       
   810 	'wp-includes/SimplePie/Exception.php',
       
   811 	'wp-includes/SimplePie/File.php',
       
   812 	'wp-includes/SimplePie/gzdecode.php',
       
   813 	'wp-includes/SimplePie/IRI.php',
       
   814 	'wp-includes/SimplePie/Item.php',
       
   815 	'wp-includes/SimplePie/Locator.php',
       
   816 	'wp-includes/SimplePie/Misc.php',
       
   817 	'wp-includes/SimplePie/Parser.php',
       
   818 	'wp-includes/SimplePie/Rating.php',
       
   819 	'wp-includes/SimplePie/Registry.php',
       
   820 	'wp-includes/SimplePie/Restriction.php',
       
   821 	'wp-includes/SimplePie/Sanitize.php',
       
   822 	'wp-includes/SimplePie/Source.php',
       
   823 	// 6.7 - directories
       
   824 	'wp-includes/SimplePie/Cache/',
       
   825 	'wp-includes/SimplePie/Content/',
       
   826 	'wp-includes/SimplePie/Decode/',
       
   827 	'wp-includes/SimplePie/HTTP/',
       
   828 	'wp-includes/SimplePie/Net/',
       
   829 	'wp-includes/SimplePie/Parse/',
       
   830 	'wp-includes/SimplePie/XML/',
       
   831 	// 6.8
       
   832 	'wp-includes/blocks/post-content/editor.css',
       
   833 	'wp-includes/blocks/post-content/editor.min.css',
       
   834 	'wp-includes/blocks/post-content/editor-rtl.css',
       
   835 	'wp-includes/blocks/post-content/editor-rtl.min.css',
       
   836 	'wp-includes/blocks/post-template/editor.css',
       
   837 	'wp-includes/blocks/post-template/editor.min.css',
       
   838 	'wp-includes/blocks/post-template/editor-rtl.css',
       
   839 	'wp-includes/blocks/post-template/editor-rtl.min.css',
       
   840 	'wp-includes/js/dist/undo-manager.js',
       
   841 	'wp-includes/js/dist/undo-manager.min.js',
       
   842 	'wp-includes/js/dist/fields.min.js',
       
   843 	'wp-includes/js/dist/fields.js',
   773 );
   844 );
   774 
   845 
   775 /**
   846 /**
   776  * Stores Requests files to be preloaded and deleted.
   847  * Stores Requests files to be preloaded and deleted.
   777  *
   848  *
   780  *
   851  *
   781  * All other files/directories should not have a key.
   852  * All other files/directories should not have a key.
   782  *
   853  *
   783  * @since 6.2.0
   854  * @since 6.2.0
   784  *
   855  *
   785  * @global array $_old_requests_files
   856  * @global string[] $_old_requests_files
   786  * @var array
   857  * @var string[]
   787  * @name $_old_requests_files
   858  * @name $_old_requests_files
   788  */
   859  */
   789 global $_old_requests_files;
   860 global $_old_requests_files;
   790 
   861 
   791 $_old_requests_files = array(
   862 $_old_requests_files = array(
   877  * @since 3.2.0
   948  * @since 3.2.0
   878  * @since 4.7.0 New themes were not automatically installed for 4.4-4.6 on
   949  * @since 4.7.0 New themes were not automatically installed for 4.4-4.6 on
   879  *              upgrade. New themes are now installed again. To disable new
   950  *              upgrade. New themes are now installed again. To disable new
   880  *              themes from being installed on upgrade, explicitly define
   951  *              themes from being installed on upgrade, explicitly define
   881  *              CORE_UPGRADE_SKIP_NEW_BUNDLED as true.
   952  *              CORE_UPGRADE_SKIP_NEW_BUNDLED as true.
   882  * @global array $_new_bundled_files
   953  * @global string[] $_new_bundled_files
   883  * @var array
   954  * @var string[]
   884  * @name $_new_bundled_files
   955  * @name $_new_bundled_files
   885  */
   956  */
   886 global $_new_bundled_files;
   957 global $_new_bundled_files;
   887 
   958 
   888 $_new_bundled_files = array(
   959 $_new_bundled_files = array(
   899 	'themes/twentytwenty/'      => '5.3',
   970 	'themes/twentytwenty/'      => '5.3',
   900 	'themes/twentytwentyone/'   => '5.6',
   971 	'themes/twentytwentyone/'   => '5.6',
   901 	'themes/twentytwentytwo/'   => '5.9',
   972 	'themes/twentytwentytwo/'   => '5.9',
   902 	'themes/twentytwentythree/' => '6.1',
   973 	'themes/twentytwentythree/' => '6.1',
   903 	'themes/twentytwentyfour/'  => '6.4',
   974 	'themes/twentytwentyfour/'  => '6.4',
       
   975 	'themes/twentytwentyfive/'  => '6.7',
   904 );
   976 );
   905 
   977 
   906 /**
   978 /**
   907  * Upgrades the core of WordPress.
   979  * Upgrades the core of WordPress.
   908  *
   980  *
   916  * The files in the `$_new_bundled_files` list will be added to the installation
   988  * The files in the `$_new_bundled_files` list will be added to the installation
   917  * if the version is greater than or equal to the old version being upgraded.
   989  * if the version is greater than or equal to the old version being upgraded.
   918  *
   990  *
   919  * The steps for the upgrader for after the new release is downloaded and
   991  * The steps for the upgrader for after the new release is downloaded and
   920  * unzipped is:
   992  * unzipped is:
       
   993  *
   921  *   1. Test unzipped location for select files to ensure that unzipped worked.
   994  *   1. Test unzipped location for select files to ensure that unzipped worked.
   922  *   2. Create the .maintenance file in current WordPress base.
   995  *   2. Create the .maintenance file in current WordPress base.
   923  *   3. Copy new WordPress directory over old WordPress files.
   996  *   3. Copy new WordPress directory over old WordPress files.
   924  *   4. Upgrade WordPress to new version.
   997  *   4. Upgrade WordPress to new version.
   925  *     4.1. Copy all files/folders other than wp-content
   998  *      1. Copy all files/folders other than wp-content
   926  *     4.2. Copy any language files to WP_LANG_DIR (which may differ from WP_CONTENT_DIR
   999  *      2. Copy any language files to `WP_LANG_DIR` (which may differ from `WP_CONTENT_DIR`
   927  *     4.3. Copy any new bundled themes/plugins to their respective locations
  1000  *      3. Copy any new bundled themes/plugins to their respective locations
   928  *   5. Delete new WordPress directory path.
  1001  *   5. Delete new WordPress directory path.
   929  *   6. Delete .maintenance file.
  1002  *   6. Delete .maintenance file.
   930  *   7. Remove old files.
  1003  *   7. Remove old files.
   931  *   8. Delete 'update_core' option.
  1004  *   8. Delete 'update_core' option.
   932  *
  1005  *
   944  * your changes remain.
  1017  * your changes remain.
   945  *
  1018  *
   946  * @since 2.7.0
  1019  * @since 2.7.0
   947  *
  1020  *
   948  * @global WP_Filesystem_Base $wp_filesystem          WordPress filesystem subclass.
  1021  * @global WP_Filesystem_Base $wp_filesystem          WordPress filesystem subclass.
   949  * @global array              $_old_files
  1022  * @global string[]           $_old_files
   950  * @global array              $_old_requests_files
  1023  * @global string[]           $_old_requests_files
   951  * @global array              $_new_bundled_files
  1024  * @global string[]           $_new_bundled_files
   952  * @global wpdb               $wpdb                   WordPress database abstraction object.
  1025  * @global wpdb               $wpdb                   WordPress database abstraction object.
   953  * @global string             $wp_version
       
   954  * @global string             $required_php_version
       
   955  * @global string             $required_mysql_version
       
   956  *
  1026  *
   957  * @param string $from New release unzipped path.
  1027  * @param string $from New release unzipped path.
   958  * @param string $to   Path to old WordPress installation.
  1028  * @param string $to   Path to old WordPress installation.
   959  * @return string|WP_Error New WordPress version on success, WP_Error on failure.
  1029  * @return string|WP_Error New WordPress version on success, WP_Error on failure.
   960  */
  1030  */
   961 function update_core( $from, $to ) {
  1031 function update_core( $from, $to ) {
   962 	global $wp_filesystem, $_old_files, $_old_requests_files, $_new_bundled_files, $wpdb;
  1032 	global $wp_filesystem, $_old_files, $_old_requests_files, $_new_bundled_files, $wpdb;
   963 
  1033 
       
  1034 	/*
       
  1035 	 * Give core update script an additional 300 seconds (5 minutes)
       
  1036 	 * to finish updating large files when running on slower servers.
       
  1037 	 */
   964 	if ( function_exists( 'set_time_limit' ) ) {
  1038 	if ( function_exists( 'set_time_limit' ) ) {
   965 		set_time_limit( 300 );
  1039 		set_time_limit( 300 );
   966 	}
  1040 	}
   967 
  1041 
   968 	/*
  1042 	/*
  1010 
  1084 
  1011 		return new WP_Error( 'insane_distro', __( 'The update could not be unpacked' ) );
  1085 		return new WP_Error( 'insane_distro', __( 'The update could not be unpacked' ) );
  1012 	}
  1086 	}
  1013 
  1087 
  1014 	/*
  1088 	/*
  1015 	 * Import $wp_version, $required_php_version, and $required_mysql_version from the new version.
  1089 	 * Import $wp_version, $required_php_version, $required_php_extensions, and $required_mysql_version from the new version.
  1016 	 * DO NOT globalize any variables imported from `version-current.php` in this function.
  1090 	 * DO NOT globalize any variables imported from `version-current.php` in this function.
  1017 	 *
  1091 	 *
  1018 	 * BC Note: $wp_filesystem->wp_content_dir() returned unslashed pre-2.8.
  1092 	 * BC Note: $wp_filesystem->wp_content_dir() returned unslashed pre-2.8.
  1019 	 */
  1093 	 */
  1020 	$versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
  1094 	$versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
  1116 				$mysql_version
  1190 				$mysql_version
  1117 			)
  1191 			)
  1118 		);
  1192 		);
  1119 	}
  1193 	}
  1120 
  1194 
  1121 	// Add a warning when the JSON PHP extension is missing.
  1195 	if ( isset( $required_php_extensions ) && is_array( $required_php_extensions ) ) {
  1122 	if ( ! extension_loaded( 'json' ) ) {
  1196 		$missing_extensions = new WP_Error();
  1123 		return new WP_Error(
  1197 
  1124 			'php_not_compatible_json',
  1198 		foreach ( $required_php_extensions as $extension ) {
  1125 			sprintf(
  1199 			if ( extension_loaded( $extension ) ) {
  1126 				/* translators: 1: WordPress version number, 2: The PHP extension name needed. */
  1200 				continue;
  1127 				__( 'The update cannot be installed because WordPress %1$s requires the %2$s PHP extension.' ),
  1201 			}
  1128 				$wp_version,
  1202 
  1129 				'JSON'
  1203 			$missing_extensions->add(
  1130 			)
  1204 				"php_not_compatible_{$extension}",
  1131 		);
  1205 				sprintf(
       
  1206 					/* translators: 1: WordPress version number, 2: The PHP extension name needed. */
       
  1207 					__( 'The update cannot be installed because WordPress %1$s requires the %2$s PHP extension.' ),
       
  1208 					$wp_version,
       
  1209 					$extension
       
  1210 				)
       
  1211 			);
       
  1212 		}
       
  1213 
       
  1214 		// Add a warning when required PHP extensions are missing.
       
  1215 		if ( ! empty( $missing_extensions->errors ) ) {
       
  1216 			return $missing_extensions;
       
  1217 		}
  1132 	}
  1218 	}
  1133 
  1219 
  1134 	/** This filter is documented in wp-admin/includes/update-core.php */
  1220 	/** This filter is documented in wp-admin/includes/update-core.php */
  1135 	apply_filters( 'update_feedback', __( 'Preparing to install the latest version&#8230;' ) );
  1221 	apply_filters( 'update_feedback', __( 'Preparing to install the latest version&#8230;' ) );
  1136 
  1222 
  1529  * a fatal error. Preloading ensures the code is in memory before the
  1615  * a fatal error. Preloading ensures the code is in memory before the
  1530  * code is updated.
  1616  * code is updated.
  1531  *
  1617  *
  1532  * @since 6.2.0
  1618  * @since 6.2.0
  1533  *
  1619  *
  1534  * @global array              $_old_requests_files Requests files to be preloaded.
  1620  * @global string[]           $_old_requests_files Requests files to be preloaded.
  1535  * @global WP_Filesystem_Base $wp_filesystem       WordPress filesystem subclass.
  1621  * @global WP_Filesystem_Base $wp_filesystem       WordPress filesystem subclass.
  1536  * @global string             $wp_version          The WordPress version string.
  1622  * @global string             $wp_version          The WordPress version string.
  1537  *
  1623  *
  1538  * @param string $to Path to old WordPress installation.
  1624  * @param string $to Path to old WordPress installation.
  1539  */
  1625  */
  1641 /**
  1727 /**
  1642  * Cleans up Genericons example files.
  1728  * Cleans up Genericons example files.
  1643  *
  1729  *
  1644  * @since 4.2.2
  1730  * @since 4.2.2
  1645  *
  1731  *
  1646  * @global array              $wp_theme_directories
  1732  * @global string[]           $wp_theme_directories
  1647  * @global WP_Filesystem_Base $wp_filesystem
  1733  * @global WP_Filesystem_Base $wp_filesystem
  1648  */
  1734  */
  1649 function _upgrade_422_remove_genericons() {
  1735 function _upgrade_422_remove_genericons() {
  1650 	global $wp_theme_directories, $wp_filesystem;
  1736 	global $wp_theme_directories, $wp_filesystem;
  1651 
  1737 
  1687  *
  1773  *
  1688  * @ignore
  1774  * @ignore
  1689  * @since 4.2.2
  1775  * @since 4.2.2
  1690  *
  1776  *
  1691  * @param string $directory Directory path. Expects trailingslashed.
  1777  * @param string $directory Directory path. Expects trailingslashed.
  1692  * @return array
  1778  * @return string[]
  1693  */
  1779  */
  1694 function _upgrade_422_find_genericons_files_in_folder( $directory ) {
  1780 function _upgrade_422_find_genericons_files_in_folder( $directory ) {
  1695 	$directory = trailingslashit( $directory );
  1781 	$directory = trailingslashit( $directory );
  1696 	$files     = array();
  1782 	$files     = array();
  1697 
  1783 
  1761 			$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
  1847 			$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
  1762 			update_site_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
  1848 			update_site_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
  1763 		} else {
  1849 		} else {
  1764 			$deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
  1850 			$deactivated_plugins = get_option( 'wp_force_deactivated_plugins', array() );
  1765 			$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
  1851 			$deactivated_plugins = array_merge( $deactivated_plugins, $deactivated_gutenberg );
  1766 			update_option( 'wp_force_deactivated_plugins', $deactivated_plugins );
  1852 			update_option( 'wp_force_deactivated_plugins', $deactivated_plugins, false );
  1767 		}
  1853 		}
  1768 		deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
  1854 		deactivate_plugins( array( 'gutenberg/gutenberg.php' ), true );
  1769 	}
  1855 	}
  1770 }
  1856 }