Changeset 56065 for trunk/src/wp-includes/blocks/template-part.php
- Timestamp:
- 06/27/2023 02:20:18 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/template-part.php
r55828 r56065 19 19 $content = null; 20 20 $area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; 21 $stylesheet = get_stylesheet(); 21 22 22 23 if ( 23 24 isset( $attributes['slug'] ) && 24 25 isset( $attributes['theme'] ) && 25 get_stylesheet()=== $attributes['theme']26 $stylesheet === $attributes['theme'] 26 27 ) { 27 28 $template_part_id = $attributes['theme'] . '//' . $attributes['slug']; 28 29 $template_part_query = new WP_Query( 29 30 array( 30 'post_type' => 'wp_template_part',31 'post_status' => 'publish',32 'post_name__in' => array( $attributes['slug'] ),33 'tax_query' => array(31 'post_type' => 'wp_template_part', 32 'post_status' => 'publish', 33 'post_name__in' => array( $attributes['slug'] ), 34 'tax_query' => array( 34 35 array( 35 36 'taxonomy' => 'wp_theme', … … 38 39 ), 39 40 ), 40 'posts_per_page' => 1, 41 'no_found_rows' => true, 41 'posts_per_page' => 1, 42 'no_found_rows' => true, 43 'lazy_load_term_meta' => false, // Do not lazy load term meta, as template parts only have one term. 42 44 ) 43 45 ); … … 65 67 // Else, if the template part was provided by the active theme, 66 68 // render the corresponding file content. 67 $parent_theme_folders = get_block_theme_folders( get_template() ); 68 $child_theme_folders = get_block_theme_folders( get_stylesheet() ); 69 $child_theme_part_file_path = get_theme_file_path( '/' . $child_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' ); 70 $parent_theme_part_file_path = get_theme_file_path( '/' . $parent_theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' ); 71 $template_part_file_path = 0 === validate_file( $attributes['slug'] ) && file_exists( $child_theme_part_file_path ) ? $child_theme_part_file_path : $parent_theme_part_file_path; 72 if ( 0 === validate_file( $attributes['slug'] ) && file_exists( $template_part_file_path ) ) { 73 $content = file_get_contents( $template_part_file_path ); 74 $content = is_string( $content ) && '' !== $content 75 ? _inject_theme_attribute_in_block_template_content( $content ) 76 : ''; 69 if ( 0 === validate_file( $attributes['slug'] ) ) { 70 $themes = array( $stylesheet ); 71 $template = get_template(); 72 if ( $stylesheet !== $template ) { 73 $themes[] = $template; 74 } 75 76 foreach ( $themes as $theme ) { 77 $theme_folders = get_block_theme_folders( $theme ); 78 $template_part_file_path = get_theme_file_path( '/' . $theme_folders['wp_template_part'] . '/' . $attributes['slug'] . '.html' ); 79 if ( file_exists( $template_part_file_path ) ) { 80 $content = (string) file_get_contents( $template_part_file_path ); 81 $content = '' !== $content ? _inject_theme_attribute_in_block_template_content( $content ) : ''; 82 break; 83 } 84 } 77 85 } 78 86 … … 173 181 * Returns an array of area variation objects for the template part block. 174 182 * 183 * @param array $instance_variations The variations for instances. 184 * 175 185 * @return array Array containing the block variation objects. 176 186 */ 177 function build_template_part_block_area_variations( ) {187 function build_template_part_block_area_variations( $instance_variations ) { 178 188 $variations = array(); 179 189 $defined_areas = get_allowed_block_template_part_areas(); 190 180 191 foreach ( $defined_areas as $area ) { 181 192 if ( 'uncategorized' !== $area['area'] ) { 193 $has_instance_for_area = false; 194 foreach ( $instance_variations as $variation ) { 195 if ( $variation['attributes']['area'] === $area['area'] ) { 196 $has_instance_for_area = true; 197 break; 198 } 199 } 200 201 $scope = $has_instance_for_area ? array() : array( 'inserter' ); 202 182 203 $variations[] = array( 183 'name' => $area['area'],204 'name' => 'area_' . $area['area'], 184 205 'title' => $area['label'], 185 206 'description' => $area['description'], … … 187 208 'area' => $area['area'], 188 209 ), 189 'scope' => array( 'inserter' ),210 'scope' => $scope, 190 211 'icon' => $area['icon'], 191 212 ); … … 223 244 foreach ( $template_parts as $template_part ) { 224 245 $variations[] = array( 225 'name' => sanitize_title( $template_part->slug ),246 'name' => 'instance_' . sanitize_title( $template_part->slug ), 226 247 'title' => $template_part->title, 227 248 // If there's no description for the template part don't show the … … 255 276 */ 256 277 function build_template_part_block_variations() { 257 return array_merge( build_template_part_block_area_variations(), build_template_part_block_instance_variations() ); 278 $instance_variations = build_template_part_block_instance_variations(); 279 $area_variations = build_template_part_block_area_variations( $instance_variations ); 280 return array_merge( $area_variations, $instance_variations ); 258 281 } 259 282
Note: See TracChangeset
for help on using the changeset viewer.