How to Auto Login After Registration in WordPress with core php

后端 未结 3 1177
轻奢々
轻奢々 2020-12-23 11:11

I\'ve been trying for days now to take users who have just registered to my WordPress site and automatically log them in and then redirect them to a URL of my choice. By def

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 11:18

    Thanks for your support guys..i did on my own with the following code..thanks for your time and support :)

    $getdetails= mysql_fetch_array(mysql_query("SELECT * FROM `wp_users` WHERE `ID`='$user_id'"));
    $username=$getdetails['user_login'];
    
    
    $creds = array();
    $creds['user_login'] = $username;
    $creds['user_password'] = $password;
    $creds['remember'] = true;
    
        $user = wp_signon( $creds, false );
        if ( is_wp_error($user) ){
            echo $user->get_error_message();
        }else{
            wp_redirect( home_url() );
        }
    

提交回复
热议问题