你只需要register_setting()
并将自动保存。看到了吗Settings API 了解更多信息。下面是一个完整的示例:
function spw_cb() {
if( !($value = get_option(\'sprockets_per_widget\')) ) {
$value = 7;
}
?>
<input type="text" size="3" name="sprockets_per_widget" value="<?php echo $value; ?>" /> Numeric only!
<?php
}
function spw_init() {
add_settings_field(\'sprockets_per_widget\', \'Sprockets per Widget\', \'spw_cb\', \'general\');
register_setting(\'general\', \'sprockets_per_widget\', \'intval\');
}
add_action(\'admin_init\', \'spw_init\');