Edit: dimension.php
<?php if (class_exists('WP_Customize_Control')) { class WP_Customize_Dimension_Control extends WP_Customize_Control { public $type = 'dimension'; public function enqueue() { wp_enqueue_script('jquery'); } protected function render_content() { $value = json_decode($this->value(), true); if (!is_array($value)) { $value = array(); } $defaults = array('top' => '', 'right' => '', 'bottom' => '', 'left' => ''); $value = wp_parse_args($value, $defaults); ?> <label> <span class="customize-control-title"><?php echo esc_html($this->label); ?></span> <?php if (!empty($this->description)): ?> <span class="description customize-control-description"><?php echo esc_html($this->description); ?></span> <?php endif; ?> <div class="dimension-wrapper"> <?php foreach (array('top', 'right', 'bottom', 'left') as $side): ?> <div class="dimension-input"> <input type="number" min="0" step="1" placeholder="0" class="dimension-field" data-side="<?php echo esc_attr($side); ?>" value="<?php echo esc_attr($value[$side]); ?>"> <span class="dimension-label"><?php echo esc_html(ucfirst($side)); ?></span> </div> <?php endforeach; ?> </div> <input type="hidden" class="dimension-hidden-input" <?php $this->link(); ?> value="<?php echo esc_attr(wp_json_encode($value)); ?>" /> </label> <style> .customize-control-dimension .dimension-wrapper { display: grid; grid-template-columns: 23% 23% 23% 23% !important; gap: 10px; margin-top: 10px; } .customize-control-dimension .dimension-input { display: flex; flex-direction: column; align-items: center; } .customize-control-dimension .dimension-field { width: 60px; padding: 8px; text-align: center; border: 1px solid #ddd; border-radius: 3px; } .customize-control-dimension .dimension-field:focus { border-color: #5b9dd9; box-shadow: 0 0 2px rgba(30, 140, 190, 0.8); outline: none; } .customize-control-dimension .dimension-label { font-size: 11px; margin-top: 5px; color: #666; font-weight: 500; text-transform: capitalize; } </style> <script> jQuery(document).ready(function($) { var controlId = '<?php echo esc_js($this->id); ?>'; var wrapper = $('#customize-control-' + controlId + ' .dimension-wrapper'); var hiddenInput = $('#customize-control-' + controlId + ' .dimension-hidden-input'); function updateDimensionValue() { var data = {}; wrapper.find('.dimension-field').each(function() { var side = $(this).data('side'); var value = $(this).val(); data[side] = value || ''; }); var jsonValue = JSON.stringify(data); hiddenInput.val(jsonValue).trigger('change'); } wrapper.on('input change keyup', '.dimension-field', function() { updateDimensionValue(); }); }); </script> <?php } } }
Save
Back