Make WordPress Core

Changeset 48652


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.

Location:
trunk/src
Files:
3 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
  • trunk/src/wp-admin/themes.php

    r48640 r48652  
    390390
    391391    <?php if ( $theme['hasUpdate'] ) : ?>
    392         <div class="update-message notice inline notice-warning notice-alt">
    393         <?php if ( $theme['hasPackage'] ) : ?>
    394             <p><?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?></p>
     392        <?php if ( $theme['updateResponse']['compatibleWP'] && $theme['updateResponse']['compatiblePHP'] ) : ?>
     393            <div class="update-message notice inline notice-warning notice-alt"><p>
     394                <?php if ( $theme['hasPackage'] ) : ?>
     395                    <?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?>
     396                <?php else : ?>
     397                    <?php _e( 'New version available.' ); ?>
     398                <?php endif; ?>
     399            </p></div>
    395400        <?php else : ?>
    396             <p><?php _e( 'New version available.' ); ?></p>
     401            <div class="notice inline notice-error notice-alt"><p>
     402                <?php
     403                if ( $theme['updateResponse']['compatibleWP'] && $theme['updateResponse']['compatiblePHP'] ) {
     404                    _e( 'There is a new version available, but it doesn&#8217;t work with your versions of WordPress and PHP.' );
     405                    if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
     406                        printf(
     407                            /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
     408                            ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     409                            self_admin_url( 'update-core.php' ),
     410                            esc_url( wp_get_update_php_url() )
     411                        );
     412                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     413                    } elseif ( current_user_can( 'update_core' ) ) {
     414                        printf(
     415                            /* translators: %s: URL to WordPress Updates screen. */
     416                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     417                            self_admin_url( 'update-core.php' )
     418                        );
     419                    } elseif ( current_user_can( 'update_php' ) ) {
     420                        printf(
     421                            /* translators: %s: URL to Update PHP page. */
     422                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     423                            esc_url( wp_get_update_php_url() )
     424                        );
     425                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     426                    }
     427                } elseif ( ! $theme['updateResponse']['compatibleWP'] ) {
     428                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of WordPress.' );
     429                    if ( current_user_can( 'update_core' ) ) {
     430                        printf(
     431                            /* translators: %s: URL to WordPress Updates screen. */
     432                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     433                            self_admin_url( 'update-core.php' )
     434                        );
     435                    }
     436                } elseif ( ! $theme['updateResponse']['compatiblePHP'] ) {
     437                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of PHP.' );
     438                    if ( current_user_can( 'update_php' ) ) {
     439                        printf(
     440                            /* translators: %s: URL to Update PHP page. */
     441                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     442                            esc_url( wp_get_update_php_url() )
     443                        );
     444                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     445                    }
     446                }
     447                ?>
     448            </p></div>
    397449        <?php endif; ?>
    398         </div>
    399450    <?php endif; ?>
    400451
     
    660711
    661712    <# if ( data.hasUpdate ) { #>
    662         <# if ( data.hasPackage ) { #>
    663             <div class="update-message notice inline notice-warning notice-alt"><p><?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?></p></div>
     713        <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
     714            <div class="update-message notice inline notice-warning notice-alt"><p>
     715                <# if ( data.hasPackage ) { #>
     716                    <?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?>
     717                <# } else { #>
     718                    <?php _e( 'New version available.' ); ?>
     719                <# } #>
     720            </p></div>
    664721        <# } else { #>
    665             <div class="update-message notice inline notice-warning notice-alt"><p><?php _e( 'New version available.' ); ?></p></div>
     722            <div class="notice inline notice-error notice-alt"><p>
     723                <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
     724                    <?php
     725                    _e( 'There is a new version available, but it doesn&#8217;t work with your versions of WordPress and PHP.' );
     726                    if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
     727                        printf(
     728                            /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
     729                            ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     730                            self_admin_url( 'update-core.php' ),
     731                            esc_url( wp_get_update_php_url() )
     732                        );
     733                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     734                    } elseif ( current_user_can( 'update_core' ) ) {
     735                        printf(
     736                            /* translators: %s: URL to WordPress Updates screen. */
     737                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     738                            self_admin_url( 'update-core.php' )
     739                        );
     740                    } elseif ( current_user_can( 'update_php' ) ) {
     741                        printf(
     742                            /* translators: %s: URL to Update PHP page. */
     743                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     744                            esc_url( wp_get_update_php_url() )
     745                        );
     746                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     747                    }
     748                    ?>
     749                <# } else if ( ! data.updateResponse.compatibleWP ) { #>
     750                    <?php
     751                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of WordPress.' );
     752                    if ( current_user_can( 'update_core' ) ) {
     753                        printf(
     754                            /* translators: %s: URL to WordPress Updates screen. */
     755                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     756                            self_admin_url( 'update-core.php' )
     757                        );
     758                    }
     759                    ?>
     760                <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
     761                    <?php
     762                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of PHP.' );
     763                    if ( current_user_can( 'update_php' ) ) {
     764                        printf(
     765                            /* translators: %s: URL to Update PHP page. */
     766                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     767                            esc_url( wp_get_update_php_url() )
     768                        );
     769                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     770                    }
     771                    ?>
     772                <# } #>
     773            </p></div>
    666774        <# } #>
    667775    <# } #>
     
    854962                <# } #>
    855963
     964                <# if ( data.hasUpdate ) { #>
     965                    <# if ( data.updateResponse.compatibleWP && data.updateResponse.compatiblePHP ) { #>
     966                        <div class="notice notice-warning notice-alt notice-large">
     967                            <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
     968                            {{{ data.update }}}
     969                        </div>
     970                    <# } else { #>
     971                        <div class="notice notice-error notice-alt notice-large">
     972                            <h3 class="notice-title"><?php _e( 'Update Incompatible' ); ?></h3>
     973                            <p>
     974                                <# if ( ! data.updateResponse.compatibleWP && ! data.updateResponse.compatiblePHP ) { #>
     975                                    <?php
     976                                    _e( 'There is a new version available, but it doesn&#8217;t work with your versions of WordPress and PHP.' );
     977                                    if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
     978                                        printf(
     979                                            /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
     980                                            ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     981                                            self_admin_url( 'update-core.php' ),
     982                                            esc_url( wp_get_update_php_url() )
     983                                        );
     984                                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     985                                    } elseif ( current_user_can( 'update_core' ) ) {
     986                                        printf(
     987                                            /* translators: %s: URL to WordPress Updates screen. */
     988                                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     989                                            self_admin_url( 'update-core.php' )
     990                                        );
     991                                    } elseif ( current_user_can( 'update_php' ) ) {
     992                                        printf(
     993                                            /* translators: %s: URL to Update PHP page. */
     994                                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     995                                            esc_url( wp_get_update_php_url() )
     996                                        );
     997                                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     998                                    }
     999                                    ?>
     1000                                <# } else if ( ! data.updateResponse.compatibleWP ) { #>
     1001                                    <?php
     1002                                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of WordPress.' );
     1003                                    if ( current_user_can( 'update_core' ) ) {
     1004                                        printf(
     1005                                            /* translators: %s: URL to WordPress Updates screen. */
     1006                                            ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     1007                                            self_admin_url( 'update-core.php' )
     1008                                        );
     1009                                    }
     1010                                    ?>
     1011                                <# } else if ( ! data.updateResponse.compatiblePHP ) { #>
     1012                                    <?php
     1013                                    _e( 'There is a new version available, but it doesn&#8217;t work with your version of PHP.' );
     1014                                    if ( current_user_can( 'update_php' ) ) {
     1015                                        printf(
     1016                                            /* translators: %s: URL to Update PHP page. */
     1017                                            ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     1018                                            esc_url( wp_get_update_php_url() )
     1019                                        );
     1020                                        wp_update_php_annotation( '</p><p><em>', '</em>' );
     1021                                    }
     1022                                    ?>
     1023                                <# } #>
     1024                            </p>
     1025                        </div>
     1026                    <# } #>
     1027                <# } #>
     1028
    8561029                <# if ( data.actions.autoupdate ) { #>
    8571030                    <?php echo wp_theme_auto_update_setting_template(); ?>
    858                 <# } #>
    859 
    860                 <# if ( data.hasUpdate ) { #>
    861                 <div class="notice notice-warning notice-alt notice-large">
    862                     <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
    863                     {{{ data.update }}}
    864                 </div>
    8651031                <# } #>
    8661032
  • trunk/src/wp-includes/customize/class-wp-customize-theme-control.php

    r48638 r48652  
    9191
    9292            <# if ( 'installed' === data.theme.type && data.theme.hasUpdate ) { #>
    93                 <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
    94                     <p>
    95                         <?php
    96                         if ( is_multisite() ) {
    97                             _e( 'New version available.' );
    98                         } else {
    99                             printf(
    100                                 /* translators: %s: "Update now" button. */
    101                                 __( 'New version available. %s' ),
    102                                 '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>'
    103                             );
    104                         }
    105                         ?>
    106                     </p>
    107                 </div>
     93                <# if ( data.theme.updateResponse.compatibleWP && data.theme.updateResponse.compatiblePHP ) { #>
     94                    <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
     95                        <p>
     96                            <?php
     97                            if ( is_multisite() ) {
     98                                _e( 'New version available.' );
     99                            } else {
     100                                printf(
     101                                    /* translators: %s: "Update now" button. */
     102                                    __( 'New version available. %s' ),
     103                                    '<button class="button-link update-theme" type="button">' . __( 'Update now' ) . '</button>'
     104                                );
     105                            }
     106                            ?>
     107                        </p>
     108                    </div>
     109                <# } else { #>
     110                    <div class="update-message notice inline notice-warning notice-alt" data-slug="{{ data.theme.id }}">
     111                        <p>
     112                            <# if ( ! data.theme.updateResponse.compatibleWP && ! data.theme.updateResponse.compatiblePHP ) { #>
     113                                <?php
     114                                _e( 'There is a new version available, but it doesn&#8217;t work with your versions of WordPress and PHP.' );
     115                                if ( current_user_can( 'update_core' ) && current_user_can( 'update_php' ) ) {
     116                                    printf(
     117                                        /* translators: 1: URL to WordPress Updates screen, 2: URL to Update PHP page. */
     118                                        ' ' . __( '<a href="%1$s">Please update WordPress</a>, and then <a href="%2$s">learn more about updating PHP</a>.' ),
     119                                        self_admin_url( 'update-core.php' ),
     120                                        esc_url( wp_get_update_php_url() )
     121                                    );
     122                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
     123                                } elseif ( current_user_can( 'update_core' ) ) {
     124                                    printf(
     125                                        /* translators: %s: URL to WordPress Updates screen. */
     126                                        ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     127                                        self_admin_url( 'update-core.php' )
     128                                    );
     129                                } elseif ( current_user_can( 'update_php' ) ) {
     130                                    printf(
     131                                        /* translators: %s: URL to Update PHP page. */
     132                                        ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     133                                        esc_url( wp_get_update_php_url() )
     134                                    );
     135                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
     136                                }
     137                                ?>
     138                            <# } else if ( ! data.theme.updateResponse.compatibleWP ) { #>
     139                                <?php
     140                                _e( 'There is a new version available, but it doesn&#8217;t work with your version of WordPress.' );
     141                                if ( current_user_can( 'update_core' ) ) {
     142                                    printf(
     143                                        /* translators: %s: URL to WordPress Updates screen. */
     144                                        ' ' . __( '<a href="%s">Please update WordPress</a>.' ),
     145                                        self_admin_url( 'update-core.php' )
     146                                    );
     147                                }
     148                                ?>
     149                            <# } else if ( ! data.theme.updateResponse.compatiblePHP ) { #>
     150                                <?php
     151                                _e( 'There is a new version available, but it doesn&#8217;t work with your version of PHP.' );
     152                                if ( current_user_can( 'update_php' ) ) {
     153                                    printf(
     154                                        /* translators: %s: URL to Update PHP page. */
     155                                        ' ' . __( '<a href="%s">Learn more about updating PHP</a>.' ),
     156                                        esc_url( wp_get_update_php_url() )
     157                                    );
     158                                    wp_update_php_annotation( '</p><p><em>', '</em>' );
     159                                }
     160                                ?>
     161                            <# } #>
     162                        </p>
     163                    </div>
     164                <# } #>
    108165            <# } #>
    109166
Note: See TracChangeset for help on using the changeset viewer.