_build_template_result_from_post

The timeline below displays how wordpress function _build_template_result_from_post has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Utilities used to fetch and create templates.
 *
 * @package WordPress
 * @since 5.8.0
 */
/**
 * Build a unified template object based a post Object.
 *
 * @access private
 * @since 5.8.0
 *
 * @param WP_Post $post Template post.
 *
 * @return WP_Block_Template|WP_Error Template.
 */
function _build_template_result_from_post($post)
{
    $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 = 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;
    $template->source = 'custom';
    $template->type = $post->post_type;
    $template->description = $post->post_excerpt;
    $template->title = $post->post_title;
    $template->status = $post->post_status;
    $template->has_theme_file = false;
    return $template;
}