Make WordPress Core

Changeset 53008


Ignore:
Timestamp:
03/29/2022 08:53:31 AM (3 years ago)
Author:
audrasjb
Message:

Themes: Hide block themes live preview link following installation.

Prevent the Customizer/Live Preview button from showing for installed block themes when on the theme installation page.

Props antonvlasenko, costdev, ironprogrammer.
Merges [52819] to the 5.9 branch.
Fixes #54878.

Location:
branches/5.9
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9

  • branches/5.9/src/js/_enqueues/wp/theme.js

    r51083 r53008  
    623623                _this.model.set( { 'installed': true } );
    624624            }
     625            if ( response.blockTheme ) {
     626                _this.model.set( { 'block_theme': true } );
     627            }
    625628        } );
    626629
  • branches/5.9/src/wp-admin/includes/ajax-actions.php

    r52170 r53008  
    35693569    $update_php = network_admin_url( 'update.php?action=install-theme' );
    35703570
     3571    $installed_themes = search_theme_directories();
     3572
     3573    if ( false === $installed_themes ) {
     3574        $installed_themes = array();
     3575    }
     3576
     3577    foreach ( $installed_themes as $theme_slug => $theme_data ) {
     3578        // Ignore child themes.
     3579        if ( str_contains( $theme_slug, '/' ) ) {
     3580            unset( $installed_themes[ $theme_slug ] );
     3581        }
     3582    }
     3583
    35713584    foreach ( $api->themes as &$theme ) {
    35723585        $theme->install_url = add_query_arg(
     
    36003613        }
    36013614
     3615        $is_theme_installed = array_key_exists( $theme->slug, $installed_themes );
     3616
     3617        // We only care about installed themes.
     3618        $theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();
     3619
    36023620        if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
     3621            $customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );
     3622
    36033623            $theme->customize_url = add_query_arg(
    36043624                array(
    36053625                    'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
    36063626                ),
    3607                 wp_customize_url( $theme->slug )
     3627                $customize_url
    36083628            );
    36093629        }
     
    41394159        }
    41404160    }
     4161
     4162    $theme = wp_get_theme( $slug );
     4163    $status['blockTheme'] = $theme->is_block_theme();
    41414164
    41424165    if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
  • branches/5.9/src/wp-admin/theme-install.php

    r51923 r53008  
    3636}
    3737
    38 foreach ( $installed_themes as $k => $v ) {
    39     if ( false !== strpos( $k, '/' ) ) {
    40         unset( $installed_themes[ $k ] );
     38foreach ( $installed_themes as $theme_slug => $theme_data ) {
     39    // Ignore child themes.
     40    if ( str_contains( $theme_slug, '/' ) ) {
     41        unset( $installed_themes[ $theme_slug ] );
    4142    }
    4243}
     
    374375                    <# if ( data.customize_url ) { #>
    375376                        <# if ( ! data.active ) { #>
    376                             <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
     377                            <# if ( ! data.block_theme ) { #>
     378                                <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
     379                            <# } #>
    377380                        <# } else { #>
    378381                            <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Customize' ); ?></a>
Note: See TracChangeset for help on using the changeset viewer.