Skip to content

Commit

Permalink
Make it so the changes in block-templates.php is no longer required
Browse files Browse the repository at this point in the history
  • Loading branch information
Aljullu committed May 15, 2024
1 parent 89a3927 commit 1390923
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions lib/compat/wordpress-6.6/compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,55 @@ function gutenberg_change_patterns_link_and_remove_template_parts_submenu_item()
}
}
add_action( 'admin_init', 'gutenberg_change_patterns_link_and_remove_template_parts_submenu_item' );

/**
* Given that we can't modify `locate_block_template()` in `wp-includes` to call `gutenberg_get_block_templates()` instead of `get_block_templates()` we need to filter the results and return the correct template.
*
* @global string $_wp_current_template_content
* @global int $_wp_current_template_id
*/
$template_filters = array(
'404_template',
'archive_template',
'attachment_template',
'author_template',
'category_template',
'date_template',
'embed_template',
'frontpage_template',
'home_template',
'index_template',
'page_template',
'paged_template',
'privacypolicy_template',
'search_template',
'single_template',
'singular_template',
'tag_template',
'taxonomy_template',
);
foreach ( $template_filters as $template_filter ) {
add_filter(
$template_filter,
function (
$template,
$type,
$templates
) {
global $_wp_current_template_content, $_wp_current_template_id;
foreach ( $templates as $template_slug ) {
$located_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( 'wp_template', $template_slug );
if ( isset( $located_template ) ) {
$_wp_current_template_id = $located_template->id;
$_wp_current_template_content = $located_template->content;

return ABSPATH . WPINC . '/template-canvas.php';
}
}

return $template;
},
10,
3
);
}

0 comments on commit 1390923

Please sign in to comment.