Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename WP_Theme::is_block_based to WP_Theme::is_block_theme and wp_is_block_template_theme to wp_is_block_theme #2014

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -1993,11 +1993,11 @@ function wp_welcome_panel() {
$customize_url = null;
$can_edit_theme_options = current_user_can( 'edit_theme_options' );
$can_customize = current_user_can( 'customize' );
$is_block_based_theme = wp_is_block_template_theme();
$is_block_theme = wp_is_block_theme();

if ( $is_block_based_theme && $can_edit_theme_options ) {
if ( $is_block_theme && $can_edit_theme_options ) {
$customize_url = esc_url( admin_url( 'site-editor.php' ) );
} elseif ( ! $is_block_based_theme && $can_customize ) {
} elseif ( ! $is_block_theme && $can_customize ) {
$customize_url = wp_customize_url();
}
?>
Expand All @@ -2012,7 +2012,7 @@ function wp_welcome_panel() {
<?php endif; ?>
<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>
<?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
<?php $themes_link = $can_customize && ! $is_block_based_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
<?php $themes_link = $can_customize && ! $is_block_theme ? add_query_arg( 'autofocus[panel]', 'themes', admin_url( 'customize.php' ) ) : admin_url( 'themes.php' ); ?>
<p class="hide-if-no-customize">
<?php
/* translators: %s: URL to Themes panel in Customizer or Themes screen. */
Expand Down
6 changes: 3 additions & 3 deletions src/wp-admin/includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,11 +704,11 @@ function wp_prepare_themes_for_js( $themes = null ) {

$can_edit_theme_options = current_user_can( 'edit_theme_options' );
$can_customize = current_user_can( 'customize' );
$is_block_based_theme = $theme->is_block_based();
$is_block_theme = $theme->is_block_theme();

if ( $is_block_based_theme && $can_edit_theme_options ) {
if ( $is_block_theme && $can_edit_theme_options ) {
$customize_action = esc_url( admin_url( 'site-editor.php' ) );
} elseif ( ! $is_block_based_theme && $can_customize && $can_edit_theme_options ) {
} elseif ( ! $is_block_theme && $can_customize && $can_edit_theme_options ) {
$customize_action = esc_url(
add_query_arg(
array(
Expand Down
8 changes: 4 additions & 4 deletions src/wp-admin/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
/* translators: %s: Number of available theme updates. */
$submenu['themes.php'][5] = array( sprintf( __( 'Themes %s' ), $count ), $appearance_cap, 'themes.php' );

if ( wp_is_block_template_theme() ) {
if ( wp_is_block_theme() ) {
$submenu['themes.php'][6] = array(
sprintf(
/* translators: %s: "beta" label */
Expand All @@ -216,9 +216,9 @@

// Hide Customize link on block themes unless a plugin or theme is using
// customize_register to add a setting.
if ( ! wp_is_block_template_theme() || has_action( 'customize_register' ) ) {
if ( ! wp_is_block_theme() || has_action( 'customize_register' ) ) {
$customize_url = add_query_arg( 'return', urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 'customize.php' );
$position = wp_is_block_template_theme() ? 7 : 6;
$position = wp_is_block_theme() ? 7 : 6;

$submenu['themes.php'][ $position ] = array( __( 'Customize' ), 'customize', esc_url( $customize_url ), '', 'hide-if-no-customize' );
}
Expand Down Expand Up @@ -255,7 +255,7 @@
*/
function _add_themes_utility_last() {
add_submenu_page(
wp_is_block_template_theme() ? 'tools.php' : 'themes.php',
wp_is_block_theme() ? 'tools.php' : 'themes.php',
__( 'Theme Editor' ),
__( 'Theme Editor' ),
'edit_themes',
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
);
}

if ( ! wp_is_block_template_theme() ) {
if ( ! wp_is_block_theme() ) {
wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/theme-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
</div>
<?php endif; ?>

<?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_template_theme() && current_user_can( 'customize' ) ) : ?>
<?php if ( preg_match( '/\.css$/', $file ) && ! wp_is_block_theme() && current_user_can( 'customize' ) ) : ?>
<div id="message" class="notice-info notice">
<p><strong><?php _e( 'Did you know?' ); ?></strong></p>
<p>
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/admin-bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function wp_admin_bar_site_menu( $wp_admin_bar ) {
*/
function wp_admin_bar_edit_site_menu( $wp_admin_bar ) {
// Don't show if a block theme is not activated.
if ( ! wp_is_block_template_theme() ) {
if ( ! wp_is_block_theme() ) {
return;
}

Expand Down Expand Up @@ -447,7 +447,7 @@ function wp_admin_bar_customize_menu( $wp_admin_bar ) {
global $wp_customize;

// Don't show if a block theme is activated.
if ( wp_is_block_template_theme() ) {
if ( wp_is_block_theme() ) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ public function is_allowed( $check = 'both', $blog_id = null ) {
*
* @return bool
*/
public function is_block_based() {
public function is_block_theme() {
$paths_to_index_block_template = array(
$this->get_file_path( '/block-templates/index.html' ),
$this->get_file_path( '/templates/index.html' ),
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ function create_initial_post_types() {
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'has_archive' => false,
'show_ui' => wp_is_block_template_theme(),
'show_ui' => wp_is_block_theme(),
'show_in_menu' => false,
'show_in_rest' => true,
'rewrite' => false,
Expand Down Expand Up @@ -416,7 +416,7 @@ function create_initial_post_types() {
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'has_archive' => false,
'show_ui' => wp_is_block_template_theme(),
'show_ui' => wp_is_block_theme(),
'show_in_menu' => false,
'show_in_rest' => true,
'rewrite' => false,
Expand Down Expand Up @@ -503,7 +503,7 @@ function create_initial_post_types() {
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'has_archive' => false,
'show_ui' => wp_is_block_template_theme(),
'show_ui' => wp_is_block_theme(),
'show_in_menu' => 'themes.php',
'show_in_admin_bar' => false,
'show_in_rest' => true,
Expand Down
5 changes: 2 additions & 3 deletions src/wp-includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,6 @@ function create_initial_theme_features() {
*
* @return boolean Whether the current theme is a block-based theme or not.
*/
function wp_is_block_template_theme() {
return is_readable( get_theme_file_path( '/block-templates/index.html' ) ) ||
is_readable( get_theme_file_path( '/templates/index.html' ) );
function wp_is_block_theme() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anton-vlasenko As Gutenberg has to support WP 5.7 and 5.8, how will renaming this function impact the plugin? Are you planning to rename it in Gutenberg too and deprecate the original name? Or does renaming not affect Gutenberg?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hellofromtonya Companion issue is here and the PR for that issue seems to have been updated in line with this page.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @costdev for pointing that out.

Copy link
Author

@anton-vlasenko anton-vlasenko Dec 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hellofromtonya
Yes, I'm planning to rename it in Gutenberg. I've created a PR that renames it.
IMO it doesn't make sense to keep both wp_is_block_theme and wp_is_block_template_theme functions in WordPress Core.
I think we still have time to rename it in Gutenberg before the Gutenberg 12.1.0 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @anton-vlasenko. Part of the consolidation discuss is to help with the backports from Gutenberg to Core. So wanted to make sure whatever happens here also happens in the Gutenberg repo too, i.e. code matches.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making sure, @hellofromtonya.
I 100% agree.
We need to be careful to make sure we don't break Gutenberg.

return wp_get_theme()->is_block_theme();
}
18 changes: 6 additions & 12 deletions tests/phpunit/tests/theme/wpTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,25 @@ public function test_network_disable_multiple_themes() {
}

/**
* @dataProvider data_is_block_based
* @dataProvider data_is_block_theme
* @ticket 54460
*
* @covers WP_Theme::is_block_based
* @covers WP_Theme::is_block_theme
*
* @param string $theme_dir Directory of the theme to test.
* @param bool $expected Expected result.
*/
public function test_is_block_based( $theme_dir, $expected ) {
$theme = new WP_Theme( $theme_dir, $this->theme_root );
$actual = $theme->is_block_based();

if ( $expected ) {
$this->assertTrue( $actual );
} else {
$this->assertFalse( $actual );
}
public function test_is_block_theme( $theme_dir, $expected ) {
hellofromtonya marked this conversation as resolved.
Show resolved Hide resolved
$theme = new WP_Theme( $theme_dir, $this->theme_root );
$this->assertSame( $expected, $theme->is_block_theme() );
}

/**
* Data provider.
*
* @return array
*/
public function data_is_block_based() {
public function data_is_block_theme() {
return array(
'default - non-block theme' => array(
'theme_dir' => 'default',
Expand Down