0

The problem is that new arguments don't display at customizer.

at first, we extend WP_Customize_Control with this class:

class WP_Customize_Foo_Control extends WP_Customize_Control {
    public $type = 'foo';

    public function render_content() {
        echo $this->label;
        echo $this->description;

        echo $this->foo;  // <--- problem is here, it's not display
        echo $this->moo;  // <--- problem is here, it's not display
    }
}

at the next step we use add_setting and add_control to display our new control in static_front_page section.

$wp_customize->add_setting( 'foo_one', array(
    'type' => 'theme_mod',
    ));

$wp_customize->add_control( new WP_Customize_Foo_Control(
    $wp_customize,
    'foo_one',
    array(
        'label'         => 'Label',
        'description'   => 'desc',
        'type'          => 'foo',
        'section'       => 'static_front_page',

        'foo'           => 'John Doe',
        'moo'           => array('some','array','goes','here')

        ) 
    ));

problem is that, foo and moo arguments is not display in customizer.

1 Answer 1

1

If you check out the source of WP_Customize_Control::__construct:

public function __construct( $manager, $id, $args = array() ) {
    $keys = array_keys( get_object_vars( $this ) );
    foreach ( $keys as $key ) {
        if ( isset( $args[ $key ] ) ) {
            $this->$key = $args[ $key ];
        }
    }

    // [redacted]
 }

So you can see, in order for it pick up your custom arguments, they need to be declared as properties of your custom class:

class WP_Customize_Foo_Control extends WP_Customize_Control {
    public $foo;
    public $moo;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.