wp/wp-admin/includes/update-core.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
   290 // 3.3
   290 // 3.3
   291 'wp-admin/css/colors-classic-rtl.css',
   291 'wp-admin/css/colors-classic-rtl.css',
   292 'wp-admin/css/colors-classic-rtl.dev.css',
   292 'wp-admin/css/colors-classic-rtl.dev.css',
   293 'wp-admin/css/colors-fresh-rtl.css',
   293 'wp-admin/css/colors-fresh-rtl.css',
   294 'wp-admin/css/colors-fresh-rtl.dev.css',
   294 'wp-admin/css/colors-fresh-rtl.dev.css',
   295 'wp-admin/css/dashboard-rtl.css',
       
   296 'wp-admin/css/dashboard-rtl.dev.css',
   295 'wp-admin/css/dashboard-rtl.dev.css',
   297 'wp-admin/css/dashboard.css',
       
   298 'wp-admin/css/dashboard.dev.css',
   296 'wp-admin/css/dashboard.dev.css',
   299 'wp-admin/css/farbtastic-rtl.css',
       
   300 'wp-admin/css/global-rtl.css',
   297 'wp-admin/css/global-rtl.css',
   301 'wp-admin/css/global-rtl.dev.css',
   298 'wp-admin/css/global-rtl.dev.css',
   302 'wp-admin/css/global.css',
   299 'wp-admin/css/global.css',
   303 'wp-admin/css/global.dev.css',
   300 'wp-admin/css/global.dev.css',
   304 'wp-admin/css/install-rtl.css',
       
   305 'wp-admin/css/install-rtl.dev.css',
   301 'wp-admin/css/install-rtl.dev.css',
   306 'wp-admin/css/login-rtl.css',
       
   307 'wp-admin/css/login-rtl.dev.css',
   302 'wp-admin/css/login-rtl.dev.css',
   308 'wp-admin/css/login.css',
       
   309 'wp-admin/css/login.dev.css',
   303 'wp-admin/css/login.dev.css',
   310 'wp-admin/css/ms.css',
   304 'wp-admin/css/ms.css',
   311 'wp-admin/css/ms.dev.css',
   305 'wp-admin/css/ms.dev.css',
   312 'wp-admin/css/nav-menu-rtl.css',
   306 'wp-admin/css/nav-menu-rtl.css',
   313 'wp-admin/css/nav-menu-rtl.dev.css',
   307 'wp-admin/css/nav-menu-rtl.dev.css',
   315 'wp-admin/css/nav-menu.dev.css',
   309 'wp-admin/css/nav-menu.dev.css',
   316 'wp-admin/css/plugin-install-rtl.css',
   310 'wp-admin/css/plugin-install-rtl.css',
   317 'wp-admin/css/plugin-install-rtl.dev.css',
   311 'wp-admin/css/plugin-install-rtl.dev.css',
   318 'wp-admin/css/plugin-install.css',
   312 'wp-admin/css/plugin-install.css',
   319 'wp-admin/css/plugin-install.dev.css',
   313 'wp-admin/css/plugin-install.dev.css',
   320 'wp-admin/css/press-this-rtl.css',
       
   321 'wp-admin/css/press-this-rtl.dev.css',
   314 'wp-admin/css/press-this-rtl.dev.css',
   322 'wp-admin/css/press-this.css',
       
   323 'wp-admin/css/press-this.dev.css',
   315 'wp-admin/css/press-this.dev.css',
   324 'wp-admin/css/theme-editor-rtl.css',
   316 'wp-admin/css/theme-editor-rtl.css',
   325 'wp-admin/css/theme-editor-rtl.dev.css',
   317 'wp-admin/css/theme-editor-rtl.dev.css',
   326 'wp-admin/css/theme-editor.css',
   318 'wp-admin/css/theme-editor.css',
   327 'wp-admin/css/theme-editor.dev.css',
   319 'wp-admin/css/theme-editor.dev.css',
   328 'wp-admin/css/theme-install-rtl.css',
   320 'wp-admin/css/theme-install-rtl.css',
   329 'wp-admin/css/theme-install-rtl.dev.css',
   321 'wp-admin/css/theme-install-rtl.dev.css',
   330 'wp-admin/css/theme-install.css',
   322 'wp-admin/css/theme-install.css',
   331 'wp-admin/css/theme-install.dev.css',
   323 'wp-admin/css/theme-install.dev.css',
   332 'wp-admin/css/widgets-rtl.css',
       
   333 'wp-admin/css/widgets-rtl.dev.css',
   324 'wp-admin/css/widgets-rtl.dev.css',
   334 'wp-admin/css/widgets.css',
       
   335 'wp-admin/css/widgets.dev.css',
   325 'wp-admin/css/widgets.dev.css',
   336 'wp-admin/includes/internal-linking.php',
   326 'wp-admin/includes/internal-linking.php',
   337 'wp-includes/images/admin-bar-sprite-rtl.png',
   327 'wp-includes/images/admin-bar-sprite-rtl.png',
   338 'wp-includes/js/jquery/ui.button.js',
   328 'wp-includes/js/jquery/ui.button.js',
   339 'wp-includes/js/jquery/ui.core.js',
   329 'wp-includes/js/jquery/ui.core.js',
   560 'wp-admin/js/custom-fields.min.js',
   550 'wp-admin/js/custom-fields.min.js',
   561 // 3.7
   551 // 3.7
   562 'wp-admin/js/cat.js',
   552 'wp-admin/js/cat.js',
   563 'wp-admin/js/cat.min.js',
   553 'wp-admin/js/cat.min.js',
   564 'wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.min.js',
   554 'wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.min.js',
       
   555 // 3.8
       
   556 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/page_bug.gif',
       
   557 'wp-includes/js/tinymce/themes/advanced/skins/wp_theme/img/more_bug.gif',
       
   558 'wp-includes/js/thickbox/tb-close-2x.png',
       
   559 'wp-includes/js/thickbox/tb-close.png',
       
   560 'wp-includes/images/wpmini-blue-2x.png',
       
   561 'wp-includes/images/wpmini-blue.png',
       
   562 'wp-admin/css/colors-fresh.css',
       
   563 'wp-admin/css/colors-classic.css',
       
   564 'wp-admin/css/colors-fresh.min.css',
       
   565 'wp-admin/css/colors-classic.min.css',
       
   566 'wp-admin/js/about.min.js',
       
   567 'wp-admin/js/about.js',
       
   568 'wp-admin/images/arrows-dark-vs-2x.png',
       
   569 'wp-admin/images/wp-logo-vs.png',
       
   570 'wp-admin/images/arrows-dark-vs.png',
       
   571 'wp-admin/images/wp-logo.png',
       
   572 'wp-admin/images/arrows-pr.png',
       
   573 'wp-admin/images/arrows-dark.png',
       
   574 'wp-admin/images/press-this.png',
       
   575 'wp-admin/images/press-this-2x.png',
       
   576 'wp-admin/images/arrows-vs-2x.png',
       
   577 'wp-admin/images/welcome-icons.png',
       
   578 'wp-admin/images/wp-logo-2x.png',
       
   579 'wp-admin/images/stars-rtl-2x.png',
       
   580 'wp-admin/images/arrows-dark-2x.png',
       
   581 'wp-admin/images/arrows-pr-2x.png',
       
   582 'wp-admin/images/menu-shadow-rtl.png',
       
   583 'wp-admin/images/arrows-vs.png',
       
   584 'wp-admin/images/about-search-2x.png',
       
   585 'wp-admin/images/bubble_bg-rtl-2x.gif',
       
   586 'wp-admin/images/wp-badge-2x.png',
       
   587 'wp-admin/images/wordpress-logo-2x.png',
       
   588 'wp-admin/images/bubble_bg-rtl.gif',
       
   589 'wp-admin/images/wp-badge.png',
       
   590 'wp-admin/images/menu-shadow.png',
       
   591 'wp-admin/images/about-globe-2x.png',
       
   592 'wp-admin/images/welcome-icons-2x.png',
       
   593 'wp-admin/images/stars-rtl.png',
       
   594 'wp-admin/images/wp-logo-vs-2x.png',
       
   595 'wp-admin/images/about-updates-2x.png',
       
   596 // 3.9
       
   597 'wp-admin/css/colors.css',
       
   598 'wp-admin/css/colors.min.css',
       
   599 'wp-admin/css/colors-rtl.css',
       
   600 'wp-admin/css/colors-rtl.min.css',
       
   601 'wp-admin/css/media-rtl.min.css',
       
   602 'wp-admin/css/media.min.css',
       
   603 'wp-admin/css/farbtastic-rtl.min.css',
       
   604 'wp-admin/images/lock-2x.png',
       
   605 'wp-admin/images/lock.png',
       
   606 'wp-admin/js/theme-preview.js',
       
   607 'wp-admin/js/theme-install.min.js',
       
   608 'wp-admin/js/theme-install.js',
       
   609 'wp-admin/js/theme-preview.min.js',
       
   610 'wp-includes/js/plupload/plupload.html4.js',
       
   611 'wp-includes/js/plupload/plupload.html5.js',
       
   612 'wp-includes/js/plupload/changelog.txt',
       
   613 'wp-includes/js/plupload/plupload.silverlight.js',
       
   614 'wp-includes/js/plupload/plupload.flash.js',
       
   615 'wp-includes/js/plupload/plupload.js',
       
   616 'wp-includes/js/tinymce/plugins/spellchecker',
       
   617 'wp-includes/js/tinymce/plugins/inlinepopups',
       
   618 'wp-includes/js/tinymce/plugins/media/js',
       
   619 'wp-includes/js/tinymce/plugins/media/css',
       
   620 'wp-includes/js/tinymce/plugins/wordpress/img',
       
   621 'wp-includes/js/tinymce/plugins/wpdialogs/js',
       
   622 'wp-includes/js/tinymce/plugins/wpeditimage/img',
       
   623 'wp-includes/js/tinymce/plugins/wpeditimage/js',
       
   624 'wp-includes/js/tinymce/plugins/wpeditimage/css',
       
   625 'wp-includes/js/tinymce/plugins/wpgallery/img',
       
   626 'wp-includes/js/tinymce/plugins/wpfullscreen/css',
       
   627 'wp-includes/js/tinymce/plugins/paste/js',
       
   628 'wp-includes/js/tinymce/themes/advanced',
       
   629 'wp-includes/js/tinymce/tiny_mce.js',
       
   630 'wp-includes/js/tinymce/mark_loaded_src.js',
       
   631 'wp-includes/js/tinymce/wp-tinymce-schema.js',
       
   632 'wp-includes/js/tinymce/plugins/media/editor_plugin.js',
       
   633 'wp-includes/js/tinymce/plugins/media/editor_plugin_src.js',
       
   634 'wp-includes/js/tinymce/plugins/media/media.htm',
       
   635 'wp-includes/js/tinymce/plugins/wpview/editor_plugin_src.js',
       
   636 'wp-includes/js/tinymce/plugins/wpview/editor_plugin.js',
       
   637 'wp-includes/js/tinymce/plugins/directionality/editor_plugin.js',
       
   638 'wp-includes/js/tinymce/plugins/directionality/editor_plugin_src.js',
       
   639 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js',
       
   640 'wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js',
       
   641 'wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin_src.js',
       
   642 'wp-includes/js/tinymce/plugins/wpdialogs/editor_plugin.js',
       
   643 'wp-includes/js/tinymce/plugins/wpeditimage/editimage.html',
       
   644 'wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin.js',
       
   645 'wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js',
       
   646 'wp-includes/js/tinymce/plugins/fullscreen/editor_plugin_src.js',
       
   647 'wp-includes/js/tinymce/plugins/fullscreen/fullscreen.htm',
       
   648 'wp-includes/js/tinymce/plugins/fullscreen/editor_plugin.js',
       
   649 'wp-includes/js/tinymce/plugins/wplink/editor_plugin_src.js',
       
   650 'wp-includes/js/tinymce/plugins/wplink/editor_plugin.js',
       
   651 'wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js',
       
   652 'wp-includes/js/tinymce/plugins/wpgallery/editor_plugin.js',
       
   653 'wp-includes/js/tinymce/plugins/tabfocus/editor_plugin.js',
       
   654 'wp-includes/js/tinymce/plugins/tabfocus/editor_plugin_src.js',
       
   655 'wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin.js',
       
   656 'wp-includes/js/tinymce/plugins/wpfullscreen/editor_plugin_src.js',
       
   657 'wp-includes/js/tinymce/plugins/paste/editor_plugin.js',
       
   658 'wp-includes/js/tinymce/plugins/paste/pasteword.htm',
       
   659 'wp-includes/js/tinymce/plugins/paste/editor_plugin_src.js',
       
   660 'wp-includes/js/tinymce/plugins/paste/pastetext.htm',
       
   661 'wp-includes/js/tinymce/langs/wp-langs.php',
       
   662 // 4.1
       
   663 'wp-includes/js/jquery/ui/jquery.ui.accordion.min.js',
       
   664 'wp-includes/js/jquery/ui/jquery.ui.autocomplete.min.js',
       
   665 'wp-includes/js/jquery/ui/jquery.ui.button.min.js',
       
   666 'wp-includes/js/jquery/ui/jquery.ui.core.min.js',
       
   667 'wp-includes/js/jquery/ui/jquery.ui.datepicker.min.js',
       
   668 'wp-includes/js/jquery/ui/jquery.ui.dialog.min.js',
       
   669 'wp-includes/js/jquery/ui/jquery.ui.draggable.min.js',
       
   670 'wp-includes/js/jquery/ui/jquery.ui.droppable.min.js',
       
   671 'wp-includes/js/jquery/ui/jquery.ui.effect-blind.min.js',
       
   672 'wp-includes/js/jquery/ui/jquery.ui.effect-bounce.min.js',
       
   673 'wp-includes/js/jquery/ui/jquery.ui.effect-clip.min.js',
       
   674 'wp-includes/js/jquery/ui/jquery.ui.effect-drop.min.js',
       
   675 'wp-includes/js/jquery/ui/jquery.ui.effect-explode.min.js',
       
   676 'wp-includes/js/jquery/ui/jquery.ui.effect-fade.min.js',
       
   677 'wp-includes/js/jquery/ui/jquery.ui.effect-fold.min.js',
       
   678 'wp-includes/js/jquery/ui/jquery.ui.effect-highlight.min.js',
       
   679 'wp-includes/js/jquery/ui/jquery.ui.effect-pulsate.min.js',
       
   680 'wp-includes/js/jquery/ui/jquery.ui.effect-scale.min.js',
       
   681 'wp-includes/js/jquery/ui/jquery.ui.effect-shake.min.js',
       
   682 'wp-includes/js/jquery/ui/jquery.ui.effect-slide.min.js',
       
   683 'wp-includes/js/jquery/ui/jquery.ui.effect-transfer.min.js',
       
   684 'wp-includes/js/jquery/ui/jquery.ui.effect.min.js',
       
   685 'wp-includes/js/jquery/ui/jquery.ui.menu.min.js',
       
   686 'wp-includes/js/jquery/ui/jquery.ui.mouse.min.js',
       
   687 'wp-includes/js/jquery/ui/jquery.ui.position.min.js',
       
   688 'wp-includes/js/jquery/ui/jquery.ui.progressbar.min.js',
       
   689 'wp-includes/js/jquery/ui/jquery.ui.resizable.min.js',
       
   690 'wp-includes/js/jquery/ui/jquery.ui.selectable.min.js',
       
   691 'wp-includes/js/jquery/ui/jquery.ui.slider.min.js',
       
   692 'wp-includes/js/jquery/ui/jquery.ui.sortable.min.js',
       
   693 'wp-includes/js/jquery/ui/jquery.ui.spinner.min.js',
       
   694 'wp-includes/js/jquery/ui/jquery.ui.tabs.min.js',
       
   695 'wp-includes/js/jquery/ui/jquery.ui.tooltip.min.js',
       
   696 'wp-includes/js/jquery/ui/jquery.ui.widget.min.js',
       
   697 'wp-includes/js/tinymce/skins/wordpress/images/dashicon-no-alt.png'
   565 );
   698 );
   566 
   699 
   567 /**
   700 /**
   568  * Stores new files in wp-content to copy
   701  * Stores new files in wp-content to copy
   569  *
   702  *
   587 	'plugins/akismet/'       => '2.0',
   720 	'plugins/akismet/'       => '2.0',
   588 	'themes/twentyten/'      => '3.0',
   721 	'themes/twentyten/'      => '3.0',
   589 	'themes/twentyeleven/'   => '3.2',
   722 	'themes/twentyeleven/'   => '3.2',
   590 	'themes/twentytwelve/'   => '3.5',
   723 	'themes/twentytwelve/'   => '3.5',
   591 	'themes/twentythirteen/' => '3.6',
   724 	'themes/twentythirteen/' => '3.6',
       
   725 	'themes/twentyfourteen/' => '3.8',
       
   726 	'themes/twentyfifteen/'  => '4.1',
   592 );
   727 );
   593 
   728 
   594 /**
   729 /**
   595  * Upgrade the core of WordPress.
   730  * Upgrade the core of WordPress.
   596  *
   731  *
   640 function update_core($from, $to) {
   775 function update_core($from, $to) {
   641 	global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
   776 	global $wp_filesystem, $_old_files, $_new_bundled_files, $wpdb;
   642 
   777 
   643 	@set_time_limit( 300 );
   778 	@set_time_limit( 300 );
   644 
   779 
   645 	// Sanity check the unzipped distribution
   780 	/**
   646 	apply_filters( 'update_feedback', __('Verifying the unpacked files…') );
   781 	 * Filter feedback messages displayed during the core update process.
       
   782 	 *
       
   783 	 * The filter is first evaluated after the zip file for the latest version
       
   784 	 * has been downloaded and unzipped. It is evaluated five more times during
       
   785 	 * the process:
       
   786 	 *
       
   787 	 * 1. Before WordPress begins the core upgrade process.
       
   788 	 * 2. Before Maintenance Mode is enabled.
       
   789 	 * 3. Before WordPress begins copying over the necessary files.
       
   790 	 * 4. Before Maintenance Mode is disabled.
       
   791 	 * 5. Before the database is upgraded.
       
   792 	 *
       
   793 	 * @since 2.5.0
       
   794 	 *
       
   795 	 * @param string $feedback The core update feedback messages.
       
   796 	 */
       
   797 	apply_filters( 'update_feedback', __( 'Verifying the unpacked files…' ) );
       
   798 
       
   799 	// Sanity check the unzipped distribution.
   647 	$distro = '';
   800 	$distro = '';
   648 	$roots = array( '/wordpress/', '/wordpress-mu/' );
   801 	$roots = array( '/wordpress/', '/wordpress-mu/' );
   649 	foreach ( $roots as $root ) {
   802 	foreach ( $roots as $root ) {
   650 		if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) ) {
   803 		if ( $wp_filesystem->exists( $from . $root . 'readme.html' ) && $wp_filesystem->exists( $from . $root . 'wp-includes/version.php' ) ) {
   651 			$distro = $root;
   804 			$distro = $root;
   657 		return new WP_Error( 'insane_distro', __('The update could not be unpacked') );
   810 		return new WP_Error( 'insane_distro', __('The update could not be unpacked') );
   658 	}
   811 	}
   659 
   812 
   660 	// Import $wp_version, $required_php_version, and $required_mysql_version from the new version
   813 	// Import $wp_version, $required_php_version, and $required_mysql_version from the new version
   661 	// $wp_filesystem->wp_content_dir() returned unslashed pre-2.8
   814 	// $wp_filesystem->wp_content_dir() returned unslashed pre-2.8
       
   815 	global $wp_version, $required_php_version, $required_mysql_version;
       
   816 
   662 	$versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
   817 	$versions_file = trailingslashit( $wp_filesystem->wp_content_dir() ) . 'upgrade/version-current.php';
   663 	if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
   818 	if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $versions_file ) ) {
   664 		 $wp_filesystem->delete( $from, true );
   819 		$wp_filesystem->delete( $from, true );
   665 		 return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' );
   820 		return new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' );
   666 	}
   821 	}
   667 
   822 
   668 	$wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE );
   823 	$wp_filesystem->chmod( $versions_file, FS_CHMOD_FILE );
   669 	require( WP_CONTENT_DIR . '/upgrade/version-current.php' );
   824 	require( WP_CONTENT_DIR . '/upgrade/version-current.php' );
   670 	$wp_filesystem->delete( $versions_file );
   825 	$wp_filesystem->delete( $versions_file );
   671 
   826 
   672 	$php_version    = phpversion();
   827 	$php_version    = phpversion();
   673 	$mysql_version  = $wpdb->db_version();
   828 	$mysql_version  = $wpdb->db_version();
   674 	$old_wp_version = $GLOBALS['wp_version']; // The version of WordPress we're updating from
   829 	$old_wp_version = $wp_version; // The version of WordPress we're updating from
   675 	$development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' )  ); // a dash in the version indicates a Development release
   830 	$development_build = ( false !== strpos( $old_wp_version . $wp_version, '-' )  ); // a dash in the version indicates a Development release
   676 	$php_compat     = version_compare( $php_version, $required_php_version, '>=' );
   831 	$php_compat     = version_compare( $php_version, $required_php_version, '>=' );
   677 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
   832 	if ( file_exists( WP_CONTENT_DIR . '/db.php' ) && empty( $wpdb->is_mysql ) )
   678 		$mysql_compat = true;
   833 		$mysql_compat = true;
   679 	else
   834 	else
   687 	elseif ( !$php_compat )
   842 	elseif ( !$php_compat )
   688 		return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) );
   843 		return new WP_Error( 'php_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires PHP version %2$s or higher. You are running version %3$s.'), $wp_version, $required_php_version, $php_version ) );
   689 	elseif ( !$mysql_compat )
   844 	elseif ( !$mysql_compat )
   690 		return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );
   845 		return new WP_Error( 'mysql_not_compatible', sprintf( __('The update cannot be installed because WordPress %1$s requires MySQL version %2$s or higher. You are running version %3$s.'), $wp_version, $required_mysql_version, $mysql_version ) );
   691 
   846 
       
   847 	/** This filter is documented in wp-admin/includes/update-core.php */
   692 	apply_filters( 'update_feedback', __( 'Preparing to install the latest version…' ) );
   848 	apply_filters( 'update_feedback', __( 'Preparing to install the latest version…' ) );
   693 
   849 
   694 	// Don't copy wp-content, we'll deal with that below
   850 	// Don't copy wp-content, we'll deal with that below
   695 	$skip = array( 'wp-content' );
   851 	// We also copy version.php last so failed updates report their old version
       
   852 	$skip = array( 'wp-content', 'wp-includes/version.php' );
   696 	$check_is_writable = array();
   853 	$check_is_writable = array();
   697 
   854 
   698 	// Check to see which files don't really need updating - only available for 3.7 and higher
   855 	// Check to see which files don't really need updating - only available for 3.7 and higher
   699 	if ( function_exists( 'get_core_checksums' ) ) {
   856 	if ( function_exists( 'get_core_checksums' ) ) {
       
   857 		// Find the local version of the working directory
       
   858 		$working_dir_local = WP_CONTENT_DIR . '/upgrade/' . basename( $from ) . $distro;
       
   859 
   700 		$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
   860 		$checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
   701 		if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) )
   861 		if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) )
   702 			$checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2
   862 			$checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2
   703 		if ( is_array( $checksums ) ) {
   863 		if ( is_array( $checksums ) ) {
   704 			foreach( $checksums as $file => $checksum ) {
   864 			foreach( $checksums as $file => $checksum ) {
   705 				if ( 'wp-content' == substr( $file, 0, 10 ) )
   865 				if ( 'wp-content' == substr( $file, 0, 10 ) )
   706 					continue;
   866 					continue;
   707 				if ( ! file_exists( ABSPATH . $file ) )
   867 				if ( ! file_exists( ABSPATH . $file ) )
       
   868 					continue;
       
   869 				if ( ! file_exists( $working_dir_local . $file ) )
   708 					continue;
   870 					continue;
   709 				if ( md5_file( ABSPATH . $file ) === $checksum )
   871 				if ( md5_file( ABSPATH . $file ) === $checksum )
   710 					$skip[] = $file;
   872 					$skip[] = $file;
   711 				else
   873 				else
   712 					$check_is_writable[ $file ] = ABSPATH . $file;
   874 					$check_is_writable[ $file ] = ABSPATH . $file;
   732 			if ( $files_not_writable )
   894 			if ( $files_not_writable )
   733 				return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), implode( ', ', $error_data ) );
   895 				return new WP_Error( 'files_not_writable', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), implode( ', ', $error_data ) );
   734 		}
   896 		}
   735 	}
   897 	}
   736 
   898 
       
   899 	/** This filter is documented in wp-admin/includes/update-core.php */
   737 	apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );
   900 	apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );
   738 	// Create maintenance file to signal that we are upgrading
   901 	// Create maintenance file to signal that we are upgrading
   739 	$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
   902 	$maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
   740 	$maintenance_file = $to . '.maintenance';
   903 	$maintenance_file = $to . '.maintenance';
   741 	$wp_filesystem->delete($maintenance_file);
   904 	$wp_filesystem->delete($maintenance_file);
   742 	$wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
   905 	$wp_filesystem->put_contents($maintenance_file, $maintenance_string, FS_CHMOD_FILE);
   743 
   906 
       
   907 	/** This filter is documented in wp-admin/includes/update-core.php */
   744 	apply_filters( 'update_feedback', __( 'Copying the required files&#8230;' ) );
   908 	apply_filters( 'update_feedback', __( 'Copying the required files&#8230;' ) );
   745 	// Copy new versions of WP files into place.
   909 	// Copy new versions of WP files into place.
   746 	$result = _copy_dir( $from . $distro, $to, $skip );
   910 	$result = _copy_dir( $from . $distro, $to, $skip );
   747 	if ( is_wp_error( $result ) )
   911 	if ( is_wp_error( $result ) )
   748 		$result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) );
   912 		$result = new WP_Error( $result->get_error_code(), $result->get_error_message(), substr( $result->get_error_data(), strlen( $to ) ) );
   749 
   913 
       
   914 	// Since we know the core files have copied over, we can now copy the version file
       
   915 	if ( ! is_wp_error( $result ) ) {
       
   916 		if ( ! $wp_filesystem->copy( $from . $distro . 'wp-includes/version.php', $to . 'wp-includes/version.php', true /* overwrite */ ) ) {
       
   917 			$wp_filesystem->delete( $from, true );
       
   918 			$result = new WP_Error( 'copy_failed_for_version_file', __( 'The update cannot be installed because we will be unable to copy some files. This is usually due to inconsistent file permissions.' ), 'wp-includes/version.php' );
       
   919 		}
       
   920 		$wp_filesystem->chmod( $to . 'wp-includes/version.php', FS_CHMOD_FILE );
       
   921 	}
       
   922 
   750 	// Check to make sure everything copied correctly, ignoring the contents of wp-content
   923 	// Check to make sure everything copied correctly, ignoring the contents of wp-content
   751 	$skip = array( 'wp-content' );
   924 	$skip = array( 'wp-content' );
   752 	$failed = array();
   925 	$failed = array();
   753 	if ( isset( $checksums ) && is_array( $checksums ) ) {
   926 	if ( isset( $checksums ) && is_array( $checksums ) ) {
   754 		foreach ( $checksums as $file => $checksum ) {
   927 		foreach ( $checksums as $file => $checksum ) {
   755 			if ( 0 === strpos( $file, 'wp-content' ) )
   928 			if ( 'wp-content' == substr( $file, 0, 10 ) )
   756 				continue;
   929 				continue;
   757 
   930 			if ( ! file_exists( $working_dir_local . $file ) )
       
   931 				continue;
   758 			if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) == $checksum )
   932 			if ( file_exists( ABSPATH . $file ) && md5_file( ABSPATH . $file ) == $checksum )
   759 				$skip[] = $file;
   933 				$skip[] = $file;
   760 			else
   934 			else
   761 				$failed[] = $file;
   935 				$failed[] = $file;
   762 		}
   936 		}
   763 	}
   937 	}
   764 
   938 
   765 	// Some files didn't copy properly
   939 	// Some files didn't copy properly
   766 	if ( ! empty( $failed ) ) {
   940 	if ( ! empty( $failed ) ) {
   767 		$total_size = 0;
   941 		$total_size = 0;
   768 		// Find the local version of the working directory
       
   769 		$working_dir_local = WP_CONTENT_DIR . '/upgrade/' . basename( $from ) . $distro;
       
   770 		foreach ( $failed as $file ) {
   942 		foreach ( $failed as $file ) {
   771 			if ( file_exists( $working_dir_local . $file ) )
   943 			if ( file_exists( $working_dir_local . $file ) )
   772 				$total_size += filesize( $working_dir_local . $file );
   944 				$total_size += filesize( $working_dir_local . $file );
   773 		}
   945 		}
   774 
   946 
   805 					$result = new WP_Error( $result->get_error_code() . '_languages', $result->get_error_message(), substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) );
   977 					$result = new WP_Error( $result->get_error_code() . '_languages', $result->get_error_message(), substr( $result->get_error_data(), strlen( $wp_lang_dir ) ) );
   806 			}
   978 			}
   807 		}
   979 		}
   808 	}
   980 	}
   809 
   981 
       
   982 	/** This filter is documented in wp-admin/includes/update-core.php */
   810 	apply_filters( 'update_feedback', __( 'Disabling Maintenance mode&#8230;' ) );
   983 	apply_filters( 'update_feedback', __( 'Disabling Maintenance mode&#8230;' ) );
   811 	// Remove maintenance file, we're done with potential site-breaking changes
   984 	// Remove maintenance file, we're done with potential site-breaking changes
   812 	$wp_filesystem->delete( $maintenance_file );
   985 	$wp_filesystem->delete( $maintenance_file );
   813 
   986 
   814 	// 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve.
   987 	// 3.5 -> 3.5+ - an empty twentytwelve directory was created upon upgrade to 3.5 for some users, preventing installation of Twenty Twelve.
   875 		if ( !$wp_filesystem->exists($old_file) )
  1048 		if ( !$wp_filesystem->exists($old_file) )
   876 			continue;
  1049 			continue;
   877 		$wp_filesystem->delete($old_file, true);
  1050 		$wp_filesystem->delete($old_file, true);
   878 	}
  1051 	}
   879 
  1052 
       
  1053 	// Remove any Genericons example.html's from the filesystem
       
  1054 	_upgrade_422_remove_genericons();
       
  1055 
   880 	// Upgrade DB with separate request
  1056 	// Upgrade DB with separate request
   881 	apply_filters('update_feedback', __('Upgrading database&#8230;'));
  1057 	/** This filter is documented in wp-admin/includes/update-core.php */
       
  1058 	apply_filters( 'update_feedback', __( 'Upgrading database&#8230;' ) );
   882 	$db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
  1059 	$db_upgrade_url = admin_url('upgrade.php?step=upgrade_db');
   883 	wp_remote_post($db_upgrade_url, array('timeout' => 60));
  1060 	wp_remote_post($db_upgrade_url, array('timeout' => 60));
       
  1061 
       
  1062 	// Clear the cache to prevent an update_option() from saving a stale db_version to the cache
       
  1063 	wp_cache_flush();
       
  1064 	// (Not all cache backends listen to 'flush')
       
  1065 	wp_cache_delete( 'alloptions', 'options' );
   884 
  1066 
   885 	// Remove working directory
  1067 	// Remove working directory
   886 	$wp_filesystem->delete($from, true);
  1068 	$wp_filesystem->delete($from, true);
   887 
  1069 
   888 	// Force refresh of update information
  1070 	// Force refresh of update information
   889 	if ( function_exists('delete_site_transient') )
  1071 	if ( function_exists('delete_site_transient') )
   890 		delete_site_transient('update_core');
  1072 		delete_site_transient('update_core');
   891 	else
  1073 	else
   892 		delete_option('update_core');
  1074 		delete_option('update_core');
   893 
  1075 
   894 	// If we made it this far:
  1076 	/**
       
  1077 	 * Fires after WordPress core has been successfully updated.
       
  1078 	 *
       
  1079 	 * @since 3.3.0
       
  1080 	 *
       
  1081 	 * @param string $wp_version The current WordPress version.
       
  1082 	 */
   895 	do_action( '_core_updated_successfully', $wp_version );
  1083 	do_action( '_core_updated_successfully', $wp_version );
   896 
  1084 
   897 	// Clear the option that blocks auto updates after failures, now that we've been successful.
  1085 	// Clear the option that blocks auto updates after failures, now that we've been successful.
   898 	if ( function_exists( 'delete_site_option' ) )
  1086 	if ( function_exists( 'delete_site_option' ) )
   899 		delete_site_option( 'auto_core_update_failed' );
  1087 		delete_site_option( 'auto_core_update_failed' );
   941 			if ( !$wp_filesystem->is_dir($to . $filename) ) {
  1129 			if ( !$wp_filesystem->is_dir($to . $filename) ) {
   942 				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
  1130 				if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
   943 					return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
  1131 					return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
   944 			}
  1132 			}
   945 
  1133 
   946 			// generate the $sub_skip_list for the subdirectory as a sub-set of the existing $skip_list
  1134 			/*
       
  1135 			 * Generate the $sub_skip_list for the subdirectory as a sub-set
       
  1136 			 * of the existing $skip_list.
       
  1137 			 */
   947 			$sub_skip_list = array();
  1138 			$sub_skip_list = array();
   948 			foreach ( $skip_list as $skip_item ) {
  1139 			foreach ( $skip_list as $skip_item ) {
   949 				if ( 0 === strpos( $skip_item, $filename . '/' ) )
  1140 				if ( 0 === strpos( $skip_item, $filename . '/' ) )
   950 					$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
  1141 					$sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
   951 			}
  1142 			}
   977 		return;
  1168 		return;
   978 
  1169 
   979  	if ( 'do-core-upgrade' != $action && 'do-core-reinstall' != $action )
  1170  	if ( 'do-core-upgrade' != $action && 'do-core-reinstall' != $action )
   980  		return;
  1171  		return;
   981 
  1172 
   982 	// Load the updated default text localization domain for new strings
  1173 	// Load the updated default text localization domain for new strings.
   983 	load_default_textdomain();
  1174 	load_default_textdomain();
   984 
  1175 
   985 	// See do_core_upgrade()
  1176 	// See do_core_upgrade()
   986 	show_message( __('WordPress updated successfully') );
  1177 	show_message( __('WordPress updated successfully') );
   987 
  1178 
   993 <script type="text/javascript">
  1184 <script type="text/javascript">
   994 window.location = 'about.php?updated';
  1185 window.location = 'about.php?updated';
   995 </script>
  1186 </script>
   996 	<?php
  1187 	<?php
   997 
  1188 
   998 	// Include admin-footer.php and exit
  1189 	// Include admin-footer.php and exit.
   999 	include(ABSPATH . 'wp-admin/admin-footer.php');
  1190 	include(ABSPATH . 'wp-admin/admin-footer.php');
  1000 	exit();
  1191 	exit();
  1001 }
  1192 }
  1002 add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
  1193 add_action( '_core_updated_successfully', '_redirect_to_about_wordpress' );
       
  1194 
       
  1195 /**
       
  1196  * Cleans up Genericons example files.
       
  1197  *
       
  1198  * @since 4.2.2
       
  1199  */
       
  1200 function _upgrade_422_remove_genericons() {
       
  1201 	global $wp_theme_directories, $wp_filesystem;
       
  1202 
       
  1203 	// A list of the affected files using the filesystem absolute paths.
       
  1204 	$affected_files = array();
       
  1205 
       
  1206 	// Themes
       
  1207 	foreach ( $wp_theme_directories as $directory ) {
       
  1208 		$affected_theme_files = _upgrade_422_find_genericons_files_in_folder( $directory );
       
  1209 		$affected_files       = array_merge( $affected_files, $affected_theme_files );
       
  1210 	}
       
  1211 
       
  1212 	// Plugins
       
  1213 	$affected_plugin_files = _upgrade_422_find_genericons_files_in_folder( WP_PLUGIN_DIR );
       
  1214 	$affected_files        = array_merge( $affected_files, $affected_plugin_files );
       
  1215 
       
  1216 	foreach ( $affected_files as $file ) {
       
  1217 		$gen_dir = $wp_filesystem->find_folder( trailingslashit( dirname( $file ) ) );
       
  1218 		if ( empty( $gen_dir ) ) {
       
  1219 			continue;
       
  1220 		}
       
  1221 
       
  1222 		// The path when the file is accessed via WP_Filesystem may differ in the case of FTP
       
  1223 		$remote_file = $gen_dir . basename( $file );
       
  1224 
       
  1225 		if ( ! $wp_filesystem->exists( $remote_file ) ) {
       
  1226 			continue;
       
  1227 		}
       
  1228 
       
  1229 		if ( ! $wp_filesystem->delete( $remote_file, false, 'f' ) ) {
       
  1230 			$wp_filesystem->put_contents( $remote_file, '' );
       
  1231 		}
       
  1232 	}
       
  1233 }
       
  1234 
       
  1235 /**
       
  1236  * Recursively find Genericons example files in a given folder.
       
  1237  *
       
  1238  * @ignore
       
  1239  * @since 4.2.2
       
  1240  *
       
  1241  * @param string $directory Directory path. Expects trailingslashed.
       
  1242  * @return array
       
  1243  */
       
  1244 function _upgrade_422_find_genericons_files_in_folder( $directory ) {
       
  1245 	$directory = trailingslashit( $directory );
       
  1246 	$files     = array();
       
  1247 
       
  1248 	if ( file_exists( "{$directory}example.html" ) && false !== strpos( file_get_contents( "{$directory}example.html" ), '<title>Genericons</title>' ) ) {
       
  1249 		$files[] = "{$directory}example.html";
       
  1250 	}
       
  1251 
       
  1252 	foreach ( glob( $directory . '*', GLOB_ONLYDIR ) as $dir ) {
       
  1253 		$files = array_merge( $files, _upgrade_422_find_genericons_files_in_folder( $dir ) );
       
  1254 	}
       
  1255 
       
  1256 	return $files;
       
  1257 }