', $attrs); // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
$choices = WPStarter_Settings::options_for($field);
if (!empty($field['open']) && '' !== (string) $value && !array_key_exists((string) $value, $choices)) {
// A saved choice whose plugin is not loaded here stays shown.
$choices[(string) $value] = (string) $value;
}
foreach ($choices as $option_value => $option_label) {
printf(
'
',
esc_attr((string) $option_value),
selected((string) $value, (string) $option_value, false),
esc_html($option_label)
);
}
echo '';
break;
case 'multi':
$chosen = array_map('strval', (array) $value);
$choices = WPStarter_Settings::options_for($field);
// With some plugins skipped on this request, a saved
// choice may belong to one of them; keep it too.
if (!empty($field['open']) || WPStarter_Feature::plugins_skipped()) {
// Saved items that are not registered right now stay visible so they can be unticked.
foreach (array_diff($chosen, array_map('strval', array_keys($choices))) as $missing) {
$choices[$missing] = $missing;
}
}
$long = count($choices) > 12;
if ($long) {
// Long lists (such as every active plugin) scroll, with quick choices.
printf(
'
· ',
esc_attr($id),
esc_html__('Select all', 'wp-plugin-starter-template'),
esc_html__('Clear', 'wp-plugin-starter-template')
);
}
// The group carries data-wps-setting; the JS saves every checked value.
printf(
'
';
break;
case 'url':
printf(
'
',
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
esc_attr((string) $value),
esc_attr(isset($field['placeholder']) ? $field['placeholder'] : '')
);
break;
case 'times':
printf(
'
',
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
esc_attr((string) $value),
esc_attr(isset($field['placeholder']) ? $field['placeholder'] : '')
);
break;
case 'int':
printf(
'
',
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
esc_attr((string) $value),
esc_attr(isset($field['min']) ? (string) $field['min'] : ''),
esc_attr(isset($field['max']) ? (string) $field['max'] : '')
);
if (!empty($field['unit'])) {
echo '
' . esc_html($field['unit']) . '';
}
break;
case 'lines':
case 'domains':
printf(
'
',
isset($field['rows']) ? (int) $field['rows'] : 3,
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
esc_attr(isset($field['placeholder']) ? $field['placeholder'] : ''),
esc_textarea((string) $value)
);
break;
case 'media':
// The hidden input carries data-wps-setting; the JS sets it
// from the media dialog and saves it.
$image_id = (int) $value;
$preview = $image_id ? wp_get_attachment_image_url($image_id, 'thumbnail') : '';
echo '
';
break;
case 'bool':
printf(
'
',
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
checked((bool) $value, true, false)
);
break;
case 'text':
default:
printf(
'
',
$attrs, // phpcs:ignore WordPress.Security.EscapeOutput -- escaped above.
esc_attr((string) $value),
esc_attr(isset($field['placeholder']) ? $field['placeholder'] : '')
);
break;
}
?>