Upgrade/Install: Check theme compatibility during bulk upgrades.

Previously, bulk upgrades did not verify that a theme package was compatible with the site's WordPress version or the server's PHP version.

This was previusly done for plugins in #59198, but themes were missed.

Follow-up to: [56525].

Props salcode, lakshmananphp.
Fixes #59758.

Built from https://develop.svn.wordpress.org/trunk@57252


git-svn-id: http://core.svn.wordpress.org/trunk@56758 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2024-01-08 23:19:16 +00:00
parent a38245a657
commit c59c7d90c4
2 changed files with 53 additions and 17 deletions

View File

@ -371,6 +371,8 @@ class Theme_Upgrader extends WP_Upgrader {
* @since 3.0.0 * @since 3.0.0
* @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional. * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
* *
* @global string $wp_version The WordPress version string.
*
* @param string[] $themes Array of the theme slugs. * @param string[] $themes Array of the theme slugs.
* @param array $args { * @param array $args {
* Optional. Other arguments for upgrading several themes at once. Default empty array. * Optional. Other arguments for upgrading several themes at once. Default empty array.
@ -381,6 +383,8 @@ class Theme_Upgrader extends WP_Upgrader {
* @return array[]|false An array of results, or false if unable to connect to the filesystem. * @return array[]|false An array of results, or false if unable to connect to the filesystem.
*/ */
public function bulk_upgrade( $themes, $args = array() ) { public function bulk_upgrade( $themes, $args = array() ) {
global $wp_version;
$defaults = array( $defaults = array(
'clear_update_cache' => true, 'clear_update_cache' => true,
); );
@ -442,23 +446,55 @@ class Theme_Upgrader extends WP_Upgrader {
// Get the URL to the zip file. // Get the URL to the zip file.
$r = $current->response[ $theme ]; $r = $current->response[ $theme ];
$result = $this->run( if ( isset( $r['requires'] ) && ! is_wp_version_compatible( $r['requires'] ) ) {
array( $result = new WP_Error(
'package' => $r['package'], 'incompatible_wp_required_version',
'destination' => get_theme_root( $theme ), sprintf(
'clear_destination' => true, /* translators: 1: Current WordPress version, 2: WordPress version required by the new theme version. */
'clear_working' => true, __( 'Your WordPress version is %1$s, however the new theme version requires %2$s.' ),
'is_multi' => true, $wp_version,
'hook_extra' => array( $r['requires']
'theme' => $theme, )
'temp_backup' => array( );
'slug' => $theme,
'src' => get_theme_root( $theme ), $this->skin->before( $result );
'dir' => 'themes', $this->skin->error( $result );
$this->skin->after();
} elseif ( isset( $r['requires_php'] ) && ! is_php_version_compatible( $r['requires_php'] ) ) {
$result = new WP_Error(
'incompatible_php_required_version',
sprintf(
/* translators: 1: Current PHP version, 2: PHP version required by the new theme version. */
__( 'The PHP version on your server is %1$s, however the new theme version requires %2$s.' ),
PHP_VERSION,
$r['requires_php']
)
);
$this->skin->before( $result );
$this->skin->error( $result );
$this->skin->after();
} else {
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
$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,
'temp_backup' => array(
'slug' => $theme,
'src' => get_theme_root( $theme ),
'dir' => 'themes',
),
), ),
), )
) );
); remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
}
$results[ $theme ] = $result; $results[ $theme ] = $result;

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-alpha-57251'; $wp_version = '6.5-alpha-57252';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.