Skip to content

Commit b3fbf5c

Browse files
westonruterdmsnell
andcommitted
Use static var to prevent recomputing version needlessly
Co-authored-by: dmsnell <[email protected]>
1 parent 46ca5f8 commit b3fbf5c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

plugins/optimization-detective/class-od-html-tag-processor.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,17 @@ public function append_html( string $bookmark, string $html ): bool {
194194
return false;
195195
}
196196

197+
// WordPress 6.5 changed the $end arg in the WP_HTML_Text_Replacement constructor to $length.
198+
static $is_old_text_replacement_signature = null;
199+
if ( null === $is_old_text_replacement_signature ) {
200+
$is_old_text_replacement_signature = version_compare( get_bloginfo( 'version' ), '6.5', '<' );
201+
}
202+
197203
$start = $this->bookmarks[ $bookmark ]->start;
198204

199205
$this->lexical_updates[] = new WP_HTML_Text_Replacement(
200206
$start,
201-
// In WordPress 6.5, the signature was changed from $end to $length.
202-
version_compare( get_bloginfo( 'version' ), '6.5', '<' ) ? $start : 0,
207+
$is_old_text_replacement_signature ? $start : 0,
203208
$html
204209
);
205210
return true;

0 commit comments

Comments
 (0)