Changeset 59073 for trunk/src/wp-includes/block-template-utils.php
- Timestamp:
- 09/20/2024 02:05:50 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/block-template-utils.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-template-utils.php
r59003 r59073 592 592 $template->is_custom = true; 593 593 $template->modified = null; 594 595 if ( 'wp_template' === $template_type ) { 596 $registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template_file['slug'] ); 597 if ( $registered_template ) { 598 $template->plugin = $registered_template->plugin; 599 $template->title = empty( $template->title ) || $template->title === $template->slug ? $registered_template->title : $template->title; 600 $template->description = empty( $template->description ) ? $registered_template->description : $template->description; 601 } 602 } 594 603 595 604 if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) { … … 1015 1024 } 1016 1025 1026 if ( 'wp_template' === $post->post_type ) { 1027 $registered_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $template->slug ); 1028 if ( $registered_template ) { 1029 $template->plugin = $registered_template->plugin; 1030 $template->origin = 1031 'theme' !== $template->origin && 'theme' !== $template->source ? 1032 'plugin' : 1033 $template->origin; 1034 $template->title = empty( $template->title ) || $template->title === $template->slug ? $registered_template->title : $template->title; 1035 $template->description = empty( $template->description ) ? $registered_template->description : $template->description; 1036 } 1037 } 1038 1017 1039 $hooked_blocks = get_hooked_blocks(); 1018 1040 if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { … … 1158 1180 $query_result[] = _build_block_template_result_from_file( $template_file, $template_type ); 1159 1181 } 1182 1183 if ( 'wp_template' === $template_type ) { 1184 // Add templates registered in the template registry. Filtering out the ones which have a theme file. 1185 $registered_templates = WP_Block_Templates_Registry::get_instance()->get_by_query( $query ); 1186 $matching_registered_templates = array_filter( 1187 $registered_templates, 1188 function ( $registered_template ) use ( $template_files ) { 1189 foreach ( $template_files as $template_file ) { 1190 if ( $template_file['slug'] === $registered_template->slug ) { 1191 return false; 1192 } 1193 } 1194 return true; 1195 } 1196 ); 1197 $query_result = array_merge( $query_result, $matching_registered_templates ); 1198 } 1160 1199 } 1161 1200 … … 1288 1327 list( $theme, $slug ) = $parts; 1289 1328 1290 if ( get_stylesheet() !== $theme ) { 1291 /** This filter is documented in wp-includes/block-template-utils.php */ 1292 return apply_filters( 'get_block_file_template', null, $id, $template_type ); 1293 } 1294 1295 $template_file = _get_block_template_file( $template_type, $slug ); 1296 if ( null === $template_file ) { 1297 /** This filter is documented in wp-includes/block-template-utils.php */ 1298 return apply_filters( 'get_block_file_template', null, $id, $template_type ); 1299 } 1300 1301 $block_template = _build_block_template_result_from_file( $template_file, $template_type ); 1329 if ( get_stylesheet() === $theme ) { 1330 $template_file = _get_block_template_file( $template_type, $slug ); 1331 if ( null !== $template_file ) { 1332 $block_template = _build_block_template_result_from_file( $template_file, $template_type ); 1333 1334 /** This filter is documented in wp-includes/block-template-utils.php */ 1335 return apply_filters( 'get_block_file_template', $block_template, $id, $template_type ); 1336 } 1337 } 1338 1339 $block_template = WP_Block_Templates_Registry::get_instance()->get_by_slug( $slug ); 1302 1340 1303 1341 /** … … 1666 1704 } 1667 1705 1668 $content = get_comment_delimited_block_content(1706 $content = get_comment_delimited_block_content( 1669 1707 'core/template-part', 1670 1708 $attributes, 1671 1709 $changes->post_content 1672 1710 ); 1673 $content = apply_block_hooks_to_content( $content, $template, 'set_ignored_hooked_blocks_metadata' );1711 $content = apply_block_hooks_to_content( $content, $template, 'set_ignored_hooked_blocks_metadata' ); 1674 1712 $changes->post_content = remove_serialized_parent_block( $content ); 1675 1713
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)