From fdbd29eaba67e30d13ac8a72fe550b2f8fc03e46 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 22 Jun 2023 14:12:09 +0000 Subject: [PATCH] Code Modernization: Use `str_starts_with()` in `WP_Theme_JSON` class methods. This aims to make the code more readable and consistent, as the function is already used extensively in core files. WordPress core includes a polyfill for `str_starts_with()` on PHP < 8.0 as of WordPress 5.9. Follow-up to [55703], [55959]. Props spacedmonkey. Fixes #58012. git-svn-id: https://develop.svn.wordpress.org/trunk@55987 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme-json.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index cf56000f87..1af02531cc 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3495,7 +3495,7 @@ class WP_Theme_JSON { $prefix_len = strlen( $prefix ); $token_in = '|'; $token_out = '--'; - if ( 0 === strpos( $value, $prefix ) ) { + if ( str_starts_with( $value, $prefix ) ) { $unwrapped_name = str_replace( $token_in, $token_out, @@ -3519,7 +3519,7 @@ class WP_Theme_JSON { $prefix = 'var:'; foreach ( $tree as $key => $data ) { - if ( is_string( $data ) && 0 === strpos( $data, $prefix ) ) { + if ( is_string( $data ) && str_starts_with( $data, $prefix ) ) { $tree[ $key ] = self::convert_custom_properties( $data ); } elseif ( is_array( $data ) ) { $tree[ $key ] = self::resolve_custom_css_format( $data );