How to generate wordpress login session

时间:2017-06-15 09:40:53

标签: php wordpress woocommerce

i have try to make facebook login on woo-commerce my-account page below is my code..

js code

     jQuery.ajax({
            type:"POST",
            url: ajaxUrl,
            data: {
                action: "Generate_Session",
                username: response.name,
                email : response.email,
            },
            success:function(data){
                alert(data);
            }
     })

function.php is blelow

function Generate_Session()
 {
$username = $_POST['username'];
$password = '';
$email = $_POST['email'];
echo $username;
$gsdf='';
$user_id = wp_create_user( $username, $password, $email );
$user = new WP_User( $user_id );
$user->set_role( 'seller' );

 add_filter('wp_authenticate_user', 'myplugin_auth_login',10,2);
  function myplugin_auth_login ($username, $password) {
 //do any extra validation stuff here
 return $user;
  }



wp_die();
 }
 // creating Ajax call for WordPress
  add_action( 'wp_ajax_nopriv_Generate_Session', 'Generate_Session' );
  add_action( 'wp_ajax_Generate_Session', 'Generate_Session' );

WHen i get data into facebook login then i make new user as per my requirmnet.. then after i try to generate session varialbe. but i can't make it when try to access woocommerce dashboard then it redirect on my-account page

1 个答案:

答案 0 :(得分:1)

在你的ajax函数中使用wp_insert_user()插入用户的电子邮件和随机密码。然后在它下面使用wp_signon()函数。在wp_signon()函数中使用创建用户时使用的用户名和密码。现在您将能够看到用户将登录。欢呼