From 412b7647c49e2ef0861fefaf4979d6d371792040 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 13 Mar 2024 10:44:11 +0000 Subject: [PATCH] Interactivity API: Do not process directives when there aren't any. Short-circuits directive processing when the markup does not actually contain any `data-wp-*` attributes. This reduces function calls and memory usage for the best case scenario due to not involving `WP_HTML_Tag_Processor`. Reviewed by gziolo, swissspidy. Merges [57824] to the to the 6.5 branch. Props joemcgill, swissspidy, gziolo, cbravobernal, flixos90. Fixes #60749. Built from https://develop.svn.wordpress.org/branches/6.5@57825 git-svn-id: http://core.svn.wordpress.org/branches/6.5@57326 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/interactivity-api/class-wp-interactivity-api.php | 4 ++++ wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-includes/interactivity-api/class-wp-interactivity-api.php b/wp-includes/interactivity-api/class-wp-interactivity-api.php index 9e5b1be1fa..28cb7ee20a 100644 --- a/wp-includes/interactivity-api/class-wp-interactivity-api.php +++ b/wp-includes/interactivity-api/class-wp-interactivity-api.php @@ -204,6 +204,10 @@ final class WP_Interactivity_API { * @return string The processed HTML content. It returns the original content when the HTML contains unbalanced tags. */ public function process_directives( string $html ): string { + if ( ! str_contains( $html, 'data-wp-' ) ) { + return $html; + } + $context_stack = array(); $namespace_stack = array(); $result = $this->process_directives_args( $html, $context_stack, $namespace_stack ); diff --git a/wp-includes/version.php b/wp-includes/version.php index d4769c9742..8715099ab1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5-RC2-57823'; +$wp_version = '6.5-RC2-57825'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.