Make WordPress Core

Changeset 47816


Ignore:
Timestamp:
05/18/2020 12:30:04 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Themes: Prevent activation and live preview of themes that require a higher version of PHP or WordPress.

Props afragen, jorbin, TimothyBlynJacobs, SergeyBiryukov.
See #48491.

Location:
trunk/src
Files:
6 edited

Legend:

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

    r47474 r47816  
    178178        <form id="customize-controls" class="wrap wp-full-overlay-sidebar">
    179179                <div id="customize-header-actions" class="wp-full-overlay-header">
    180                         <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?>
    181                         <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" >
    182                                 <?php submit_button( $save_text, 'primary save', 'save', false ); ?>
    183                                 <button id="publish-settings" class="publish-settings button-primary button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button>
    184                         </div>
     180                        <?php
     181                        $compatible_wp  = is_wp_version_compatible( $wp_customize->theme()->get( 'RequiresWP' ) );
     182                        $compatible_php = is_php_version_compatible( $wp_customize->theme()->get( 'RequiresPHP' ) );
     183                        ?>
     184                        <?php if ( $compatible_wp && $compatible_php ) : ?>
     185                                <?php $save_text = $wp_customize->is_theme_active() ? __( 'Publish' ) : __( 'Activate &amp; Publish' ); ?>
     186                                <div id="customize-save-button-wrapper" class="customize-save-button-wrapper" >
     187                                        <?php submit_button( $save_text, 'primary save', 'save', false ); ?>
     188                                        <button id="publish-settings" class="publish-settings button-primary button dashicons dashicons-admin-generic" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled></button>
     189                                </div>
     190                        <?php else : ?>
     191                                <?php $save_text = _x( 'Cannot Activate', 'theme' ); ?>
     192                                <div id="customize-save-button-wrapper" class="customize-save-button-wrapper disabled" >
     193                                        <button class="button button-primary disabled" aria-label="<?php esc_attr_e( 'Publish Settings' ); ?>" aria-expanded="false" disabled><?php echo $save_text; ?></button>
     194                                </div>
     195                        <?php endif; ?>
    185196                        <span class="spinner"></span>
    186197                        <button type="button" class="customize-controls-preview-toggle">
  • trunk/src/wp-admin/includes/ajax-actions.php

    r47808 r47816  
    35723572                );
    35733573
    3574                 $theme->num_ratings = number_format_i18n( $theme->num_ratings );
    3575                 $theme->preview_url = set_url_scheme( $theme->preview_url );
     3574                $theme->num_ratings    = number_format_i18n( $theme->num_ratings );
     3575                $theme->preview_url    = set_url_scheme( $theme->preview_url );
     3576                $theme->compatible_wp  = is_wp_version_compatible( $theme->requires );
     3577                $theme->compatible_php = is_php_version_compatible( $theme->requires_php );
    35763578        }
    35773579
  • trunk/src/wp-admin/includes/theme.php

    r47808 r47816  
    685685
    686686                $prepared_themes[ $slug ] = array(
    687                         'id'           => $slug,
    688                         'name'         => $theme->display( 'Name' ),
    689                         'screenshot'   => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
    690                         'description'  => $theme->display( 'Description' ),
    691                         'author'       => $theme->display( 'Author', false, true ),
    692                         'authorAndUri' => $theme->display( 'Author' ),
    693                         'version'      => $theme->display( 'Version' ),
    694                         'tags'         => $theme->display( 'Tags' ),
    695                         'parent'       => $parent,
    696                         'active'       => $slug === $current_theme,
    697                         'hasUpdate'    => isset( $updates[ $slug ] ),
    698                         'hasPackage'   => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
    699                         'update'       => get_theme_update_available( $theme ),
    700                         'actions'      => array(
     687                        'id'            => $slug,
     688                        'name'          => $theme->display( 'Name' ),
     689                        'screenshot'    => array( $theme->get_screenshot() ), // @todo Multiple screenshots.
     690                        'description'   => $theme->display( 'Description' ),
     691                        'author'        => $theme->display( 'Author', false, true ),
     692                        'authorAndUri'  => $theme->display( 'Author' ),
     693                        'tags'          => $theme->display( 'Tags' ),
     694                        'version'       => $theme->get( 'Version' ),
     695                        'compatibleWP'  => is_wp_version_compatible( $theme->get( 'RequiresWP' ) ),
     696                        'compatiblePHP' => is_php_version_compatible( $theme->get( 'RequiresPHP' ) ),
     697                        'parent'        => $parent,
     698                        'active'        => $slug === $current_theme,
     699                        'hasUpdate'     => isset( $updates[ $slug ] ),
     700                        'hasPackage'    => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
     701                        'update'        => get_theme_update_available( $theme ),
     702                        'actions'       => array(
    701703                                'activate'  => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&amp;stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
    702704                                'customize' => $customize_action,
     
    819821                                                <# } #>
    820822                                        <?php } ?>
    821                                         <button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
     823
     824                                        <# if ( data.compatibleWP && data.compatiblePHP ) { #>
     825                                                <button type="button" class="button button-primary preview-theme" data-slug="{{ data.id }}"><?php _e( 'Live Preview' ); ?></button>
     826                                        <# } else { #>
     827                                                <button class="button button-primary disabled"><?php _e( 'Live Preview' ); ?></button>
     828                                        <# } #>
    822829                                <# } else { #>
    823830                                        <button type="button" class="button theme-install" data-slug="{{ data.id }}"><?php _e( 'Install' ); ?></button>
  • trunk/src/wp-admin/theme-install.php

    r47794 r47816  
    283283
    284284                <div class="theme-actions">
     285                        <# console.log( data ); #>
    285286                        <# if ( data.installed ) { #>
    286                                 <?php
    287                                 /* translators: %s: Theme name. */
    288                                 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    289                                 ?>
    290                                 <# if ( data.activate_url ) { #>
    291                                         <a class="button button-primary activate" href="{{ data.activate_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    292                                 <# } #>
    293                                 <# if ( data.customize_url ) { #>
    294                                         <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
     287                                <# if ( data.compatible_wp && data.compatible_php ) { #>
     288                                        <?php
     289                                        /* translators: %s: Theme name. */
     290                                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
     291                                        ?>
     292                                        <# if ( data.activate_url ) { #>
     293                                                <a class="button button-primary activate" href="{{ data.activate_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
     294                                        <# } #>
     295                                        <# if ( data.customize_url ) { #>
     296                                                <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
     297                                        <# } else { #>
     298                                                <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button>
     299                                        <# } #>
    295300                                <# } else { #>
    296                                         <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button>
     301                                        <?php
     302                                        /* translators: %s: Theme name. */
     303                                        $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
     304                                        ?>
     305                                        <# if ( data.activate_url ) { #>
     306                                                <a class="button button-primary disabled" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
     307                                        <# } #>
     308                                        <# if ( data.customize_url ) { #>
     309                                                <a class="button disabled"><?php _e( 'Live Preview' ); ?></a>
     310                                        <# } else { #>
     311                                                <button class="button disabled"><?php _e( 'Preview' ); ?></button>
     312                                        <# } #>
    297313                                <# } #>
    298314                        <# } else { #>
  • trunk/src/wp-admin/themes.php

    r47808 r47816  
    354354                                <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
    355355                        <?php } ?>
    356                 <?php } else { ?>
     356                <?php } elseif ( $theme['compatibleWP'] && $theme['compatiblePHP'] ) { ?>
    357357                        <?php
    358358                        /* translators: %s: Theme name. */
     
    362362                        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
    363363                                <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
     364                        <?php } ?>
     365                <?php } else { ?>
     366                        <?php
     367                        /* translators: %s: Theme name. */
     368                        $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
     369                        ?>
     370                        <a class="button disabled" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
     371                        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
     372                                <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
    364373                        <?php } ?>
    365374                <?php } ?>
     
    519528                                <# } #>
    520529                        <# } else { #>
    521                                 <?php
    522                                 /* translators: %s: Theme name. */
    523                                 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    524                                 ?>
    525                                 <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
    526                                 <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     530                                <# if ( data.compatibleWP && data.compatiblePHP ) { #>
     531                                        <?php
     532                                        /* translators: %s: Theme name. */
     533                                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
     534                                        ?>
     535                                        <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
     536                                        <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     537                                <# } else { #>
     538                                        <?php
     539                                        /* translators: %s: Theme name. */
     540                                        $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
     541                                        ?>
     542                                        <a class="button disabled" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
     543                                        <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
     544                                <# } #>
    527545                        <# } #>
    528546                </div>
     
    593611                        </div>
    594612                        <div class="inactive-theme">
    595                                 <?php
    596                                 /* translators: %s: Theme name. */
    597                                 $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    598                                 ?>
    599                                 <# if ( data.actions.activate ) { #>
    600                                         <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
     613                                <# if ( data.compatibleWP && data.compatiblePHP ) { #>
     614                                        <?php
     615                                        /* translators: %s: Theme name. */
     616                                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
     617                                        ?>
     618                                        <# if ( data.actions.activate ) { #>
     619                                                <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
     620                                        <# } #>
     621                                        <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
     622                                <# } else { #>
     623                                        <?php
     624                                        /* translators: %s: Theme name. */
     625                                        $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
     626                                        ?>
     627                                        <# if ( data.actions.activate ) { #>
     628                                                <a class="button disabled" aria-label="<?php echo $aria_label; ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
     629                                        <# } #>
     630                                        <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
    601631                                <# } #>
    602                                 <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
    603632                        </div>
    604633
  • trunk/src/wp-includes/customize/class-wp-customize-theme-control.php

    r47090 r47816  
    122122                                        <h3 class="theme-name" id="{{ data.section }}-{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
    123123                                        <div class="theme-actions">
    124                                                 <button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button>
     124                                                <# if ( data.theme.compatibleWP && data.theme.compatiblePHP ) { #>
     125                                                        <button type="button" class="button button-primary preview-theme" aria-label="<?php echo esc_attr( $preview_label ); ?>" data-slug="{{ data.theme.id }}"><?php _e( 'Live Preview' ); ?></button>
     126                                                <# } else { #>
     127                                                        <button type="button" class="button button-primary disabled" aria-label="<?php echo esc_attr( $preview_label ); ?>"><?php _e( 'Live Preview' ); ?></button>
     128                                                <# } #>
    125129                                        </div>
    126130                                </div>
Note: See TracChangeset for help on using the changeset viewer.