Skip to content

Commit fdbd29e

Browse files
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
1 parent fe36455 commit fdbd29e

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎src/wp-includes/class-wp-theme-json.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,7 @@ private static function convert_custom_properties( $value ) {
34953495
$prefix_len = strlen( $prefix );
34963496
$token_in = '|';
34973497
$token_out = '--';
3498-
if ( 0 === strpos( $value, $prefix ) ) {
3498+
if ( str_starts_with( $value, $prefix ) ) {
34993499
$unwrapped_name = str_replace(
35003500
$token_in,
35013501
$token_out,
@@ -3519,7 +3519,7 @@ private static function resolve_custom_css_format( $tree ) {
35193519
$prefix = 'var:';
35203520

35213521
foreach ( $tree as $key => $data ) {
3522-
if ( is_string( $data ) && 0 === strpos( $data, $prefix ) ) {
3522+
if ( is_string( $data ) && str_starts_with( $data, $prefix ) ) {
35233523
$tree[ $key ] = self::convert_custom_properties( $data );
35243524
} elseif ( is_array( $data ) ) {
35253525
$tree[ $key ] = self::resolve_custom_css_format( $data );

0 commit comments

Comments
 (0)