PluginProbe
Cool Timeline (Horizontal & Vertical Timeline) / trunk
Cool Timeline (Horizontal & Vertical Timeline) vtrunk
3.4.0 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 2.2.3 2.3.3 2.4 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.6.1 2.7.1 2.8.3 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 All 79 releases
cool-timeline / admin / codestar-framework / fields / button_set / button_set.php

button_set.php in Cool Timeline (Horizontal & Vertical Timeline) trunk, at admin/codestar-framework/fields/button_set/button_set.php

76 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if ( ! defined( 'ABSPATH' ) ) {
2 die;
3 } // Cannot access directly.
4 // phpcs:ignoreFile WordPress.Security.EscapeOutput.OutputNotEscaped
5 /**
6 *
7 * Field: button_set
8 *
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12 if ( ! class_exists( 'CSF_Field_button_set' ) ) {
13 class CSF_Field_button_set extends CSF_Fields {
14
15
16 public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
17
18 parent::__construct( $field, $value, $unique, $where, $parent );
19 }
20
21 public function render() {
22
23 $args = wp_parse_args(
24 $this->field,
25 array(
26 'multiple' => false,
27 'options' => array(),
28 'query_args' => array(),
29 )
30 );
31
32 $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
33
34 echo $this->field_before();
35
36 if ( isset( $this->field['options'] ) ) {
37
38 $options = $this->field['options'];
39 $options = ( is_array( $options ) ) ? $options : array_filter( $this->field_data( $options, false, $args['query_args'] ) );
40
41 if ( is_array( $options ) && ! empty( $options ) ) {
42
43 echo '<div class="csf-siblings csf--button-group" data-multiple="' . esc_attr( $args['multiple'] ) . '">';
44
45 foreach ( $options as $key => $option ) {
46
47 $type = ( $args['multiple'] ) ? 'checkbox' : 'radio';
48 $extra = ( $args['multiple'] ) ? '[]' : '';
49 $active = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' csf--active' : '';
50 $checked = ( in_array( $key, $value ) || ( empty( $value ) && empty( $key ) ) ) ? ' checked' : '';
51
52 echo '<div class="csf--sibling csf--button' . esc_attr( $active ) . '">';
53 echo '<input type="' . esc_attr( $type ) . '" name="' . esc_attr( $this->field_name( $extra ) ) . '" value="' . esc_attr( $key ) . '"' . $this->field_attributes() . esc_attr( $checked ) . '/>';
54 echo $option;
55 echo '</div>';
56
57 }
58
59 echo '</div>';
60
61 } else {
62
63 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
64 echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
65
66 }
67 }
68
69 echo $this->field_after();
70
71 }
72
73 }
74 }
75
76