dream1849 2017-06-15 09:40
浏览 43
已采纳

如何生成wordpress登录会话

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条回答 默认 最新

  • dongye7231 2017-06-15 10:46
    关注

    in your ajax function insert user with email and random password using wp_insert_user(). Then Use wp_signon() function below it.In wp_signon() function Use user name and password which you have used while creating user. Now you will be able to see user will be logged in. cheers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了