Make WordPress Core


Ignore:
Timestamp:
08/01/2023 08:29:47 PM (3 years ago)
Author:
flixos90
Message:

Themes: Use isset instead of array_key_exists in WP_Theme_JSON class.

With the minimum PHP version requirement raised to 7.0, we can now use isset on constants that are arrays. Since isset is slightly faster than array_key_exists (and the different handling of null values is irrelevant for the updates here), remaining instances of array_key_exists in the WP_Theme_JSON class are replaced in this changeset.

Props soean.
Fixes #57067.

File:
1 edited

Legend:

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

    r56181 r56345  
    546546                $class_name = '';
    547547
    548                 /*
    549                  * TODO: Replace array_key_exists() with isset() check once WordPress drops
    550                  * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    551                  */
    552                 if ( array_key_exists( $element, static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES ) ) {
     548                if ( isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ] ) ) {
    553549                        $class_name = static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ];
    554550                }
     
    741737                        $schema_styles_elements[ $element ] = $styles_non_top_level;
    742738
    743                         /*
    744                          * TODO: Replace array_key_exists() with isset() check once WordPress drops
    745                          * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    746                          */
    747                         if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
     739                        if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
    748740                                foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
    749741                                        $schema_styles_elements[ $element ][ $pseudo_selector ] = $styles_non_top_level;
     
    19291921                                $path_string = implode( '.', $value_path );
    19301922                                if (
    1931                                         /*
    1932                                          * TODO: Replace array_key_exists() with isset() check once WordPress drops
    1933                                          * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    1934                                          */
    1935                                         array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) &&
     1923                                        isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
    19361924                                        _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
    19371925                                ) {
     
    21372125                                );
    21382126
    2139                                 /*
    2140                                  * Handle any pseudo selectors for the element.
    2141                                  * TODO: Replace array_key_exists() with isset() check once WordPress drops
    2142                                  * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    2143                                  */
    2144                                 if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
     2127                                // Handle any pseudo selectors for the element.
     2128                                if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
    21452129                                        foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
    21462130
     
    22912275                                        );
    22922276
    2293                                         /*
    2294                                          * Handle any pseudo selectors for the element.
    2295                                          * TODO: Replace array_key_exists() with isset() check once WordPress drops
    2296                                          * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    2297                                          */
    2298                                         if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
     2277                                        // Handle any pseudo selectors for the element.
     2278                                        if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
    22992279                                                foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
    23002280                                                        if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) {
     
    23742354                $element_pseudo_allowed = array();
    23752355
    2376                 /*
    2377                  * TODO: Replace array_key_exists() with isset() check once WordPress drops
    2378                  * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    2379                  */
    2380                 if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
     2356                if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
    23812357                        $element_pseudo_allowed = static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ];
    23822358                }
     
    24032379                 */
    24042380                if ( $pseudo_selector && isset( $node[ $pseudo_selector ] ) &&
    2405                         /*
    2406                          * TODO: Replace array_key_exists() with isset() check once WordPress drops
    2407                          * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    2408                          */
    2409                         array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS )
     2381                        isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] )
    24102382                        && in_array( $pseudo_selector, static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ], true )
    24112383                ) {
     
    28962868                         * $output is stripped of pseudo selectors. Re-add and process them
    28972869                         * or insecure styles here.
    2898                          *
    2899                          * TODO: Replace array_key_exists() with isset() check once WordPress drops
    2900                          * support for PHP 5.6. See https://core.trac.wordpress.org/ticket/57067.
    29012870                         */
    2902                         if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
     2871                        if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
    29032872                                foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] as $pseudo_selector ) {
    29042873                                        if ( isset( $input[ $pseudo_selector ] ) ) {
Note: See TracChangeset for help on using the changeset viewer.