Make WordPress Core

Changeset 52330


Ignore:
Timestamp:
12/07/2021 12:00:45 AM (3 years ago)
Author:
hellofromTonya
Message:

Themes: Better names for WP_Theme::is_block_theme() and wp_is_block_theme() and make wp_is_block_theme() a wrapper.

This commit renames the following method and function to better represent block theme terminology:

  • WP_Theme::is_block_based() to WP_Theme::is_block_theme()
  • wp_is_block_template_theme() to wp_is_block_theme()

It also changes wp_is_block_theme() to be a helper wrapper (sugar syntax) for wp_get_theme()->is_block_theme();. Why? To ensure both the method and function behave the same, to help Gutenberg maintain WordPress cross-version compatibility, and to make it less cumbersome to port changes from Gutenberg to Core.

Follow-up to [52069], [52247], [52279].

Props antonvlasenko, costdev, hellofromTonya, noisysocks.
Fixes #54550.

Location:
trunk
Files:
10 edited

Legend:

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

    r52279 r52330  
    19941994    $can_edit_theme_options = current_user_can( 'edit_theme_options' );
    19951995    $can_customize          = current_user_can( 'customize' );
    1996     $is_block_based_theme   = wp_is_block_template_theme();
    1997 
    1998     if ( $is_block_based_theme && $can_edit_theme_options ) {
     1996    $is_block_theme         = wp_is_block_theme();
     1997
     1998    if ( $is_block_theme && $can_edit_theme_options ) {
    19991999        $customize_url = esc_url( admin_url( 'site-editor.php' ) );
    2000     } elseif ( ! $is_block_based_theme && $can_customize ) {
     2000    } elseif ( ! $is_block_theme && $can_customize ) {
    20012001        $customize_url = wp_customize_url();
    20022002    }
     
    20132013        <a class="button button-primary button-hero hide-if-customize" href="<?php echo esc_url( admin_url( 'themes.php' ) ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
    20142014        <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
    2015             <?php $themes_link = $can_customize && ! $is_block_based_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
     2015            <?php $themes_link = $can_customize && ! $is_block_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
    20162016            <p class="hide-if-no-customize">
    20172017                <?php
  • trunk/src/wp-admin/includes/theme.php

    r52279 r52330  
    705705        $can_edit_theme_options = current_user_can( 'edit_theme_options' );
    706706        $can_customize          = current_user_can( 'customize' );
    707         $is_block_based_theme   = $theme->is_block_based();
    708 
    709         if ( $is_block_based_theme && $can_edit_theme_options ) {
     707        $is_block_theme         = $theme->is_block_theme();
     708
     709        if ( $is_block_theme && $can_edit_theme_options ) {
    710710            $customize_action = esc_url( admin_url( 'site-editor.php' ) );
    711         } elseif ( ! $is_block_based_theme && $can_customize && $can_edit_theme_options ) {
     711        } elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) {
    712712            $customize_action = esc_url(
    713713                add_query_arg(
  • trunk/src/wp-admin/menu.php

    r52232 r52330  
    203203    $submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap, 'themes.php' );
    204204
    205 if ( wp_is_block_template_theme() ) {
     205if ( wp_is_block_theme() ) {
    206206    $submenu['themes.php'][6] = array(
    207207        sprintf(
     
    217217// Hide Customize link on block themes unless a plugin or theme is using
    218218// customize_register to add a setting.
    219 if ( ! wp_is_block_template_theme() || has_action( 'customize_register' ) ) {
     219if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) {
    220220    $customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
    221     $position      = wp_is_block_template_theme() ? 7 : 6;
     221    $position      = wp_is_block_theme() ? 7 : 6;
    222222
    223223    $submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
     
    256256function _add_themes_utility_last() {
    257257    add_submenu_page(
    258         wp_is_block_template_theme() ? 'tools.php' : 'themes.php',
     258        wp_is_block_theme() ? 'tools.php' : 'themes.php',
    259259        __( 'Theme Editor' ),
    260260        __( 'Theme Editor' ),
  • trunk/src/wp-admin/site-editor.php

    r52281 r52330  
    2020}
    2121
    22 if ( ! wp_is_block_template_theme() ) {
     22if ( ! wp_is_block_theme() ) {
    2323    wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) );
    2424}
  • trunk/src/wp-admin/theme-editor.php

    r52279 r52330  
    197197<?php endif; ?>
    198198
    199 <?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_template_theme() && current_user_can( 'customize' ) ) : ?>
     199<?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) : ?>
    200200    <div id="message" class="notice-info notice">
    201201        <p><strong><?php _e( 'Did you know?' ); ?></strong></p>
  • trunk/src/wp-includes/admin-bar.php

    r52158 r52330  
    418418function wp_admin_bar_edit_site_menu( $wp_admin_bar ) {
    419419    // Don't show if a block theme is not activated.
    420     if ( ! wp_is_block_template_theme() ) {
     420    if ( ! wp_is_block_theme() ) {
    421421        return;
    422422    }
     
    448448
    449449    // Don't show if a block theme is activated.
    450     if ( wp_is_block_template_theme() ) {
     450    if ( wp_is_block_theme() ) {
    451451        return;
    452452    }
  • trunk/src/wp-includes/class-wp-theme.php

    r52297 r52330  
    14681468     * @return bool
    14691469     */
    1470     public function is_block_based() {
     1470    public function is_block_theme() {
    14711471        $paths_to_index_block_template = array(
    14721472            $this->get_file_path( '/block-templates/index.html' ),
  • trunk/src/wp-includes/post.php

    r52275 r52330  
    357357            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
    358358            'has_archive'           => false,
    359             'show_ui'               => wp_is_block_template_theme(),
     359            'show_ui'               => wp_is_block_theme(),
    360360            'show_in_menu'          => false,
    361361            'show_in_rest'          => true,
     
    417417            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
    418418            'has_archive'           => false,
    419             'show_ui'               => wp_is_block_template_theme(),
     419            'show_ui'               => wp_is_block_theme(),
    420420            'show_in_menu'          => false,
    421421            'show_in_rest'          => true,
     
    504504            '_builtin'              => true, /* internal use only. don't use this when registering your own post type. */
    505505            'has_archive'           => false,
    506             'show_ui'               => wp_is_block_template_theme(),
     506            'show_ui'               => wp_is_block_theme(),
    507507            'show_in_menu'          => 'themes.php',
    508508            'show_in_admin_bar'     => false,
  • trunk/src/wp-includes/theme.php

    r52256 r52330  
    40914091 * @return boolean Whether the current theme is a block-based theme or not.
    40924092 */
    4093 function wp_is_block_template_theme() {
    4094     return is_readable( get_theme_file_path( '/block-templates/index.html' ) ) ||
    4095         is_readable( get_theme_file_path( '/templates/index.html' ) );
    4096 }
     4093function wp_is_block_theme() {
     4094    return wp_get_theme()->is_block_theme();
     4095}
  • trunk/tests/phpunit/tests/theme/wpTheme.php

    r52279 r52330  
    249249
    250250    /**
    251      * @dataProvider data_is_block_based
     251     * @dataProvider data_is_block_theme
    252252     * @ticket 54460
    253253     *
    254      * @covers WP_Theme::is_block_based
     254     * @covers WP_Theme::is_block_theme
    255255     *
    256256     * @param string $theme_dir Directory of the theme to test.
    257257     * @param bool   $expected  Expected result.
    258258     */
    259     public function test_is_block_based( $theme_dir, $expected ) {
    260         $theme  = new WP_Theme( $theme_dir, $this->theme_root );
    261         $actual = $theme->is_block_based();
    262 
    263         if ( $expected ) {
    264             $this->assertTrue( $actual );
    265         } else {
    266             $this->assertFalse( $actual );
    267         }
     259    public function test_is_block_theme( $theme_dir, $expected ) {
     260        $theme = new WP_Theme( $theme_dir, $this->theme_root );
     261        $this->assertSame( $expected, $theme->is_block_theme() );
    268262    }
    269263
     
    273267     * @return array
    274268     */
    275     public function data_is_block_based() {
     269    public function data_is_block_theme() {
    276270        return array(
    277271            'default - non-block theme' => array(
Note: See TracChangeset for help on using the changeset viewer.