+ // Don't copy wp-content, we'll deal with that below
+ $skip = array( 'wp-content' );
+ $check_is_writable = array();
+
+ // Check to see which files don't really need updating - only available for 3.7 and higher
+ if ( function_exists( 'get_core_checksums' ) ) {
+ $checksums = get_core_checksums( $wp_version, isset( $wp_local_package ) ? $wp_local_package : 'en_US' );
+ if ( is_array( $checksums ) && isset( $checksums[ $wp_version ] ) )
+ $checksums = $checksums[ $wp_version ]; // Compat code for 3.7-beta2
+ if ( is_array( $checksums ) ) {
+ foreach( $checksums as $file => $checksum ) {
+ if ( 'wp-content' == substr( $file, 0, 10 ) )
+ continue;
+ if ( ! file_exists( ABSPATH . $file ) )
+ continue;
+ if ( md5_file( ABSPATH . $file ) === $checksum )
+ $skip[] = $file;
+ else
+ $check_is_writable[ $file ] = ABSPATH . $file;
+ }
+ }
+ }
+
+ // If we're using the direct method, we can predict write failures that are due to permissions.
+ if ( $check_is_writable && 'direct' === $wp_filesystem->method ) {
+ $files_writable = array_filter( $check_is_writable, array( $wp_filesystem, 'is_writable' ) );
+ if ( $files_writable !== $check_is_writable ) {
+ $files_not_writable = array_diff_key( $check_is_writable, $files_writable );
+ foreach ( $files_not_writable as $relative_file_not_writable => $file_not_writable ) {
+ // If the writable check failed, chmod file to 0644 and try again, same as copy_dir().
+ $wp_filesystem->chmod( $file_not_writable, FS_CHMOD_FILE );
+ if ( $wp_filesystem->is_writable( $file_not_writable ) )
+ unset( $files_not_writable[ $relative_file_not_writable ] );
+ }
+
+ // Store package-relative paths (the key) of non-writable files in the WP_Error object.
+ $error_data = version_compare( $old_wp_version, '3.7-beta2', '>' ) ? array_keys( $files_not_writable ) : '';
+
+ if ( $files_not_writable )
+ 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 ) );
+ }
+ }
+
+ apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );