Skip to content

Commit

Permalink
fix: check the input type to avoid type problems [Codeinwp/neve-pro-a…
Browse files Browse the repository at this point in the history
…ddon#2544]
  • Loading branch information
cristian-ungureanu committed Aug 9, 2023
1 parent 8bcac2c commit 900d1f0
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions globals/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,48 +700,46 @@ function neve_get_default_meta_value( $field, $default ) {

$components = apply_filters(
'neve_meta_filter',
array(
[
'author' => __( 'Author', 'neve' ),
'category' => __( 'Category', 'neve' ),
'date' => __( 'Date', 'neve' ),
'comments' => __( 'Comments', 'neve' ),
)
]
);

$default_data = get_theme_mod( $field, $default );
if ( empty( $default_data ) ) {
return $new_control_data;

if ( is_string( $default_data ) ) {
$default_data = json_decode( $default_data, true );
}

$default_data = json_decode( $default_data, true );
if ( ! is_array( $default_data ) ) {
return $new_control_data;
$default_data = [];
}

foreach ( $default_data as $meta_component ) {
if ( ! array_key_exists( $meta_component, $components ) ) {
continue;
if ( array_key_exists( $meta_component, $components ) ) {
$new_control_data[ $meta_component ] = (object) [
'slug' => $meta_component,
'title' => $components[ $meta_component ],
'visibility' => 'yes',
'hide_on_mobile' => false,
'blocked' => 'yes',
];
}
$new_control_data[ $meta_component ] = (object) [
'slug' => $meta_component,
'title' => $components[ $meta_component ],
'visibility' => 'yes',
'hide_on_mobile' => false,
'blocked' => 'yes',
];
}

foreach ( $components as $component_id => $label ) {
if ( array_key_exists( $component_id, $new_control_data ) ) {
continue;
if ( ! array_key_exists( $component_id, $new_control_data ) ) {
$new_control_data[ $component_id ] = (object) [
'slug' => $component_id,
'title' => $label,
'visibility' => 'no',
'hide_on_mobile' => false,
'blocked' => 'yes',
];
}
$new_control_data[ $component_id ] = (object) [
'slug' => $component_id,
'title' => $label,
'visibility' => 'no',
'hide_on_mobile' => false,
'blocked' => 'yes',
];
}

return array_values( $new_control_data );
Expand Down

0 comments on commit 900d1f0

Please sign in to comment.