Question

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.

Fatal error: Call to a member function check_capabilities() on a non-object in C:\Users\SISIR\Dropbox\wamp\www\l\wp-includes\class-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'
                    )
                    )
                                                    );                                          
    }

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top