render_block_core_template_part( array $attributes ): string
- Since
- 5.9.0
- Source
wp-includes/blocks/template-part.php:19
core/template-part block on the server.Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$attributesarray- The block attributes.
Return value
string- The render.
Performance profile
How much work a call to render_block_core_template_part() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 17–147
- Plugin surface
- 3 hooks
- Called by
- 0
Reaches the database via get_post().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 202.
Third-party callbacks on 'render_block_core_template_part_post', 'render_block_core_template_part_file', 'render_block_core_template_part_none' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()one call below render_block_core_template_part() - querycontent query
get_post()one call below render_block_core_template_part()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 42 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_template_part() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$attributes && !isset($attributes) | 17–21 | none |
!$attributes && isset($attributes) && $theme !== false | 21–25 | get_stylesheet() |
!$attributes && !isset($attributes) && $content !== null && isset($seen_ids[$template_part_id]) | 22–24 | __() |
!$attributes && isset($attributes) && $theme !== false && $content !== null && isset($seen_ids[$template_part_id]) | 26–28 | get_stylesheet(), __() |
!$attributes && $content === null | 27–29 | __(), sprintf() |
!$attributes && isset($attributes) && $theme !== false && $content === null | 31–33 | get_stylesheet(), __(), sprintf() |
!$attributes && !isset($attributes) && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 54–67 | get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme !== false && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 58–71 | get_stylesheet(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && !isset($attributes) && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 62–75 | get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() | 62–68 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() | 63–71 | get_stylesheet(), ->have_posts(), validate_file(), do_action() |
!$attributes && !isset($attributes) && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 64–73 | get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
30 further outcomes, up to 145 instructions
!$attributes && isset($attributes) && $theme !== false && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 66–79 | get_stylesheet(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() | 66–74 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && isset($seen_ids[$template_part_id]) | 67–71 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action(), __() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && isset($seen_ids[$template_part_id]) | 68–74 | get_stylesheet(), ->have_posts(), validate_file(), do_action(), __() |
!$attributes && isset($attributes) && $theme !== false && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 68–77 | get_stylesheet(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && $content !== null && isset($seen_ids[$template_part_id]) | 71–77 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action(), __() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content === null | 72–76 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action(), __(), sprintf() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content === null | 73–79 | get_stylesheet(), ->have_posts(), validate_file(), do_action(), __(), sprintf() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && $content === null | 76–82 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action(), __(), sprintf() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() | 80–93 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) | 83–93 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && isset($seen_ids[$template_part_id]) | 85–96 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), __() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) && $content !== null && isset($seen_ids[$template_part_id]) | 88–96 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), __() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content === null | 90–101 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), __(), sprintf() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) && $content === null | 93–101 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), __(), sprintf() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 99–114 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 100–117 | get_stylesheet(), ->have_posts(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 103–120 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 107–122 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 108–125 | get_stylesheet(), ->have_posts(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 109–120 | get_stylesheet(), ->have_posts(), _build_block_template_result_from_post(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 110–123 | get_stylesheet(), ->have_posts(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 111–128 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 113–126 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 117–139 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) && $content !== null && !isset($seen_ids[$template_part_id]) && empty($attributes) | 120–139 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 125–147 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && !->have_posts() && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 127–145 | get_stylesheet(), ->have_posts(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 128–147 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), get_block_wrapper_attributes() |
!$attributes && isset($attributes) && $theme === false && ->have_posts() && !isset($block_template) && $content !== null && !isset($seen_ids[$template_part_id]) && !empty($attributes) | 130–145 | get_stylesheet(), ->have_posts(), ->next_post(), validate_file(), get_block_file_template(), _get_block_template_file(), do_action(), get_allowed_block_template_part_areas(), _wp_apply_block_content_filters(), tag_escape(), esc_attr(), get_block_wrapper_attributes() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 200 | 17–147 | 26 | 2 fewer instructions than PHP 8.5 |
| 8.5 | 202 | 17–147 | 26 | |
| 8.4 | 202 | 17–147 | 26 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 205 | 17–150 | 26 | |
| 8.2 | 205 | 17–150 | 26 | |
| 8.1 | 205 | 17–150 | 26 | |
| 7.4 | 205 | 17–150 | 26 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 3
3 hooks fire while render_block_core_template_part() runs, in this order:
- do_action( render_block_core_template_part_post )actionline 65 (+46 into the body)
Fires when a block template part is loaded from a template post stored in the database.
- do_action( render_block_core_template_part_file )actionline 98 (+79 into the body)
Fires when a block template part is loaded from a template part in the theme.
- do_action( render_block_core_template_part_none )actionline 109 (+90 into the body)
Fires when a requested block template part does not exist in the database nor in the theme.
Uses · 13
- get_stylesheet()Retrieves name of the current stylesheet.
- _build_block_template_result_from_post()Builds a unified template object based a post Object.
- do_action()Calls the callback functions that have been added to an action hook.
- validate_file()Validates a file name and path against an allowed set of rules.
- get_block_file_template()Retrieves a unified template object based on a theme file or plugin registration.
- _get_block_template_file()Retrieves the template file from the theme for a given slug.
- __()Retrieves the translation of $text.
- get_allowed_block_template_part_areas()Returns a filtered list of allowed area values for template parts.
- _wp_apply_block_content_filters()Applies standard content filters similar to the 'the_content' filter.
- tag_escape()Escapes an HTML tag name.
- esc_attr()Escaping for HTML attributes.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
Show all 13
- WP_Query::__construct()Constructor.
Source code
function render_block_core_template_part( $attributes ) { static $seen_ids = array(); $template_part_id = null; $content = null; $area = WP_TEMPLATE_PART_AREA_UNCATEGORIZED; $theme = $attributes['theme'] ?? get_stylesheet(); if ( isset( $attributes['slug'] ) && get_stylesheet() === $theme ) { $template_part_id = $theme . '//' . $attributes['slug']; $template_part_query = new WP_Query( array( 'post_type' => 'wp_template_part', 'post_status' => 'publish', 'post_name__in' => array( $attributes['slug'] ), 'tax_query' => array( array( 'taxonomy' => 'wp_theme', 'field' => 'name', 'terms' => $theme, ), ), 'posts_per_page' => 1, 'no_found_rows' => true, 'lazy_load_term_meta' => false, // Do not lazy load term meta, as template parts only have one term. ) ); $template_part_post = $template_part_query->have_posts() ? $template_part_query->next_post() : null; if ( $template_part_post ) { // A published post might already exist if this template part was customized elsewhere // or if it's part of a customized template. $block_template = _build_block_template_result_from_post( $template_part_post ); $content = $block_template->content; if ( isset( $block_template->area ) ) { $area = $block_template->area; } /** * Fires when a block template part is loaded from a template post stored in the database. * * @since 5.9.0 * * @param string $template_part_id The requested template part namespaced to the theme. * @param array $attributes The block attributes. * @param WP_Post $template_part_post The template part post object. * @param string $content The template part content. */ do_action( 'render_block_core_template_part_post', $template_part_id, $attributes, $template_part_post, $content ); } else { $template_part_file_path = ''; // Else, if the template part was provided by the active theme, // render the corresponding file content. if ( 0 === validate_file( $attributes['slug'] ) ) { $block_template = get_block_file_template( $template_part_id, 'wp_template_part' ); if ( isset( $block_template->content ) ) { $content = $block_template->content; } if ( isset( $block_template->area ) ) { $area = $block_template->area; } // Needed for the `render_block_core_template_part_file` and `render_block_core_template_part_none` actions below. $block_template_file = _get_block_template_file( 'wp_template_part', $attributes['slug'] ); if ( $block_template_file ) { $template_part_file_path = $block_template_file['path']; } } if ( '' !== $content && null !== $content ) { /** * Fires when a block template part is loaded from a template part in the theme. * * @since 5.9.0 * * @param string $template_part_id The requested template part namespaced to the theme. * @param array $attributes The block attributes. * @param string $template_part_file_path Absolute path to the template path. * @param string $content The template part content. */ do_action( 'render_block_core_template_part_file', $template_part_id, $attributes, $template_part_file_path, $content );Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/template-part.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.