[wp-trac] [WordPress Trac] #58299: Block template is located twice in `get_query_template()`

WordPress Trac noreply at wordpress.org
Thu May 11 12:29:49 UTC 2023


#58299: Block template is located twice in `get_query_template()`
--------------------------+-----------------------------
 Reporter:  dlh           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:  5.9
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 `get_query_template()` currently calls `locate_block_template()` twice
 instead of once when a template is rendered, leading to a second call to
 `resolve_block_template()`, `get_block_templates()`, and so on.

 The first call is hardcoded directly after `locate_template()` here:
 https://github.com/WordPress/wordpress-develop/blob/c40e0c/src/wp-
 includes/template.php#L66

 This call was added in [51003], the original commit to add support for
 block templates to classic themes.

 The second call occurs during the `{$type}_template` filter here:
 https://github.com/WordPress/wordpress-develop/blob/c40e0c/src/wp-includes
 /block-template.php#L25

 This second call was added in [52316] for #54553. However, as far as I can
 tell, the only thing that was needed to fix the issue in #54553 was the
 callback added to `pre_get_posts`.

 Adding `locate_block_template()` as a filter on `{$type}_template` would
 have been necessary in the Gutenberg plugin, but not in core, given the
 call that was added directly to `get_query_template()`.

 You can test this using the linked PR, which would remove the
 `{$type}_template` filters and leave just the `pre_get_posts` addition.
 With that PR applied, the verification steps in ticket:54553#comment:7
 should still pass.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58299>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list