Skip to content

Commit

Permalink
Simplify checks for empty content
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jun 4, 2024
1 parent bc0fb8a commit 61f1e67
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions packages/block-library/src/button/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,15 @@ function render_block_core_button( $attributes, $content ) {
return $content;
}

// Build a string of the inner text.
$text = '';
while ( $p->next_token() ) {
$token_name = $p->get_token_name();
// Stop when encountering the closing tag.
if ( $tag === $token_name ) {
break;
}

if ( '#text' === $token_name ) {
$text .= $p->get_modifiable_text();
continue;
}
}
// If the next token is the closing tag, the button is empty.
$p->next_token();
$is_empty = $p->get_token_name() === $tag;

/*
* When there's no text, render nothing for the block.
* See https://github.com/WordPress/gutenberg/issues/17221.
*/
if ( '' === trim( $text ) ) {
if ( $is_empty ) {
return '';
}

Expand Down

0 comments on commit 61f1e67

Please sign in to comment.