Make WordPress Core


Ignore:
Timestamp:
02/17/2022 06:45:35 PM (3 years ago)
Author:
hellofromTonya
Message:

Editor: Adds an additional check to guard against incompete presets.

Adds an additional guard to ensure the value of $preset_metadata['value_key'] actually exists as a key in the $preset array. Fixes Warning: Undefined array key error.

Intentionally adds the check into the existing isset() as it's native to PHP, more efficient, and a good pattern.

Follow-up [52049].

Props jeherve, swissspidy, sergeybiryukov, jrf.
Fixes #55161.

File:
1 edited

Legend:

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

    r52757 r52763  
    10931093
    10941094                $value = '';
    1095                 if ( isset( $preset_metadata['value_key'] ) ) {
     1095                if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {
    10961096                    $value_key = $preset_metadata['value_key'];
    10971097                    $value     = $preset[ $value_key ];
     
    18381838                    ) {
    18391839                        $value = null;
    1840                         if ( isset( $preset_metadata['value_key'] ) ) {
     1840                        if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {
    18411841                            $value = $preset[ $preset_metadata['value_key'] ];
    18421842                        } elseif (
Note: See TracChangeset for help on using the changeset viewer.