PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.53.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.53.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / class.admin.taxonomies.ui.php

class.admin.taxonomies.ui.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.53.0, at inc/class.admin.taxonomies.ui.php

888 lines 28.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Custom Taxonomy UI Admin UI
5 *
6
7 */
8 class taxopress_admin_ui
9 {
10 /**
11 * Return an opening `<fieldset>` tag.
12 *
13 * @param array $args Array of arguments.
14 * @return string $value Opening `<fieldset>` tag.
15 */
16 public function get_fieldset_start($args = [])
17 {
18 $fieldset = '<fieldset';
19
20 if (!empty($args['id'])) {
21 $fieldset .= ' id="' . esc_attr($args['id']) . '"';
22 }
23
24 if (!empty($args['classes'])) {
25 $classes = 'class="' . implode(' ', $args['classes']) . '"';
26 $fieldset .= ' ' . $classes;
27 }
28
29 if (!empty($args['aria-expanded'])) {
30 $fieldset .= ' aria-expanded="' . $args['aria-expanded'] . '"';
31 }
32
33 $fieldset .= ' tabindex="0">';
34
35 return $fieldset;
36 }
37
38 /**
39 * Return an closing `<fieldset>` tag.
40 *
41 * @return string $value Closing `<fieldset>` tag.
42 */
43 public function get_fieldset_end()
44 {
45 return '</fieldset>';
46 }
47
48 /**
49 * Return an opening `<legend>` tag.
50 *
51 * @return string
52 */
53 public function get_legend_start()
54 {
55 return '<legend class="screen-reader-text">';
56 }
57
58 /**
59 * Return a closing `</legend>` tag.
60 *
61 * @return string
62 */
63 public function get_legend_end()
64 {
65 return '</legend>';
66 }
67
68 /**
69 * Return string wrapped in a `<p>` tag.
70 *
71 * @param string $text Content to wrap in a `<p>` tag.
72 * @return string $value Content wrapped in a `<p>` tag.
73 */
74 public function get_p($text = '')
75 {
76 return '<p>' . $text . '</p>';
77 }
78
79 /**
80 * Return a populated `<select>` input.
81 *
82 * @param array $args Arguments to use with the `<select>` input.
83 * @return string $value Complete <select> input with options and selected attribute.
84 */
85 public function get_select_checkbox_input($args = [])
86 {
87 $defaults = $this->get_default_input_parameters(
88 [
89 'class' => '',
90 'selections' => []
91 ]
92 );
93
94
95 $args = wp_parse_args($args, $defaults);
96
97 $value = '';
98 if ($args['wrap']) {
99 $value = $this->get_tr_start();
100 $value .= $this->get_th_start();
101 $value .= $this->get_label($args['name'], $args['labeltext']);
102 if ($args['required']) {
103 $value .= $this->get_required_span();
104 }
105 if (!empty($args['helptext'])) {
106 $value .= $this->get_help($args['helptext']);
107 }
108 $value .= $this->get_th_end();
109 $value .= $this->get_td_start();
110 }
111
112 $checkbox_html = '<input class="' . $args['class'] . '" type="checkbox" id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" value="1" />';
113
114 if (!empty($args['selections']['options']) && is_array($args['selections']['options'])) {
115 foreach ($args['selections']['options'] as $val) {
116 $result = '';
117 $selected_result = false;
118 $bool = taxopress_disp_boolean($val['attr']);
119
120 if (is_numeric($args['selections']['selected'])) {
121 $selected = taxopress_disp_boolean($args['selections']['selected']);
122 } elseif (in_array($args['selections']['selected'], ['true', 'false'], true)) {
123 $selected = $args['selections']['selected'];
124 }
125
126
127 if (!empty($selected) && $selected === $bool) {
128 $result = ' selected="selected"';
129 $selected_result = true;
130 } else {
131 if (array_key_exists('default', $val) && !empty($val['default'])) {
132 if (empty($selected)) {
133 $result = ' selected="selected"';
134 $selected_result = true;
135 }
136 }
137 }
138
139 if (!is_numeric($args['selections']['selected']) && (!empty($args['selections']['selected']) && $args['selections']['selected'] === $val['attr'])) {
140 $result = ' selected="selected"';
141 $selected_result = true;
142 }
143
144 if ($selected_result) {
145 }
146
147 if ($selected_result && (int)$val['attr'] === 1) {
148 $checkbox_html = '<input class="' . $args['class'] . '" type="checkbox" id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" value="1" checked="checked" />';
149 }
150 }
151 }
152 $value .= $checkbox_html;
153
154 if (!empty($args['aftertext'])) {
155 $value .= ' ' . $args['aftertext'];
156 }
157
158 if ($args['wrap']) {
159 $value .= $this->get_td_end();
160 $value .= $this->get_tr_end();
161 }
162
163 return $value;
164 }
165
166 /**
167 * Return a populated `radio` input.
168 *
169 * @param array $args Arguments to use with the `radio` input.
170 * @return string $value Complete radio input with options and selected attribute.
171 */
172 public function get_radio_input($args = [])
173 {
174 $defaults = $this->get_default_input_parameters(
175 [
176 'class' => '',
177 'selections' => []
178 ]
179 );
180
181
182 $args = wp_parse_args($args, $defaults);
183
184 $value = '';
185 if ($args['wrap']) {
186 $value = $this->get_tr_start();
187 $value .= $this->get_th_start();
188 $value .= $this->get_label($args['name'], $args['labeltext']);
189 if ($args['required']) {
190 $value .= $this->get_required_span();
191 }
192 if (!empty($args['helptext'])) {
193 $value .= $this->get_help($args['helptext']);
194 }
195 $value .= $this->get_th_end();
196 $value .= $this->get_td_start();
197 }
198
199 $radio_html = '';
200
201 if (!empty($args['selections']['options']) && is_array($args['selections']['options'])) {
202 if (isset($args['selections']['selected']) && $args['selections']['selected'] !== '') {
203 $selected_option = $args['selections']['selected'];
204 } else {
205 $selected_option = '';
206 }
207 foreach ($args['selections']['options'] as $val) {
208 $checked = '';
209 if (($selected_option == '' && !empty($val['default']) && $val['default'] == 'true') || ($selected_option !== '' && $selected_option == $val['attr'])) {
210 $checked = 'checked="checked"';
211 }
212
213 $radio_html .= '<div class="taxopress-radio-input"><label> <input class="' . $args['class'] . '" type="radio" id="' . $args['name'] . '-' . $val['attr'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" value="' . $val['attr'] . '" ' . $checked . ' />' . $val['text'] . '</label></div>';
214 }
215 }
216 $value .= $radio_html;
217
218 if (!empty($args['aftertext'])) {
219 $value .= '<p class="taxopress-field-description description">' . $args['aftertext'] . '</p>';
220 }
221
222 if ($args['wrap']) {
223 $value .= $this->get_td_end();
224 $value .= $this->get_tr_end();
225 }
226
227 return $value;
228 }
229
230 /**
231 * Return a populated `<select>` input.
232 *
233 * @param array $args Arguments to use with the `<select>` input.
234 * @return string $value Complete <select> input with options and selected attribute.
235 */
236 public function get_select_checkbox_input_main($args = [])
237 {
238 $defaults = $this->get_default_input_parameters(
239 [
240 'class' => '',
241 'selections' => [],
242 'multiple' => false
243 ]
244 );
245
246 $args = wp_parse_args($args, $defaults);
247
248 $selectedresult = (isset($args['selections']) && isset($args['selections']['selected']) && !empty($args['selections']['selected'])) ? true : false;
249
250 $multiple_select = ($args['multiple'] === true) ? '[]' : '';
251 $multiple_text = ($args['multiple'] === true) ? 'multiple' : '';
252
253 $value = '';
254 if ($args['wrap']) {
255 $value = $this->get_tr_start();
256 $value .= $this->get_th_start();
257 $value .= $this->get_label($args['name'], $args['labeltext']);
258 if ($args['required']) {
259 $value .= $this->get_required_span();
260 }
261 if (!empty($args['helptext'])) {
262 $value .= $this->get_help($args['helptext']);
263 }
264 $value .= $this->get_th_end();
265 $value .= $this->get_td_start();
266 }
267
268 $value .= '<select class="' . $args['class'] . '" id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']' . $multiple_select . '" ' . $multiple_text . ' data-placeholder="' . sprintf(esc_html__('Select %1s...', 'simple-tags'), $args['labeltext']) . '">';
269 if (!empty($args['selections']['options']) && is_array($args['selections']['options'])) {
270 foreach ($args['selections']['options'] as $val) {
271 $result = '';
272 $bool = taxopress_disp_boolean($val['attr']);
273 $post_type_attr = isset($val['post_type']) ? 'data-post_type="' . $val['post_type'] . '"' : '';
274
275 if (is_numeric($args['selections']['selected'])) {
276 $selected = taxopress_disp_boolean($args['selections']['selected']);
277 } elseif (!is_array($args['selections']['selected']) && in_array($args['selections']['selected'], ['true', 'false'], true)) {
278 $selected = $args['selections']['selected'];
279 }
280
281 if (is_array($args['selections']['selected']) && in_array($val['attr'], $args['selections']['selected'])) {
282 $result = ' selected="selected"';
283 } elseif (!empty($selected) && $selected === $bool) {
284 $result = ' selected="selected"';
285 } else {
286 if (array_key_exists('default', $val) && !empty($val['default'])) {
287 if (empty($selected) && !$selectedresult) {
288 $result = ' selected="selected"';
289 }
290 }
291 }
292
293 if (!is_numeric($args['selections']['selected']) && (!empty($args['selections']['selected']) && $args['selections']['selected'] === $val['attr'])) {
294 $result = ' selected="selected"';
295 }
296
297 $value .= '<option ' . $post_type_attr . ' value="' . $val['attr'] . '"' . $result . '>' . $val['text'] . '</option>';
298 }
299 }
300 $value .= '</select>';
301
302 if (!empty($args['aftertext'])) {
303 $value .= ' ' . $this->get_description($args['aftertext']);
304 }
305
306 if ($args['wrap']) {
307 $value .= $this->get_td_end();
308 $value .= $this->get_tr_end();
309 }
310
311 return $value;
312 }
313
314 /**
315 * Return a populated `<select>` input.
316 *
317 * @param array $args Arguments to use with the `<select>` input.
318 * @return string $value Complete <select> input with options and selected attribute.
319 */
320 public function get_select_number_select($args = [])
321 {
322 $defaults = $this->get_default_input_parameters(
323 ['selections' => []]
324 );
325
326 $args = wp_parse_args($args, $defaults);
327
328 $value = '';
329 if ($args['wrap']) {
330 $value = $this->get_tr_start();
331 $value .= $this->get_th_start();
332 $value .= $this->get_label($args['name'], $args['labeltext']);
333 if ($args['required']) {
334 $value .= $this->get_required_span();
335 }
336 if (!empty($args['helptext'])) {
337 $value .= $this->get_help($args['helptext']);
338 }
339 $value .= $this->get_th_end();
340 $value .= $this->get_td_start();
341 }
342
343 $value .= '<select id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']">';
344 if (!empty($args['selections']['options']) && is_array($args['selections']['options'])) {
345 foreach ($args['selections']['options'] as $val) {
346 $result = '';
347 $bool = ($val['attr']);
348
349 if (is_numeric($args['selections']['selected'])) {
350 $selected = ($args['selections']['selected']);
351 } elseif (in_array($args['selections']['selected'], ['true', 'false'], true)) {
352 $selected = $args['selections']['selected'];
353 }
354
355 if (!empty($selected) && $selected === $bool) {
356 $result = ' selected="selected"';
357 } else {
358 if (array_key_exists('default', $val) && !empty($val['default'])) {
359 if (empty($selected)) {
360 $result = ' selected="selected"';
361 }
362 }
363 }
364
365 if (!is_numeric($args['selections']['selected']) && (!empty($args['selections']['selected']) && $args['selections']['selected'] === $val['attr'])) {
366 $result = ' selected="selected"';
367 }
368
369 $value .= '<option value="' . $val['attr'] . '"' . $result . '>' . $val['text'] . '</option>';
370 }
371 }
372 $value .= '</select>';
373
374 if (!empty($args['aftertext'])) {
375 $value .= ' ' . $this->get_description($args['aftertext']);
376 }
377
378 if ($args['wrap']) {
379 $value .= $this->get_td_end();
380 $value .= $this->get_tr_end();
381 }
382
383 return $value;
384 }
385
386 /**
387 * Return some array_merged default arguments for all input types.
388 *
389 * @param array $additions Arguments array to merge with our defaults.
390 * @return array $value Merged arrays for our default parameters.
391 */
392 public function get_default_input_parameters($additions = [])
393 {
394 return array_merge(
395 [
396 'namearray' => '',
397 'name' => '',
398 'textvalue' => '',
399 'labeltext' => '',
400 'aftertext' => '',
401 'helptext' => '',
402 'helptext_after' => false,
403 'required' => false,
404 'wrap' => true,
405 'placeholder' => true,
406 ],
407 (array)$additions
408 );
409 }
410
411 /**
412 * Return an opening `<tr>` tag.
413 *
414 * @return string $value Opening `<tr>` tag with attributes.
415 */
416 public function get_tr_start()
417 {
418 return '<tr valign="top">';
419 }
420
421 /**
422 * Return an opening `<th>` tag.
423 *
424 * @return string $value Opening `<th>` tag with attributes.
425 */
426 public function get_th_start()
427 {
428 return '<th scope="row">';
429 }
430
431 /**
432 * Return a form <label> with for attribute.
433 *
434 * @param string $label_for Form input to associate `<label>` with.
435 * @param string $label_text Text to display in the `<label>` tag.
436 * @return string $value `<label>` tag with filled out parts.
437 */
438 public function get_label($label_for = '', $label_text = '', $labeldescription = false)
439 {
440 if ($labeldescription === 2) {
441 return '<label for="' . esc_attr($label_for) . '"><code>' . htmlentities('[' . $label_text . ']') . '</code></label>';
442 } elseif ($labeldescription === 3) {
443 return '<label for="' . esc_attr($label_for) . '"><code>' . htmlentities($label_text) . '</code></label>';
444 } elseif ($labeldescription) {
445 return '<label for="' . esc_attr($label_for) . '"><code>' . htmlentities('<' . $label_text . '> </' . $label_text . '>') . '</code></label>';
446 } else {
447 return '<label for="' . esc_attr($label_for) . '">' . wp_strip_all_tags($label_text) . '</label>';
448 }
449 }
450
451 /**
452 * Return a `<span>` to indicate required status, with class attribute.
453 *
454 * @return string Span tag.
455 */
456 public function get_required_span()
457 {
458 return ' <span class="required">*</span>';
459 }
460
461 /**
462 * Return an `<a>` tag with title attribute holding help text.
463 *
464 * @param string $help_text Text to use in the title attribute.
465 * @return string <a> tag with filled out parts.
466 */
467 public function get_help($help_text = '')
468 {
469 return '<span class="taxopress-help-tooltip dashicons-before dashicons-editor-help"><span class="tooltip-text">' . esc_html($help_text) . '</span></span>';
470 }
471
472 /**
473 * Return a closing `</th>` tag.
474 *
475 * @return string $value Closing `</th>` tag.
476 */
477 public function get_th_end()
478 {
479 return '</th>';
480 }
481
482 /**
483 * Return an opening `<td>` tag.
484 *
485 * @return string $value Opening `<td>` tag.
486 */
487 public function get_td_start()
488 {
489 return '<td>';
490 }
491
492 /**
493 * Return a `<span>` tag with the help text.
494 *
495 * @param string $help_text Text to display after the input.
496 * @return string
497 */
498 public function get_description($help_text = '')
499 {
500 return '<p class="taxopress-field-description description">' . $help_text . '</p>';
501 }
502
503 /**
504 * Return a closing `</td>` tag.
505 *
506 * @return string $value Closing `</td>` tag.
507 */
508 public function get_td_end()
509 {
510 return '</td>';
511 }
512
513 /**
514 * Return a closing `</tr>` tag.
515 *
516 * @return string $value Closing `</tr>` tag.
517 */
518 public function get_tr_end()
519 {
520 return '</tr>';
521 }
522
523 /**
524 * Return a text input.
525 *
526 * @param array $args Arguments to use with the text input.
527 * @return string Complete text `<input>` with proper attributes.
528 */
529 public function get_text_input($args = [])
530 {
531 $defaults = $this->get_default_input_parameters(
532 [
533 'maxlength' => '',
534 'onblur' => '',
535 'class' => '',
536 ]
537 );
538 $args = wp_parse_args($args, $defaults);
539
540 $value = '';
541 if ($args['wrap']) {
542 $value .= $this->get_tr_start();
543 $value .= $this->get_th_start();
544 $value .= $this->get_label($args['name'], $args['labeltext']);
545 if ($args['required']) {
546 $value .= $this->get_required_span();
547 }
548 $value .= $this->get_th_end();
549 $value .= $this->get_td_start();
550 }
551
552 if (isset($args['toplabel'])) {
553 $value .= $this->get_label($args['name'], $args['toplabel']) . '<br />';
554 }
555
556 $value .= '<input type="text" id="' . $args['name'] . '" class="' . $args['class'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" value="' . $args['textvalue'] . '"';
557
558 if ($args['maxlength']) {
559 $value .= ' ' . $this->get_maxlength($args['maxlength']);
560 }
561
562 if ($args['onblur']) {
563 $value .= ' ' . $this->get_onblur($args['onblur']);
564 }
565
566 $value .= ' ' . $this->get_aria_required($args['required']);
567
568 $value .= ' ' . $this->get_required_attribute($args['required']);
569
570 if (!empty($args['aftertext'])) {
571 if ($args['placeholder']) {
572 $value .= ' ' . $this->get_placeholder($args['aftertext']);
573 }
574 }
575
576 if (!empty($args['data'])) {
577 foreach ($args['data'] as $dkey => $dvalue) {
578 $value .= " data-{$dkey}=\"{$dvalue}\"";
579 }
580 }
581
582 $value .= ' />';
583
584 if (!empty($args['aftertext'])) {
585 $value .= $this->get_hidden_text($args['aftertext']);
586 }
587
588 if ($args['helptext']) {
589 $value .= '<br/>' . $this->get_description($args['helptext']);
590 }
591
592 if ($args['wrap']) {
593 $value .= $this->get_td_end();
594 $value .= $this->get_tr_end();
595 }
596
597 return $value;
598 }
599
600 /**
601 * Return a number input.
602 *
603 * @param array $args Arguments to use with the text input.
604 * @return string Complete text `<input>` with proper attributes.
605 */
606 public function get_number_input($args = [])
607 {
608 $defaults = $this->get_default_input_parameters(
609 [
610 'maxlength' => '',
611 'onblur' => '',
612 'min' => '1',
613 'max' => '1000000000',
614 'other_attr' => '',
615 'class' => '',
616 ]
617 );
618 $args = wp_parse_args($args, $defaults);
619
620 $value = '';
621 if ($args['wrap']) {
622 $value .= $this->get_tr_start();
623 $value .= $this->get_th_start();
624 $value .= $this->get_label($args['name'], $args['labeltext']);
625 if ($args['required']) {
626 $value .= $this->get_required_span();
627 }
628 $value .= $this->get_th_end();
629 $value .= $this->get_td_start();
630 }
631
632 if (isset($args['toplabel'])) {
633 $value .= $this->get_label($args['name'], $args['toplabel']) . '<br />';
634 }
635
636 $value .= '<input min="' . $args['min'] . '" max="' . $args['max'] . '" type="number" id="' . $args['name'] . '" class="' . $args['class'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" value="' . $args['textvalue'] . '" ' . $args['other_attr'] . '';
637
638 if ($args['maxlength']) {
639 $value .= ' ' . $this->get_maxlength($args['maxlength']);
640 }
641
642 if ($args['onblur']) {
643 $value .= ' ' . $this->get_onblur($args['onblur']);
644 }
645
646 $value .= ' ' . $this->get_aria_required($args['required']);
647
648 $value .= ' ' . $this->get_required_attribute($args['required']);
649
650 if (!empty($args['aftertext'])) {
651 if ($args['placeholder']) {
652 $value .= ' ' . $this->get_placeholder($args['aftertext']);
653 }
654 }
655
656 if (!empty($args['data'])) {
657 foreach ($args['data'] as $dkey => $dvalue) {
658 $value .= " data-{$dkey}=\"{$dvalue}\"";
659 }
660 }
661
662 $value .= ' />';
663
664 if (!empty($args['aftertext'])) {
665 $value .= $this->get_hidden_text($args['aftertext']);
666 }
667
668 if ($args['helptext']) {
669 $value .= '<br/>' . $this->get_description($args['helptext']);
670 }
671
672 if ($args['wrap']) {
673 $value .= $this->get_td_end();
674 $value .= $this->get_tr_end();
675 }
676
677 return $value;
678 }
679
680 /**
681 * Return a maxlength HTML attribute with a specified length.
682 *
683 * @param string $length How many characters the max length should be set to.
684 * @return string $value Maxlength HTML attribute.
685 */
686 public function get_maxlength($length = '')
687 {
688 return 'maxlength="' . esc_attr($length) . '"';
689 }
690
691 /**
692 * Return a onblur HTML attribute for a specified value.
693 *
694 * @param string $text Text to place in the onblur attribute.
695 * @return string $value Onblur HTML attribute.
696 */
697 public function get_onblur($text = '')
698 {
699 return 'onblur="' . esc_attr($text) . '"';
700 }
701
702 /**
703 * Return an aria-required attribute set to true.
704 *
705 * @param bool $required Whether or not the field is required.
706 * @return string Aria required attribute
707 */
708 public function get_aria_required($required = false)
709 {
710 $attr = $required ? 'true' : 'false';
711
712 return 'aria-required="' . $attr . '"';
713 }
714
715 /**
716 * Return an html attribute denoting a required field.
717 *
718 * @param bool $required Whether or not the field is required.
719 * @return string `Required` attribute.
720 */
721 public function get_required_attribute($required = false)
722 {
723 $attr = '';
724 if ($required) {
725 $attr .= 'required="true"';
726 }
727
728 return $attr;
729 }
730
731 /**
732 * Return a placeholder HTML attribtue for a specified value.
733 *
734 * @param string $text Text to place in the placeholder attribute.
735 * @return string $value Placeholder HTML attribute.
736 */
737 public function get_placeholder($text = '')
738 {
739 return 'placeholder="' . esc_attr($text) . '"';
740 }
741
742 /**
743 * Return a span that will only be visible for screenreaders.
744 *
745 * @param string $text Text to visually hide.
746 * @return string $value Visually hidden text meant for screen readers.
747 */
748 public function get_hidden_text($text = '')
749 {
750 return '<span class="visuallyhidden">' . $text . '</span>';
751 }
752
753 /**
754 * Return a `<textarea>` input.
755 *
756 * @param array $args Arguments to use with the textarea input.
757 * @return string $value Complete <textarea> input with proper attributes.
758 */
759 public function get_textarea_input($args = [])
760 {
761 $defaults = $this->get_default_input_parameters(
762 [
763 'rows' => '',
764 'cols' => '',
765 'class' => '',
766 ]
767 );
768 $args = wp_parse_args($args, $defaults);
769
770 $value = '';
771
772 if ($args['wrap']) {
773 $value .= $this->get_tr_start();
774 $value .= $this->get_th_start();
775 $value .= $this->get_label($args['name'], $args['labeltext']);
776 if ($args['required']) {
777 $value .= $this->get_required_span();
778 }
779 $value .= $this->get_th_end();
780 $value .= $this->get_td_start();
781 }
782
783 $value .= '<textarea id="' . $args['name'] . '" name="' . $args['namearray'] . '[' . $args['name'] . ']" class="' . $args['class'] . '" rows="' . $args['rows'] . '" cols="' . $args['cols'] . '">' . $args['textvalue'] . '</textarea>';
784
785 if (!empty($args['aftertext'])) {
786 $value .= $args['aftertext'];
787 }
788
789 if ($args['helptext']) {
790 $value .= '<br/>' . $this->get_description($args['helptext']);
791 }
792
793 if ($args['wrap']) {
794 $value .= $this->get_td_end();
795 $value .= $this->get_tr_end();
796 }
797
798 return $value;
799 }
800
801 /**
802 * Return a checkbox `<input>`.
803 *
804 * @param array $args Arguments to use with the checkbox input.
805 * @return string $value Complete checkbox `<input>` with proper attributes.
806 */
807 public function get_check_input($args = [])
808 {
809 $defaults = $this->get_default_input_parameters(
810 [
811 'checkvalue' => '',
812 'checked' => 'true',
813 'checklisttext' => '',
814 'labeldescription' => false,
815 'default' => false,
816 'add_delete' => false,
817 ]
818 );
819 $args = wp_parse_args($args, $defaults);
820
821 $value = '';
822 if ($args['wrap']) {
823 $value .= $this->get_tr_start();
824 $value .= $this->get_th_start();
825 $value .= $args['checklisttext'];
826 if ($args['required']) {
827 $value .= $this->get_required_span();
828 }
829 $value .= $this->get_th_end();
830 $value .= $this->get_td_start();
831 }
832
833 if (isset($args['checked']) && 'false' === $args['checked']) {
834 $value .= '<input type="checkbox" id="' . $args['name'] . '" name="' . $args['namearray'] . '[]" value="' . $args['checkvalue'] . '" />';
835 } else {
836 $value .= '<input type="checkbox" id="' . $args['name'] . '" name="' . $args['namearray'] . '[]" value="' . $args['checkvalue'] . '" checked="checked" />';
837 }
838 $value .= $this->get_label($args['name'], $args['labeltext'], $args['labeldescription']);
839
840 if ($args['add_delete']) {
841 $value .= '<span class="delete">' . esc_html__('Delete', 'simple-tags') . '</span>';
842 }
843
844 $value .= '<br/>';
845
846 if ($args['wrap']) {
847 $value .= $this->get_td_end();
848 $value .= $this->get_tr_end();
849 }
850
851 return $value;
852 }
853
854 /**
855 * Return a button `<input>`.
856 *
857 * @param array $args Arguments to use with the button input.
858 * @return string Complete button `<input>`.
859 */
860 public function get_button($args = [])
861 {
862 $value = '';
863 $value .= '<input id="' . $args['id'] . '" class="button" type="button" value="' . $args['textvalue'] . '" />';
864
865 return $value;
866 }
867
868 /**
869 * Returns an HTML block for previewing the menu icon.
870 *
871 * @param string $menu_icon URL or a name of the dashicons class.
872 *
873 * @return string $value HTML block with a layout of the menu icon preview.
874 */
875 public function get_menu_icon_preview($menu_icon = '')
876 {
877 $content = '';
878 if (!empty($menu_icon)) {
879 $content = '<img src="' . $menu_icon . '">';
880 if (0 === strpos($menu_icon, 'dashicons-')) {
881 $content = '<div class="dashicons-before ' . $menu_icon . '"></div>';
882 }
883 }
884
885 return '<div id="menu_icon_preview">' . $content . '</div>';
886 }
887 }
888