Make WordPress Core


Ignore:
Timestamp:
08/01/2023 02:10:08 AM (3 years ago)
Author:
isabel_brison
Message:

Editor: fix duplication in templates list.

Excludes parent template when a child template is defined during template retrieval.

Props oandregal, mukesh27, flixos90, bgardner.
See #57756.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r56287 r56329  
    361361                        }
    362362
     363                        /*
     364                         * The child theme items (stylesheet) are processed before the parent theme's (template).
     365                         * If a child theme defines a template, prevent the parent template from being added to the list as well.
     366                         */
     367                        if ( isset( $template_files[ $template_slug ] ) ) {
     368                                continue;
     369                        }
     370
    363371                        $new_template_item = array(
    364372                                'slug'  => $template_slug,
     
    371379                                $candidate = _add_block_template_part_area_info( $new_template_item );
    372380                                if ( ! isset( $area ) || ( isset( $area ) && $area === $candidate['area'] ) ) {
    373                                         $template_files[] = $candidate;
     381                                        $template_files[ $template_slug ] = $candidate;
    374382                                }
    375383                        }
     
    381389                                        ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
    382390                                ) {
    383                                         $template_files[] = $candidate;
     391                                        $template_files[ $template_slug ] = $candidate;
    384392                                }
    385393                        }
     
    387395        }
    388396
    389         return $template_files;
     397        return array_values( $template_files );
    390398}
    391399
Note: See TracChangeset for help on using the changeset viewer.