Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I now have this function that works well :

function wpPartValidate_settings( $input ) {
   if ( check_admin_referer( 'wpPart_nonce_field', 'wpPart_nonce_verify_adm' ) ) {

    // Create our array for storing the validated options
    $output = array();

    foreach( $input as $key => $value ) {

      // Check to see if the current option has a value. If so, process it.
      if( isset( $input[$key] ) ) {

        // Strip all HTML and PHP tags and properly handle quoted strings
        $output[$key] = strip_tags( stripslashes( $input[ $key ] ) );

      } // end if
    } // end foreach
  } // end if
  // Return the array processing any additional functions filtered by this action
  return apply_filters( 'wpPartValidate_settings', $output, $input );
}

I wonder how to implement filters into that function.

The goal is to inform the administrator that one input has not been correctly filled (with a correct email, url, numbers, date...)

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

First of all I would recommend you to rename your function to wpPartSanitize_settings, because this function doesn't validate anything. As it doesn't validate anything, then you aren't able to "inform" administrator that one input is invalid.

Nevertheless, to create your hook for wpPartValidate_settings filter, just do it like this:

add_filter( 'wpPartValidate_settings', 'wpse8170_sanitize_settings', 10, 2 );
function wpse8170_sanitize_settings( $output, $input ) {
    // ...
    return $output;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.