Skip to content

Commit

Permalink
#3995 - switch and button_set not saving within tabbed interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
kprovance committed Mar 22, 2024
1 parent d5021e6 commit a96cc84
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function output_field( array $field ) {

$default = $field['default'] ?? '';

$value = empty( $this->parent->options[ $orig_field_id ] ) ? $default : $this->parent->options[ $orig_field_id ];
$value = empty( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $default : $this->parent->options[ $orig_field_id ];

$this->parent->render_class->field_input( $field, $value );

Expand Down

1 comment on commit a96cc84

@shyambaseapp
Copy link

@shyambaseapp shyambaseapp commented on a96cc84 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning: Undefined array key "from-email" in /home/vagrant/wordpress/wordpress/wp-content/plugins/redux-framework/redux-core/inc/extensions/tabbed/tabbed/class-redux-tabbed.php on line 127

// Use the || operator instead of && for better condition checking
$value = empty( $this->parent->options[ $orig_field_id ] ) || 0 !== (int) $this->parent->options[ $orig_field_id ] ? $default : $this->parent->options[ $orig_field_id ];

Your original code used && to check two conditions: whether the array key $orig_field_id is empty and whether it is not equal to zero.
The issue arises if the array key $orig_field_id doesn't exist, as this causes an "Undefined array key" warning.
By using || instead of &&, you ensure that if $orig_field_id is empty or not equal to zero, the $value is assigned $default. Otherwise, it falls back to the $this->parent->options[$orig_field_id] value. This approach avoids the warning when the array key is undefined.

Please sign in to comment.