我想出了如何继续。我用所需的选择选项创建了一个文本文件,并用下面的代码替换了模板中的输入字段。
<?php
$file_path = \'FILE_PATH_HERE\'; // path to the file with select options
if ( !file_exists( $file_path ) ) {
echo \'<input type="text" name="location" placeholder="\' . __("Location ...", "custom-settings") . \'" value="\' . esc_attr($location) . \'" />\';
} else {
$file_array = str_replace("\\n","", file($file_path));
$options = \'<option value="">\' . __("Select a location ...", "custom-settings") . \'</option>\';
$options .= \'<option value="0">\' . __("All locations", "custom-settings") . \'</option>\';
foreach ($file_array as $location)
$options .= \'<option value="\' . $location . \'">\' . $location .\'</option>\';
$select = \'<select id="location" name="location">\' . $options . \'</select>\';
echo $select;
}
?>