From b6310be0a26903812c573635bdc5b021d58a9d40 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:23:40 +0900 Subject: [PATCH] Button Block: Add back compat for WP6.4 regarding HTML Tag Processor (#63082) * Button Block: Add back compat for WP6.4 regarding HTML tag processor * Don't use conditional statement * Update packages/block-library/src/button/index.php Re-add conditional statement Co-authored-by: Anton Vlasenko <43744263+anton-vlasenko@users.noreply.github.com> * Fix lint and update comment * Remove space --------- Co-authored-by: t-hamano Co-authored-by: dmsnell Co-authored-by: anton-vlasenko Co-authored-by: talldan Co-authored-by: ndiego Co-authored-by: beckej13820 --- packages/block-library/src/button/index.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/button/index.php b/packages/block-library/src/button/index.php index f272fa9eb62b1..6550e50a8f21c 100644 --- a/packages/block-library/src/button/index.php +++ b/packages/block-library/src/button/index.php @@ -17,7 +17,20 @@ * @return string The block content. */ function render_block_core_button( $attributes, $content ) { - $p = new WP_HTML_Tag_Processor( $content ); + /* + * The current Gutenberg plugin supports WordPress 6.4, but the next_token() + * method does not exist in WordPress 6.4. Therefore, if Gutenberg is used + * as a plugin, use the Gutenberg class that has the `next_token()` method. + * + * TODO: After the Gutenberg plugin drops support for WordPress 6.4, this + * conditional statement will be removed and the core class `WP_HTML_Tag_Processor` + * should be used. + */ + if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && class_exists( 'Gutenberg_HTML_Tag_Processor_6_5' ) ) { + $p = new Gutenberg_HTML_Tag_Processor_6_5( $content ); + } else { + $p = new WP_HTML_Tag_Processor( $content ); + } /* * The button block can render an `` or `