| 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( 'DarkifyField_palette' ) ) { |
| 11 |
class DarkifyField_palette extends DarkifyFields { |
| 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 |
$palettes = ( ! empty( $this->field['options'] ) ) ? $this->field['options'] : array(); |
| 20 |
|
| 21 |
|
| 22 |
echo wp_kses_post( $this->field_before() ); |
| 23 |
|
| 24 |
if ( ! empty( $palettes ) ) { |
| 25 |
|
| 26 |
echo '<div class="darkify-siblings darkify--palettes">'; |
| 27 |
|
| 28 |
foreach ( $palettes as $key => $palette ) { |
| 29 |
$active = ( $key === $this->value ) ? ' darkify--active' : ''; |
| 30 |
$checked = ( $key === $this->value ) ? ' checked' : ''; |
| 31 |
$pro_only = isset($palette['pro_only']) ? ' disabled' : ''; |
| 32 |
$darkify_pro_only_class = isset($palette['pro_only']) ? ' darkify-pro-only' : ''; |
| 33 |
|
| 34 |
echo '<div class="darkify--sibling darkify--palette' . esc_attr( $active ) . esc_attr($darkify_pro_only_class) . '">'; |
| 35 |
echo '<div class="darkify--palette--colors">'; |
| 36 |
if ( ! empty( $palette ) ) { |
| 37 |
|
| 38 |
foreach ( $palette['colors'] as $color ) { |
| 39 |
echo '<span style="background-color: ' . esc_attr( $color ) . ';"></span>'; |
| 40 |
|
| 41 |
} |
| 42 |
} |
| 43 |
echo '</div>'; |
| 44 |
echo '<input ' . esc_attr($pro_only) . ' type="radio" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $key ) . '"' . wp_kses_post( $this->field_attributes() ) . esc_attr( $checked ) . '/>'; |
| 45 |
echo '<p class="darkify-palette-name">' . esc_html($palette['name']); |
| 46 |
|
| 47 |
if (! empty($palette['demo_url'])) { |
| 48 |
echo ' <a href="' . esc_url($palette['demo_url']) . '" tooltip="' . esc_html__('Demo', 'darkify') . '" class="darkify-live-demo-palette" target="_blank"><i class="icofont-external-link"></i></a>'; |
| 49 |
} |
| 50 |
echo '</p>'; |
| 51 |
echo '</div>'; |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
echo '</div>'; |
| 56 |
|
| 57 |
} |
| 58 |
|
| 59 |
echo wp_kses_post( $this->field_after() ); |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
|