Make WordPress Core


Ignore:
Timestamp:
07/28/2020 12:08:00 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Themes: Display a message in theme grid and Theme Details modal if a theme update requires a higher version of PHP or WordPress.

This applies to the Themes screen and the Customizer theme browser.

Props afragen, SergeyBiryukov.
See #48491.

File:
1 edited

Legend:

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

    r48636 r48652  
    685685        }
    686686
     687        $update_requires_wp  = isset( $updates[ $slug ]['requires'] ) ? $updates[ $slug ]['requires'] : null;
     688        $update_requires_php = isset( $updates[ $slug ]['requires_php'] ) ? $updates[ $slug ]['requires_php'] : null;
     689
    687690        $auto_update        = in_array( $slug, $auto_updates, true );
    688691        $auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
    689692
    690693        $prepared_themes[ $slug ] = array(
    691             'id'            => $slug,
    692             'name'          => $theme->display( 'Name' ),
    693             'screenshot'    => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
    694             'description'   => $theme->display( 'Description' ),
    695             'author'        => $theme->display( 'Author', false, true ),
    696             'authorAndUri'  => $theme->display( 'Author' ),
    697             'tags'          => $theme->display( 'Tags' ),
    698             'version'       => $theme->get( 'Version' ),
    699             'compatibleWP'  => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
    700             'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
    701             'parent'        => $parent,
    702             'active'        => $slug === $current_theme,
    703             'hasUpdate'     => isset( $updates[ $slug ] ),
    704             'hasPackage'    => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
    705             'update'        => get_theme_update_available( $theme ),
    706             'autoupdate'    => $auto_update,
    707             'actions'       => array(
     694            'id'             => $slug,
     695            'name'           => $theme->display( 'Name' ),
     696            'screenshot'     => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
     697            'description'    => $theme->display( 'Description' ),
     698            'author'         => $theme->display( 'Author', false, true ),
     699            'authorAndUri'   => $theme->display( 'Author' ),
     700            'tags'           => $theme->display( 'Tags' ),
     701            'version'        => $theme->get( 'Version' ),
     702            'compatibleWP'   => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
     703            'compatiblePHP'  => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
     704            'updateResponse' => array(
     705                'compatibleWP'  => is_wp_version_compatible( $update_requires_wp ),
     706                'compatiblePHP' => is_php_version_compatible( $update_requires_php ),
     707            ),
     708            'parent'         => $parent,
     709            'active'         => $slug === $current_theme,
     710            'hasUpdate'      => isset( $updates[ $slug ] ),
     711            'hasPackage'     => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
     712            'update'         => get_theme_update_available( $theme ),
     713            'autoupdate'     => $auto_update,
     714            'actions'        => array(
    708715                'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    709716                'customize'  => $customize_action,
     
    794801
    795802                    <# if ( data.hasUpdate ) { #>
    796                         <div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}">
    797                             <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
    798                             {{{ data.update }}}
    799                         </div>
     803                        <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
     804                            <div class="notice notice-warning notice-alt notice-large" data-slug="{{ data.id }}">
     805                                <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
     806                                {{{ data.update }}}
     807                            </div>
     808                        <# } else { #>
     809                            <div class="notice notice-error notice-alt notice-large" data-slug="{{ data.id }}">
     810                                <h3 class="notice-title"><?php _e( 'Update Incompatible' ); ?></h3>
     811                                <p>
     812                                    <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
     813                                        <?php
     814                                        _e( 'There is a new version available, but it doesn&#8217;t work with your versions of WordPress and PHP.' );
     815                                        if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
     816                                            printf(
     817                                                /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
     818                                                ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     819                                                self_admin_url( 'update-core.php' ),
     820                                                esc_url( wp_get_update_php_url() )
     821                                            );
     822                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
     823                                        } elseif ( current_user_can( 'update_core' ) ) {
     824                                            printf(
     825                                                /* translators: %s: URL to WordPress Updates screen. */
     826                                                ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     827                                                self_admin_url( 'update-core.php' )
     828                                            );
     829                                        } elseif ( current_user_can( 'update_php' ) ) {
     830                                            printf(
     831                                                /* translators: %s: URL to Update PHP page. */
     832                                                ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     833                                                esc_url( wp_get_update_php_url() )
     834                                            );
     835                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
     836                                        }
     837                                        ?>
     838                                    <# } else if ( ! data.updateResponse.compatibleWP ) { #>
     839                                        <?php
     840                                        _e( 'There is a new version available, but it doesn&#8217;t work with your version of WordPress.' );
     841                                        if ( current_user_can( 'update_core' ) ) {
     842                                            printf(
     843                                                /* translators: %s: URL to WordPress Updates screen. */
     844                                                ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     845                                                self_admin_url( 'update-core.php' )
     846                                            );
     847                                        }
     848                                        ?>
     849                                    <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
     850                                        <?php
     851                                        _e( 'There is a new version available, but it doesn&#8217;t work with your version of PHP.' );
     852                                        if ( current_user_can( 'update_php' ) ) {
     853                                            printf(
     854                                                /* translators: %s: URL to Update PHP page. */
     855                                                ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     856                                                esc_url( wp_get_update_php_url() )
     857                                            );
     858                                            wp_update_php_annotation( '</p><p><em>', '</em>' );
     859                                        }
     860                                        ?>
     861                                    <# } #>
     862                                </p>
     863                            </div>
     864                        <# } #>
    800865                    <# } #>
    801866
Note: See TracChangeset for help on using the changeset viewer.