class-wc-customizer-control-cropping.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if ( ! defined( 'ABSPATH' ) ) {
  11. exit;
  12. }
  13. /**
  14. * WC_Customizer_Control_Cropping class.
  15. */
  16. class WC_Customizer_Control_Cropping extends WP_Customize_Control {
  17. /**
  18. * Declare the control type.
  19. *
  20. * @var string
  21. */
  22. public $type = 'woocommerce-cropping-control';
  23. /**
  24. * Render control.
  25. */
  26. public function render_content() {
  27. if ( empty( $this->choices ) ) {
  28. return;
  29. }
  30. $value = $this->value( 'cropping' );
  31. $custom_width = $this->value( 'custom_width' );
  32. $custom_height = $this->value( 'custom_height' );
  33. ?>
  34. <span class="customize-control-title">
  35. <?php echo esc_html( $this->label ); ?>
  36. </span>
  37. <?php if ( ! empty( $this->description ) ) : ?>
  38. <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
  39. <?php endif; ?>
  40. <ul id="input_<?php echo esc_attr( $this->id ); ?>" class="woocommerce-cropping-control">
  41. <?php foreach ( $this->choices as $key => $radio ) : ?>
  42. <li>
  43. <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 ); ?> />
  44. <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>
  45. <?php if ( 'custom' === $key ) : ?>
  46. <span class="woocommerce-cropping-control-aspect-ratio">
  47. <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' ); ?> />
  48. </span>
  49. <?php endif; ?>
  50. </li>
  51. <?php endforeach; ?>
  52. </ul>
  53. <?php
  54. }
  55. }