我的 wordpress 网站上有一个注册表单。以下是我用于注册用户的代码。
$username = $wpdb->escape(trim($_POST['txtFullName']));
$email = $wpdb->escape(trim($_POST['txtEmail']));
$password = $wpdb->escape(trim($_POST['txtPassword']));
$confirmpassword = $wpdb->escape(trim($_POST['txtConfirmPassword']));
gender = $wpdb->escape(trim($_POST['gender']));
$user_id = wp_insert_user( array ('user_pass' => apply_filters('pre_user_user_pass', $password), 'user_login' => apply_filters('pre_user_user_login', $username), 'user_email' => apply_filters('pre_user_user_email', $email), 'role' => 'author' ) );
$authid = $user_id;
do_action('user_register', $user_id);
// Insert into Post table
$post = array();
$post['post_author'] = $authid ;
$post['post_date'] = date('Y-m-d H:i:s') ;
$post['post_date_gmt'] = date('Y-m-d H:i:s') ;
$post['post_name'] = $username ;
$post['post_status'] = 'pending' ;
$post['post_title'] = $username ;
$post['post_type'] = 'post';
$post['post_category'] = $gender;
wp_insert_post( $post, $wp_error );
注册后,我也尝试将用户插入帖子表中。如果我输入了用户名test'name
,它将像testname
在用户表中一样插入,但它将像test\'name
在帖子表中一样插入。我也必须删除帖子表中的引号。怎么做?