class-wc-customizer-control-cropping.php
65 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Custom control for radio buttons with nested options. |
| 4 | * |
| 5 | * Used for our image cropping settings. |
| 6 | * |
| 7 | * @version 3.3.0 |
| 8 | * @package WooCommerce |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * WC_Customizer_Control_Cropping class. |
| 17 | */ |
| 18 | class WC_Customizer_Control_Cropping extends WP_Customize_Control { |
| 19 | |
| 20 | /** |
| 21 | * Declare the control type. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | public $type = 'woocommerce-cropping-control'; |
| 26 | |
| 27 | /** |
| 28 | * Render control. |
| 29 | */ |
| 30 | public function render_content() { |
| 31 | if ( empty( $this->choices ) ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | $value = $this->value( 'cropping' ); |
| 36 | $custom_width = $this->value( 'custom_width' ); |
| 37 | $custom_height = $this->value( 'custom_height' ); |
| 38 | ?> |
| 39 | |
| 40 | <span class="customize-control-title"> |
| 41 | <?php echo esc_html( $this->label ); ?> |
| 42 | </span> |
| 43 | |
| 44 | <?php if ( ! empty( $this->description ) ) : ?> |
| 45 | <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span> |
| 46 | <?php endif; ?> |
| 47 | |
| 48 | <ul id="input_<?php echo esc_attr( $this->id ); ?>" class="woocommerce-cropping-control"> |
| 49 | <?php foreach ( $this->choices as $key => $radio ) : ?> |
| 50 | <li> |
| 51 | <input type="radio" name="<?php echo esc_attr( $this->id ); ?>" value="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $this->id . $key ); ?>" <?php $this->link( 'cropping' ); ?> <?php checked( $value, $key ); ?> /> |
| 52 | <label for="<?php echo esc_attr( $this->id . $key ); ?>"><?php echo esc_html( $radio['label'] ); ?><br/><span class="description"><?php echo esc_html( $radio['description'] ); ?></span></label> |
| 53 | |
| 54 | <?php if ( 'custom' === $key ) : ?> |
| 55 | <span class="woocommerce-cropping-control-aspect-ratio"> |
| 56 | <input type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $custom_width ); ?>" <?php $this->link( 'custom_width' ); ?> /> : <input type="text" pattern="\d*" size="3" value="<?php echo esc_attr( $custom_height ); ?>" <?php $this->link( 'custom_height' ); ?> /> |
| 57 | </span> |
| 58 | <?php endif; ?> |
| 59 | </li> |
| 60 | <?php endforeach; ?> |
| 61 | </ul> |
| 62 | <?php |
| 63 | } |
| 64 | } |
| 65 |