| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Field: image_select |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'DarkifyField_image_select' ) ) { |
| 11 |
class DarkifyField_image_select 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 |
$args = wp_parse_args( $this->field, array( |
| 20 |
'multiple' => false, |
| 21 |
'inline' => false, |
| 22 |
'options' => array(), |
| 23 |
) ); |
| 24 |
|
| 25 |
$inline = ( $args['inline'] ) ? ' darkify--inline-list' : ''; |
| 26 |
|
| 27 |
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); |
| 28 |
|
| 29 |
echo wp_kses_post($this->field_before()); |
| 30 |
|
| 31 |
if ( ! empty( $args['options'] ) ) { |
| 32 |
|
| 33 |
echo '<div class="darkify-siblings darkify--image-group'. esc_attr( $inline ) .'" data-multiple="'. esc_attr( $args['multiple'] ) .'">'; |
| 34 |
|
| 35 |
$num = 1; |
| 36 |
|
| 37 |
foreach ( $args['options'] as $key => $option ) { |
| 38 |
|
| 39 |
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; |
| 40 |
$extra = ( $args['multiple'] ) ? '[]' : ''; |
| 41 |
$active = ( in_array( $key, $value ) ) ? ' darkify--active' : ''; |
| 42 |
$checked = ( in_array( $key, $value ) ) ? ' checked' : ''; |
| 43 |
$pro_only = isset($option['pro_only']) ? ' disabled' : ''; |
| 44 |
$darkify_pro_only_class = isset($option['pro_only']) ? ' darkify-pro-only' : ''; |
| 45 |
|
| 46 |
echo '<div class="darkify--sibling darkify--image' . esc_attr($active) . esc_attr($darkify_pro_only_class) . '">'; |
| 47 |
echo '<figure>'; |
| 48 |
echo '<img src="' . esc_url($option['image']) . '" alt="' . esc_attr($option['text']) . '" />'; |
| 49 |
echo '</figure>'; |
| 50 |
echo '<input ' . esc_attr($pro_only) . ' type="' . esc_attr($type) . '" name="' . esc_attr($this->field_name($extra)) . '" value="' . esc_attr($key) . '"' . wp_kses_post($this->field_attributes()) . esc_attr($checked) . '/>'; |
| 51 |
|
| 52 |
echo '<p class="darkify-image-title">' . esc_html($option['text']); |
| 53 |
|
| 54 |
if (! empty($option['option_demo_url'])) { |
| 55 |
echo ' <a href="' . esc_url($option['option_demo_url']) . '" tooltip="' . esc_html__('Demo', 'darkify') . '" class="darkify-live-demo-icon" target="_blank"><i class="icofont-external-link"></i></a>'; |
| 56 |
} |
| 57 |
echo '</p>'; |
| 58 |
|
| 59 |
echo '</div>'; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
echo '</div>'; |
| 64 |
|
| 65 |
} |
| 66 |
echo '<div class="clear"></div>'; |
| 67 |
echo wp_kses_post($this->field_after()); |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
public function output() { |
| 72 |
|
| 73 |
$output = ''; |
| 74 |
$bg_image = array(); |
| 75 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 76 |
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 77 |
|
| 78 |
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { |
| 79 |
$output = $elements .'{background-image:url('. wp_kses_post($this->value) .')'. $important .';}'; |
| 80 |
} |
| 81 |
|
| 82 |
$this->parent->output_css .= $output; |
| 83 |
|
| 84 |
return $output; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
} |
| 90 |
|