这是一个非常好的问题——我的建议是使用瞬态。例如,在验证回调中:
wpse51669_validation_cb($settings){
//Perform validation checks
if( $valid ){
//If settings validate
return $validate_settings;
}
//Otherwise add settings error
add_settings_error(\'my-plug-in-settings\',\'error-with-xyz\', \'I fell over\',\'error\');
//And add the failed settings to a transient
set_transient( \'my-plug-in-settings-invalid\', $settings, 60);
return false;
}
然后在设置页面上,如果选项已验证-检查瞬态,如果发现“失败”设置,则使用“失败”设置:
if( isset($_GET[\'settings-updated\']) && $_GET[\'settings-updated\'] && get_transient(\'my-plug-in-settings-invalid\') ){
$options_to_display = get_transient(\'my-plug-in-settings-invalid\');
delete_transient(\'my-plug-in-settings-invalid\');
}else{
$options_to_display = get_option(\'my-plug-in-settings\');
}