_get_block_template_file example


            do_action( 'render_block_core_template_part_post', $template_part_id$attributes$template_part_post$content );
        } else {
            $template_part_file_path = '';
            // Else, if the template part was provided by the active theme,             // render the corresponding file content.             if ( 0 === validate_file( $attributes['slug'] ) ) {
                $block_template_file = _get_block_template_file( 'wp_template_part', $attributes['slug'] );
                if ( $block_template_file ) {
                    $template_part_file_path = $block_template_file['path'];
                    $content                 = (string) file_get_contents( $template_part_file_path );
                    $content                 = '' !== $content ? _inject_theme_attribute_in_block_template_content( $content ) : '';
                    if ( isset( $block_template_file['area'] ) ) {
                        $area = $block_template_file['area'];
                    }
                }
            }

            if ( '' !== $content && null !== $content ) {
                
$terms                  = get_the_terms( $post, 'wp_theme' );

    if ( is_wp_error( $terms ) ) {
        return $terms;
    }

    if ( ! $terms ) {
        return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.' ) );
    }

    $theme          = $terms[0]->name;
    $template_file  = _get_block_template_file( $post->post_type, $post->post_name );
    $has_theme_file = get_stylesheet() === $theme && null !== $template_file;

    $origin           = get_post_meta( $post->ID, 'origin', true );
    $is_wp_suggestion = get_post_meta( $post->ID, 'is_wp_suggestion', true );

    $template                 = new WP_Block_Template();
    $template->wp_id          = $post->ID;
    $template->id             = $theme . '//' . $post->post_name;
    $template->theme          = $theme;
    $template->content        = $post->post_content;
    $template->slug           = $post->post_name;
    
        if (
            count( $templates ) &&
            $fallback_template_slug === $templates[0]->slug &&
            'theme' === $templates[0]->source
        ) {
            // Unfortunately, we cannot trust $templates[0]->theme, since it will always             // be set to the active theme's slug by _build_block_template_result_from_file(),             // even if the block template is really coming from the active theme's parent.             // (The reason for this is that we want it to be associated with the active theme             // -- not its parent -- once we edit it and store it to the DB as a wp_template CPT.)             // Instead, we use _get_block_template_file() to locate the block template file.             $template_file = _get_block_template_file( 'wp_template', $fallback_template_slug );
            if ( $template_file && get_template() === $template_file['theme'] ) {
                // The block template is part of the parent theme, so we                 // have to give precedence to the child theme's PHP template.                 array_shift( $templates );
            }
        }
    }

    return count( $templates ) ? $templates[0] : null;
}

Home | Imprint | This part of the site doesn't use cookies.