Last active
January 15, 2023 14:50
-
-
Save onocom/15b653713648794fc6c2 to your computer and use it in GitHub Desktop.
コンタクトフォーム7でフォームの送信先を動的に変更したい機会があり、無理やり書き換えることを試みた。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( "O_SYSTEM_CRYPT_KEY" , "OrehaJaian!Gakidaisho!OiNobitaButtobasuzo!" ); // 暗号化キー | |
define( "REPLACE_MAIL_ADDRESS" , "[email protected]" ); // 置換対象となるメールアドレス | |
// コンタクトフォーム7にhiddenフィールドを追加 | |
add_filter( 'wpcf7_form_hidden_fields', 'oc_wpcf7_form_hidden_fields'); | |
function oc_wpcf7_form_hidden_fields( $hidden ) { | |
$email = "[email protected]"; // 送信したいアドレスをhiddenフィールドに暗号化して設定しておく | |
$cript_mail = openssl_encrypt($email, 'AES-128-ECB', O_SYSTEM_CRYPT_KEY); | |
$hidden["_wpcf7_mail"] = $cript_author; | |
return $hidden; | |
} | |
// 送信時に書き換え | |
add_filter( 'wpcf7_mail_components', 'oc_wpcf7_mail_components'); | |
function oc_wpcf7_mail_components( $components ) { | |
if( $components['recipient'] == REPLACE_MAIL_ADDRESS && $_POST['_wpcf7_mail'] ) { | |
$cript_mail = $_POST['_wpcf7_mail']; | |
$email = openssl_decrypt($cript_mail, 'AES-128-ECB', O_SYSTEM_CRYPT_KEY); | |
if( $email ) { | |
$components['recipient'] = $email; | |
} | |
} | |
return $components; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment