_build_block_template_result_from_post() – Build a unified template object based a post Object.

Description

Build a unified template object based a post Object.

Usage

$WP_Block_Template|WP_Error = _build_block_template_result_from_post( $post );

Parameters

$post
( WP_Post ) required – Template post.

Returns

WP_Block_Template|WP_Error Template.

Source

File name: wordpress/wp-includes/block-template-utils.php
Lines:

1 to 47 of 47
function _build_block_template_result_from_post( $post ) {
  $default_template_types = get_default_block_template_types();
  $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;
  $has_theme_file = wp_get_theme()->get_stylesheet() === $theme &&
    null !== _get_block_template_file( $post->post_type, $post->post_name );

  $origin = get_post_meta( $post->ID, 'origin', 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;
  $template->source         = 'custom';
  $template->origin         = ! empty( $origin ) ? $origin : null;
  $template->type           = $post->post_type;
  $template->description    = $post->post_excerpt;
  $template->title          = $post->post_title;
  $template->status         = $post->post_status;
  $template->has_theme_file = $has_theme_file;
  $template->is_custom      = true;
  $template->author         = $post->post_author;

  if ( 'wp_template' === $post->post_type && isset( $default_template_types[ $template->slug ] ) ) {
    $template->is_custom = false;
  }

  if ( 'wp_template_part' === $post->post_type ) {
    $type_terms = get_the_terms( $post, 'wp_template_part_area' );
    if ( ! is_wp_error( $type_terms ) && false !== $type_terms ) {
      $template->area = $type_terms[0]->name;
    }
  }

  return $template;
}
 

 View on GitHub View on Trac

Invoked by

    Call hooks

    API Letters: ,,,