2
任何人都知道如何淨化wordpress的$_POST
?或者當我使用WP_QUERY
時已經過消毒處理?謝謝!
我在想我是用mysql_escape()
還是esc_sql()
[wordpress函數]。
function checkIfEmailAndPasswordHaveUser($email, $password) {
$args = array(
'post_type' => 'my_custom_post_type',
'meta_query' => array(
array(
'key' => 'email',
'value' => $email
),
array(
'key' => 'password',
'value' => $password
),
),
);
$query = new WP_Query($args);
if(!$query->have_posts()) {
return false;
} else {
// return the user's ID
return $query->posts[0]->ID;
}
}
$post_user_email = trim($_POST['user_email']);
$post_user_password = trim($_POST['user_password']);
// check if user_id exist
$result = checkIfEmailAndPasswordHaveUser($post_user_email, $post_user_password);
https://codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data – Phiter
WP爲您清理它。 – staypuftman
看起來像是這些功能來防止XSS攻擊。我希望能夠防止SQL注入。我的意思是,當我使用WP_QUERY或ACF函數時,是否必須使用mysql_escape? –