0

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...)

| improve this question | | | | |
1

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;
}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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