PluginProbe
QuadMenu – Mega Menu / 1.8.8
QuadMenu – Mega Menu v1.8.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 / lib / ReduxCore / inc / fields / checkbox / field_checkbox.php

field_checkbox.php in QuadMenu – Mega Menu 1.8.8, at lib/ReduxCore/inc/fields/checkbox/field_checkbox.php

164 lines 6.4 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 ReduxFramework
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 ( 'ReduxFramework_checkbox' ) ) {
28
29 /**
30 * Main ReduxFramework_checkbox class
31 *
32 * @since 1.0.0
33 */
34 class ReduxFramework_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 ) {
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 ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . '][' . $k . ']', array(
97 '[' => '_',
98 ']' => ''
99 ) ) . '_' . array_search ( $k, array_keys ( $this->field[ 'options' ] ) ) . '">';
100 echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field[ 'name' ] . '[' . $k . ']' . $this->field[ 'name_suffix' ] . '" value="' . $this->value[ $k ] . '" ' . '/>';
101 echo '<input type="checkbox" class="checkbox ' . $this->field[ 'class' ] . '" id="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . '][' . $k . ']', array(
102 '[' => '_',
103 ']' => ''
104 ) ) . '_' . array_search ( $k, array_keys ( $this->field[ 'options' ] ) ) . '" value="1" ' . checked ( $this->value[ $k ], '1', false ) . '/>';
105 echo ' ' . $v . '</label>';
106 echo '</li>';
107 }
108
109 echo '</ul>';
110 } else if ( empty ( $this->field[ 'data' ] ) ) {
111 echo '<ul class="data-full"><li>';
112
113 if ( !empty( $this->field[ 'label' ] ) ) {
114 echo '<label>';
115 }
116
117 // Got the "Checked" status as "0" or "1" then insert it as the "value" option
118 //$ch_value = 1; // checked($this->value, '1', false) == "" ? "0" : "1";
119 echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . $this->field[ 'name' ] . $this->field[ 'name_suffix' ] . '" value="' . $this->value . '" ' . '/>';
120 echo '<input type="checkbox" id="' . strtr ( $this->parent->args[ 'opt_name' ] . '[' . $this->field[ 'id' ] . ']', array(
121 '[' => '_',
122 ']' => ''
123 ) ) . '" value="1" class="checkbox ' . $this->field[ 'class' ] . '" ' . checked ( $this->value, '1', false ) . '/>';
124
125 if ( !empty( $this->field[ 'label' ] ) ) {
126 echo ' ' . $this->field[ 'label' ];
127 echo '</label>';
128 }
129
130 echo '</li></ul>';
131 }
132 }
133
134 /**
135 * Enqueue Function.
136 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
137 *
138 * @since 1.0.0
139 * @access public
140 * @return void
141 */
142 public function enqueue () {
143
144 if ($this->parent->args['dev_mode']) {
145 wp_enqueue_style (
146 'redux-field-checkbox-css',
147 ReduxFramework::$_url . 'inc/fields/checkbox/field_checkbox.css',
148 array(),
149 time (),
150 'all'
151 );
152 }
153
154 wp_enqueue_script (
155 'redux-field-checkbox-js',
156 ReduxFramework::$_url . 'inc/fields/checkbox/field_checkbox' . Redux_Functions::isMin () . '.js',
157 array( 'jquery', 'redux-js' ),
158 time (),
159 true
160 );
161 }
162 }
163 }
164