すっかり忘れていたContactForm7での確認用メールアドレスを記述する方法をメモ。

functions.php

// Contactform7に確認用メールアドレスを追加
/****************************************/
add_filter( ‘wpcf7_validate_email’,
‘wpcf7_text_validation_filter_extend’, 11, 2 );
add_filter( ‘wpcf7_validate_email*’,
‘wpcf7_text_validation_filter_extend’, 11, 2 );
function wpcf7_text_validation_filter_extend( $result, $tag ) {
$type = $tag[‘type’];
$name = $tag[‘name’];
$_POST[$name]
= trim( strtr( (string) $_POST[$name], “\n”, ” ” ) );
if ( ‘email’ == $type || ‘email*’ == $type ) {
if (preg_match(‘/(.*)_confirm$/’, $name, $matches)){
$target_name = $matches[1];
if ($_POST[$name] != $_POST[$target_name]) {
$result[‘valid’] = false;
$result[‘reason’][$name] = ‘確認用のメールアドレスが一致していません’;
}
}
}
return $result;
}

Contact Form 7内

[email* your-email]
[email* your-email_confirm placeholder”確認のため再度ご入力ください”]