[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 17:55:17 UTC 2021

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

Comment (by hellofromTonya):

 Replying to [comment:3 antonvlasenko]:
 > When replacing `wp_is_block_template_theme` with
 `wp_get_theme()→is_block_based()`, we must take into account that
 `get_stylesheet_directory` and `get_template_directory` functions use
 filters (`get_stylesheet_directory` and `template_directory` filters
 > These functions are used by `wp_is_block_template_theme` function

 Yes, but `wp_get_theme()` is also filterable as:
 - it invokes `get_stylesheet()` which is filtered through `'stylesheet'`
 which is also invoked within `get_stylesheet_directory()`
 - and it invokes `get_option()` which is also filterable
 - and `WP_Theme::get_file_path()` invokes the same `'theme_file_path'`
 filter as in `get_theme_file_path()`.

 This is why using `wp_get_theme()` instead of `new WP_Theme()` ensures the
 filters are available.

 Filters that are not invoked with the `wp_get_theme()->is_block_based()`
 approach are:
 * `'stylesheet_directory'` which is in `get_stylesheet_directory()`
 * `'theme_root'` which is invoked in `get_theme_root()`
 However, the combination of these 2 filters is available through the
 `'theme_file_path'` filter.

 The question then is this: Does any of the Gutenberg code dependent upon
 the `'stylesheet_directory'` and/or `'theme_root'` filters? Searching the
 codebase, I did not find any code in Core that is hooked into either of
 these filters.

 So I think it's safe to remove the wrapper function. It don't think it
 adds value. And once it's in a final release, it has to be maintained for
 backwards-compatibility. Unless there's a compelling reason to add it,
 removing it reduces maintenance and documentation costs/effort.

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

More information about the wp-trac mailing list