[wp-trac] [WordPress Trac] #54552: Consider consolidating wp_is_block_template_theme() and WP_Theme::is_block_based()

WordPress Trac noreply at wordpress.org
Thu Dec 2 15:48:24 UTC 2021


#54552: Consider consolidating wp_is_block_template_theme() and
WP_Theme::is_block_based()
----------------------------+---------------------
 Reporter:  noisysocks      |       Owner:  (none)
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  5.9
Component:  Themes          |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:
----------------------------+---------------------
Changes (by hellofromTonya):

 * keywords:   => needs-patch


Comment:

 Thanks @noisysocks for opening this ticket to discuss the consolidation
 and naming for what's needed not only for 5.9 but for the future.

 This is a follow-up to [52279].

 == Consolidate?

 === What's used in Core?

 Let's explore how Core uses functionality to get information about a
 theme. @costdev gave a good inside look. I'd like to add to his comment.

 `get_theme_file_path()` is used by themes to get its file path. Core
 itself uses it in only 3 places: twice in `wp_is_block_template_theme()`
 and once in `get_block_editor_theme_styles()`.

 How does Core get information about the current theme?

 It uses helper functions (such as `get_stylesheet()` and
 `get_stylesheet_directory()`) and/or `wp_get_theme()` which uses
 `get_stylesheet()` to default to the current theme. Which is primarily
 used? `wp_get_theme()` is primarily used with a fallback to the helper
 functions.

 === My thoughts

 I think the helper global function `wp_is_block_template_theme()` is not
 needed and is redundant. It's usages can be replaced with
 `wp_get_theme()->is_block_based()`. By not passing a stylesheet name,
 `wp_get_theme()` will default to the current theme. Therefore, it is doing
 the same thing as `wp_is_block_template_theme()`.

 == Is the method name the right name?

 Is "block-based" themes the right now? Isn't the new terminology more
 aligned with block theme whereas "block-based" themes term was before FSE.
 Is yes, then I'd suggest changing the method name to `is_block_theme()`
 which would change invoking it to

 {{{#!php
 wp_get_theme()->is_block_theme()
 }}}

 @noisysocks @antonvlasenko @costdev what do you think about renaming the
 method?

 == My vote

 1. Remove `wp_is_block_template_theme()`
 2. Rename the `WP_Theme::is_block_based()` to `WP_Theme::is_block_theme()`
 3. Replace all instances of `wp_is_block_template_theme()` with
 `wp_get_theme()->is_block_theme()`

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54552#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list