| 1 |
<?php |
| 2 |
/** |
| 3 |
* The framework button set fields file. |
| 4 |
* |
| 5 |
* @package Smart_Post_Show |
| 6 |
* @subpackage Smart_Post_Show/admin |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die; |
| 11 |
} // Cannot access directly. |
| 12 |
|
| 13 |
if ( ! class_exists( 'SP_PC_Field_button_set' ) ) { |
| 14 |
/** |
| 15 |
* SP_PC_Field_button_set |
| 16 |
*/ |
| 17 |
class SP_PC_Field_button_set extends SP_PC_Fields { |
| 18 |
|
| 19 |
/** |
| 20 |
* Field constructor. |
| 21 |
* |
| 22 |
* @param array $field The field type. |
| 23 |
* @param string $value The values of the field. |
| 24 |
* @param string $unique The unique ID for the field. |
| 25 |
* @param string $where To where show the output CSS. |
| 26 |
* @param string $parent The parent args. |
| 27 |
*/ |
| 28 |
public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 29 |
|
| 30 |
parent::__construct( $field, $value, $unique, $where, $parent ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Render |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function render() { |
| 39 |
|
| 40 |
$args = wp_parse_args( |
| 41 |
$this->field, |
| 42 |
array( |
| 43 |
'multiple' => false, |
| 44 |
'options' => array(), |
| 45 |
) |
| 46 |
); |
| 47 |
|
| 48 |
$value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value ); |
| 49 |
|
| 50 |
echo wp_kses_post( $this->field_before() ); |
| 51 |
|
| 52 |
if ( ! empty( $args['options'] ) ) { |
| 53 |
|
| 54 |
echo '<div class="spf-siblings spf--button-group" data-multiple="' . esc_attr( $args['multiple'] ) . '">'; |
| 55 |
|
| 56 |
foreach ( $args['options'] as $key => $option ) { |
| 57 |
|
| 58 |
$type = ( $args['multiple'] ) ? 'checkbox' : 'radio'; |
| 59 |
$extra = ( $args['multiple'] ) ? '[]' : ''; |
| 60 |
$active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' spf--active' : ''; |
| 61 |
$checked = ( in_array( $key, $value ) ) ? ' checked' : ''; |
| 62 |
$checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : ''; |
| 63 |
$pcp_pro_only_class = isset( $option['pro_only'] ) ? ' pcp-pro-only' : ''; |
| 64 |
echo '<div class="spf--sibling spf--button' . esc_attr( $active ) . esc_attr( $pcp_pro_only_class ) . '">'; |
| 65 |
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 ) . '/>'; |
| 66 |
if ( isset( $option['text'] ) && ! empty( $option['text'] ) ) { |
| 67 |
echo esc_html( $option['text'] ); |
| 68 |
} else { |
| 69 |
echo wp_kses_post( $option ); |
| 70 |
} |
| 71 |
|
| 72 |
echo '</div>'; |
| 73 |
|
| 74 |
} |
| 75 |
|
| 76 |
echo '</div>'; |
| 77 |
|
| 78 |
} |
| 79 |
echo wp_kses_post( $this->field_after() ); |
| 80 |
echo '<div class="clear"></div>'; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
|