wppaste
WordPress

render_block_core_button( array $attributes, string $content ): string

Since
6.6.0
Source
wp-includes/blocks/button.php:18
Renders the core/button block on the server,

Compatibility

WordPress
since 6.6.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.
$contentstring
The block content.

Return value

string
The block content.

Performance profile

How much work a call to render_block_core_button() 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
Moderate

Only touches the object cache, via wp_cache_get().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
14–124

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 156.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • cacheobject cachewp_cache_get()one call below render_block_core_button()

What one call costs · 46 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_button() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!->next_tag() && $tag === null14->next_tag()
->next_tag() && $tag === null19–21->next_tag(), ->get_tag()
!->next_tag() && $tag !== null && !->next_token()20–27->next_tag(), ->next_token()
!->next_tag() && $tag !== null && ->next_token()24–32->next_tag(), ->next_token(), ->get_token_name()
->next_tag() && $tag !== null && !->next_token()25–34->next_tag(), ->get_tag(), ->next_token()
->next_tag() && $tag !== null && ->next_token()29–39->next_tag(), ->get_tag(), ->next_token(), ->get_token_name()
!->next_tag() && $tag !== null && !->next_token() && !$width41–42->next_tag(), ->next_token(), str_ends_with(), ->next_tag()
!->next_tag() && $tag !== null && ->next_token() && !$width45–47->next_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag()
$tag !== null && !->next_token() && !$width46–49->next_tag(), ->get_tag(), ->next_token(), str_ends_with(), ->next_tag()
!->next_tag() && $tag !== null && !->next_token() && $width49–72->next_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag()
$tag !== null && ->next_token() && !$width50–54->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag()
!->next_tag() && $tag !== null && ->next_token() && $width53–77->next_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag()
34 further outcomes, up to 124 instructions
$tag !== null && !->next_token() && $width54–79->next_tag(), ->get_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag()
$tag !== null && ->next_token() && $width58–84->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag()
$tag !== null && !->next_token() && !$width && !str_ends_with()69–72->next_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && !$width && !str_ends_with()73–77->next_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && !$width && !str_ends_with()74–79->next_tag(), ->get_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && !str_ends_with()74–77->next_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && !$width && str_ends_with() && !isset([…][$resolved_width])74–77->next_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && !str_ends_with()77–102->next_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && !$width && !str_ends_with()78–84->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && !str_ends_with()78–82->next_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && !$width && str_ends_with() && !isset([…][$resolved_width])78–82->next_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && !str_ends_with()79–84->next_tag(), ->get_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && !$width && str_ends_with() && !isset([…][$resolved_width])79–84->next_tag(), ->get_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && !$width && str_ends_with() && isset([…][$resolved_width])79–82->next_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && !str_ends_with()81–107->next_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && !str_ends_with()82–109->next_tag(), ->get_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && $width && !str_ends_with()82–107->next_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && $width && str_ends_with() && !isset([…][$resolved_width])82–107->next_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && !str_ends_with()83–89->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && !$width && str_ends_with() && !isset([…][$resolved_width])83–89->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && !$width && str_ends_with() && isset([…][$resolved_width])83–87->next_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && !$width && str_ends_with() && isset([…][$resolved_width])84–89->next_tag(), ->get_tag(), ->next_token(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && !str_ends_with()86–114->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && $width && !str_ends_with()86–112->next_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && $width && str_ends_with() && !isset([…][$resolved_width])86–112->next_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && $width && !str_ends_with()87–114->next_tag(), ->get_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && $width && str_ends_with() && !isset([…][$resolved_width])87–114->next_tag(), ->get_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && !->next_token() && $width && str_ends_with() && isset([…][$resolved_width])87–112->next_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && !$width && str_ends_with() && isset([…][$resolved_width])88–94->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && $width && !str_ends_with()91–119->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), _wp_to_kebab_case(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && $width && str_ends_with() && !isset([…][$resolved_width])91–119->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->set_attribute(), ->get_updated_html()
$tag !== null && ->next_token() && $width && str_ends_with() && isset([…][$resolved_width])91–117->next_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && !->next_token() && $width && str_ends_with() && isset([…][$resolved_width])92–119->next_tag(), ->get_tag(), ->next_token(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()
->next_tag() && $tag !== null && ->next_token() && $width && str_ends_with() && isset([…][$resolved_width])96–124->next_tag(), ->get_tag(), ->next_token(), ->get_token_name(), wp_get_global_settings(), str_ends_with(), ->next_tag(), ->add_class(), ->get_attribute(), ->add_class(), ->add_class(), ->set_attribute(), ->get_updated_html()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15614–12429
8.515614–12429
8.415614–124297 fewer instructions than PHP 8.3
8.316314–13129
8.216314–13129
8.116314–131295 fewer instructions than PHP 7.4
7.416814–13429

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.

Uses · 5

Source code

function render_block_core_button( $attributes, $content ) {	$p = new WP_HTML_Tag_Processor( $content ); 	/*	 * The button block can render an `<a>` or `<button>` and also has a	 * `<div>` wrapper. Find the a or button tag.	 */	$tag = null;	while ( $p->next_tag() ) {		$tag = $p->get_tag();		if ( 'A' === $tag || 'BUTTON' === $tag ) {			break;		}	} 	/*	 * If this happens, the likelihood is there's no block content,	 * or the block has been modified by a plugin.	 */	if ( null === $tag ) {		return $content;	} 	// If the next token is the closing tag, the button is empty.	$is_empty = true;	while ( $p->next_token() && $tag !== $p->get_token_name() && $is_empty ) {		if ( '#comment' !== $p->get_token_type() ) {			/**			 * Anything else implies this is not empty.			 * This might include any text content (including a space),			 * inline images or other HTML.			 */			$is_empty = false;		}	} 	/*	 * When there's no text, render nothing for the block.	 * See https://github.com/WordPress/gutenberg/issues/17221 for the	 * reasoning behind this.	 */	if ( $is_empty ) {		return '';	} 	$width = $attributes['style']['dimensions']['width'] ?? null; 	if ( $width ) {		// Resolve preset references to their actual values.		$resolved_width = $width;		$is_preset      = str_starts_with( $width, 'var:preset|dimension|' ); 		if ( $is_preset ) {			$slug              = substr( $width, strlen( 'var:preset|dimension|' ) );			$dimension_presets = wp_get_global_settings(				array( 'dimensions', 'dimensionSizes' ),				array( 'block_name' => 'core/button' )			); 			// Search origins in priority order: custom > theme > default.			if ( is_array( $dimension_presets ) ) {				foreach ( array( 'custom', 'theme', 'default' ) as $origin ) {					if ( empty( $dimension_presets[ $origin ] ) || ! is_array( $dimension_presets[ $origin ] ) ) {						continue;					}					foreach ( $dimension_presets[ $origin ] as $preset ) {						if ( isset( $preset['slug'] ) && $preset['slug'] === $slug ) {							$resolved_width = $preset['size'] ?? $width;							break 2;						}					}				}			}		} 		$is_percentage = str_ends_with( $resolved_width, '%' ); 		$processor = new WP_HTML_Tag_Processor( $content );		// Target the outer wrapper div.		if ( $processor->next_tag( array( 'class_name' => 'wp-block-button' ) ) ) {

Changelog

Introduced in 6.6.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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/button.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.