[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 10:19:02 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:                  |     Focuses:
----------------------------+---------------------

Comment (by costdev):

 == What's the difference?

 **wp_is_block_template_theme()**
 Evaluates the current theme.

 **WP_Theme::is_block_based()**
 Evaluates whichever theme is returned from, for example:
 - `new WP_Theme( $stylesheet, $theme_root )`
 - `wp_get_theme( $stylesheet, $theme_root )`

 == Is a class method needed?
 - If we are going to have this functionality in only one place, the class
 itself makes the most sense to me.
 - `wp_is_block_template_theme()`, by design, will only evaluate the
 current theme.

 == Is a 'helper' method needed?
 - The existing `wp_is_block_template_theme()` is a maintenance overhead -
 path updates would require changes in `WP_Theme::is_block_based()` and
 `wp_is_block-template_theme()`.
 - `WP_Theme::is_block_based()` is already a `public` method.
 - If we do want a 'helper' method for the current theme, then I'd agree
 that we should rename the 'helper' method so that they are aligned.
 - I don't think a 'helper' method needs to be anything more than this:

 {{{#!php
 <?php

 /**
  * Returns whether the current theme is a block-based theme or not.
  *
  * @since 5.9.0
  *
  * @return boolean Whether the current theme is a block-based theme or
 not.
  */
 function wp_is_block_based_theme() {
         return wp_get_theme()->is_block_based();
 }
 }}}

 == Is a 'helper' method worth having?
 - This is a minimal and arguable improvement in readability.
 - There are currently 24 instances of `wp_get_theme()` in the Bundled
 Themes. Without additional 'helpers' for other `WP_Theme` methods, this
 would result using `wp_is_block_based_theme()` to check if it's block
 based, and `wp_get_theme()->` for everything else.
 - IMO, this is likely going to result in using
 `wp_get_theme->is_block_based()` directly and the ultimate deprecation of
 `wp_is_block_based_theme()`.

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


More information about the wp-trac mailing list