Contact form 7 add confirmは保守されなくなって久しいプラグインですが、いまだに使用している人は多いと思います。
私もその一人です。
以前、新しいContact form 7との組み合わせでContact form 7 add confirmが動かなくなった時に、対処方法に関する記事を書きました。
昨日、Contact form 7 add confirm関連でPHPのWarningが出るようになってしまうトラブルがありました。
このトラブルはContact form 7とは関係なく、Contact form 7 add confirm本体とPHPのバージョンの組み合わせで起きる問題です。
その時の対処方法をまとめておきます。
Use of undefined constant WPCF7_VERSIONの消し方
Use of undefined constant WPCF7_VERSION というWarningメッセージが表示されるようになりました。
発生個所はプラグイン内部の2つのソースコードです。
- contact-from-7-add-confirm/modules/confirm.php on line 51
- contact-from-7-add-confirm/modules/back.php on line 57
if(WPCF7_VERSION >= "4.2.0") {
if ( is_admin() ) {
add_action( 'admin_init', 'wpcf7c_add_tag_generator_confirm', 55 );
}
if(WPCF7_VERSION >= "4.2.0") {
if ( is_admin() ) {
add_action( 'admin_init', 'wpcf7c_add_tag_generator_back', 55 );
}
シングルクォートでWPCF7_VERSIONをくくってあげれば、大丈夫です。
if('WPCF7_VERSION' >= "4.2.0") {
if ( is_admin() ) {
add_action( 'admin_init', 'wpcf7c_add_tag_generator_confirm', 55 );
}
if('WPCF7_VERSION' >= "4.2.0") {
if ( is_admin() ) {
add_action( 'admin_init', 'wpcf7c_add_tag_generator_back', 55 );
}
PHP7.xのバージョンが古い場合は、問題なく動作しますが、PHP7.2以降だとWarningになるようです。
Unquoted strings that are non-existent global constants are taken to be strings of themselves. This behaviour used to emit an
https://www.php.net/manual/en/migration72.deprecated.phpE_NOTICE
, but will now emit anE_WARNING
. In the next major version of PHP, an Error exception will be thrown instead.
まとめ
Contact form 7 add confirmは保守されていないので使うのはキケンだと思う人が多いかもしれませんが、まだまだ使えると思います。