@@ -78,47 +78,8 @@ public function get_items( $request ) {
7878 if ( isset ( $ request ['post_type ' ] ) ) {
7979 $ query ['post_type ' ] = $ request ['post_type ' ];
8080 }
81- $ template_files = _get_block_templates_files ( 'wp_template ' , $ query );
82- $ query_result = array ();
83- foreach ( $ template_files as $ template_file ) {
84- $ query_result [] = _build_block_template_result_from_file ( $ template_file , 'wp_template ' );
85- }
86-
87- // Add templates registered in the template registry. Filtering out the ones which have a theme file.
88- $ registered_templates = WP_Block_Templates_Registry::get_instance ()->get_by_query ( $ query );
89- $ matching_registered_templates = array_filter (
90- $ registered_templates ,
91- function ( $ registered_template ) use ( $ template_files ) {
92- foreach ( $ template_files as $ template_file ) {
93- if ( $ template_file ['slug ' ] === $ registered_template ->slug ) {
94- return false ;
95- }
96- }
97- return true ;
98- }
99- );
100-
101- $ query_result = array_merge ( $ query_result , $ matching_registered_templates );
102-
103- /**
104- * Filters the array of queried block templates array after they've been fetched.
105- *
106- * @since 5.9.0
107- *
108- * @param WP_Block_Template[] $query_result Array of found block templates.
109- * @param array $query {
110- * Arguments to retrieve templates. All arguments are optional.
111- *
112- * @type string[] $slug__in List of slugs to include.
113- * @type int $wp_id Post ID of customized template.
114- * @type string $area A 'wp_template_part_area' taxonomy value to filter by (for 'wp_template_part' template type only).
115- * @type string $post_type Post type to get the templates for.
116- * }
117- * @param string $template_type wp_template or wp_template_part.
118- */
119- $ query_result = apply_filters ( 'get_block_templates ' , $ query_result , $ query , 'wp_template ' );
120-
121- $ templates = array ();
81+ $ query_result = gutenberg_get_registered_block_templates ( $ query );
82+ $ templates = array ();
12283 foreach ( $ query_result as $ template ) {
12384 $ item = $ this ->prepare_item_for_response ( $ template , $ request );
12485 $ item ->data ['type ' ] = 'wp_registered_template ' ;
0 commit comments