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

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