kompass/components/partials/text-element.php

41 lines
1.3 KiB
PHP
Raw Normal View History

2024-03-16 14:21:57 +01:00
<?php
2024-05-27 16:59:30 +02:00
function _kompass_print_textbox($settingName, $settingValue, $style = '', $appendix = '', $lines = 1, $data_type = 'text') {
if (1 === $lines) {
2024-06-01 11:16:07 +02:00
echo '<input required style="' . $style . '" type="' . $data_type . '" name="' . $settingName . '" value="' . $settingValue . '" />';
2024-05-27 16:59:30 +02:00
} else {
2024-06-01 11:16:07 +02:00
echo '<textarea required style="' . $style . '" name="' . $settingName . '" rows=' . $lines . '>' . $settingValue . '</textarea>';
2024-05-27 16:59:30 +02:00
}
if (null !== $appendix) {
echo '&nbsp;' . $appendix;
}
2024-03-16 14:21:57 +01:00
if (defined('WP_DEBUG') && WP_DEBUG == true) {
echo '<br />' . $settingName;
}
}
function kompass_print_textbox(array $args) {
if (!isset($args['setting'])) {
wp_die('Missing argument setting at text-element ' . print_r($args, true));
}
2024-03-16 14:21:57 +01:00
$setting = get_option($args['setting'], null);
$setting = $setting ?? ( $args['value'] ?? '' );
2024-05-27 16:59:30 +02:00
$appendix = $args['appendix'] ?? null;
$lines = $args['lines'] ?? 1;
$type = $args['type'] ?? 'text';
2024-05-27 16:59:30 +02:00
$style = isset($args['style']) ? $args['style'] : '';
2024-03-16 14:21:57 +01:00
$value = esc_attr($setting);
if (isset($args['unit_division'])) {
$value = (int)$value / (int)$args['unit_division'];
}
if ($value === null && isset($args['value'])) {
$value = $args['value'];
}
2024-05-27 16:59:30 +02:00
_kompass_print_textbox($args['setting'], $value, $style, $appendix, $lines, $type);
2024-03-16 14:21:57 +01:00
}