Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
_build_block_template_result_from_file() WordPress Function
The build_block_template_result_from_file() function is used to build a block template result from a given file. This function is useful for creating custom blocks that need to load a template file from the filesystem.
_build_block_template_result_from_file( array $template_file, string $template_type ) #
Build a unified template object based on a theme file.
Parameters
- $template_file
(array)(Required)Theme file.
- $template_type
(string)(Required)'wp_template' or 'wp_template_part'.
Return
(WP_Block_Template) Template.
Source
File: wp-includes/block-template-utils.php
function _build_block_template_result_from_file( $template_file, $template_type ) { $default_template_types = get_default_block_template_types(); $template_content = file_get_contents( $template_file['path'] ); $theme = wp_get_theme()->get_stylesheet(); $template = new WP_Block_Template(); $template->id = $theme . '//' . $template_file['slug']; $template->theme = $theme; $template->content = _inject_theme_attribute_in_block_template_content( $template_content ); $template->slug = $template_file['slug']; $template->source = 'theme'; $template->type = $template_type; $template->title = ! empty( $template_file['title'] ) ? $template_file['title'] : $template_file['slug']; $template->status = 'publish'; $template->has_theme_file = true; $template->is_custom = true; if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) { $template->description = $default_template_types[ $template_file['slug'] ]['description']; $template->title = $default_template_types[ $template_file['slug'] ]['title']; $template->is_custom = false; } if ( 'wp_template' === $template_type && isset( $template_file['postTypes'] ) ) { $template->post_types = $template_file['postTypes']; } if ( 'wp_template_part' === $template_type && isset( $template_file['area'] ) ) { $template->area = $template_file['area']; } return $template; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |