Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the Theme Customizer API to upload a logo for a WP theme. I also want to let the user set the css for the logo size via a number input in the same Customizer section.

What's the best way to automatically populate the the logo width and height settings with the logo's dimensions when the user uploads a image?

This is my control for the logo setting:

$wp_customize->add_control(
    new WP_Customize_Image_Control(
        $wp_customize,
        'logo',
        array(
            'label' => 'Upload a logo image',
            'section' => 'logo',
            'settings' => 'sst_logo'
        )
    )
);

Here is my custom control class where I have two number fields for the width and the height of the logo image:

class Logo_Size extends WP_Customize_Control {
    public $type = 'text';
    public function render_content() {
        ?>
            <label>
                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
                <input class="sst-logo-width" type="number" data-customize-setting-link="sst_logo_width">
                <input class="sst-logo-height" type="number" data-customize-setting-link="sst_logo_height">
            </label>
        <?php
    }
}

Do I have to extend the WP_Customize_Image_Control class and modify the constructor somehow? Needless to say, OOP PHP is not my strength. Any advice will be greatly appreciated!

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.