1
0

palette.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: palette
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_palette' ) ) {
  11. class CSF_Field_palette extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $palette = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array();
  17. echo $this->field_before();
  18. if ( ! empty( $palette ) ) {
  19. echo '<div class="csf-siblings csf--palettes">';
  20. foreach ( $palette as $key => $colors ) {
  21. $active = ( $key === $this->value ) ? ' csf--active' : '';
  22. $checked = ( $key === $this->value ) ? ' checked' : '';
  23. echo '<div class="csf--sibling csf--palette'. esc_attr( $active ) .'">';
  24. if ( ! empty( $colors ) ) {
  25. foreach ( $colors as $color ) {
  26. echo '<span style="background-color: '. esc_attr( $color ) .';"></span>';
  27. }
  28. }
  29. echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>';
  30. echo '</div>';
  31. }
  32. echo '</div>';
  33. }
  34. echo $this->field_after();
  35. }
  36. }
  37. }