| 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 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
public function render() { |
| 18 |
|
| 19 |
$palette = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array(); |
| 20 |
|
| 21 |
echo $this->field_before(); |
| 22 |
|
| 23 |
if ( ! empty( $palette ) ) { |
| 24 |
|
| 25 |
echo '<div class="csf-siblings csf--palettes">'; |
| 26 |
|
| 27 |
foreach ( $palette as $key => $colors ) { |
| 28 |
|
| 29 |
$active = ( $key === $this->value ) ? ' csf--active' : ''; |
| 30 |
$checked = ( $key === $this->value ) ? ' checked' : ''; |
| 31 |
|
| 32 |
echo '<div class="csf--sibling csf--palette'. esc_attr( $active ) .'">'; |
| 33 |
|
| 34 |
if ( ! empty( $colors ) ) { |
| 35 |
|
| 36 |
foreach ( $colors as $color ) { |
| 37 |
|
| 38 |
echo '<span style="background-color: '. esc_attr( $color ) .';"></span>'; |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
echo '<input type="radio" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $key ) .'"'. $this->field_attributes() . esc_attr( $checked ) .'/>'; |
| 45 |
echo '</div>'; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
echo '</div>'; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
echo $this->field_after(); |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
} |
| 59 |
|