PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / redux / ReduxCore / inc / fields / checkbox / field_checkbox.php

field_checkbox.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/fields/checkbox/field_checkbox.php

173 lines 5.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Redux Framework is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * any later version.
8 * Redux Framework is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
14 *
15 * @package ReduxFrameworkLegacy
16 * @subpackage Field_Checkbox
17 * @author Daniel J Griffiths (Ghost1227)
18 * @author Dovy Paukstys
19 * @version 3.0.0
20 */
21 // Exit if accessed directly
22 if ( ! defined( 'ABSPATH' ) ) {
23 exit;
24 }
25
26 // Don't duplicate me!
27 if ( ! class_exists( 'ReduxFrameworkLegacy_checkbox' ) ) {
28
29 /**
30 * Main ReduxFrameworkLegacy_checkbox class
31 *
32 * @since 1.0.0
33 */
34 class ReduxFrameworkLegacy_checkbox {
35
36 /**
37 * Field Constructor.
38 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
39 *
40 * @since 1.0.0
41 * @access public
42 * @return void
43 */
44 function __construct( $field = array(), $value = '', $parent = null ) {
45
46 $this->parent = $parent;
47 $this->field = $field;
48 $this->value = $value;
49 }
50
51 /**
52 * Field Render Function.
53 * Takes the vars and outputs the HTML for the field in the settings
54 *
55 * @since 1.0.0
56 * @access public
57 * @return void
58 */
59 public function render() {
60 if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) {
61 if ( empty( $this->field['args'] ) ) {
62 $this->field['args'] = array();
63 }
64
65 $this->field['options'] = $this->parent->get_wordpress_data( $this->field['data'], $this->field['args'] );
66 if ( empty( $this->field['options'] ) ) {
67 return;
68 }
69 }
70
71 $this->field['data_class'] = ( isset( $this->field['multi_layout'] ) ) ? 'data-' . $this->field['multi_layout'] : 'data-full';
72
73 if ( ! empty( $this->field['options'] ) && ( is_array( $this->field['options'] ) || is_array( $this->field['default'] ) ) ) {
74
75 echo '<ul class="' . $this->field['data_class'] . '">';
76
77 if ( ! isset( $this->value ) ) {
78 $this->value = array();
79 }
80
81 if ( ! is_array( $this->value ) ) {
82 $this->value = array();
83 }
84
85 if ( empty( $this->field['options'] ) && isset( $this->field['default'] ) && is_array( $this->field['default'] ) ) {
86 $this->field['options'] = $this->field['default'];
87 }
88
89 foreach ( $this->field['options'] as $k => $v ) {
90
91 if ( empty( $this->value[ $k ] ) ) {
92 $this->value[ $k ] = '';
93 }
94
95 echo '<li>';
96 echo '<label for="' . strtr(
97 $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $k . ']',
98 array(
99 '[' => '_',
100 ']' => '',
101 )
102 ) . '_' . array_search( $k, array_keys( $this->field['options'] ) ) . '">';
103 echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field['name'] . '[' . $k . ']' . $this->field['name_suffix'] . '" value="' . $this->value[ $k ] . '" ' . '/>';
104 echo '<input type="checkbox" class="checkbox ' . $this->field['class'] . '" id="' . strtr(
105 $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $k . ']',
106 array(
107 '[' => '_',
108 ']' => '',
109 )
110 ) . '_' . array_search( $k, array_keys( $this->field['options'] ) ) . '" value="1" ' . checked( $this->value[ $k ], '1', false ) . '/>';
111 echo ' ' . $v . '</label>';
112 echo '</li>';
113 }
114
115 echo '</ul>';
116 } elseif ( empty( $this->field['data'] ) ) {
117 echo '<ul class="data-full"><li>';
118
119 if ( ! empty( $this->field['label'] ) ) {
120 echo '<label>';
121 }
122
123 // Got the "Checked" status as "0" or "1" then insert it as the "value" option
124 // $ch_value = 1; // checked($this->value, '1', false) == "" ? "0" : "1";
125 echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field['name'] . $this->field['name_suffix'] . '" value="' . $this->value . '" ' . '/>';
126 echo '<input type="checkbox" id="' . strtr(
127 $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']',
128 array(
129 '[' => '_',
130 ']' => '',
131 )
132 ) . '" value="1" class="checkbox ' . $this->field['class'] . '" ' . checked( $this->value, '1', false ) . '/>';
133
134 if ( ! empty( $this->field['label'] ) ) {
135 echo ' ' . $this->field['label'];
136 echo '</label>';
137 }
138
139 echo '</li></ul>';
140 }
141 }
142
143 /**
144 * Enqueue Function.
145 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
146 *
147 * @since 1.0.0
148 * @access public
149 * @return void
150 */
151 public function enqueue() {
152
153 if ( $this->parent->args['dev_mode'] ) {
154 wp_enqueue_style(
155 'redux-field-checkbox-css',
156 ReduxFrameworkLegacy::$_url . 'inc/fields/checkbox/field_checkbox.css',
157 array(),
158 time(),
159 'all'
160 );
161 }
162
163 wp_enqueue_script(
164 'redux-field-checkbox-js',
165 ReduxFrameworkLegacy::$_url . 'inc/fields/checkbox/field_checkbox' . ReduxLegacy_Functions::isMin() . '.js',
166 array( 'jquery', 'redux-js' ),
167 time(),
168 true
169 );
170 }
171 }
172 }
173