Rich Cresswell
Rich Cresswell

Reputation: 5

wordpress error on line 160 of ...wp-includes\class-wp-customize-control.php whilst adding hooks for extra functions

Thanks in advance for any help with this, Error Call to a member function check_capabilities()

stuck in a rut with this one!

Directory layout:

Functions calls customize.php like this:

<?php require_once('functions/customize.php'); ?>

customize.php:

<?php
add_action('customize_register', 'adaptive_customize_register');
function adaptive_customize_register($wp_customize) {
//logo
$wp_customize->add_section('adaptive_logo', array(
'title' => __('Add Logo', 'adaptive_framework'), 
'description' => __('Upload your main logo, this shows in the header',      'adaptive_framework'), 
'priority' => '25'
));
    $wp_customize->add_setting('adaptive_custom_settings[add_logo]', array(
    'default' => 0,
    'type' => 'option'
));

$wp_customize->add_control('adaptive_custom_settings[display_logo]', array(
    'label' => __('Display logo?','adaptive_framework'),
    'section' => 'adaptive_logo',
    'settings' => 'adaptive_custom_settings[display_top_logo]',
    'type' => 'checkbox'
    ));
}



?>

If anyone can help with please as I get error as follows:

Fatal error: Call to a member function check_capabilities() on a non-object in C:\xampp\htdocs\wordpress\wp-includes\class-wp-customize-control.php on line 160

Upvotes: 1

Views: 1786

Answers (2)

Thomas
Thomas

Reputation: 61

The settings parameter of add_control() has to match the name of the setting defined in add_setting(). Otherwise the control is added to an unknown setting which causes the capabilities error.

Therefore change adaptive_custom_settings[display_top_logo] to adaptive_custom_settings[add_logo]

    <?php
    add_action('customize_register', 'adaptive_customize_register');
    function adaptive_customize_register($wp_customize) {
    //logo
    $wp_customize->add_section('adaptive_logo', array(
        'title' => __('Add Logo', 'adaptive_framework'), 
        'description' => __('Upload your main logo, this shows in the header',         'adaptive_framework'), 
        'priority' => '25'
    ));
    $wp_customize->add_setting('adaptive_custom_settings[add_logo]', array(
        'default' => 0,
        'type' => 'option'
    ));

    $wp_customize->add_control('adaptive_custom_settings[display_logo]', array(
        'label' => __('Display logo?','adaptive_framework'),
        'section' => 'adaptive_logo',
        'settings' => 'adaptive_custom_settings[add_logo]',
        'type' => 'checkbox'
    ));
    }
    ?>

Upvotes: 6

Rich Cresswell
Rich Cresswell

Reputation: 5

Had to end this thread as the code I'm using is now no longer required, I will look to get the finished code as working in an example online.

Upvotes: -3

Related Questions