wpseek.com
WordPress开发者和主题制作者的搜索引擎



_build_block_template_object_from_post_object › WordPress Function

Since6.5.1
已弃用n/a
_build_block_template_object_from_post_object ( $post, $terms = array(), $meta = array() )
访问:
  • private
参数: (3)
  • (WP_Post) $post Template post.
    Required: Yes
  • (array) $terms Additional terms to inform the template object.
    Required: No
    默认: array()
  • (array) $meta Additional meta fields to inform the template object.
    Required: No
    默认: array()
返回:
  • (WP_Block_Template|WP_Error) Template or error object.
定义在:
文档:

Builds a block template object from a post object.

This is a helper function that creates a block template object from a given post object. It is self-sufficient in that it only uses information passed as arguments; it does not query the database for additional information.


源码

function _build_block_template_object_from_post_object( $post, $terms = array(), $meta = array() ) {
	if ( empty( $terms['wp_theme'] ) ) {
		return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.' ) );
	}
	$theme = $terms['wp_theme'];

	$default_template_types = get_default_block_template_types();

	$template_file  = _get_block_template_file( $post->post_type, $post->post_name );
	$has_theme_file = get_stylesheet() === $theme && null !== $template_file;

	$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( $meta['origin'] ) ? $meta['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      = empty( $meta['is_wp_suggestion'] );
	$template->author         = $post->post_author;
	$template->modified       = $post->post_modified;

	if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
		$template->post_types = $template_file['postTypes'];
	}

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

	if ( 'wp_template_part' === $post->post_type && isset( $terms['wp_template_part_area'] ) ) {
		$template->area = $terms['wp_template_part_area'];
	}

	return $template;
}