wp-customize-color-palette-control.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * Color Palette Customizer Control
  4. *
  5. * Based on https://github.com/HardeepAsrani/o2
  6. */
  7. if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'Color_Palette_Control' ) ) {
  8. class Color_Palette_Control extends WP_Customize_Control {
  9. public $type = 'color-palette';
  10. public function enqueue() {
  11. wp_enqueue_style( 'color-customization', get_template_directory_uri() . '/inc/customizer/wp-customize-color-palette-control.css' );
  12. }
  13. public function render_content() {
  14. ?>
  15. <label>
  16. <?php if ( ! empty( $this->label ) ) : ?>
  17. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  18. <?php endif;
  19. if ( ! empty( $this->description ) ) : ?>
  20. <span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
  21. <?php endif; ?>
  22. <div class="color-palette-group">
  23. <?php foreach ( $this->choices as $value => $label ) : ?>
  24. <input name="color_palette_<?php echo esc_attr( $this->id ); ?>" id="color_palette_<?php echo esc_attr( $this->id ); ?>_<?php echo esc_attr( $value ); ?>" type="radio" value="<?php echo esc_attr( $value ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> >
  25. <label for="color_palette_<?php echo esc_attr( $this->id ); ?>_<?php echo esc_attr( $value ); ?>" class="color-option">
  26. <div class="custom-color-palette">
  27. <span class="color-palette-label"><?php echo esc_html( $label['label'] ); ?></span>
  28. <?php foreach ( $label['colors'] as $slug => $color ) : ?>
  29. <div class="color-stripe" style="background-color: <?php echo esc_attr( $color ); ?>">&nbsp;</div>
  30. <?php endforeach; ?>
  31. </tr>
  32. </div>
  33. </label>
  34. </input>
  35. <?php endforeach; ?>
  36. </div>
  37. </label>
  38. <?php }
  39. }
  40. }