Contact Form 7 4.1 Beta

Contact Form 7 4.1 is going to be released soon. In 4.1, I’ve reconstructed the user-input validation process to require less coding and result in fewer errors. If you are a developer of Contact Form 7 add-on plugins that add custom validation, you might need to modify your code to make it work with Contact Form 7 4.1.


You can download Contact Form 7 4.1-beta from the WordPress.org plugin directory. Testing your code with the beta before Contact Form 7 4.1 is officially released is highly recommended. If you notice that the add-on plugin you are using stops working after upgrading to Contact Form 7 4.1, please inform the author of the plugin.

In Contact Form 7 4.1, the WPCF7_Validation class has been introduced, and the $result parameter passed through validation filter functions is now an instance of the WPCF7_Validation class (it was previously a multi-dimensional associative array).

The WPCF7_Validation class implements the ArrayAccess interface, so its instances are supposed to be able to accept array-access as if they are normal arrays. Unfortunately, there seems to be a defect in PHP’s ArrayAccess implementation because an ArrayAccess instance can’t be accessed multi-dimensionally.

If you have a code like this in your add-on:


if ( $condition_of_invalidity ) {
	$result['valid'] = false;
	$result['reason'][$name] = wpcf7_get_message( 'blar_blar' ); // this line causes an error.
}

You need to modify it like so to make it continue working in Contact Form 7 4.1 and later:


if ( $condition_of_invalidity ) {
	$result['valid'] = false;
	$result['reason'] = array( $name => wpcf7_get_message( 'blar_blar' ) );
}

If you don’t mind backward compatibility with Contact Form 7 4.0.x or older, you can make it simpler by using the invalidate() method of the WPCF7_Validation class:


if ( $condition_of_invalidity ) {
	$result->invalidate( $name, wpcf7_get_message( 'blar_blar' ) );
}