実現したいこと
PHPで暗号化した文字列をトークンとして発行し、その値を使って自動返信メールにトークン付きURLとして掲載したい
発生している問題・分からないこと
PHPで発行したトークンをショートコードとして利用しようと試みたが、そのまま表示される、または何も表示されない
該当のソースコード
functions.php
1function token_url() 2{ 3 $now = time(); 4 $expiry_string = $now + (5 * 60); //5分間の制限 5 $password = 'psword'; 6 $cipher = 'AES-256-ECB'; 7 8 $encrypted_expiry_string = rawurlencode(openssl_encrypt($expiry_string, $cipher, $password)); 9 return $encrypted_expiry_string; 10} 11wpcf7_add_form_tag('token', 'token_url', true);
form
1[token token-url] 2 3===== 4 5表示結果→OK
mail_pattern1
1資料DLのURLです 2https://sample.com/test.pdf?token=[token-url] 3 4===== 5 6表示結果: 7 8資料DLのURLです 9https://sample.com/test.pdf?token= 10 11→非表示のためNG
mail_pattern2
1資料DLのURLです 2https://sample.com/test.pdf?token=[token] 3 4===== 5 6表示結果: 7 8資料DLのURLです 9https://sample.com/test.pdf?token=[token] 10 11→ショートコードのままのためNG
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
公式サイトにあったadd_actionの書き方も真似してみましたがこちらも上手く行きませんでした。
functions.php
1add_action('wpcf7_init', 'custom_add_form_tag_token'); 2 3function custom_add_form_tag_token() 4{ 5 wpcf7_add_form_tag('token', 'custom_token_form_tag_handler'); // "token" is the type of the form-tag 6} 7 8function custom_token_form_tag_handler($tag) 9{ 10 $now = time(); 11 $expiry_string = $now + (5 * 60); 12 $password = 'psword'; 13 $cipher = 'AES-256-ECB'; 14 15 $encrypted_expiry_string = rawurlencode(openssl_encrypt($expiry_string, $cipher, $password)); 16 return $encrypted_expiry_string; 17}
補足
phpにて時間制限付きトークンを発行しそれをContact Form 7のメール本文に掲載できるのであれば、ショートコードを使わなくても問題ありません。
ソース上でのおかしな点や、そもそも違う方法での実装アイディアなど、助言いただけますと幸いです。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。