PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 1.1.6
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v1.1.6
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Admin / Setting_Callbacks.php

Setting_Callbacks.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 1.1.6, at classes/Admin/Setting_Callbacks.php

444 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace JP\CC\Admin;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 class Setting_Callbacks {
10
11 private static $_prefix;
12 private static $_options;
13
14 public static function init( $prefix, $options = array() ) {
15 static::$_prefix = $prefix;
16 static::$_options = $options;
17 }
18
19 /**
20 * Header Callback
21 *
22 * Renders the header.
23 *
24 * @param array $args Arguments passed by the setting
25 */
26 public static function header( $args ) {
27 echo '<hr/>';
28 }
29
30 /**
31 * Checkbox Callback
32 *
33 * Renders checkboxes.
34 *
35 * @param array $args Arguments passed by the setting
36 */
37 public static function checkbox( $args ) {
38 $checked = isset( static::$_options[ $args['id'] ] ) ? checked( 1, static::$_options[ $args['id'] ], false ) : '';
39 $html = '<input type="checkbox" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="1" ' . $checked . '/>';
40 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
41
42 echo $html;
43 }
44
45 /**
46 * Multicheck Callback
47 *
48 * Renders multiple checkboxes.
49 *
50 * @param array $args Arguments passed by the setting
51 */
52 public static function multicheck( $args ) {
53 if ( ! empty( $args['options'] ) ) {
54 foreach ( $args['options'] as $key => $option ):
55 if ( isset( static::$_options[ $args['id'] ][ $key ] ) ) {
56 $enabled = $option;
57 } else {
58 $enabled = null;
59 }
60 echo '<input name="' . static::$_prefix . 'settings[' . $args['id'] . '][' . $key . ']" id="' . static::$_prefix . 'settings_' . $args['id'] . '[' . $key . ']" type="checkbox" value="' . $option . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
61 echo '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '[' . $key . ']">' . $option . '</label><br/>';
62 endforeach;
63 echo '<p class="description">' . $args['desc'] . '</p>';
64 }
65 }
66
67 /**
68 * Radio Callback
69 *
70 * Renders radio boxes.
71 *
72 * @param array $args Arguments passed by the setting
73 */
74 public static function radio( $args ) {
75
76 foreach ( $args['options'] as $key => $option ) :
77 $checked = false;
78
79 if ( isset( static::$_options[ $args['id'] ] ) && static::$_options[ $args['id'] ] == $key ) {
80 $checked = true;
81 } elseif ( isset( $args['std'] ) && $args['std'] == $key && ! isset( static::$_options[ $args['id'] ] ) ) {
82 $checked = true;
83 }
84
85 echo '<input name="' . static::$_prefix . 'settings[' . $args['id'] . ']"" id="' . static::$_prefix . 'settings_' . $args['id'] . '[' . $key . ']" type="radio" value="' . $key . '" ' . checked( true, $checked, false ) . '/>&nbsp;';
86 echo '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '[' . $key . ']">' . $option . '</label><br/>';
87 endforeach;
88
89 echo '<p class="description">' . $args['desc'] . '</p>';
90 }
91
92 /**
93 * Text Callback
94 *
95 * Renders text fields.
96 *
97 * @param array $args Arguments passed by the setting
98 */
99 public static function text( $args ) {
100
101 if ( isset( static::$_options[ $args['id'] ] ) ) {
102 $value = static::$_options[ $args['id'] ];
103 } else {
104 $value = isset( $args['std'] ) ? $args['std'] : '';
105 }
106
107 $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
108 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
109 $html = '<input type="text" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
110 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
111
112 echo $html;
113 }
114
115 /**
116 * Number Callback
117 *
118 * Renders number fields.
119 *
120 * @param array $args Arguments passed by the setting
121 */
122 public static function number( $args ) {
123
124
125 if ( isset( static::$_options[ $args['id'] ] ) ) {
126 $value = static::$_options[ $args['id'] ];
127 } else {
128 $value = isset( $args['std'] ) ? $args['std'] : '';
129 }
130
131 $max = isset( $args['max'] ) ? $args['max'] : 999999;
132 $min = isset( $args['min'] ) ? $args['min'] : 0;
133 $step = isset( $args['step'] ) ? $args['step'] : 1;
134
135 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
136 $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
137 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
138
139 echo $html;
140 }
141
142 /**
143 * Textarea Callback
144 *
145 * Renders textarea fields.
146 *
147 * @param array $args Arguments passed by the setting
148 */
149 public static function textarea( $args ) {
150
151
152 if ( isset( static::$_options[ $args['id'] ] ) ) {
153 $value = static::$_options[ $args['id'] ];
154 } else {
155 $value = isset( $args['std'] ) ? $args['std'] : '';
156 }
157
158 $html = '<textarea class="large-text" cols="50" rows="5" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
159 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
160
161 echo $html;
162 }
163
164 /**
165 * Password Callback
166 *
167 * Renders password fields.
168 *
169 * @param array $args Arguments passed by the setting
170 */
171 public static function password( $args ) {
172
173
174 if ( isset( static::$_options[ $args['id'] ] ) ) {
175 $value = static::$_options[ $args['id'] ];
176 } else {
177 $value = isset( $args['std'] ) ? $args['std'] : '';
178 }
179
180 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
181 $html = '<input type="password" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
182 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
183
184 echo $html;
185 }
186
187 /**
188 * Missing Callback
189 *
190 * If a function is missing for settings callbacks alert the user.
191 *
192 * @param array $args Arguments passed by the setting
193 *
194 * @return void
195 */
196 public static function missing( $args ) {
197 printf( __( 'The callback function used for the <strong>%s</strong> setting is missing.', 'content-control' ), $args['id'] );
198 }
199
200 /**
201 * Select Callback
202 *
203 * Renders select fields.
204 *
205 * @param array $args Arguments passed by the setting
206 */
207 public static function select( $args ) {
208
209
210 if ( isset( static::$_options[ $args['id'] ] ) ) {
211 $value = static::$_options[ $args['id'] ];
212 } else {
213 $value = isset( $args['std'] ) ? $args['std'] : '';
214 }
215
216 if ( isset( $args['placeholder'] ) ) {
217 $placeholder = $args['placeholder'];
218 } else {
219 $placeholder = '';
220 }
221
222 if ( isset( $args['chosen'] ) ) {
223 $chosen = 'class="'. static::$_prefix . '-chosen"';
224 } else {
225 $chosen = '';
226 }
227
228 $html = '<select id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" ' . $chosen . 'data-placeholder="' . $placeholder . '" />';
229
230 foreach ( $args['options'] as $option => $name ) :
231 $selected = selected( $option, $value, false );
232 $html .= '<option value="' . $option . '" ' . $selected . '>' . $name . '</option>';
233 endforeach;
234
235 $html .= '</select>';
236 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
237
238 echo $html;
239 }
240
241 /**
242 * Dashicon Callback
243 *
244 * Renders select fields with dashicon preview.
245 *
246 * @param array $args Arguments passed by the setting
247 */
248 public static function dashicon( $args ) {
249
250
251 if ( isset( static::$_options[ $args['id'] ] ) ) {
252 $value = static::$_options[ $args['id'] ];
253 } else {
254 $value = isset( $args['std'] ) ? $args['std'] : '';
255 }
256
257 $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
258 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
259
260 $html = '<div class="dashicon-picker">';
261
262 $html .= '<input class="regular-text" type="hidden" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
263 $html .= '<span id="' . static::$_prefix . 'settings_' . $args['id'] . '_preview" class="dashicons-picker-preview dashicons ' . $value . '"></span>';
264
265 $html .= '<input type="button" data-target="#'. static::$_prefix . 'settings_' . $args['id'] . '" data-preview="#'. static::$_prefix . '_settings_' . $args['id'] . '_preview" class="button dashicons-picker" value="' . __( 'Choose Icon', 'content-control' ) . '" />';
266 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
267
268 $html .= '</div>';
269
270 echo $html;
271 }
272
273 /**
274 * Color select Callback
275 *
276 * Renders color select fields.
277 *
278 * @param array $args Arguments passed by the setting
279 */
280 public static function color_select( $args ) {
281
282
283 if ( isset( static::$_options[ $args['id'] ] ) ) {
284 $value = static::$_options[ $args['id'] ];
285 } else {
286 $value = isset( $args['std'] ) ? $args['std'] : '';
287 }
288 $html = '<select id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']"/>';
289
290 foreach ( $args['options'] as $option => $color ) :
291 $selected = selected( $option, $value, false );
292 $html .= '<option value="' . $option . '" ' . $selected . '>' . $color['label'] . '</option>';
293 endforeach;
294
295 $html .= '</select>';
296 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
297
298 echo $html;
299 }
300
301 /**
302 * Rich Editor Callback
303 *
304 * Renders rich editor fields.
305 *
306 * @param array $args Arguments passed by the setting
307 *
308 * @global $wp_version WordPress Version
309 */
310 public static function rich_editor( $args ) {
311 global $wp_version;
312
313 if ( isset( static::$_options[ $args['id'] ] ) ) {
314 $value = static::$_options[ $args['id'] ];
315
316 if ( empty( $args['allow_blank'] ) && empty( $value ) ) {
317 $value = isset( $args['std'] ) ? $args['std'] : '';
318 }
319 } else {
320 $value = isset( $args['std'] ) ? $args['std'] : '';
321 }
322
323 $rows = isset( $args['size'] ) ? $args['size'] : 20;
324
325 if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
326 ob_start();
327 wp_editor( stripslashes( $value ), static::$_prefix . 'settings_' . $args['id'], array(
328 'textarea_name' => static::$_prefix . 'settings[' . $args['id'] . ']',
329 'textarea_rows' => $rows,
330 ) );
331 $html = ob_get_clean();
332 } else {
333 $html = '<textarea class="large-text" rows="10" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
334 }
335
336 $html .= '<br/><label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
337
338 echo $html;
339 }
340
341 /**
342 * Upload Callback
343 *
344 * Renders upload fields.
345 *
346 * @param array $args Arguments passed by the setting
347 */
348 public static function upload( $args ) {
349
350
351 if ( isset( static::$_options[ $args['id'] ] ) ) {
352 $value = static::$_options[ $args['id'] ];
353 } else {
354 $value = isset( $args['std'] ) ? $args['std'] : '';
355 }
356
357 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
358 $html = '<input type="text" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
359 $html .= '<span>&nbsp;<input type="button" class="' . static::$_prefix . 'settings_upload_button button-secondary" value="' . __( 'Upload File', 'content-control' ) . '"/></span>';
360 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
361
362 echo $html;
363 }
364
365 /**
366 * Color picker Callback
367 *
368 * Renders color picker fields.
369 *
370 * @param array $args Arguments passed by the setting
371 */
372 public static function color( $args ) {
373
374
375 if ( isset( static::$_options[ $args['id'] ] ) ) {
376 $value = static::$_options[ $args['id'] ];
377 } else {
378 $value = isset( $args['std'] ) ? $args['std'] : '';
379 }
380
381 $default = isset( $args['std'] ) ? $args['std'] : '';
382
383 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
384 $html = '<input type="text" class="'. static::$_prefix . 'color-picker" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
385 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
386
387 echo $html;
388 }
389
390 /**
391 * Descriptive text callback.
392 *
393 * Renders descriptive text onto the settings field.
394 *
395 * @param array $args Arguments passed by the setting
396 *
397 * @return void
398 */
399 public static function descriptive_text( $args ) {
400 echo wp_kses_post( $args['desc'] );
401 }
402
403 /**
404 * Registers the license field callback for Software Licensing
405 *
406 * @param array $args Arguments passed by the setting
407 */
408 public static function license_key( $args ) {
409
410
411 if ( isset( static::$_options[ $args['id'] ] ) ) {
412 $value = static::$_options[ $args['id'] ];
413 } else {
414 $value = isset( $args['std'] ) ? $args['std'] : '';
415 }
416
417 $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
418 $html = '<input type="text" class="' . $size . '-text" id="' . static::$_prefix . 'settings_' . $args['id'] . '" name="' . static::$_prefix . 'settings[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"/>';
419
420 if ( 'valid' == get_option( $args['options']['is_valid_license_option'] ) ) {
421 $html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' . __( 'Deactivate License', 'content-control' ) . '"/>';
422 }
423 $html .= '<label class="field-description" for="' . static::$_prefix . 'settings_' . $args['id'] . '"> ' . $args['desc'] . '</label>';
424
425 wp_nonce_field( $args['id'] . '-nonce', $args['id'] . '-nonce' );
426
427 echo $html;
428 }
429
430 /**
431 * Hook Callback
432 *
433 * Adds a do_action() hook in place of the field
434 *
435 * @param array $args Arguments passed by the setting
436 *
437 * @return void
438 */
439 public static function hook( $args ) {
440 do_action( static::$_prefix . $args['id'], $args );
441 }
442
443 }
444