'; foreach ($fields as $field) { self::field($widget, $field, $instance[(string) ($field['id'] ?? '')] ?? ($field['default'] ?? ''), ''); } echo ''; } private static function field(SchemaWidget $widget, array $field, $value, string $parent): void { $type = (string) ($field['type'] ?? 'text'); $id = (string) ($field['id'] ?? ''); if (in_array($type, ['content', 'subheading', 'submessage'], true)) { self::display_field($field, $type); return; } if ($id === '') { return; } $key = $parent === '' ? $id : $parent . '[' . $id . ']'; $field_id = $widget->get_field_id(str_replace(['[', ']'], ['-', ''], $key)); $field_name = $widget->get_field_name($key); $dependency = !empty($field['dependency']) ? wp_json_encode($field['dependency']) : ''; echo '
'; if (!empty($field['label'])) { echo ''; } if (!empty($field['description'])) { echo '

' . wp_kses_post((string) $field['description']) . '

'; } switch ($type) { case 'switcher': self::switcher($field_id, $field_name, (bool) $value); break; case 'radio': case 'button_set': case 'palette': self::radios($field_id, $field_name, (array) ($field['options'] ?? []), (string) $value, $type); break; case 'select': self::select($field_id, $field_name, $field, $value); break; case 'checkbox': self::checkboxes($field_id, $field_name, $field, $value); break; case 'number': case 'spinner': case 'slider': self::number($field_id, $field_name, $field, $value, $type); break; case 'textarea': echo ''; break; case 'upload': self::upload($field_id, $field_name, (string) $value); break; case 'color': echo ''; break; case 'icon': echo '
'; break; case 'link': self::link($widget, $key, is_array($value) ? $value : []); break; case 'spacing': self::spacing($widget, $key, is_array($value) ? $value : []); break; case 'background': self::background($widget, $key, is_array($value) ? $value : []); break; case 'group': self::group($widget, $field, is_array($value) ? $value : [], $key); break; case 'fieldset': case 'accordion': self::nested($widget, $field, is_array($value) ? $value : [], $key); break; case 'text': default: echo ''; } echo '
'; } private static function display_field(array $field, string $type): void { $content = (string) ($field['content'] ?? $field['label'] ?? ''); echo '
' . wp_kses_post($content) . '
'; } private static function switcher(string $id, string $name, bool $value): void { echo ''; echo ''; } private static function radios(string $id, string $name, array $options, string $value, string $type): void { echo '
'; foreach ($options as $key => $label) { $option_id = $id . '-' . sanitize_html_class((string) $key); echo ''; } echo '
'; } private static function select(string $id, string $name, array $field, $value): void { $multiple = !empty($field['multiple']); echo ''; } private static function checkboxes(string $id, string $name, array $field, $value): void { $options = (array) ($field['options'] ?? []); if (!$options) { self::switcher($id, $name, (bool) $value); return; } $values = array_map('strval', (array) $value); foreach ($options as $key => $label) { echo ' '; } } private static function number(string $id, string $name, array $field, $value, string $type): void { $min = isset($field['min']) ? ' min="' . esc_attr((string) $field['min']) . '"' : ''; $max = isset($field['max']) ? ' max="' . esc_attr((string) $field['max']) . '"' : ''; $step = ' step="' . esc_attr((string) ($field['step'] ?? 1)) . '"'; $input_type = $type === 'slider' ? 'range' : 'number'; echo '
' . esc_html((string) $value) . '
'; } private static function upload(string $id, string $name, string $value): void { echo '
'; if ($value !== '') { echo ''; } echo ''; echo '
'; } private static function link(SchemaWidget $widget, string $key, array $value): void { echo ''; } private static function spacing(SchemaWidget $widget, string $key, array $value): void { echo '
'; foreach (['top' => '上', 'right' => '右', 'bottom' => '下', 'left' => '左'] as $edge => $label) { echo ''; } echo '
'; } private static function background(SchemaWidget $widget, string $key, array $value): void { echo '
'; self::plain_input($widget, $key . '[color]', (string) ($value['color'] ?? ''), 'text', '背景颜色'); self::plain_input($widget, $key . '[image]', (string) ($value['image'] ?? ''), 'url', '背景图片 URL'); foreach ([ 'position' => ['center center' => '居中', 'top center' => '顶部', 'bottom center' => '底部', 'center left' => '左侧', 'center right' => '右侧'], 'repeat' => ['no-repeat' => '不重复', 'repeat' => '平铺', 'repeat-x' => '水平平铺', 'repeat-y' => '垂直平铺'], 'attachment' => ['scroll' => '滚动', 'fixed' => '固定'], 'size' => ['cover' => '覆盖', 'contain' => '包含', 'auto' => '原始尺寸'], ] as $part => $options) { $name = $widget->get_field_name($key . '[' . $part . ']'); echo ''; } echo '
'; } private static function group(SchemaWidget $widget, array $field, array $rows, string $key): void { $token = '__index_' . substr(md5($key), 0, 8) . '__'; echo '
'; foreach ($rows as $index => $row) { self::group_row($widget, $field, is_array($row) ? $row : [], $key, (string) $index); } echo '
'; } private static function group_row(SchemaWidget $widget, array $field, array $row, string $key, string $index): void { echo '
' . esc_html__('项目', 'aksrt') . '
'; foreach ((array) ($field['fields'] ?? []) as $child) { $child_id = (string) ($child['id'] ?? ''); self::field($widget, $child, $row[$child_id] ?? ($child['default'] ?? ''), $key . '[' . $index . ']'); } echo '
'; } private static function nested(SchemaWidget $widget, array $field, array $value, string $key): void { echo '
' . esc_html((string) ($field['label'] ?? '更多设置')) . '
'; foreach ((array) ($field['fields'] ?? []) as $child) { $child_id = (string) ($child['id'] ?? ''); self::field($widget, $child, $value[$child_id] ?? ($child['default'] ?? ''), $key); } echo '
'; } private static function plain_input(SchemaWidget $widget, string $key, string $value, string $type, string $placeholder): void { $name = $widget->get_field_name($key); $id = $widget->get_field_id(str_replace(['[', ']'], ['-', ''], $key)); echo ''; } }