| 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( 'SP_PC_Field_image_select' ) ) { |
| 11 |
class SP_PC_Field_image_select extends SP_PC_Fields { |
| 12 |
|
| 13 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 14 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Render method. |
| 19 |
* |
| 20 |
* @return void |
| 21 |
*/ |
| 22 |
public function render() { |
| 23 |
|
| 24 |
$args = wp_parse_args( |
| 25 |
$this->field, |
| 26 |
array( |
| 27 |
'multiple' => false, |
| 28 |
'options' => array(), |
| 29 |
) |
| 30 |
); |
| 31 |
|
| 32 |
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); |
| 33 |
|
| 34 |
echo wp_kses_post( $this->field_before() ); |
| 35 |
|
| 36 |
if ( ! empty( $args['options'] ) ) { |
| 37 |
|
| 38 |
echo '<div class="spf-siblings spf--image-group" data-multiple="' . esc_attr( $args['multiple'] ) . '">'; |
| 39 |
|
| 40 |
$num = 1; |
| 41 |
|
| 42 |
foreach ( $args['options'] as $key => $option ) { |
| 43 |
|
| 44 |
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; |
| 45 |
$extra = ( $args['multiple'] ) ? '[]' : ''; |
| 46 |
$active = ( in_array( $key, $value ) ) ? ' spf--active' : ''; |
| 47 |
$checked = ( in_array( $key, $value ) ) ? ' checked' : ''; |
| 48 |
|
| 49 |
echo '<div class="spf--sibling spf--image' . esc_attr( $active ) . '">'; |
| 50 |
echo '<img src="' . esc_url( $option ) . '" alt="' . esc_attr( $key ) . '" />'; |
| 51 |
/* echo '<img src="' . $option . '" alt="' . $num++ . '" />'; */ |
| 52 |
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 ) . '/>'; |
| 53 |
echo '</div>'; |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
echo '</div>'; |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
echo '<div class="clear"></div>'; |
| 62 |
|
| 63 |
echo wp_kses_post( $this->field_after() ); |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* The output method. |
| 69 |
* |
| 70 |
* @return mixed |
| 71 |
*/ |
| 72 |
public function output() { |
| 73 |
|
| 74 |
$output = ''; |
| 75 |
$bg_image = array(); |
| 76 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 77 |
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 78 |
|
| 79 |
if ( ! empty( $elements ) && isset( $this->value ) && '' !== $this->value ) { |
| 80 |
$output = $elements . '{background-image:url(' . $this->value . ')' . $important . ';}'; |
| 81 |
} |
| 82 |
|
| 83 |
$this->parent->output_css .= $output; |
| 84 |
|
| 85 |
return $output; |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
} |
| 90 |
} |
| 91 |
|