PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.43.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.43.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.43.0, at inc/class.admin.taxonomies.ui.php

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