From 4b8fa1bc8b0e87fc77a6966185e8005e651a82ab Mon Sep 17 00:00:00 2001 From: dmsnell Date: Sat, 8 Jun 2024 10:57:14 +0000 Subject: [PATCH] HTML API: Return subclass from `::create_fragment` When the `WP_HTML_Processor` was introduced with its `::create_fragment()` static creator method, that method has been returning a `new self(...)`. Unfortunately, this means that subclasses cannot use that method since it will return the `WP_HTML_Processor` instead of the subclass. With this patch, the static creator method returns `new static(...)` to preserve the intended behavior. A new test asserts this behavior for future changes. Developed in https://github.com/WordPress/wordpress-develop/pull/6729 Discussed in https://core.trac.wordpress.org/ticket/61374 Props dmsnell, jonsurrell. Follow-up to [56274]. Fixes #61374. Built from https://develop.svn.wordpress.org/trunk@58363 git-svn-id: http://core.svn.wordpress.org/trunk@57812 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/html-api/class-wp-html-processor.php | 5 +++-- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-includes/html-api/class-wp-html-processor.php b/wp-includes/html-api/class-wp-html-processor.php index 93d74b5d1c..eeafca44f7 100644 --- a/wp-includes/html-api/class-wp-html-processor.php +++ b/wp-includes/html-api/class-wp-html-processor.php @@ -276,18 +276,19 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * - The only supported document encoding is `UTF-8`, which is the default value. * * @since 6.4.0 + * @since 6.6.0 Returns `static` instead of `self` so it can create subclass instances. * * @param string $html Input HTML fragment to process. * @param string $context Context element for the fragment, must be default of ``. * @param string $encoding Text encoding of the document; must be default of 'UTF-8'. - * @return WP_HTML_Processor|null The created processor if successful, otherwise null. + * @return static|null The created processor if successful, otherwise null. */ public static function create_fragment( $html, $context = '', $encoding = 'UTF-8' ) { if ( '' !== $context || 'UTF-8' !== $encoding ) { return null; } - $processor = new self( $html, self::CONSTRUCTOR_UNLOCK_CODE ); + $processor = new static( $html, self::CONSTRUCTOR_UNLOCK_CODE ); $processor->state->context_node = array( 'BODY', array() ); $processor->state->insertion_mode = WP_HTML_Processor_State::INSERTION_MODE_IN_BODY; diff --git a/wp-includes/version.php b/wp-includes/version.php index efdace903b..b9ad2cc932 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-beta1-58362'; +$wp_version = '6.6-beta1-58363'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.