Make WordPress Core

Changeset 56059


Ignore:
Timestamp:
06/27/2023 09:34:34 AM (16 months ago)
Author:
isabel_brison
Message:

General: add block theme previews.

Adds a preview link to block themes in the themes screen, opening the previews in the site editor.

Props onemaggie, andraganescu, audrasjb, flixos90, peterwilsoncc, spacedmonkey, scruffian.
Fixes #58561.

Location:
trunk/src/wp-admin
Files:
1 added
4 edited

Legend:

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

    r54122 r56059  
    169169// Append '(Draft)' to draft page titles in the privacy page dropdown.
    170170add_filter( 'list_pages', '_wp_privacy_settings_filter_draft_page_titles', 10, 2 );
     171
     172// Attaches filters to enable theme previews in the Site Editor.
     173if ( ! empty( $_GET['wp_theme_preview'] ) ) {
     174    add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
     175    add_filter( 'template', 'wp_get_theme_preview_path' );
     176    add_action( 'init', 'wp_attach_theme_preview_middleware' );
     177}
  • trunk/src/wp-admin/includes/admin.php

    r54797 r56059  
    7272/** WordPress Theme Administration API */
    7373require_once ABSPATH . 'wp-admin/includes/theme.php';
     74require_once ABSPATH . 'wp-admin/includes/theme-previews.php';
    7475
    7576/** WordPress Privacy Functions */
  • trunk/src/wp-admin/includes/theme.php

    r55276 r56059  
    712712
    713713        if ( $is_block_theme && $can_edit_theme_options ) {
    714             $customize_action = esc_url( admin_url( 'site-editor.php' ) );
     714            $customize_action = admin_url( 'site-editor.php' );
     715            if ( $current_theme !== $slug ) {
     716                $customize_action = add_query_arg( 'wp_theme_preview', $slug, $customize_action );
     717            }
    715718        } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) {
    716             $customize_action = esc_url(
    717                 add_query_arg(
    718                     array(
    719                         'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
    720                     ),
    721                     wp_customize_url( $slug )
    722                 )
     719            $customize_action = wp_customize_url( $slug );
     720        }
     721        if ( null !== $customize_action ) {
     722            $customize_action = add_query_arg(
     723                array(
     724                    'return' => urlencode( sanitize_url( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) ),
     725                ),
     726                $customize_action
    723727            );
     728            $customize_action = esc_url( $customize_action );
    724729        }
    725730
  • trunk/src/wp-admin/themes.php

    r55414 r56059  
    556556            <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    557557            <?php
    558             if ( ! $theme['blockTheme'] && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
     558            // Only classic themes require the "customize" capability.
     559            if ( current_user_can( 'edit_theme_options' ) && ( $theme['blockTheme'] || current_user_can( 'customize' ) ) ) {
    559560                /* translators: %s: Theme name. */
    560561                $live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
     
    915916                    ?>
    916917                    <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    917                     <# if ( ! data.blockTheme ) { #>
    918                         <?php
    919                         /* translators: %s: Theme name. */
    920                         $live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
    921                         ?>
    922                         <a aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>" class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
    923                     <# } #>
     918                    <?php
     919                    /* translators: %s: Theme name. */
     920                    $live_preview_aria_label = sprintf( _x( 'Live Preview %s', 'theme' ), '{{ data.name }}' );
     921                    ?>
     922                    <a aria-label="<?php echo esc_attr( $live_preview_aria_label ); ?>" class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
    924923                <# } else { #>
    925924                    <?php
Note: See TracChangeset for help on using the changeset viewer.