1

I have a little problem with the Customizer, I try to create a custom control spacing, 4 inputs for the text padding (top/right/bottom/left), here's the code for the customizer:

array(
    'id' => 'type_number',
    'transport' => 'postMessage',
    'default'    => array(
        'top'    => '1.5em',
        'bottom' => '10px',
        'left'   => '40%',
        'right'  => '2rem',
    ),
    'control' => array(
        'type' => 'custom-spacing',
        'label' => esc_html__( 'Border Radius', 'custom' ),
        'desc' => esc_html__( 'Enter values including any valid CSS unit - top/right/bottom/left.', 'custom' ),
        'choices'     => array(
            'top'     => true,
            'bottom'  => true,
            'left'    => true,
            'right'   => true,
        ),
        'inline_css' => array(
            'target' => '#scroll-top',
            'alter' => 'border-radius',
        ),
    ),
)

And the custom control:

class Custom_Customizer_Spacing_Control extends WP_Customize_Control {
public $type = 'custom-spacing';
public function render_content() {
    $defaults = array(
        'top'    => '',
        'right'  => '',
        'bottom' => '',
        'left'   => ''
    );

    $value = wp_parse_args( $this->value(), $defaults );
    $name = '_customize-spacing-' . $this->id; ?>

    <?php if ( ! empty( $this->label ) ) : ?>
        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    <?php endif;
    if ( ! empty( $this->description ) ) : ?>
        <span class="description customize-control-description"><?php echo $this->description; ?></span>
    <?php endif;

    if ( $this->choices['top'] === true ) { ?>
        <input type="hidden" class="spacing-value" id="<?php echo esc_attr( $this->id ); ?>-top" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value['top'] ); ?>" <?php $this->link(); ?> />
    <?php }

    if ( $this->choices['top'] === true ) { ?>
        <div class="field-spacing-input input-prepend">
            <span class="spacing-icon"><i class="dashicons dashicons-arrow-up-alt"></i></span>
            <input type="text" class="spacing-input" id="<?php echo esc_attr( $this->id ); ?>-top" value="<?php echo esc_attr( $value['top'] ); ?>" />
        </div>
    <?php }
}

}

But the value of the hidden input gives me this "[object Object]" and I cannot find why, I searched on the web but I can not find a solution, can you help me please, thank you very much :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.