Make WordPress Core

Ticket #42411: 42411.0.diff

File 42411.0.diff, 6.7 KB (added by westonruter, 6 years ago)

https://github.com/xwp/wordpress-develop/pull/300/files

  • src/wp-admin/theme-install.php

    diff --git src/wp-admin/theme-install.php src/wp-admin/theme-install.php
    index 43f105f377..63a73d0f07 100644
    get_current_screen()->set_help_sidebar( 
    123123
    124124include(ABSPATH . 'wp-admin/admin-header.php');
    125125
     126$is_customize_preview_available = true;
     127
     128/** This filter is documented in wp-includes/class-wp-customize-manager.php */
     129if ( ! apply_filters( 'customize_changeset_branching', false ) ) {
     130        $is_customize_preview_available = count( get_posts( array(
     131                'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ),
     132                'author' => 'any',
     133                'posts_per_page' => 1,
     134                'order' => 'DESC',
     135                'orderby' => 'date',
     136                'post_type' => 'customize_changeset',
     137                'no_found_rows' => true,
     138                'cache_results' => true,
     139                'update_post_meta_cache' => false,
     140                'update_post_term_cache' => false,
     141                'lazy_load_term_meta' => false,
     142        ) ) ) === 0;
     143}
     144
    126145?>
    127146<div class="wrap">
    128147        <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
    include(ABSPATH . 'wp-admin/admin-header.php'); 
    150169                <p><?php _e( 'The Theme Installer screen requires JavaScript.' ); ?></p>
    151170        </div>
    152171
     172        <?php if ( ! $is_customize_preview_available ) : ?>
     173                <div class="notice notice-info">
     174                        <p><?php _e( 'Live preview for inactive themes is not currently available because there are drafted or scheduled changes for the active theme.' ); ?></p>
     175                </div>
     176        <?php endif; ?>
     177
    153178        <div class="upload-theme">
    154179        <?php install_themes_upload(); ?>
    155180        </div>
    if ( $tab ) { 
    277302                                <# if ( data.activate_url ) { #>
    278303                                        <a class="button button-primary activate" href="{{ data.activate_url }}" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    279304                                <# } #>
    280                                 <# if ( data.customize_url ) { #>
     305                                <# if ( data.customize_url && <?php echo wp_json_encode( $is_customize_preview_available ); ?> ) { #>
    281306                                        <a class="button load-customize" href="{{ data.customize_url }}"><?php _e( 'Live Preview' ); ?></a>
    282307                                <# } else { #>
    283308                                        <button class="button preview install-theme-preview"><?php _e( 'Preview' ); ?></button>
  • src/wp-admin/themes.php

    diff --git src/wp-admin/themes.php src/wp-admin/themes.php
    index 9218983239..c5a8a2deb8 100644
    wp_enqueue_script( 'theme' ); 
    148148wp_enqueue_script( 'updates' );
    149149
    150150require_once( ABSPATH . 'wp-admin/admin-header.php' );
     151
     152$is_customize_preview_available = true;
     153
     154/** This filter is documented in wp-includes/class-wp-customize-manager.php */
     155if ( ! apply_filters( 'customize_changeset_branching', false ) ) {
     156        $is_customize_preview_available = count( get_posts( array(
     157                'post_status' => array_diff( get_post_stati(), array( 'auto-draft', 'publish', 'trash', 'inherit', 'private' ) ),
     158                'author' => 'any',
     159                'posts_per_page' => 1,
     160                'order' => 'DESC',
     161                'orderby' => 'date',
     162                'post_type' => 'customize_changeset',
     163                'no_found_rows' => true,
     164                'cache_results' => true,
     165                'update_post_meta_cache' => false,
     166                'update_post_term_cache' => false,
     167                'lazy_load_term_meta' => false,
     168        ) ) ) === 0;
     169}
     170
    151171?>
    152172
    153173<div class="wrap">
    if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) : ?> 
    178198<?php
    179199endif;
    180200
     201if ( ! $is_customize_preview_available ) :
     202        ?>
     203        <div class="notice notice-info">
     204                <p><?php _e( 'Live preview for inactive themes is not currently available because there are drafted or scheduled changes for the active theme.' ); ?></p>
     205        </div>
     206        <?php
     207endif;
     208
    181209$ct = wp_get_theme();
    182210
    183211if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
    foreach ( $themes as $theme ) : 
    296324                        $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    297325                        ?>
    298326                        <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
    299                         <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
     327                        <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) && $is_customize_preview_available ) { ?>
    300328                                <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
    301329                        <?php } ?>
    302330                <?php } ?>
    $can_install = current_user_can( 'install_themes' ); 
    431459                                $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
    432460                                ?>
    433461                                <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
    434                                 <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     462                                <?php if ( $is_customize_preview_available ) : ?>
     463                                        <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
     464                                <?php endif; ?>
    435465                        <# } #>
    436466                </div>
    437467        </div>
    $can_install = current_user_can( 'install_themes' ); 
    492522                                <# if ( data.actions.activate ) { #>
    493523                                        <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
    494524                                <# } #>
    495                                 <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
     525                                <?php if ( $is_customize_preview_available ) : ?>
     526                                        <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
     527                                <?php endif; ?>
    496528                        </div>
    497529
    498530                        <# if ( ! data.active && data.actions['delete'] ) { #>
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index 12256d2173..a063e3e148 100644
    final class WP_Customize_Manager { 
    782782                 *
    783783                 * @since 4.9.0
    784784                 *
    785                  * @param bool                 $allow_branching Whether branching is allowed. If `false`, the default,
    786                  *                                              then only one saved changeset exists at a time.
    787                  * @param WP_Customize_Manager $wp_customize    Manager instance.
     785                 * @param bool $allow_branching Whether branching is allowed. If `false`, the default,
     786                 *                              then only one saved changeset exists at a time.
    788787                 */
    789                 $this->branching = apply_filters( 'customize_changeset_branching', $this->branching, $this );
     788                $this->branching = apply_filters( 'customize_changeset_branching', $this->branching );
    790789
    791790                return $this->branching;
    792791        }