PluginProbe
WANotifier for Forms and Actions / 0.1.0
WANotifier for Forms and Actions v0.1.0
3.1.1 3.1.0 3.0.4 2.7.10 2.7.11 2.7.12 2.7.13 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 3.0.0 3.0.1 3.0.2 3.0.3 trunk 0.1.0 0.1.1 1.0.0 1.0.1 1.0.2 All 67 releases
notifier / includes / functions / functions-notifier-meta-box-fields.php

functions-notifier-meta-box-fields.php in WANotifier for Forms and Actions 0.1.0, at includes/functions/functions-notifier-meta-box-fields.php

519 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Notifier Meta Box Functions
4 *
5 * @package Notifier
6 */
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly
9 }
10
11 /**
12 * Output a text input box.
13 *
14 * @param array $field
15 */
16 function notifier_wp_text_input( $field ) {
17 global $post;
18
19 $field = apply_filters ('notifier_wp_text_input_args', $field, $post);
20
21 $field = wp_parse_args(
22 $field, array(
23 'label' => '',
24 'placeholder' => '',
25 'class' => '',
26 'style' => '',
27 'wrapper_class' => '',
28 'value' => '',
29 'name' => $field['id'],
30 'description' => '',
31 'type' => 'text',
32 'limit' => 0,
33 'conditional_logic' => '',
34 'show_wrapper' => true,
35 'custom_attributes' => array(),
36 'data_type' => '',
37 'required' => ''
38 )
39 );
40
41 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
42
43 switch ( $field['data_type'] ) {
44 case 'url':
45 $field['class'] .= ' notifier_input_url';
46 $field['value'] = esc_url( $field['value'] );
47 break;
48
49 default:
50 break;
51 }
52
53 $show_limit_text = '';
54 if (0 != $field['limit']) {
55 $show_limit_text = '<span class="limit-text"><span class="limit-used">0</span> / <span>' . $field['limit'] . '</span></span>';
56 $field['custom_attributes']['data-limit'] = $field['limit'];
57 $field['class'] = $field['class'] . ' force-text-limit';
58 }
59
60 // Custom attribute handling
61 $custom_attributes = array();
62
63 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
64 foreach ( $field['custom_attributes'] as $attribute => $value ) {
65 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
66 }
67 }
68
69 if ( '' != $field['required'] ) {
70 $custom_attributes[] = 'required="required"';
71 }
72
73 $custom_attributes_string = implode( ' ', $custom_attributes );
74
75 if ($field['show_wrapper']) {
76 do_action('notifier_before_meta_field_wrapper', $field, $post);
77 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
78 }
79
80 if ( '' != $field['label'] ) {
81 echo '<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] . $show_limit_text ) . '</label>';
82 }
83
84 do_action('notifier_before_meta_field', $field, $post);
85
86 echo '<input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . esc_attr( $custom_attributes_string ) . ' /> ';
87
88 do_action('notifier_after_meta_field', $field, $post);
89
90 if ( '' != $field['description'] ) {
91 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
92 }
93
94 do_action('notifier_after_meta_field_description', $field, $post);
95
96 if ($field['show_wrapper']) {
97 echo '</p>';
98 do_action('notifier_after_meta_field_wrapper', $field, $post);
99 }
100 }
101
102 /**
103 * Output a hidden input box.
104 *
105 * @param array $field
106 */
107 function notifier_wp_hidden_input( $field ) {
108 global $post;
109
110 $field = apply_filters ('notifier_wp_hidden_input', $field, $post);
111
112 $field = wp_parse_args(
113 $field, array(
114 'class' => '',
115 'value' => ''
116 )
117 );
118
119 do_action('notifier_before_meta_field', $field, $post);
120
121 echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
122
123 do_action('notifier_after_meta_field', $field, $post);
124 }
125
126 /**
127 * Output a textarea input box.
128 *
129 * @param array $field
130 */
131 function notifier_wp_textarea_input( $field ) {
132 global $post;
133
134 $field = apply_filters ('notifier_wp_textarea_input', $field, $post);
135
136 $field = wp_parse_args(
137 $field, array(
138 'label' => '',
139 'placeholder' => '',
140 'class' => '',
141 'style' => '',
142 'wrapper_class' => '',
143 'value' => '',
144 'name' => $field['id'],
145 'description' => '',
146 'limit' => 0,
147 'conditional_logic' => '',
148 'show_wrapper' => true,
149 'custom_attributes' => array(),
150 'rows' => 2,
151 'cols' => 20,
152 'required' => ''
153 )
154 );
155
156 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
157
158 $show_limit_text = '';
159 if ($field['limit'] != 0) {
160 $show_limit_text = '<span class="limit-text"><span class="limit-used">0</span> / <span>' . $field['limit'] . '</span></span>';
161 $field['custom_attributes']['data-limit'] = $field['limit'];
162 $field['class'] = $field['class'] . ' force-text-limit';
163 }
164
165 // Custom attribute handling
166 $custom_attributes = array();
167
168 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
169 foreach ( $field['custom_attributes'] as $attribute => $value ) {
170 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
171 }
172 }
173
174 if ( '' != $field['required'] ) {
175 $custom_attributes[] = 'required="required"';
176 }
177
178 $custom_attributes_string = implode( ' ', $custom_attributes );
179
180 if ($field['show_wrapper']) {
181 do_action('notifier_before_meta_field_wrapper', $field, $post);
182 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
183 }
184
185 if ( '' != $field['label'] ) {
186 echo '<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] . $show_limit_text ) . '</label>';
187 }
188
189 do_action('notifier_before_meta_field', $field, $post);
190
191 echo '<textarea class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="' . esc_attr( $field['rows'] ) . '" cols="' . esc_attr( $field['cols'] ) . '" ' . esc_attr( $custom_attributes_string ) . ' >' . esc_textarea( $field['value'] ) . '</textarea> ';
192
193 do_action('notifier_after_meta_field', $field, $post);
194
195 if ( '' != $field['description'] ) {
196 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
197 }
198
199 do_action('notifier_after_meta_field_description', $field, $post);
200
201 if ($field['show_wrapper']) {
202 echo '</p>';
203 do_action('notifier_after_meta_field_wrapper', $field, $post);
204 }
205 }
206
207 /**
208 * Output a checkbox input box.
209 *
210 * @param array $field
211 */
212 function notifier_wp_checkbox( $field ) {
213 global $post;
214
215 $field = apply_filters ('notifier_wp_checkbox', $field, $post);
216
217 $field = wp_parse_args(
218 $field, array(
219 'label' => '',
220 'class' => '',
221 'style' => '',
222 'wrapper_class' => '',
223 'value' => '',
224 'cbvalue' => 'yes',
225 'name' => $field['id'],
226 'description' => '',
227 'conditional_logic' => '',
228 'show_wrapper' => true,
229 'custom_attributes' => array(),
230 'required' => ''
231 )
232 );
233
234 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
235
236 // Custom attribute handling
237 $custom_attributes = array();
238
239 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
240 foreach ( $field['custom_attributes'] as $attribute => $value ) {
241 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
242 }
243 }
244
245 $custom_attributes_string = implode( ' ', $custom_attributes );
246
247 if ($field['show_wrapper']) {
248 do_action('notifier_before_meta_field_wrapper', $field, $post);
249 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
250 }
251
252 if ( '' != $field['label'] ) {
253 echo '<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
254 }
255
256 do_action('notifier_before_meta_field', $field, $post);
257
258 echo '<input type="checkbox" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . esc_attr( $custom_attributes_string ) . '/> ';
259
260 do_action('notifier_after_meta_field', $field, $post);
261
262 if ( '' != $field['description'] ) {
263 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
264 }
265
266 do_action('notifier_after_meta_field_description', $field, $post);
267
268 if ($field['show_wrapper']) {
269 echo '</p>';
270 do_action('notifier_after_meta_field_wrapper', $field, $post);
271 }
272 }
273
274 /**
275 * Output a select input box.
276 *
277 * @param array $field Data about the field to render.
278 */
279 function notifier_wp_select( $field ) {
280 global $post;
281
282 $field = apply_filters ('notifier_wp_select', $field, $post);
283
284 $field = wp_parse_args(
285 $field, array(
286 'label' => '',
287 'class' => '',
288 'style' => '',
289 'wrapper_class' => '',
290 'value' => '',
291 'name' => $field['id'],
292 'description' => '',
293 'conditional_logic' => '',
294 'show_wrapper' => true,
295 'custom_attributes' => array()
296 )
297 );
298
299 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
300
301 // Custom attribute handling
302 $custom_attributes = array();
303
304 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
305 foreach ( $field['custom_attributes'] as $attribute => $value ) {
306 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
307 }
308 }
309
310 $custom_attributes_string = implode( ' ', $custom_attributes );
311
312 $description = ! empty( $field['description'] ) ? $field['description'] : '';
313
314 if ($field['show_wrapper']) {
315 do_action('notifier_before_meta_field_wrapper', $field, $post);
316 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
317 }
318
319 if ( '' != $field['label'] ) {
320 echo '<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
321 }
322
323 do_action('notifier_before_meta_field', $field, $post);
324
325 echo '<select class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '"' . esc_attr( $custom_attributes_string ) . '/> ';
326
327 foreach ( $field['options'] as $key => $value ) {
328 if (is_array($value)) {
329 $opt_group_options = $value;
330 echo '<optgroup label="' . esc_attr($key) . '">';
331 foreach ($opt_group_options as $opt_key => $opt_val) {
332 echo '<option value="' . esc_attr( $opt_key ) . '"' . selected( $opt_key, $field['value'], false) . '>' . esc_html( $opt_val ) . '</option>';
333 }
334 echo '</optgroup>';
335 } else {
336 echo '<option value="' . esc_attr( $key ) . '"' . selected( $key, $field['value'], false) . '>' . esc_html( $value ) . '</option>';
337 }
338 }
339
340 echo '</select>';
341
342 do_action('notifier_after_meta_field', $field, $post);
343
344 if ( '' != $field['description'] ) {
345 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
346 }
347
348 do_action('notifier_after_meta_field_description', $field, $post);
349
350 if ($field['show_wrapper']) {
351 echo '</p>';
352 do_action('notifier_after_meta_field_wrapper', $field, $post);
353 }
354 }
355
356 /**
357 * Output a radio input box.
358 *
359 * @param array $field
360 */
361 function notifier_wp_radio( $field ) {
362 global $post;
363
364 $field = apply_filters ('notifier_wp_radio', $field, $post);
365
366 $field = wp_parse_args(
367 $field, array(
368 'label' => '',
369 'class' => '',
370 'style' => '',
371 'wrapper_class' => '',
372 'value' => '',
373 'name' => $field['id'],
374 'description' => '',
375 'conditional_logic' => '',
376 'show_wrapper' => true,
377 'custom_attributes' => array()
378 )
379 );
380
381 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
382
383 // Custom attribute handling
384 $custom_attributes = array();
385
386 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
387 foreach ( $field['custom_attributes'] as $attribute => $value ) {
388 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
389 }
390 }
391
392 $custom_attributes_string = implode( ' ', $custom_attributes );
393
394 if ($field['show_wrapper']) {
395 do_action('notifier_before_meta_field_wrapper', $field, $post);
396 echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js($field['conditional_logic']) . '">';
397 }
398
399 if ( '' != $field['label'] ) {
400 echo '<legend>' . wp_kses_post( $field['label'] ) . '</legend>';
401 }
402
403 do_action('notifier_before_meta_field', $field, $post);
404
405 echo '<ul class="radio-buttons">';
406
407 foreach ( $field['options'] as $key => $value ) {
408 echo '<li><label><input
409 name="' . esc_attr( $field['name'] ) . '"
410 value="' . esc_attr( $key ) . '"
411 type="radio"
412 class="' . esc_attr( $field['class'] ) . '"
413 style="' . esc_attr( $field['style'] ) . '"
414 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
415 ' . esc_attr( $custom_attributes_string ) . '
416 /> ' . esc_html( $value ) . '</label>
417 </li>';
418 }
419 echo '</ul>';
420
421 do_action('notifier_after_meta_field', $field, $post);
422
423 if ( '' != $field['description'] ) {
424 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
425 }
426
427 do_action('notifier_after_meta_field_description', $field, $post);
428
429 if ($field['show_wrapper']) {
430 echo '</fieldset>';
431 do_action('notifier_after_meta_field_wrapper', $field, $post);
432 }
433
434 }
435
436 /**
437 * Output a file upload input box.
438 *
439 * @param array $field
440 */
441 function notifier_wp_file_input( $field ) {
442 global $post;
443
444 $field = apply_filters ('notifier_wp_text_input_args', $field, $post);
445
446 $field = wp_parse_args(
447 $field, array(
448 'label' => '',
449 'placeholder' => '',
450 'class' => '',
451 'wrapper_class' => '',
452 'value' => '',
453 'name' => $field['id'],
454 'description' => '',
455 'conditional_logic' => '',
456 'show_wrapper' => true,
457 'custom_attributes' => array(),
458 'uploader_title' => 'Upload media',
459 'uploader_button_text' => 'Select',
460 'uploader_supported_file_types' => array()
461 )
462 );
463
464 $field['conditional_logic'] = ('' != $field['conditional_logic']) ? json_encode($field['conditional_logic']) : '';
465
466 // Custom attribute handling
467 $custom_attributes = array();
468
469 if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) {
470 foreach ( $field['custom_attributes'] as $attribute => $value ) {
471 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
472 }
473 }
474
475 $custom_attributes_string = implode( ' ', $custom_attributes );
476
477 if ($field['show_wrapper']) {
478 do_action('notifier_before_meta_field_wrapper', $field, $post);
479 echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '" data-conditions="' . esc_js( $field['conditional_logic'] ) . '">';
480 }
481
482 if ( '' != $field['label'] ) {
483 echo '<label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>';
484 }
485
486 do_action('notifier_before_meta_field', $field, $post);
487
488 $image_thumb = '';
489 if ( '' != $field['value'] ) {
490 $image_thumb = wp_get_attachment_thumb_url( $field['value'] );
491 }
492
493 echo '<span class="notifier-media-preview">';
494 if ('' == $image_thumb) {
495 echo '<img id="' . esc_attr( $field['id'] ) . '_preview_image" src="' . esc_url($image_thumb) . '" /><br/>';
496 echo '<video id="' . esc_attr( $field['id'] ) . '_preview_video"><source src="' . esc_url($image_thumb) . '"></video><br/>';
497 }
498 echo '</span>';
499
500 echo '<input id="' . esc_attr( $field['id'] ) . '_button" type="button" data-uploader_title="' . esc_attr($field['uploader_title']) . '" data-uploader_button_text="' . esc_attr($field['uploader_button_text']) . '" data-uploader_supported_file_types="' . esc_attr(implode(',', $field['uploader_supported_file_types'])) . '" class="notifier-media-upload-button button" value="Upload" /> ';
501
502 echo '<input id="' . esc_attr( $field['id'] ) . '_delete" type="button" class="notifier-media-delete-button button" value="Remove" />';
503
504 echo '<input class="notifier-media-attachment-id ' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" type="hidden" /><br/>';
505
506 do_action('notifier_after_meta_field', $field, $post);
507
508 if ( '' != $field['description'] ) {
509 echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
510 }
511
512 do_action('notifier_after_meta_field_description', $field, $post);
513
514 if ($field['show_wrapper']) {
515 echo '</p>';
516 do_action('notifier_after_meta_field_wrapper', $field, $post);
517 }
518 }
519