删除引号wordpress表单输入


remove quotes wordpress form input

我的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插入posts表中。我也必须删除帖子表中的引号。如何做到这一点?

您可以使用str_replace()删除引号或任何字符

与您的示例匹配:

$post['post_name'] = str_replace("'", "", $username);