Custom customizer control

General Discussion 1 post 1 voice

  1. Hello Justin,

    I have a little problem, I have created a custom control where I add multiple settings like this:

    $wp_customize->add_setting( 'setting_one', array(
    	'transport' => 'postMessage',
    	'default' => '8',
    ) );
    $wp_customize->add_setting( 'setting_two', array(
    	'transport' => 'postMessage',
    	'default' => '0',
    ) );
    $wp_customize->add_setting( 'setting_three', array(
    	'transport' => 'postMessage',
    	'default' => '8',
    ) );
    $wp_customize->add_setting( 'setting_four', array(
    	'transport' => 'postMessage',
    	'default' => '0',
    ) );
    $wp_customize->add_control( new Custom_Customizer_Control( $wp_customize, 'my_control', array(
    	'label' => esc_html__( 'Control', 'theme-name' ),
    	'section' => 'my_section',
    	'settings'   => array(
    		'one'    => array(
    			'setting_one'  => 'setting_one',
    			'setting_two'  => 'setting_two',
    		),
    		'two' => array(
    			'setting_one'  => 'setting_three',
    			'setting_two'  => 'setting_four',
    		),
    	),
    	'priority' => 10,
    ) ) );

    To get the array from the settings attribute, I enter this code in my custom control:

    $one = array_column( $this->settings, 'one' );
    
    foreach ( $one as $key => $val ) {
    	$this->json[ $key ] = array(
    		'link'  	=> $this->get_link( $key ),
    		'value' 	=> $this->value( $key ),
    	);
    }

    The problem is that I get the following error in the customizer “Warning: Illegal offset type in isset or empty”, I do not really understand the problem, can you help me?
    Thank you a lot 🙂