Disabling only specific error types of config validator

Posts in the developer's cookbook category describe topics that require technical knowledge. Be warned and use the techniques at your own risk. Unless you are an experienced developer, you are strongly advised to ask a professional for support.

While you can disable the functionality of the configuration validator, you may feel that disabling the entire functionality is overkill. Another technique that I am describing in this recipe allows you to apply more precise control over the configuration validator. You can disable only the error types you specify.

This technique uses the wpcf7_config_validator_available_error_codes filter hook. See the following example code that adds a filter to the hook:

add_filter(
    'wpcf7_config_validator_available_error_codes',
    function ( $error_codes, $contact_form ) {

        // List error codes to disable here.
        $error_codes_to_disable = array(
            'unsafe_email_without_protection',
        );

        $error_codes = array_diff( $error_codes, $error_codes_to_disable );

        return $error_codes;
    },
    10, 2
);

The callback function takes an array of error codes as the first argument ($error_codes). An error code is a string value that represents the type of error. As of this writing, there are 16 error codes defined.

The return value represents available error codes, so if you have error types you want to disable, simply remove their codes from the return value. The above example disables the unsafe_email_without_protection error type.

The second argument ($contact_form) is the contact form object that is the current target of the configuration validation. This would be useful when you want to apply this filtering only to specific contact forms.