diff -r c7c34916027a -r 177826044cd9 wp/wp-admin/includes/class-theme-upgrader.php
--- a/wp/wp-admin/includes/class-theme-upgrader.php Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/includes/class-theme-upgrader.php Mon Oct 14 18:28:13 2019 +0200
@@ -43,15 +43,15 @@
* @since 2.8.0
*/
public function upgrade_strings() {
- $this->strings['up_to_date'] = __('The theme is at the latest version.');
- $this->strings['no_package'] = __('Update package not available.');
+ $this->strings['up_to_date'] = __( 'The theme is at the latest version.' );
+ $this->strings['no_package'] = __( 'Update package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading update from %s…' ), '%s' );
- $this->strings['unpack_package'] = __('Unpacking the update…');
- $this->strings['remove_old'] = __('Removing the old version of the theme…');
- $this->strings['remove_old_failed'] = __('Could not remove the old theme.');
- $this->strings['process_failed'] = __('Theme update failed.');
- $this->strings['process_success'] = __('Theme updated successfully.');
+ $this->strings['unpack_package'] = __( 'Unpacking the update…' );
+ $this->strings['remove_old'] = __( 'Removing the old version of the theme…' );
+ $this->strings['remove_old_failed'] = __( 'Could not remove the old theme.' );
+ $this->strings['process_failed'] = __( 'Theme update failed.' );
+ $this->strings['process_success'] = __( 'Theme updated successfully.' );
}
/**
@@ -60,23 +60,23 @@
* @since 2.8.0
*/
public function install_strings() {
- $this->strings['no_package'] = __('Installation package not available.');
+ $this->strings['no_package'] = __( 'Installation package not available.' );
/* translators: %s: package URL */
$this->strings['downloading_package'] = sprintf( __( 'Downloading installation package from %s…' ), '%s' );
- $this->strings['unpack_package'] = __('Unpacking the package…');
- $this->strings['installing_package'] = __('Installing the theme…');
- $this->strings['no_files'] = __('The theme contains no files.');
- $this->strings['process_failed'] = __('Theme installation failed.');
- $this->strings['process_success'] = __('Theme installed successfully.');
+ $this->strings['unpack_package'] = __( 'Unpacking the package…' );
+ $this->strings['installing_package'] = __( 'Installing the theme…' );
+ $this->strings['no_files'] = __( 'The theme contains no files.' );
+ $this->strings['process_failed'] = __( 'Theme installation failed.' );
+ $this->strings['process_success'] = __( 'Theme installed successfully.' );
/* translators: 1: theme name, 2: version */
- $this->strings['process_success_specific'] = __('Successfully installed the theme %1$s %2$s.');
- $this->strings['parent_theme_search'] = __('This theme requires a parent theme. Checking if it is installed…');
+ $this->strings['process_success_specific'] = __( 'Successfully installed the theme %1$s %2$s.' );
+ $this->strings['parent_theme_search'] = __( 'This theme requires a parent theme. Checking if it is installed…' );
/* translators: 1: theme name, 2: version */
- $this->strings['parent_theme_prepare_install'] = __('Preparing to install %1$s %2$s…');
+ $this->strings['parent_theme_prepare_install'] = __( 'Preparing to install %1$s %2$s…' );
/* translators: 1: theme name, 2: version */
- $this->strings['parent_theme_currently_installed'] = __('The parent theme, %1$s %2$s, is currently installed.');
+ $this->strings['parent_theme_currently_installed'] = __( 'The parent theme, %1$s %2$s, is currently installed.' );
/* translators: 1: theme name, 2: version */
- $this->strings['parent_theme_install_success'] = __('Successfully installed the parent theme, %1$s %2$s.');
+ $this->strings['parent_theme_install_success'] = __( 'Successfully installed the parent theme, %1$s %2$s.' );
/* translators: %s: theme name */
$this->strings['parent_theme_not_found'] = sprintf( __( 'The parent theme could not be found. You will need to install the parent theme, %s, before you can use this child theme.' ), '%s' );
}
@@ -97,56 +97,69 @@
// Check to see if we need to install a parent theme
$theme_info = $this->theme_info();
- if ( ! $theme_info->parent() )
+ if ( ! $theme_info->parent() ) {
return $install_result;
+ }
$this->skin->feedback( 'parent_theme_search' );
if ( ! $theme_info->parent()->errors() ) {
- $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display('Name'), $theme_info->parent()->display('Version') );
+ $this->skin->feedback( 'parent_theme_currently_installed', $theme_info->parent()->display( 'Name' ), $theme_info->parent()->display( 'Version' ) );
// We already have the theme, fall through.
return $install_result;
}
// We don't have the parent theme, let's install it.
- $api = themes_api('theme_information', array('slug' => $theme_info->get('Template'), 'fields' => array('sections' => false, 'tags' => false) ) ); //Save on a bit of bandwidth.
+ $api = themes_api(
+ 'theme_information',
+ array(
+ 'slug' => $theme_info->get( 'Template' ),
+ 'fields' => array(
+ 'sections' => false,
+ 'tags' => false,
+ ),
+ )
+ ); //Save on a bit of bandwidth.
- if ( ! $api || is_wp_error($api) ) {
- $this->skin->feedback( 'parent_theme_not_found', $theme_info->get('Template') );
+ if ( ! $api || is_wp_error( $api ) ) {
+ $this->skin->feedback( 'parent_theme_not_found', $theme_info->get( 'Template' ) );
// Don't show activate or preview actions after installation
- add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') );
+ add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
return $install_result;
}
// Backup required data we're going to override:
- $child_api = $this->skin->api;
+ $child_api = $this->skin->api;
$child_success_message = $this->strings['process_success'];
// Override them
- $this->skin->api = $api;
+ $this->skin->api = $api;
$this->strings['process_success_specific'] = $this->strings['parent_theme_install_success'];//, $api->name, $api->version);
- $this->skin->feedback('parent_theme_prepare_install', $api->name, $api->version);
+ $this->skin->feedback( 'parent_theme_prepare_install', $api->name, $api->version );
- add_filter('install_theme_complete_actions', '__return_false', 999); // Don't show any actions after installing the theme.
+ add_filter( 'install_theme_complete_actions', '__return_false', 999 ); // Don't show any actions after installing the theme.
// Install the parent theme
- $parent_result = $this->run( array(
- 'package' => $api->download_link,
- 'destination' => get_theme_root(),
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true
- ) );
+ $parent_result = $this->run(
+ array(
+ 'package' => $api->download_link,
+ 'destination' => get_theme_root(),
+ 'clear_destination' => false, //Do not overwrite files.
+ 'clear_working' => true,
+ )
+ );
- if ( is_wp_error($parent_result) )
- add_filter('install_theme_complete_actions', array($this, 'hide_activate_preview_actions') );
+ if ( is_wp_error( $parent_result ) ) {
+ add_filter( 'install_theme_complete_actions', array( $this, 'hide_activate_preview_actions' ) );
+ }
// Start cleaning up after the parents installation
- remove_filter('install_theme_complete_actions', '__return_false', 999);
+ remove_filter( 'install_theme_complete_actions', '__return_false', 999 );
// Reset child's result and data
- $this->result = $child_result;
- $this->skin->api = $child_api;
+ $this->result = $child_result;
+ $this->skin->api = $child_api;
$this->strings['process_success'] = $child_success_message;
return $install_result;
@@ -165,7 +178,7 @@
* @return array
*/
public function hide_activate_preview_actions( $actions ) {
- unset($actions['activate'], $actions['preview']);
+ unset( $actions['activate'], $actions['preview'] );
return $actions;
}
@@ -187,7 +200,7 @@
*/
public function install( $package, $args = array() ) {
- $defaults = array(
+ $defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@@ -195,30 +208,33 @@
$this->init();
$this->install_strings();
- add_filter('upgrader_source_selection', array($this, 'check_package') );
- add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3);
+ add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
+ add_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ), 10, 3 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
- $this->run( array(
- 'package' => $package,
- 'destination' => get_theme_root(),
- 'clear_destination' => false, //Do not overwrite files.
- 'clear_working' => true,
- 'hook_extra' => array(
- 'type' => 'theme',
- 'action' => 'install',
- ),
- ) );
+ $this->run(
+ array(
+ 'package' => $package,
+ 'destination' => get_theme_root(),
+ 'clear_destination' => false, //Do not overwrite files.
+ 'clear_working' => true,
+ 'hook_extra' => array(
+ 'type' => 'theme',
+ 'action' => 'install',
+ ),
+ )
+ );
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
- remove_filter('upgrader_source_selection', array($this, 'check_package') );
- remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'));
+ remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
+ remove_filter( 'upgrader_post_install', array( $this, 'check_parent_theme_filter' ) );
- if ( ! $this->result || is_wp_error($this->result) )
+ if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
+ }
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
@@ -243,7 +259,7 @@
*/
public function upgrade( $theme, $args = array() ) {
- $defaults = array(
+ $defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@@ -253,9 +269,9 @@
// Is an update available?
$current = get_site_transient( 'update_themes' );
- if ( !isset( $current->response[ $theme ] ) ) {
+ if ( ! isset( $current->response[ $theme ] ) ) {
$this->skin->before();
- $this->skin->set_result(false);
+ $this->skin->set_result( false );
$this->skin->error( 'up_to_date' );
$this->skin->after();
return false;
@@ -263,33 +279,36 @@
$r = $current->response[ $theme ];
- add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2);
- add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
- add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
+ add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
+ add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
+ add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_themes() knows about the new theme.
add_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9, 0 );
}
- $this->run( array(
- 'package' => $r['package'],
- 'destination' => get_theme_root( $theme ),
- 'clear_destination' => true,
- 'clear_working' => true,
- 'hook_extra' => array(
- 'theme' => $theme,
- 'type' => 'theme',
- 'action' => 'update',
- ),
- ) );
+ $this->run(
+ array(
+ 'package' => $r['package'],
+ 'destination' => get_theme_root( $theme ),
+ 'clear_destination' => true,
+ 'clear_working' => true,
+ 'hook_extra' => array(
+ 'theme' => $theme,
+ 'type' => 'theme',
+ 'action' => 'update',
+ ),
+ )
+ );
remove_action( 'upgrader_process_complete', 'wp_clean_themes_cache', 9 );
- remove_filter('upgrader_pre_install', array($this, 'current_before'));
- remove_filter('upgrader_post_install', array($this, 'current_after'));
- remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
+ remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
+ remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
+ remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
- if ( ! $this->result || is_wp_error($this->result) )
+ if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
+ }
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
@@ -302,8 +321,8 @@
* @since 3.0.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
*
- * @param array $themes The theme slugs.
- * @param array $args {
+ * @param string[] $themes Array of the theme slugs.
+ * @param array $args {
* Optional. Other arguments for upgrading several themes at once. Default empty array.
*
* @type bool $clear_update_cache Whether to clear the update cache if successful.
@@ -313,7 +332,7 @@
*/
public function bulk_upgrade( $themes, $args = array() ) {
- $defaults = array(
+ $defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
@@ -324,14 +343,14 @@
$current = get_site_transient( 'update_themes' );
- add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2);
- add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2);
- add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4);
+ add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );
+ add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );
+ add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 );
$this->skin->header();
// Connect to the Filesystem first.
- $res = $this->fs_connect( array(WP_CONTENT_DIR) );
+ $res = $this->fs_connect( array( WP_CONTENT_DIR ) );
if ( ! $res ) {
$this->skin->footer();
return false;
@@ -344,71 +363,80 @@
// - a theme with an update available is currently in use.
// @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
$maintenance = ( is_multisite() && ! empty( $themes ) );
- foreach ( $themes as $theme )
+ foreach ( $themes as $theme ) {
$maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template();
- if ( $maintenance )
- $this->maintenance_mode(true);
+ }
+ if ( $maintenance ) {
+ $this->maintenance_mode( true );
+ }
$results = array();
- $this->update_count = count($themes);
+ $this->update_count = count( $themes );
$this->update_current = 0;
foreach ( $themes as $theme ) {
$this->update_current++;
- $this->skin->theme_info = $this->theme_info($theme);
+ $this->skin->theme_info = $this->theme_info( $theme );
- if ( !isset( $current->response[ $theme ] ) ) {
- $this->skin->set_result(true);
+ if ( ! isset( $current->response[ $theme ] ) ) {
+ $this->skin->set_result( true );
$this->skin->before();
$this->skin->feedback( 'up_to_date' );
$this->skin->after();
- $results[$theme] = true;
+ $results[ $theme ] = true;
continue;
}
// Get the URL to the zip file
$r = $current->response[ $theme ];
- $result = $this->run( array(
- 'package' => $r['package'],
- 'destination' => get_theme_root( $theme ),
- 'clear_destination' => true,
- 'clear_working' => true,
- 'is_multi' => true,
- 'hook_extra' => array(
- 'theme' => $theme
- ),
- ) );
+ $result = $this->run(
+ array(
+ 'package' => $r['package'],
+ 'destination' => get_theme_root( $theme ),
+ 'clear_destination' => true,
+ 'clear_working' => true,
+ 'is_multi' => true,
+ 'hook_extra' => array(
+ 'theme' => $theme,
+ ),
+ )
+ );
- $results[$theme] = $this->result;
+ $results[ $theme ] = $this->result;
// Prevent credentials auth screen from displaying multiple times
- if ( false === $result )
+ if ( false === $result ) {
break;
+ }
} //end foreach $plugins
- $this->maintenance_mode(false);
+ $this->maintenance_mode( false );
// Refresh the Theme Update information
wp_clean_themes_cache( $parsed_args['clear_update_cache'] );
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
- do_action( 'upgrader_process_complete', $this, array(
- 'action' => 'update',
- 'type' => 'theme',
- 'bulk' => true,
- 'themes' => $themes,
- ) );
+ do_action(
+ 'upgrader_process_complete',
+ $this,
+ array(
+ 'action' => 'update',
+ 'type' => 'theme',
+ 'bulk' => true,
+ 'themes' => $themes,
+ )
+ );
$this->skin->bulk_footer();
$this->skin->footer();
// Cleanup our hooks, in case something else does a upgrade on this connection.
- remove_filter('upgrader_pre_install', array($this, 'current_before'));
- remove_filter('upgrader_post_install', array($this, 'current_after'));
- remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme'));
+ remove_filter( 'upgrader_pre_install', array( $this, 'current_before' ) );
+ remove_filter( 'upgrader_post_install', array( $this, 'current_after' ) );
+ remove_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ) );
return $results;
}
@@ -422,7 +450,7 @@
*
* @since 3.3.0
*
- * @global WP_Filesystem_Base $wp_filesystem Subclass
+ * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param string $source The full path to the package source.
* @return string|WP_Error The source or a WP_Error.
@@ -430,30 +458,44 @@
public function check_package( $source ) {
global $wp_filesystem;
- if ( is_wp_error($source) )
+ if ( is_wp_error( $source ) ) {
return $source;
+ }
// Check the folder contains a valid theme
- $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
- if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
+ if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
return $source;
+ }
// A proper archive should have a style.css file in the single subdirectory
if ( ! file_exists( $working_directory . 'style.css' ) ) {
- return new WP_Error( 'incompatible_archive_theme_no_style', $this->strings['incompatible_archive'],
- /* translators: %s: style.css */
- sprintf( __( 'The theme is missing the %s stylesheet.' ),
+ return new WP_Error(
+ 'incompatible_archive_theme_no_style',
+ $this->strings['incompatible_archive'],
+ sprintf(
+ /* translators: %s: style.css */
+ __( 'The theme is missing the %s stylesheet.' ),
'style.css
'
)
);
}
- $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
+ $info = get_file_data(
+ $working_directory . 'style.css',
+ array(
+ 'Name' => 'Theme Name',
+ 'Template' => 'Template',
+ )
+ );
if ( empty( $info['Name'] ) ) {
- return new WP_Error( 'incompatible_archive_theme_no_name', $this->strings['incompatible_archive'],
- /* translators: %s: style.css */
- sprintf( __( 'The %s stylesheet doesn’t contain a valid theme header.' ),
+ return new WP_Error(
+ 'incompatible_archive_theme_no_name',
+ $this->strings['incompatible_archive'],
+ sprintf(
+ /* translators: %s: style.css */
+ __( 'The %s stylesheet doesn’t contain a valid theme header.' ),
'style.css
'
)
);
@@ -461,9 +503,12 @@
// If it's not a child theme, it must have at least an index.php to be legit.
if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) ) {
- return new WP_Error( 'incompatible_archive_theme_no_index', $this->strings['incompatible_archive'],
- /* translators: %s: index.php */
- sprintf( __( 'The theme is missing the %s file.' ),
+ return new WP_Error(
+ 'incompatible_archive_theme_no_index',
+ $this->strings['incompatible_archive'],
+ sprintf(
+ /* translators: %s: index.php */
+ __( 'The theme is missing the %s file.' ),
'index.php
'
)
);
@@ -484,17 +529,20 @@
* @param array $theme
* @return bool|WP_Error
*/
- public function current_before($return, $theme) {
- if ( is_wp_error($return) )
+ public function current_before( $return, $theme ) {
+ if ( is_wp_error( $return ) ) {
return $return;
+ }
- $theme = isset($theme['theme']) ? $theme['theme'] : '';
+ $theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
- if ( $theme != get_stylesheet() ) //If not current
+ if ( $theme != get_stylesheet() ) { //If not current
return $return;
+ }
//Change to maintenance mode now.
- if ( ! $this->bulk )
- $this->maintenance_mode(true);
+ if ( ! $this->bulk ) {
+ $this->maintenance_mode( true );
+ }
return $return;
}
@@ -511,14 +559,16 @@
* @param array $theme
* @return bool|WP_Error
*/
- public function current_after($return, $theme) {
- if ( is_wp_error($return) )
+ public function current_after( $return, $theme ) {
+ if ( is_wp_error( $return ) ) {
return $return;
+ }
- $theme = isset($theme['theme']) ? $theme['theme'] : '';
+ $theme = isset( $theme['theme'] ) ? $theme['theme'] : '';
- if ( $theme != get_stylesheet() ) // If not current
+ if ( $theme != get_stylesheet() ) { // If not current
return $return;
+ }
// Ensure stylesheet name hasn't changed after the upgrade:
if ( $theme == get_stylesheet() && $theme != $this->result['destination_name'] ) {
@@ -528,8 +578,9 @@
}
//Time to remove maintenance mode
- if ( ! $this->bulk )
- $this->maintenance_mode(false);
+ if ( ! $this->bulk ) {
+ $this->maintenance_mode( false );
+ }
return $return;
}
@@ -552,17 +603,20 @@
public function delete_old_theme( $removed, $local_destination, $remote_destination, $theme ) {
global $wp_filesystem;
- if ( is_wp_error( $removed ) )
+ if ( is_wp_error( $removed ) ) {
return $removed; // Pass errors through.
+ }
- if ( ! isset( $theme['theme'] ) )
+ if ( ! isset( $theme['theme'] ) ) {
return $removed;
+ }
- $theme = $theme['theme'];
+ $theme = $theme['theme'];
$themes_dir = trailingslashit( $wp_filesystem->wp_themes_dir( $theme ) );
if ( $wp_filesystem->exists( $themes_dir . $theme ) ) {
- if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) )
+ if ( ! $wp_filesystem->delete( $themes_dir . $theme, true ) ) {
return false;
+ }
}
return true;
@@ -579,13 +633,14 @@
* @return WP_Theme|false The theme's info object, or false `$theme` is not supplied
* and the last result isn't set.
*/
- public function theme_info($theme = null) {
+ public function theme_info( $theme = null ) {
- if ( empty($theme) ) {
- if ( !empty($this->result['destination_name']) )
+ if ( empty( $theme ) ) {
+ if ( ! empty( $this->result['destination_name'] ) ) {
$theme = $this->result['destination_name'];
- else
+ } else {
return false;
+ }
}
return wp_get_theme( $theme );
}