我在functions.php
当submit_form
事件在前端激发。代码如下:
add_action( "wp_ajax_nopriv_submit_form", "submit_my_form" );
add_action( "wp_ajax_submit_form", "submit_my_form" );
function submit_my_form() {
$send_to = array( "[email protected]" );
if ( is_page( "contact" ) ) {
$subject = "This subject line is for the Contact page.";
} else {
$subject = "This subject line is for every other page.";
}
$message = "Name: " . $_POST["name"] . "\\r\\n";
$message .= "Email: " . $_POST["email"] . "\\r\\n";
$message .= "Phone: " . $_POST["tel"] . "\\r\\n";
$message .= "City: " . $_POST["city"] . ", " . $_POST["state"] . "\\r\\n";
$message .= "Message: " . $_POST["message"] . "\\r\\n";
wp_mail( $send_to, $subject, $message );
wp_die();
} ?>
问题是我需要
$subject
还有可能
$send_to
变量因页面而异。答案是
this question 但它仍然不能解决我的问题。有没有办法破解
is_page()
所以它在``函数中起作用。php
file or is there a workaround that doesn\'t involve using
\\u page()`是吗?