Skip to content

Commit

Permalink
Editor: Adds additional check to guard against incompete presets. (#3…
Browse files Browse the repository at this point in the history
…8902)

Related Core ticket: https://core.trac.wordpress.org/ticket/55161

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.
  • Loading branch information
jeherve authored Feb 18, 2022
1 parent a4bf9b6 commit b9a243f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ protected static function get_settings_values_by_slug( $settings, $preset_metada
$slug = _wp_to_kebab_case( $preset['slug'] );

$value = '';
if ( isset( $preset_metadata['value_key'] ) ) {
if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {
$value_key = $preset_metadata['value_key'];
$value = $preset[ $value_key ];
} elseif (
Expand Down Expand Up @@ -1745,7 +1745,7 @@ protected static function remove_insecure_settings( $input ) {
sanitize_html_class( $preset['slug'] ) === $preset['slug']
) {
$value = null;
if ( isset( $preset_metadata['value_key'] ) ) {
if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {
$value = $preset[ $preset_metadata['value_key'] ];
} elseif (
isset( $preset_metadata['value_func'] ) &&
Expand Down

0 comments on commit b9a243f

Please sign in to comment.