Make WordPress Core

Changeset 57252


Ignore:
Timestamp:
01/08/2024 11:17:48 PM (4 months ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r57239 r57252  
    372372     * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
    373373     *
     374     * @global string $wp_version The WordPress version string.
     375     *
    374376     * @param string[] $themes Array of the theme slugs.
    375377     * @param array    $args {
     
    382384     */
    383385    public function bulk_upgrade( $themes, $args = array() ) {
     386        global $wp_version;
     387
    384388        $defaults    = array(
    385389            'clear_update_cache' => true,
     
    443447            $r = $current->response[ $theme ];
    444448
    445             $result = $this->run(
    446                 array(
    447                     'package'           => $r['package'],
    448                     'destination'       => get_theme_root( $theme ),
    449                     'clear_destination' => true,
    450                     'clear_working'     => true,
    451                     'is_multi'          => true,
    452                     'hook_extra'        => array(
    453                         'theme'       => $theme,
    454                         'temp_backup' => array(
    455                             'slug' => $theme,
    456                             'src'  => get_theme_root( $theme ),
    457                             'dir'  => 'themes',
     449            if ( isset( $r['requires'] ) && ! is_wp_version_compatible( $r['requires'] ) ) {
     450                $result = new WP_Error(
     451                    'incompatible_wp_required_version',
     452                    sprintf(
     453                        /* translators: 1: Current WordPress version, 2: WordPress version required by the new theme version. */
     454                        __( 'Your WordPress version is %1$s, however the new theme version requires %2$s.' ),
     455                        $wp_version,
     456                        $r['requires']
     457                    )
     458                );
     459
     460                $this->skin->before( $result );
     461                $this->skin->error( $result );
     462                $this->skin->after();
     463            } elseif ( isset( $r['requires_php'] ) && ! is_php_version_compatible( $r['requires_php'] ) ) {
     464                $result = new WP_Error(
     465                    'incompatible_php_required_version',
     466                    sprintf(
     467                        /* translators: 1: Current PHP version, 2: PHP version required by the new theme version. */
     468                        __( 'The PHP version on your server is %1$s, however the new theme version requires %2$s.' ),
     469                        PHP_VERSION,
     470                        $r['requires_php']
     471                    )
     472                );
     473
     474                $this->skin->before( $result );
     475                $this->skin->error( $result );
     476                $this->skin->after();
     477            } else {
     478                add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
     479                $result = $this->run(
     480                    array(
     481                        'package'           => $r['package'],
     482                        'destination'       => get_theme_root( $theme ),
     483                        'clear_destination' => true,
     484                        'clear_working'     => true,
     485                        'is_multi'          => true,
     486                        'hook_extra'        => array(
     487                            'theme'       => $theme,
     488                            'temp_backup' => array(
     489                                'slug' => $theme,
     490                                'src'  => get_theme_root( $theme ),
     491                                'dir'  => 'themes',
     492                            ),
    458493                        ),
    459                     ),
    460                 )
    461             );
     494                    )
     495                );
     496                remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
     497            }
    462498
    463499            $results[ $theme ] = $result;
Note: See TracChangeset for help on using the changeset viewer.