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.
Fixes #54878.


Built from https://develop.svn.wordpress.org/trunk@52819


git-svn-id: http://core.svn.wordpress.org/trunk@52408 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-03-04 02:39:03 +00:00
parent 66ed09edeb
commit 8db01b9c6b
5 changed files with 36 additions and 7 deletions

View File

@ -3568,6 +3568,19 @@ function wp_ajax_query_themes() {
$update_php = network_admin_url( 'update.php?action=install-theme' );
$installed_themes = search_theme_directories();
if ( false === $installed_themes ) {
$installed_themes = array();
}
foreach ( $installed_themes as $theme_slug => $theme_data ) {
// Ignore child themes.
if ( str_contains( $theme_slug, '/' ) ) {
unset( $installed_themes[ $theme_slug ] );
}
}
foreach ( $api->themes as &$theme ) {
$theme->install_url = add_query_arg(
array(
@ -3599,12 +3612,19 @@ function wp_ajax_query_themes() {
}
}
$is_theme_installed = array_key_exists( $theme->slug, $installed_themes );
// We only care about installed themes.
$theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );
$theme->customize_url = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
wp_customize_url( $theme->slug )
$customize_url
);
}
@ -4139,6 +4159,9 @@ function wp_ajax_install_theme() {
}
}
$theme = wp_get_theme( $slug );
$status['blockTheme'] = $theme->is_block_theme();
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$status['customizeUrl'] = add_query_arg(
array(

View File

@ -622,6 +622,9 @@ themes.view.Theme = wp.Backbone.View.extend({
if ( _this.model.get( 'id' ) === response.slug ) {
_this.model.set( { 'installed': true } );
}
if ( response.blockTheme ) {
_this.model.set( { 'block_theme': true } );
}
} );
wp.updates.installTheme( {

File diff suppressed because one or more lines are too long

View File

@ -35,9 +35,10 @@ if ( false === $installed_themes ) {
$installed_themes = array();
}
foreach ( $installed_themes as $k => $v ) {
if ( false !== strpos( $k, '/' ) ) {
unset( $installed_themes[ $k ] );
foreach ( $installed_themes as $theme_slug => $theme_data ) {
// Ignore child themes.
if ( str_contains( $theme_slug, '/' ) ) {
unset( $installed_themes[ $theme_slug ] );
}
}
@ -373,7 +374,9 @@ if ( $tab ) {
<# } #>
<# if ( data.customize_url ) { #>
<# if ( ! data.active ) { #>
<a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
<# if ( ! data.block_theme ) { #>
<a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
<# } #>
<# } else { #>
<a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Customize' ); ?></a>
<# } #>

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-52818';
$wp_version = '6.0-alpha-52819';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.