1

I need your help. I have a function in the customizer that returns a simple array of $default_options[$control] via apply_filters()

function abro_options( $control ) {

  $abro_defaults = array(
    'general_container_width' => 'container',
    'general_menu_position' => 'left',
    'sidebar_display' => true,
    'sidebar_position' => 'right',
  );

  // Merge defaults and theme options
  $abro_defaults = wp_parse_args( get_option('abro_options'), $abro_defaults );

  // Return controls
  return apply_filters('abro_filter_options', $abro_defaults[ $control ] );
}

How can I compare the values of child options with the default options in the child theme and change only those that match by the key?

add_filter( 'abro_filter_options','child_theme_filter_options' );
  function child_theme_filter_options( $control ) {

      $child_theme_defaults = array(
        'general_menu_position' => 'right',
        'sidebar_position' => 'left',
      );

    ///?????

    // Merge defaults and theme options
    $abro_defaults = wp_parse_args( get_option('abro_options'), $abro_defaults );

    return $abro_defaults[ $control ];
  }

2 Answers 2

1

Try this to replace matches value from two array.

$a1= array(
        'general_container_width' => 'container',
        'general_menu_position' => 'left',
        'sidebar_display' => true,
        'sidebar_position' => 'right',
    );
$a2= array(
        'general_menu_position' => 'right',
        'sidebar_position' => 'left',
      );
print_r(array_replace($a1,$a2));
Sign up to request clarification or add additional context in comments.

Comments

1

Thanks all. If someone searches for an answer, this works:

// Default options customizer
function abro_options( $control ) {

    $abro_defaults = array(
        'general_container_width' => 'container',
        'general_menu_position' => 'left',
        'sidebar_display' => true,
        'sidebar_position' => 'right',
    );

    // Merge defaults and theme options
    $abro_defaults = wp_parse_args( get_option('abro_options'), apply_filters('abro_filter_options', $abro_defaults) );

    // Return controls
    return $avtomaton_defaults[ $control ];
}

// Filter default options in child theme
add_filter( 'abro_filter_options','child_theme_filter_options' );
    function child_theme_filter_options( $control ) {

            $child_theme_defaults = array(
                'general_menu_position' => 'right',
                'sidebar_position' => 'left',
            );

        // Merge defaults and theme options
        $abro_defaults = array_replace($abro_defaults, $child_theme_defaults);

        return $abro_defaults;
    }

1 Comment

Exactly what I needed. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.