如何为 wordpress WP_QUERY 清理 $_POST?
How to sanitize $_POST for wordpress WP_QUERY?
有人知道如何清理 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);
原来 WP 会自动清理它。
有人知道如何清理 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);
原来 WP 会自动清理它。