0

I'm attempting to create a custom customizer control where the user can define the setting to be whatever the setting is of a different control. For example, there is a setting for the theme's primary color. When the user is defining the default color of their buttons, I'd like them to have the option to specify that they want it to match the primary color setting and show a swatch of that color.

I've created a class for a custom control and added the following property. However, I receive an error saying "Fatal error: Constant expression contains invalid operations" on this line. I assume this is because I'm unable to use the get_theme_mod function from within a custom control class.

  public $theme_colors = array(
    'primary' => get_theme_mod('colors_primary', '#007bff'),
    'secondary_1' => get_theme_mod('colors_secondary_1', '$gray-600'),
    'secondary_2' => get_theme_mod('colors_secondary_2', '$gray-600'),
    'secondary_3' => get_theme_mod('colors_secondary_3', '$gray-600'),
  );

Can anyone please point me in the right direction as to how to accomplish this? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.