在unction.php文件中使用is_page()是否存在黑客攻击?

时间:2015-08-24 作者:Wilhelm

我在functions.phpsubmit_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() 所以它在``函数中起作用。phpfile or is there a workaround that doesn\'t involve using\\u page()`是吗?

1 个回复
SO网友:user2791423

//您可以检索链接并获取id(例如,联系人id=4)

$link = $_SERVER[\'HTTP_REFERER\'];
$page_id = url_to_postid($link);

    if (page_id == \'4\'){
        $subject = "This subject line is for the Contact page.";
    } else {
        $subject = "This subject line is for every other page.";
    }

结束

相关推荐

有没有办法让WordPress的ajaxurl实现跨域资源共享?

WordPress已经有了jQuery WordPress应用程序调用的默认URL,它被称为ajaxurl. 然而,在某些情况下,需要启用Cross-Origin Resource Sharing (CORS),这样任何主机名都可以使用它进行访问。我当前的解决方案是在/wp-includes/http.php 使用:@header( \'Access-Control-Allow-Origin: *\' ); 以便:http。php... function send_origin_head