| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: palette |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Field_palette' ) ) { |
| 11 |
class ADMINIFY_Field_palette extends ADMINIFY_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 |
$palette = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : []; |
| 19 |
|
| 20 |
echo wp_kses_post( $this->field_before() ); |
| 21 |
|
| 22 |
if ( ! empty( $palette ) ) { |
| 23 |
echo '<div class="adminify-siblings adminify--palettes">'; |
| 24 |
|
| 25 |
foreach ( $palette as $key => $colors ) { |
| 26 |
$active = ( $key === $this->value ) ? ' adminify--active' : ''; |
| 27 |
$checked = ( $key === $this->value ) ? ' checked' : ''; |
| 28 |
|
| 29 |
echo '<div class="adminify--sibling adminify--palette' . esc_attr( $active ) . '">'; |
| 30 |
|
| 31 |
if ( ! empty( $colors ) ) { |
| 32 |
foreach ( $colors as $color ) { |
| 33 |
echo '<span style="background-color: ' . esc_attr( $color ) . ';"></span>'; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
echo '<input type="radio" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $key ) . '"' . wp_kses_post( $this->field_attributes() ) . esc_attr( $checked ) . '/>'; |
| 38 |
echo '</div>'; |
| 39 |
} |
| 40 |
|
| 41 |
echo '</div>'; |
| 42 |
} |
| 43 |
|
| 44 |
echo wp_kses_post( $this->field_after() ); |
| 45 |
} |
| 46 |
|
| 47 |
} |
| 48 |
} |
| 49 |
|