Unable to pass variable on theme cusomizer add_settings()

I have theme options saved as serialized data. And I have named the option name by getting theme name.

$theme = wp_get_theme();
$settings = sanitize_title($theme).'-options'; // do not change!

But when I am trying to pass the $settings variable with or without concatenation. It ends up with this fatal error.

Read More
Fatal error: Call to a member function check_capabilities() on a non-object in C:UsersSISIRDropboxwampwwwlwp-includesclass-wp-customize-control.php on line 160

Check the $settings.'[skin'] section which doesn’t work but when I replace that part of the code with 'lead_capture_theme_option[skin]', it works. The fatal error itself is also puzzling.

    add_action( 'customize_register', 'lead_capture_theme_customize_register', 11 );

    function lead_capture_theme_customize_register($wp_customize) {

        $theme = wp_get_theme();
        $settings = sanitize_title($theme).'-options'; // do not change!
    //  var_dump($settings);

        $wp_customize->add_section( 'lead_cap_color_scheme', array(                                             'title'          => __( 'Color Scheme', 'themename' ),
        'priority'       => 35
        )
    );

        $wp_customize->add_setting( $settings.'[skin]', array(                                              'default'        => 'light',
        'type'           => 'theme_mod',
        'capability'     => 'edit_theme_options'                                            )
    );

        $wp_customize->add_control( 'lead_capture_theme_option[skin]', array(                                               'label'        => 'Select a Color Scheme',
        'type'           => 'select',
        'choices' => array('default', 'custom'),
        'section' => 'lead_cap_color_scheme',
        'settings' => 'lead_capture_theme_option[skin]'
    )
);
                                                $wp_customize->add_setting( 'lead_capture_theme_option[logo]', array(
                'type'           => 'theme_mod',
                'capability'     => 'edit_theme_options'
                )
        );

    $wp_customize->add_control( 
                                                                new WP_Customize_Image_Control( $wp_customize, 'lead_capture_theme_option[logo]', array(
                    'label'   => 'Upload Logo',
                    'section' => 'lead_cap_color_scheme'
                    )
                    )
                                                    );                                          
    }

Related posts

Leave a Reply

1 comment

  1. Thanks to @chip_bennett to point it out!

    I registered the settings using settings api and I was trying to add the settings on customize api by the type of theme_mod that’s why it was showing the error. After changing the 'type' => 'theme_mod' to 'type' => 'option', it worked 🙂