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 / checkbox / checkbox.php

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

103 lines 3.2 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: checkbox
8 *
9 * @since 1.0.0
10 * @version 1.0.0
11 */
12 if ( ! class_exists( 'CSF_Field_checkbox' ) ) {
13 class CSF_Field_checkbox 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 'inline' => false,
27 'query_args' => array(),
28 )
29 );
30
31 $inline_class = ( $args['inline'] ) ? ' class="csf--inline-list"' : '';
32
33 echo $this->field_before();
34
35 if ( isset( $this->field['options'] ) ) {
36
37 $value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
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 '<ul' . $inline_class . '>';
44
45 foreach ( $options as $option_key => $option_value ) {
46
47 if ( is_array( $option_value ) && ! empty( $option_value ) ) {
48
49 echo '<li>';
50 echo '<ul>';
51 echo '<li><strong>' . esc_attr( $option_key ) . '</strong></li>';
52 foreach ( $option_value as $sub_key => $sub_value ) {
53 $checked = ( in_array( $sub_key, $value ) ) ? ' checked' : '';
54 echo '<li>';
55 echo '<label>';
56 echo '<input type="checkbox" name="' . esc_attr( $this->field_name( '[]' ) ) . '" value="' . esc_attr( $sub_key ) . '"' . $this->field_attributes() . esc_attr( $checked ) . '/>';
57 echo '<span class="csf--text">' . esc_attr( $sub_value ) . '</span>';
58 echo '</label>';
59 echo '</li>';
60 }
61 echo '</ul>';
62 echo '</li>';
63
64 } else {
65
66 $checked = ( in_array( $option_key, $value ) ) ? ' checked' : '';
67
68 echo '<li>';
69 echo '<label>';
70 echo '<input type="checkbox" name="' . esc_attr( $this->field_name( '[]' ) ) . '" value="' . esc_attr( $option_key ) . '"' . $this->field_attributes() . esc_attr( $checked ) . '/>';
71 echo '<span class="csf--text">' . esc_attr( $option_value ) . '</span>';
72 echo '</label>';
73 echo '</li>';
74
75 }
76 }
77
78 echo '</ul>';
79
80 } else {
81
82 // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
83 echo ( ! empty( $this->field['empty_message'] ) ) ? esc_attr( $this->field['empty_message'] ) : esc_html__( 'No data available.', 'csf' );
84
85 }
86 } else {
87
88 echo '<label class="csf-checkbox">';
89 echo '<input type="hidden" name="' . esc_attr( $this->field_name() ) . '" value="' . $this->value . '" class="csf--input"' . $this->field_attributes() . '/>';
90 echo '<input type="checkbox" name="_pseudo" class="csf--checkbox"' . esc_attr( checked( $this->value, 1, false ) ) . $this->field_attributes() . '/>';
91 echo ( ! empty( $this->field['label'] ) ) ? '<span class="csf--text">' . esc_attr( $this->field['label'] ) . '</span>' : '';
92 echo '</label>';
93
94 }
95
96 echo $this->field_after();
97
98 }
99
100 }
101 }
102
103