Make WordPress Core


Ignore:
Timestamp:
06/22/2023 02:12:09 PM (12 months ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r55986 r55987  
    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,
     
    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 ) ) {
Note: See TracChangeset for help on using the changeset viewer.