| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: image_select |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'DRK_LITE_Field_image_select' ) ) { |
| 11 |
class DRK_LITE_Field_image_select extends DRK_LITE_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 |
$args = wp_parse_args( |
| 20 |
$this->field, |
| 21 |
array( |
| 22 |
'multiple' => false, |
| 23 |
'inline' => false, |
| 24 |
'options' => array(), |
| 25 |
) |
| 26 |
); |
| 27 |
|
| 28 |
$inline = ( $args['inline'] ) ? ' drk_lite--inline-list' : ''; |
| 29 |
|
| 30 |
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); |
| 31 |
|
| 32 |
echo wp_kses_post( $this->field_before() ); |
| 33 |
|
| 34 |
if ( ! empty( $args['options'] ) ) { |
| 35 |
|
| 36 |
echo '<div class="drk_lite-siblings drk_lite--image-group' . esc_attr( $inline ) . '" data-multiple="' . esc_attr( $args['multiple'] ) . '">'; |
| 37 |
|
| 38 |
$num = 1; |
| 39 |
|
| 40 |
foreach ( $args['options'] as $key => $option ) { |
| 41 |
|
| 42 |
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; |
| 43 |
$extra = ( $args['multiple'] ) ? '[]' : ''; |
| 44 |
$active = ( in_array( $key, $value ) ) ? ' drk_lite--active' : ''; |
| 45 |
$checked = ( in_array( $key, $value ) ) ? ' checked' : ''; |
| 46 |
|
| 47 |
echo '<div class="drk_lite--sibling drk_lite--image' . esc_attr( $active ) . '">'; |
| 48 |
echo '<figure>'; |
| 49 |
echo '<img src="' . esc_url( $option ) . '" alt="img-' . esc_attr( $num++ ) . '" />'; |
| 50 |
echo '<input 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 |
echo '</figure>'; |
| 52 |
echo '</div>'; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
echo '</div>'; |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
echo wp_kses_post( $this->field_after() ); |
| 61 |
} |
| 62 |
|
| 63 |
public function output() { |
| 64 |
|
| 65 |
$output = ''; |
| 66 |
$bg_image = array(); |
| 67 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 68 |
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 69 |
|
| 70 |
if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { |
| 71 |
$output = $elements . '{background-image:url(' . $this->value . ')' . $important . ';}'; |
| 72 |
} |
| 73 |
|
| 74 |
$this->parent->output_css .= $output; |
| 75 |
|
| 76 |
return $output; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|