From 61f1e6783e3871dccad129961e0dc9e7d1d2a741 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Tue, 4 Jun 2024 17:54:28 +0800 Subject: [PATCH] Simplify checks for empty content --- packages/block-library/src/button/index.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/packages/block-library/src/button/index.php b/packages/block-library/src/button/index.php index 716bfb0ed60c8..d69b0bd1f704c 100644 --- a/packages/block-library/src/button/index.php +++ b/packages/block-library/src/button/index.php @@ -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 ''; }