我正在尝试制作一个插件,根据用户填写表单的方式重定向用户。我很难找到我的问题,我已经把它缩小到一个小片段,似乎工作。
function cf7pp_after_send_mail( $contact_form ) {
global $postid;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$postid = $posted_data[\'_wpcf7\'];
$enable = get_post_meta( $postid, "_cf7pp_enable", true);
$email = get_post_meta( $postid, "_cf7pp_email", true);
$valuepassed = get_post_meta($post_id, "_cf7pp_text_menu_b", true);
if ($enable == "1") {
if ($valuepassed == "1") {
if ($email == "2") {
include_once (\'includes/redirect.php\');
exit;
}
}
}
}
}
如果我更改:
if ($valuepassed == "1")
至
if ($valuepassed == "0")
行为改为不重定向,这很好,但我想看看传递给$valuepassed的值是什么,因为此时我无法使它像应该的那样动态地运行。我想看看是否发生了完全出乎意料的事情。
最合适的回答,由SO网友:mrhobbeys 整理而成
使用以下修改并添加die()停止脚本并输出当时的变量值。
感谢@toscho
function cf7pp_after_send_mail( $contact_form ) {
global $postid;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$postid = $posted_data[\'_wpcf7\'];
$enable = get_post_meta( $postid, "_cf7pp_enable", true);
$email = get_post_meta( $postid, "_cf7pp_email", true);
$valuepassed = get_post_meta($post_id, "_cf7pp_text_menu_b", true);
if ($enable == "1") {
// if ($valuepassed == "1") {
if ($email == "2") {
die( $valuepassed );
// include_once (\'includes/redirect.php\');
exit;
}
// }
}
}
}