Make WordPress Core


Ignore:
Timestamp:
06/04/2024 08:13:01 AM (8 months ago)
Author:
ellatrix
Message:

Editor: Fix block template files query for a post-type.

See https://github.com/WordPress/gutenberg/pull/61244.
See https://github.com/WordPress/wordpress-develop/pull/6468.

Fixes #61110.

Props mamaduka, mukesh27, grantmkin, vcanales, ellatrix, oandregal.

File:
1 edited

Legend:

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

    r58291 r58323  
    361361    if ( 'wp_template' !== $template_type && 'wp_template_part' !== $template_type ) {
    362362        return null;
     363    }
     364
     365    $default_template_types = array();
     366    if ( 'wp_template' === $template_type ) {
     367        $default_template_types = get_default_block_template_types();
    363368    }
    364369
     
    426431            if ( 'wp_template' === $template_type ) {
    427432                $candidate = _add_block_template_info( $new_template_item );
     433                $is_custom = ! isset( $default_template_types[ $candidate['slug'] ] );
     434
    428435                if (
    429436                    ! $post_type ||
    430437                    ( $post_type && isset( $candidate['postTypes'] ) && in_array( $post_type, $candidate['postTypes'], true ) )
    431438                ) {
     439                    $template_files[ $template_slug ] = $candidate;
     440                }
     441
     442                // The custom templates with no associated post types are available for all post types.
     443                if ( $post_type && ! isset( $candidate['postTypes'] ) && $is_custom ) {
    432444                    $template_files[ $template_slug ] = $candidate;
    433445                }
Note: See TracChangeset for help on using the changeset viewer.