wpseek.com
A WordPress-centric search engine for devs and theme authors



_build_template_result_from_post › WordPress Function

Since5.8.0
Deprecatedn/a
_build_template_result_from_post ( $post )
Access:
  • private
Parameters:
  • (WP_Post) $post Template post.
    Required: Yes
Returns:
  • (WP_Block_Template|WP_Error) Template.
Defined at:
Codex:

Build a unified template object based a post Object.



Source

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;
}