wp-includes/blocks/button.php:18Renders the core/button block on the server,
$attributesarray$contentstringstringfunction 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' ) ) ) {Introduced in 6.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
src/wp-includes/blocks/button.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.