Make WordPress Core


Ignore:
Timestamp:
06/27/2023 02:20:18 PM (3 years ago)
Author:
Bernhard Reiter
Message:

Editor: update Wordpress npm packages.

Updates the wordpress npm packages and their dependencies to the latest versions, as well as auto-updates to relevant core PHP files.

Props youknowriad, joemcgill, spacedmonkey, ramonopoly, peterwilsoncc, bernhard-reiter, tyxla, dmsnell.
Fixes #58623.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/template-part.php

    r55828 r56065  
    1919        $content          = null;
    2020        $area             = WP_TEMPLATE_PART_AREA_UNCATEGORIZED;
     21        $stylesheet       = get_stylesheet();
    2122
    2223        if (
    2324                isset( $attributes['slug'] ) &&
    2425                isset( $attributes['theme'] ) &&
    25                 get_stylesheet() === $attributes['theme']
     26                $stylesheet === $attributes['theme']
    2627        ) {
    2728                $template_part_id    = $attributes['theme'] . '//' . $attributes['slug'];
    2829                $template_part_query = new WP_Query(
    2930                        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(
    3435                                        array(
    3536                                                'taxonomy' => 'wp_theme',
    … …  
    3839                                        ),
    3940                                ),
    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.
    4244                        )
    4345                );
    … …  
    6567                        // Else, if the template part was provided by the active theme,
    6668                        // 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                                }
    7785                        }
    7886
    … …  
    173181 * Returns an array of area variation objects for the template part block.
    174182 *
     183 * @param array $instance_variations The variations for instances.
     184 *
    175185 * @return array Array containing the block variation objects.
    176186 */
    177 function build_template_part_block_area_variations() {
     187function build_template_part_block_area_variations( $instance_variations ) {
    178188        $variations    = array();
    179189        $defined_areas = get_allowed_block_template_part_areas();
     190
    180191        foreach ( $defined_areas as $area ) {
    181192                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
    182203                        $variations[] = array(
    183                                 'name'        => $area['area'],
     204                                'name'        => 'area_' . $area['area'],
    184205                                'title'       => $area['label'],
    185206                                'description' => $area['description'],
    … …  
    187208                                        'area' => $area['area'],
    188209                                ),
    189                                 'scope'       => array( 'inserter' ),
     210                                'scope'       => $scope,
    190211                                'icon'        => $area['icon'],
    191212                        );
    … …  
    223244        foreach ( $template_parts as $template_part ) {
    224245                $variations[] = array(
    225                         'name'        => sanitize_title( $template_part->slug ),
     246                        'name'        => 'instance_' . sanitize_title( $template_part->slug ),
    226247                        'title'       => $template_part->title,
    227248                        // If there's no description for the template part don't show the
    … …  
    255276 */
    256277function 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 );
    258281}
    259282
Note: See TracChangeset for help on using the changeset viewer.