2016-05-10 07:45:42 -04:00
< ? php
/**
2016-05-10 07:52:28 -04:00
* Upgrade API : Theme_Upgrader class
2016-05-10 07:45:42 -04:00
*
* @ package WordPress
* @ subpackage Upgrader
2016-05-10 07:52:28 -04:00
* @ since 4.6 . 0
2016-05-10 07:45:42 -04:00
*/
/**
* Core class used for upgrading / installing themes .
*
* It is designed to upgrade / install themes from a local zip , remote zip URL ,
* or uploaded zip file .
*
* @ since 2.8 . 0
2016-05-13 16:59:27 -04:00
* @ since 4.6 . 0 Moved to its own file from wp - admin / includes / class - wp - upgrader . php .
2016-05-10 07:45:42 -04:00
*
* @ see WP_Upgrader
*/
class Theme_Upgrader extends WP_Upgrader {
/**
* Result of the theme upgrade offer .
*
* @ since 2.8 . 0
* @ var array | WP_Error $result
* @ see WP_Upgrader :: $result
*/
public $result ;
/**
* Whether multiple themes are being upgraded / installed in bulk .
*
* @ since 2.9 . 0
* @ var bool $bulk
*/
public $bulk = false ;
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
/**
* New theme info .
*
* @ since 5.5 . 0
* @ var array $new_theme_data
*
* @ see check_package ()
*/
public $new_theme_data = array ();
2016-05-10 07:45:42 -04:00
/**
* Initialize the upgrade strings .
*
* @ since 2.8 . 0
*/
public function upgrade_strings () {
2017-11-30 18:11:00 -05:00
$this -> strings [ 'up_to_date' ] = __ ( 'The theme is at the latest version.' );
$this -> strings [ 'no_package' ] = __ ( 'Update package not available.' );
2019-09-02 20:41:05 -04:00
/* translators: %s: Package URL. */
2017-10-18 13:15:47 -04:00
$this -> strings [ 'downloading_package' ] = sprintf ( __ ( 'Downloading update from %s…' ), '<span class="code">%s</span>' );
2017-11-30 18:11:00 -05:00
$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.' );
2016-05-10 07:45:42 -04:00
}
/**
2017-08-22 07:52:48 -04:00
* Initialize the installation strings .
2016-05-10 07:45:42 -04:00
*
* @ since 2.8 . 0
*/
public function install_strings () {
2017-11-30 18:11:00 -05:00
$this -> strings [ 'no_package' ] = __ ( 'Installation package not available.' );
2019-09-02 20:41:05 -04:00
/* translators: %s: Package URL. */
2017-10-18 13:15:47 -04:00
$this -> strings [ 'downloading_package' ] = sprintf ( __ ( 'Downloading installation package from %s…' ), '<span class="code">%s</span>' );
2017-11-30 18:11:00 -05:00
$this -> strings [ 'unpack_package' ] = __ ( 'Unpacking the package…' );
$this -> strings [ 'installing_package' ] = __ ( 'Installing the theme…' );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$this -> strings [ 'remove_old' ] = __ ( 'Removing the old version of the theme…' );
$this -> strings [ 'remove_old_failed' ] = __ ( 'Could not remove the old theme.' );
2017-11-30 18:11:00 -05:00
$this -> strings [ 'no_files' ] = __ ( 'The theme contains no files.' );
$this -> strings [ 'process_failed' ] = __ ( 'Theme installation failed.' );
$this -> strings [ 'process_success' ] = __ ( 'Theme installed successfully.' );
2019-09-02 20:41:05 -04:00
/* translators: 1: Theme name, 2: Theme version. */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'process_success_specific' ] = __ ( 'Successfully installed the theme <strong>%1$s %2$s</strong>.' );
$this -> strings [ 'parent_theme_search' ] = __ ( 'This theme requires a parent theme. Checking if it is installed…' );
2019-09-02 20:41:05 -04:00
/* translators: 1: Theme name, 2: Theme version. */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_prepare_install' ] = __ ( 'Preparing to install <strong>%1$s %2$s</strong>…' );
2019-09-02 20:41:05 -04:00
/* translators: 1: Theme name, 2: Theme version. */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_currently_installed' ] = __ ( 'The parent theme, <strong>%1$s %2$s</strong>, is currently installed.' );
2019-09-02 20:41:05 -04:00
/* translators: 1: Theme name, 2: Theme version. */
2017-11-30 18:11:00 -05:00
$this -> strings [ 'parent_theme_install_success' ] = __ ( 'Successfully installed the parent theme, <strong>%1$s %2$s</strong>.' );
2019-09-02 20:41:05 -04:00
/* translators: %s: Theme name. */
2017-10-18 13:20:48 -04:00
$this -> strings [ 'parent_theme_not_found' ] = sprintf ( __ ( '<strong>The parent theme could not be found.</strong> You will need to install the parent theme, %s, before you can use this child theme.' ), '<strong>%s</strong>' );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
/* translators: %s: Theme error. */
2022-01-15 03:44:03 -05:00
$this -> strings [ 'current_theme_has_errors' ] = __ ( 'The active theme has the following error: "%s".' );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
2020-07-16 09:19:03 -04:00
if ( ! empty ( $this -> skin -> overwrite ) ) {
if ( 'update-theme' === $this -> skin -> overwrite ) {
$this -> strings [ 'installing_package' ] = __ ( 'Updating the theme…' );
$this -> strings [ 'process_failed' ] = __ ( 'Theme update failed.' );
$this -> strings [ 'process_success' ] = __ ( 'Theme updated successfully.' );
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
2020-07-16 09:19:03 -04:00
if ( 'downgrade-theme' === $this -> skin -> overwrite ) {
$this -> strings [ 'installing_package' ] = __ ( 'Downgrading the theme…' );
$this -> strings [ 'process_failed' ] = __ ( 'Theme downgrade failed.' );
$this -> strings [ 'process_success' ] = __ ( 'Theme downgraded successfully.' );
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
}
2016-05-10 07:45:42 -04:00
}
/**
* Check if a child theme is being installed and we need to install its parent .
*
* Hooked to the { @ see 'upgrader_post_install' } filter by Theme_Upgrader :: install () .
*
* @ since 3.4 . 0
*
* @ param bool $install_result
* @ param array $hook_extra
* @ param array $child_result
2020-01-10 21:46:05 -05:00
* @ return bool
2016-05-10 07:45:42 -04:00
*/
public function check_parent_theme_filter ( $install_result , $hook_extra , $child_result ) {
2020-01-28 19:45:18 -05:00
// Check to see if we need to install a parent theme.
2016-05-10 07:45:42 -04:00
$theme_info = $this -> theme_info ();
2017-11-30 18:11:00 -05:00
if ( ! $theme_info -> parent () ) {
2016-05-10 07:45:42 -04:00
return $install_result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
$this -> skin -> feedback ( 'parent_theme_search' );
if ( ! $theme_info -> parent () -> errors () ) {
2017-11-30 18:11:00 -05:00
$this -> skin -> feedback ( 'parent_theme_currently_installed' , $theme_info -> parent () -> display ( 'Name' ), $theme_info -> parent () -> display ( 'Version' ) );
2016-05-10 07:45:42 -04:00
// We already have the theme, fall through.
return $install_result ;
}
// We don't have the parent theme, let's install it.
2017-11-30 18:11:00 -05:00
$api = themes_api (
2018-08-16 21:51:36 -04:00
'theme_information' ,
array (
2017-11-30 18:11:00 -05:00
'slug' => $theme_info -> get ( 'Template' ),
'fields' => array (
'sections' => false ,
'tags' => false ,
),
)
2020-01-28 19:45:18 -05:00
); // Save on a bit of bandwidth.
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $api || is_wp_error ( $api ) ) {
$this -> skin -> feedback ( 'parent_theme_not_found' , $theme_info -> get ( 'Template' ) );
2020-01-28 19:45:18 -05:00
// Don't show activate or preview actions after installation.
2017-11-30 18:11:00 -05:00
add_filter ( 'install_theme_complete_actions' , array ( $this , 'hide_activate_preview_actions' ) );
2016-05-10 07:45:42 -04:00
return $install_result ;
}
// Backup required data we're going to override:
2017-11-30 18:11:00 -05:00
$child_api = $this -> skin -> api ;
2016-05-10 07:45:42 -04:00
$child_success_message = $this -> strings [ 'process_success' ];
2020-01-28 19:45:18 -05:00
// Override them.
$this -> skin -> api = $api ;
2020-08-04 13:54:04 -04:00
$this -> strings [ 'process_success_specific' ] = $this -> strings [ 'parent_theme_install_success' ];
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> skin -> feedback ( 'parent_theme_prepare_install' , $api -> name , $api -> version );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
add_filter ( 'install_theme_complete_actions' , '__return_false' , 999 ); // Don't show any actions after installing the theme.
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Install the parent theme.
2017-11-30 18:11:00 -05:00
$parent_result = $this -> run (
array (
'package' => $api -> download_link ,
'destination' => get_theme_root (),
2020-01-28 19:45:18 -05:00
'clear_destination' => false , // Do not overwrite files.
2017-11-30 18:11:00 -05:00
'clear_working' => true ,
)
);
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $parent_result ) ) {
add_filter ( 'install_theme_complete_actions' , array ( $this , 'hide_activate_preview_actions' ) );
}
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Start cleaning up after the parent's installation.
2017-11-30 18:11:00 -05:00
remove_filter ( 'install_theme_complete_actions' , '__return_false' , 999 );
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Reset child's result and data.
2017-11-30 18:11:00 -05:00
$this -> result = $child_result ;
$this -> skin -> api = $child_api ;
2016-05-10 07:45:42 -04:00
$this -> strings [ 'process_success' ] = $child_success_message ;
return $install_result ;
}
/**
* Don ' t display the activate and preview actions to the user .
*
* Hooked to the { @ see 'install_theme_complete_actions' } filter by
* Theme_Upgrader :: check_parent_theme_filter () when installing
* a child theme and installing the parent theme fails .
*
* @ since 3.4 . 0
*
* @ param array $actions Preview actions .
* @ return array
*/
public function hide_activate_preview_actions ( $actions ) {
2017-11-30 18:11:00 -05:00
unset ( $actions [ 'activate' ], $actions [ 'preview' ] );
2016-05-10 07:45:42 -04:00
return $actions ;
}
/**
* Install a theme package .
*
* @ since 2.8 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
* @ param string $package The full local path or URI of the package .
* @ param array $args {
* Optional . Other arguments for installing a theme package . Default empty array .
*
* @ type bool $clear_update_cache Whether to clear the updates cache if successful .
* Default true .
* }
*
2017-08-22 07:52:48 -04:00
* @ return bool | WP_Error True if the installation was successful , false or a WP_Error object otherwise .
2016-05-10 07:45:42 -04:00
*/
public function install ( $package , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
'overwrite_package' => false , // Do not overwrite files.
2016-05-10 07:45:42 -04:00
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> install_strings ();
2017-11-30 18:11:00 -05:00
add_filter ( 'upgrader_source_selection' , array ( $this , 'check_package' ) );
add_filter ( 'upgrader_post_install' , array ( $this , 'check_parent_theme_filter' ), 10 , 3 );
2020-07-29 09:09:04 -04:00
2016-11-13 04:53:32 -05:00
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 );
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> run (
array (
'package' => $package ,
'destination' => get_theme_root (),
2020-07-29 09:09:04 -04:00
'clear_destination' => $parsed_args [ 'overwrite_package' ],
2017-11-30 18:11:00 -05:00
'clear_working' => true ,
'hook_extra' => array (
'type' => 'theme' ,
'action' => 'install' ,
),
)
);
2016-05-10 07:45:42 -04:00
remove_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 );
2017-11-30 18:11:00 -05:00
remove_filter ( 'upgrader_source_selection' , array ( $this , 'check_package' ) );
remove_filter ( 'upgrader_post_install' , array ( $this , 'check_parent_theme_filter' ) );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
2016-05-10 07:45:42 -04:00
return $this -> result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Refresh the Theme Update information.
2016-05-10 07:45:42 -04:00
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
if ( $parsed_args [ 'overwrite_package' ] ) {
2020-12-10 18:38:04 -05:00
/** This action is documented in wp-admin/includes/class-plugin-upgrader.php */
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
do_action ( 'upgrader_overwrote_package' , $package , $this -> new_theme_data , 'theme' );
}
2016-05-10 07:45:42 -04:00
return true ;
}
/**
* Upgrade a theme .
*
* @ since 2.8 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
* @ param string $theme The theme slug .
* @ param array $args {
* Optional . Other arguments for upgrading a theme . Default empty array .
*
* @ type bool $clear_update_cache Whether to clear the update cache if successful .
* Default true .
* }
* @ return bool | WP_Error True if the upgrade was successful , false or a WP_Error object otherwise .
*/
public function upgrade ( $theme , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> upgrade_strings ();
// Is an update available?
$current = get_site_transient ( 'update_themes' );
2017-11-30 18:11:00 -05:00
if ( ! isset ( $current -> response [ $theme ] ) ) {
2016-05-10 07:45:42 -04:00
$this -> skin -> before ();
2017-11-30 18:11:00 -05:00
$this -> skin -> set_result ( false );
2016-05-10 07:45:42 -04:00
$this -> skin -> error ( 'up_to_date' );
$this -> skin -> after ();
return false ;
}
$r = $current -> response [ $theme ];
2017-11-30 18:11:00 -05:00
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 );
2016-11-13 04:53:32 -05:00
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 );
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> run (
array (
'package' => $r [ 'package' ],
'destination' => get_theme_root ( $theme ),
'clear_destination' => true ,
'clear_working' => true ,
'hook_extra' => array (
Upgrade/install: Revert upgrader rollback features.
Revert the rollback features introduced for theme and plugin upgrades during the WordPress 5.9 cycle. A bug (suspected to be in third party virtualisation software) causes the upgrades to fail consistently on some set ups. The revert is to allow contributors further time to investigate mitigation options.
Reverts [52337], [52289], [52284], [51951], [52192], [51902], [51899], [51898], [51815].
Props pbiron, dlh, peterwilsoncc, galbaras, SergeyBiryukov, afragen, costdev, bronsonquick, aristath, noisysocks, desrosj, TobiasBg, hellofromTonya, francina, Boniu91.
See #54543, #54166, #51857.
Built from https://develop.svn.wordpress.org/trunk@52351
git-svn-id: http://core.svn.wordpress.org/trunk@51943 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-09 19:06:04 -05:00
'theme' => $theme ,
'type' => 'theme' ,
'action' => 'update' ,
2017-11-30 18:11:00 -05:00
),
)
);
2016-05-10 07:45:42 -04:00
remove_action ( 'upgrader_process_complete' , 'wp_clean_themes_cache' , 9 );
2017-11-30 18:11:00 -05:00
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' ) );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! $this -> result || is_wp_error ( $this -> result ) ) {
2016-05-10 07:45:42 -04:00
return $this -> result ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
2020-07-11 21:19:03 -04:00
// Ensure any future auto-update failures trigger a failure email by removing
// the last failure notification from the list when themes update successfully.
2020-07-07 15:00:02 -04:00
$past_failure_emails = get_option ( 'auto_plugin_theme_update_emails' , array () );
if ( isset ( $past_failure_emails [ $theme ] ) ) {
unset ( $past_failure_emails [ $theme ] );
update_option ( 'auto_plugin_theme_update_emails' , $past_failure_emails );
}
2016-05-10 07:45:42 -04:00
return true ;
}
/**
* Upgrade several themes at once .
*
* @ since 3.0 . 0
* @ since 3.7 . 0 The `$args` parameter was added , making clearing the update cache optional .
*
2018-03-22 16:27:32 -04:00
* @ param string [] $themes Array of the theme slugs .
* @ param array $args {
2016-05-10 07:45:42 -04:00
* 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 .
* Default true .
* }
* @ return array [] | false An array of results , or false if unable to connect to the filesystem .
*/
public function bulk_upgrade ( $themes , $args = array () ) {
2017-11-30 18:11:00 -05:00
$defaults = array (
2016-05-10 07:45:42 -04:00
'clear_update_cache' => true ,
);
$parsed_args = wp_parse_args ( $args , $defaults );
$this -> init ();
$this -> bulk = true ;
$this -> upgrade_strings ();
$current = get_site_transient ( 'update_themes' );
2017-11-30 18:11:00 -05:00
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 );
2016-05-10 07:45:42 -04:00
$this -> skin -> header ();
2020-01-28 19:45:18 -05:00
// Connect to the filesystem first.
2017-11-30 18:11:00 -05:00
$res = $this -> fs_connect ( array ( WP_CONTENT_DIR ) );
2016-05-10 07:45:42 -04:00
if ( ! $res ) {
$this -> skin -> footer ();
return false ;
}
$this -> skin -> bulk_header ();
2020-01-28 19:45:18 -05:00
/*
* Only start maintenance mode if :
* - running Multisite and there are one or more themes specified , OR
* - 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 .
*/
2016-05-10 07:45:42 -04:00
$maintenance = ( is_multisite () && ! empty ( $themes ) );
2017-11-30 18:11:00 -05:00
foreach ( $themes as $theme ) {
2020-02-09 11:55:09 -05:00
$maintenance = $maintenance || get_stylesheet () === $theme || get_template () === $theme ;
2017-11-30 18:11:00 -05:00
}
if ( $maintenance ) {
$this -> maintenance_mode ( true );
}
2016-05-10 07:45:42 -04:00
$results = array ();
2017-11-30 18:11:00 -05:00
$this -> update_count = count ( $themes );
2016-05-10 07:45:42 -04:00
$this -> update_current = 0 ;
foreach ( $themes as $theme ) {
$this -> update_current ++ ;
2017-11-30 18:11:00 -05:00
$this -> skin -> theme_info = $this -> theme_info ( $theme );
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $current -> response [ $theme ] ) ) {
$this -> skin -> set_result ( true );
2016-05-10 07:45:42 -04:00
$this -> skin -> before ();
$this -> skin -> feedback ( 'up_to_date' );
$this -> skin -> after ();
2017-11-30 18:11:00 -05:00
$results [ $theme ] = true ;
2016-05-10 07:45:42 -04:00
continue ;
}
2020-01-28 19:45:18 -05:00
// Get the URL to the zip file.
2016-05-10 07:45:42 -04:00
$r = $current -> response [ $theme ];
2017-11-30 18:11:00 -05:00
$result = $this -> run (
array (
'package' => $r [ 'package' ],
'destination' => get_theme_root ( $theme ),
'clear_destination' => true ,
'clear_working' => true ,
'is_multi' => true ,
'hook_extra' => array (
Upgrade/install: Revert upgrader rollback features.
Revert the rollback features introduced for theme and plugin upgrades during the WordPress 5.9 cycle. A bug (suspected to be in third party virtualisation software) causes the upgrades to fail consistently on some set ups. The revert is to allow contributors further time to investigate mitigation options.
Reverts [52337], [52289], [52284], [51951], [52192], [51902], [51899], [51898], [51815].
Props pbiron, dlh, peterwilsoncc, galbaras, SergeyBiryukov, afragen, costdev, bronsonquick, aristath, noisysocks, desrosj, TobiasBg, hellofromTonya, francina, Boniu91.
See #54543, #54166, #51857.
Built from https://develop.svn.wordpress.org/trunk@52351
git-svn-id: http://core.svn.wordpress.org/trunk@51943 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-09 19:06:04 -05:00
'theme' => $theme ,
2017-11-30 18:11:00 -05:00
),
)
);
2016-05-10 07:45:42 -04:00
2021-08-02 16:55:56 -04:00
$results [ $theme ] = $result ;
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Prevent credentials auth screen from displaying multiple times.
2017-11-30 18:11:00 -05:00
if ( false === $result ) {
2016-05-10 07:45:42 -04:00
break ;
2017-11-30 18:11:00 -05:00
}
2020-01-28 19:45:18 -05:00
} // End foreach $themes.
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$this -> maintenance_mode ( false );
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Refresh the Theme Update information.
2016-11-13 04:53:32 -05:00
wp_clean_themes_cache ( $parsed_args [ 'clear_update_cache' ] );
2016-05-10 07:45:42 -04:00
/** This action is documented in wp-admin/includes/class-wp-upgrader.php */
2017-11-30 18:11:00 -05:00
do_action (
2018-08-16 21:51:36 -04:00
'upgrader_process_complete' ,
$this ,
array (
2017-11-30 18:11:00 -05:00
'action' => 'update' ,
'type' => 'theme' ,
'bulk' => true ,
'themes' => $themes ,
)
);
2016-05-10 07:45:42 -04:00
$this -> skin -> bulk_footer ();
$this -> skin -> footer ();
// Cleanup our hooks, in case something else does a upgrade on this connection.
2017-11-30 18:11:00 -05:00
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' ) );
2016-05-10 07:45:42 -04:00
2020-07-11 21:19:03 -04:00
// Ensure any future auto-update failures trigger a failure email by removing
// the last failure notification from the list when themes update successfully.
2020-07-07 15:00:02 -04:00
$past_failure_emails = get_option ( 'auto_plugin_theme_update_emails' , array () );
foreach ( $results as $theme => $result ) {
// Maintain last failure notification when themes failed to update manually.
if ( ! $result || is_wp_error ( $result ) || ! isset ( $past_failure_emails [ $theme ] ) ) {
continue ;
}
unset ( $past_failure_emails [ $theme ] );
}
2020-07-11 21:16:05 -04:00
2020-07-07 15:00:02 -04:00
update_option ( 'auto_plugin_theme_update_emails' , $past_failure_emails );
2016-05-10 07:45:42 -04:00
return $results ;
}
/**
2020-10-05 09:44:11 -04:00
* Checks that the package source contains a valid theme .
2016-05-10 07:45:42 -04:00
*
* Hooked to the { @ see 'upgrader_source_selection' } filter by Theme_Upgrader :: install () .
*
* @ since 3.3 . 0
*
2018-03-04 16:58:30 -05:00
* @ global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass .
2020-09-11 20:12:08 -04:00
* @ global string $wp_version The WordPress version string .
2016-05-10 07:45:42 -04:00
*
2020-10-05 09:44:11 -04:00
* @ param string $source The path to the downloaded package source .
* @ return string | WP_Error The source as passed , or a WP_Error object on failure .
2016-05-10 07:45:42 -04:00
*/
public function check_package ( $source ) {
2020-09-11 20:12:08 -04:00
global $wp_filesystem , $wp_version ;
2016-05-10 07:45:42 -04:00
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$this -> new_theme_data = array ();
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $source ) ) {
2016-05-10 07:45:42 -04:00
return $source ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// Check that the folder contains a valid theme.
2017-11-30 18:11:00 -05:00
$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.
2016-05-10 07:45:42 -04:00
return $source ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2020-01-28 19:45:18 -05:00
// A proper archive should have a style.css file in the single subdirectory.
2016-05-10 07:45:42 -04:00
if ( ! file_exists ( $working_directory . 'style.css' ) ) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
2018-08-16 21:51:36 -04:00
'incompatible_archive_theme_no_style' ,
$this -> strings [ 'incompatible_archive' ],
2017-11-30 18:11:00 -05:00
sprintf (
2018-08-30 09:36:25 -04:00
/* translators: %s: style.css */
2017-11-30 18:11:00 -05:00
__ ( 'The theme is missing the %s stylesheet.' ),
2016-05-10 07:45:42 -04:00
'<code>style.css</code>'
)
);
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
// All these headers are needed on Theme_Installer_Skin::do_overwrite().
2017-11-30 18:11:00 -05:00
$info = get_file_data (
2018-08-16 21:51:36 -04:00
$working_directory . 'style.css' ,
array (
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
'Name' => 'Theme Name' ,
'Version' => 'Version' ,
'Author' => 'Author' ,
'Template' => 'Template' ,
'RequiresWP' => 'Requires at least' ,
'RequiresPHP' => 'Requires PHP' ,
2017-11-30 18:11:00 -05:00
)
);
2016-05-10 07:45:42 -04:00
if ( empty ( $info [ 'Name' ] ) ) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
2018-08-16 21:51:36 -04:00
'incompatible_archive_theme_no_name' ,
$this -> strings [ 'incompatible_archive' ],
2017-11-30 18:11:00 -05:00
sprintf (
2018-08-30 09:36:25 -04:00
/* translators: %s: style.css */
Administration: Replace contracted verb forms for better consistency.
This changeset replaces contracted verb forms like `doesn't`, `can't`, or `isn't` with non-contracted forms like `does not`, `cannot`, or `is not`, for better consistency across the WordPress administration. It also updates some corresponding unit tests strings.
Props Presskopp, socalchristina, aandrewdixon, francina, SergeyBiryukov, JeffPaul, audrasjb, hellofromTonya.
Fixes #38913.
See #39176.
Built from https://develop.svn.wordpress.org/trunk@52978
git-svn-id: http://core.svn.wordpress.org/trunk@52567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-22 12:25:03 -04:00
__ ( 'The %s stylesheet does not contain a valid theme header.' ),
2016-05-10 07:45:42 -04:00
'<code>style.css</code>'
)
);
}
Themes: Accept valid block themes.
Updates theme validation to accept block themes. This replaces the requirement for an `index.php` with a requirement for either an `index.php`, `/templates/index.html` or the deprecated `/block-templates/index.html`.
Validation is updated for theme uploads, within `WP_Theme::__construct` and `validate_current_theme()`.
A block theme using the deprecated file structure is now included in the unit tests.
Props peterwilsoncc, sergeybiryukov, hellofromtonya, costdev, azaozz, gziolo, FlorianBrinkmann, Boniu91, aristath, poena, audrasjb.
Fixes #55754.
Built from https://develop.svn.wordpress.org/trunk@53416
git-svn-id: http://core.svn.wordpress.org/trunk@53005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-05-19 20:49:18 -04:00
/*
* Parent themes must contain an index file :
* - classic themes require / index . php
* - block themes require / templates / index . html or block - templates / index . html ( deprecated 5.9 . 0 ) .
*/
if (
empty ( $info [ 'Template' ] ) &&
! file_exists ( $working_directory . 'index.php' ) &&
! file_exists ( $working_directory . 'templates/index.html' ) &&
! file_exists ( $working_directory . 'block-templates/index.html' )
) {
2017-11-30 18:11:00 -05:00
return new WP_Error (
2018-08-16 21:51:36 -04:00
'incompatible_archive_theme_no_index' ,
$this -> strings [ 'incompatible_archive' ],
2017-11-30 18:11:00 -05:00
sprintf (
Themes: Accept valid block themes.
Updates theme validation to accept block themes. This replaces the requirement for an `index.php` with a requirement for either an `index.php`, `/templates/index.html` or the deprecated `/block-templates/index.html`.
Validation is updated for theme uploads, within `WP_Theme::__construct` and `validate_current_theme()`.
A block theme using the deprecated file structure is now included in the unit tests.
Props peterwilsoncc, sergeybiryukov, hellofromtonya, costdev, azaozz, gziolo, FlorianBrinkmann, Boniu91, aristath, poena, audrasjb.
Fixes #55754.
Built from https://develop.svn.wordpress.org/trunk@53416
git-svn-id: http://core.svn.wordpress.org/trunk@53005 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-05-19 20:49:18 -04:00
/* translators: 1: templates/index.html, 2: index.php, 3: Documentation URL, 4: Template, 5: style.css */
__ ( 'Template is missing. Standalone themes need to have a %1$s or %2$s template file. <a href="%3$s">Child themes</a> need to have a %4$s header in the %5$s stylesheet.' ),
'<code>templates/index.html</code>' ,
'<code>index.php</code>' ,
__ ( 'https://developer.wordpress.org/themes/advanced-topics/child-themes/' ),
'<code>Template</code>' ,
'<code>style.css</code>'
2016-05-10 07:45:42 -04:00
)
);
}
2020-07-28 12:07:02 -04:00
$requires_php = isset ( $info [ 'RequiresPHP' ] ) ? $info [ 'RequiresPHP' ] : null ;
$requires_wp = isset ( $info [ 'RequiresWP' ] ) ? $info [ 'RequiresWP' ] : null ;
if ( ! is_php_version_compatible ( $requires_php ) ) {
$error = sprintf (
/* translators: 1: Current PHP version, 2: Version required by the uploaded theme. */
__ ( 'The PHP version on your server is %1$s, however the uploaded theme requires %2$s.' ),
phpversion (),
$requires_php
);
return new WP_Error ( 'incompatible_php_required_version' , $this -> strings [ 'incompatible_archive' ], $error );
}
if ( ! is_wp_version_compatible ( $requires_wp ) ) {
$error = sprintf (
/* translators: 1: Current WordPress version, 2: Version required by the uploaded theme. */
__ ( 'Your WordPress version is %1$s, however the uploaded theme requires %2$s.' ),
2020-09-11 20:12:08 -04:00
$wp_version ,
2020-07-28 12:07:02 -04:00
$requires_wp
);
return new WP_Error ( 'incompatible_wp_required_version' , $this -> strings [ 'incompatible_archive' ], $error );
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$this -> new_theme_data = $info ;
2020-07-28 12:07:02 -04:00
2016-05-10 07:45:42 -04:00
return $source ;
}
/**
2022-01-20 18:53:05 -05:00
* Turn on maintenance mode before attempting to upgrade the active theme .
2016-05-10 07:45:42 -04:00
*
* Hooked to the { @ see 'upgrader_pre_install' } filter by Theme_Upgrader :: upgrade () and
* Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
* @ param bool | WP_Error $response The installation response before the installation has started .
* @ param array $theme Theme arguments .
* @ return bool | WP_Error The original `$response` parameter or WP_Error .
2016-05-10 07:45:42 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
public function current_before ( $response , $theme ) {
if ( is_wp_error ( $response ) ) {
return $response ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = isset ( $theme [ 'theme' ] ) ? $theme [ 'theme' ] : '' ;
2016-05-10 07:45:42 -04:00
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
// Only run if active theme.
2020-03-02 19:29:06 -05:00
if ( get_stylesheet () !== $theme ) {
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
return $response ;
2017-11-30 18:11:00 -05:00
}
2020-01-28 19:45:18 -05:00
2020-03-02 19:29:06 -05:00
// Change to maintenance mode. Bulk edit handles this separately.
2017-11-30 18:11:00 -05:00
if ( ! $this -> bulk ) {
$this -> maintenance_mode ( true );
}
2016-05-10 07:45:42 -04:00
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
return $response ;
2016-05-10 07:45:42 -04:00
}
/**
2022-01-20 18:53:05 -05:00
* Turn off maintenance mode after upgrading the active theme .
2016-05-10 07:45:42 -04:00
*
* Hooked to the { @ see 'upgrader_post_install' } filter by Theme_Upgrader :: upgrade ()
* and Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
* @ param bool | WP_Error $response The installation response after the installation has finished .
* @ param array $theme Theme arguments .
* @ return bool | WP_Error The original `$response` parameter or WP_Error .
2016-05-10 07:45:42 -04:00
*/
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
public function current_after ( $response , $theme ) {
if ( is_wp_error ( $response ) ) {
return $response ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = isset ( $theme [ 'theme' ] ) ? $theme [ 'theme' ] : '' ;
2016-05-10 07:45:42 -04:00
2022-01-20 18:53:05 -05:00
// Only run if active theme.
2020-03-02 19:29:06 -05:00
if ( get_stylesheet () !== $theme ) {
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
return $response ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
// Ensure stylesheet name hasn't changed after the upgrade:
2020-05-17 05:39:11 -04:00
if ( get_stylesheet () === $theme && $theme !== $this -> result [ 'destination_name' ] ) {
2016-05-10 07:45:42 -04:00
wp_clean_themes_cache ();
$stylesheet = $this -> result [ 'destination_name' ];
switch_theme ( $stylesheet );
}
2020-03-02 19:29:06 -05:00
// Time to remove maintenance mode. Bulk edit handles this separately.
2017-11-30 18:11:00 -05:00
if ( ! $this -> bulk ) {
$this -> maintenance_mode ( false );
}
Code Modernization: Rename parameters that use reserved keywords in `wp-admin/includes/class-theme-upgrader.php`.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names.
This commit renames the `$return` variable in `Theme_Upgrader` class methods to `$response` and updates the documentation accordingly.
Follow-up to [47409], [52946], [52996], [52997].
Props jrf, aristath, poena, justinahinon, SergeyBiryukov.
See #55327.
Built from https://develop.svn.wordpress.org/trunk@52998
git-svn-id: http://core.svn.wordpress.org/trunk@52587 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2022-03-27 10:55:02 -04:00
return $response ;
2016-05-10 07:45:42 -04:00
}
/**
* Delete the old theme during an upgrade .
*
* Hooked to the { @ see 'upgrader_clear_destination' } filter by Theme_Upgrader :: upgrade ()
* and Theme_Upgrader :: bulk_upgrade () .
*
* @ since 2.8 . 0
*
* @ global WP_Filesystem_Base $wp_filesystem Subclass
*
* @ param bool $removed
* @ param string $local_destination
* @ param string $remote_destination
* @ param array $theme
* @ return bool
*/
public function delete_old_theme ( $removed , $local_destination , $remote_destination , $theme ) {
global $wp_filesystem ;
2017-11-30 18:11:00 -05:00
if ( is_wp_error ( $removed ) ) {
2016-05-10 07:45:42 -04:00
return $removed ; // Pass errors through.
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
if ( ! isset ( $theme [ 'theme' ] ) ) {
2016-05-10 07:45:42 -04:00
return $removed ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
2017-11-30 18:11:00 -05:00
$theme = $theme [ 'theme' ];
2016-05-10 07:45:42 -04:00
$themes_dir = trailingslashit ( $wp_filesystem -> wp_themes_dir ( $theme ) );
if ( $wp_filesystem -> exists ( $themes_dir . $theme ) ) {
2017-11-30 18:11:00 -05:00
if ( ! $wp_filesystem -> delete ( $themes_dir . $theme , true ) ) {
2016-05-10 07:45:42 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
}
return true ;
}
/**
* Get the WP_Theme object for a theme .
*
* @ since 2.8 . 0
* @ since 3.0 . 0 The `$theme` argument was added .
*
* @ param string $theme The directory name of the theme . This is optional , and if not supplied ,
* the directory name from the last result will be used .
* @ return WP_Theme | false The theme ' s info object , or false `$theme` is not supplied
* and the last result isn ' t set .
*/
2017-11-30 18:11:00 -05:00
public function theme_info ( $theme = null ) {
if ( empty ( $theme ) ) {
if ( ! empty ( $this -> result [ 'destination_name' ] ) ) {
2016-05-10 07:45:42 -04:00
$theme = $this -> result [ 'destination_name' ];
2017-11-30 18:11:00 -05:00
} else {
2016-05-10 07:45:42 -04:00
return false ;
2017-11-30 18:11:00 -05:00
}
2016-05-10 07:45:42 -04:00
}
Upgrade/install: Allow plugin and theme updates from a uploaded .zip file.
Props mariovalney, cyberhobo, imath, shaunandrews, mariovalney, earnjam, desrosj, dd32, folletto, swissspidy, melchoyce, pento, joshuawold, psykro, clorith, ahortin, galbaras, pingram3541, joyously, doobeedoo, karmatosed, poena, whyisjake, earnjam, sergeybiryukov, audrasjb, azaozz.
Fixes #9757.
Built from https://develop.svn.wordpress.org/trunk@48390
git-svn-id: http://core.svn.wordpress.org/trunk@48159 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2020-07-07 13:49:05 -04:00
$theme = wp_get_theme ( $theme );
$theme -> cache_delete ();
return $theme ;
2016-05-10 07:45:42 -04:00
}
}