| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { |
| 2 |
die; } // Cannot access directly. |
| 3 |
/** |
| 4 |
* |
| 5 |
* Field: layout_preset |
| 6 |
* |
| 7 |
* @since 1.0.0 |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'SP_PC_Field_layout_preset' ) ) { |
| 11 |
class SP_PC_Field_layout_preset extends SP_PC_Fields { |
| 12 |
|
| 13 |
/** |
| 14 |
* Constructor. |
| 15 |
* |
| 16 |
* @param [type] $field |
| 17 |
* @param string $value |
| 18 |
* @param string $unique |
| 19 |
* @param string $where |
| 20 |
* @param string $parent |
| 21 |
*/ |
| 22 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 23 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Render method |
| 28 |
* |
| 29 |
* @return void |
| 30 |
*/ |
| 31 |
public function render() { |
| 32 |
|
| 33 |
$args = wp_parse_args( |
| 34 |
$this->field, |
| 35 |
array( |
| 36 |
'multiple' => false, |
| 37 |
'options' => array(), |
| 38 |
) |
| 39 |
); |
| 40 |
|
| 41 |
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); |
| 42 |
|
| 43 |
echo wp_kses_post( $this->field_before() ); |
| 44 |
|
| 45 |
if ( ! empty( $args['options'] ) ) { |
| 46 |
|
| 47 |
echo '<div class="spf-siblings spf--image-group" data-multiple="' . esc_attr( $args['multiple'] ) . '">'; |
| 48 |
|
| 49 |
$num = 1; |
| 50 |
|
| 51 |
foreach ( $args['options'] as $key => $option ) { |
| 52 |
|
| 53 |
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; |
| 54 |
$extra = ( $args['multiple'] ) ? '[]' : ''; |
| 55 |
$active = ( in_array( $key, $value ) ) ? ' spf--active' : ''; |
| 56 |
$checked = ( in_array( $key, $value ) ) ? ' checked' : ''; |
| 57 |
$pcp_pro_only_class = isset( $option['pro_only'] ) ? ' pcp-pro-only' : ''; |
| 58 |
|
| 59 |
echo '<div class="spf--sibling spf--image' . esc_attr( $active . $pcp_pro_only_class ) . '">'; |
| 60 |
echo '<img src="' . esc_url( $option['image'] ) . '" alt="' . esc_attr( $option['text'] ) . '" />'; |
| 61 |
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 ) . '/>'; |
| 62 |
echo '<span class="sp-carousel-type">' . esc_html( $option['text'] ) . '</span>'; |
| 63 |
echo '</div>'; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
echo '</div>'; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
echo '<div class="clear"></div>'; |
| 72 |
|
| 73 |
echo wp_kses_post( $this->field_after() ); |
| 74 |
|
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* The output method. |
| 79 |
* |
| 80 |
* @return mixed |
| 81 |
*/ |
| 82 |
public function output() { |
| 83 |
|
| 84 |
$output = ''; |
| 85 |
$bg_image = array(); |
| 86 |
$important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; |
| 87 |
$elements = ( is_array( $this->field['output'] ) ) ? join( ',', $this->field['output'] ) : $this->field['output']; |
| 88 |
|
| 89 |
if ( ! empty( $elements ) && isset( $this->value ) && '' !== $this->value ) { |
| 90 |
$output = $elements . '{background-image:url(' . $this->value . ')' . $important . ';}'; |
| 91 |
} |
| 92 |
|
| 93 |
$this->parent->output_css .= $output; |
| 94 |
|
| 95 |
return $output; |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
} |
| 101 |
|