I would like to know how to perform a proper validation with the register_setting()
callback function.
Here is a sample part of my code I want to work with:
register_setting( 'wpPart_options', 'wpPart_options', array( &$this, 'wpPartValidate_settings' ) );
$this
is an array of objects.
And here is the content of my wpPartValidate_settings();
function.
public function wpPartValidate_settings( $input ) {
$options = get_option( 'wpPart_options' );
if ( check_admin_referer( 'wpPart_nonce_field', 'wpPart_nonce_verify_adm' ) ) {
return $input;
}
}
Since $input
is an array, how can I perfom a proper validation on every input that comes to the validating function?
I would like, for example, to perform a strlen()
check on a text field :
if ( strlen( $input ) != 20 )
add_settings_error( 'wpPart_options', 'textField', __( 'TextField incomplete.', 'wpPart' ) , 'error' );