-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
87 lines (79 loc) · 2.31 KB
/
Copy pathindex.php
File metadata and controls
87 lines (79 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* @author Arjun Jain <http://www.arjunjain.info>
*/
require_once '../wp-load.php';
require_once 'config.php';
require_once 'lib/FacebookFunctions.php';
$fbObject=new FacebookFunctions(APP_ID,APP_SECRET);
$userId=$fbObject->GetUserId();
if($userId){
try{
$userDetails=$fbObject->API('/me');
$wpuserId= $userDetails['id'];
$wpuseremail=$userDetails['email'];
$wpfirstname=$userDetails['first_name'];
$wplastname=$userDetails['last_name'];
$wpuserId=$userDetails['id'];
if(! username_exists($wpuserId) and email_exists($wpuseremail) == false){
$random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
$userparams=array("user_pass"=>$random_password,"user_login"=>$wpuserId,"user_email"=>$wpuseremail,"first_name"=>$wpfirstname,"last_name"=>$wplastname,"role"=>WP_LEVEL);
$userid=wp_insert_user($userparams);
wp_new_user_notification($wpuserId,$random_password);
$is_error=wp_signon(array("user_login"=>$wpuserId,"user_password"=>$random_password));
if(is_wp_error($is_error)){
if (!empty($_SERVER['HTTP_REFERER'])){
?>
<script type="text/javascript">
window.opener.location.href="<?php echo $_SERVER['HTTP_REFERER']; ?>";
window.close();
</script>
<?php
}
else
{
?>
<script type="text/javascript">
window.opener.location.href="<?php echo get_bloginfo('wpurl'); ?>";
window.close();
</script>
<?php
}
}
else{
?>
<script type="text/javascript">
window.opener.location.href="<?php echo get_bloginfo('wpurl')."/wp-admin/"; ?>";
window.close();
</script>
<?php
}
}
else {
$userinfo=get_user_by('login',$wpuserId);
wp_set_auth_cookie($userinfo->ID);
do_action('wp_login', $userinfo->user_login);
?>
<script type="text/javascript">
window.opener.location.href="<?php echo get_bloginfo('wpurl')."/wp-admin/"; ?>";
window.close();
</script>
<?php
}
}
catch(FacebookApiException $e){
$userId=null;
}
catch (Exception $e){
$userId=null;
}
}
else {
$lparams=array("scope"=>"email",
"redirect_uri"=>SITE_URL,
"display"=>"popup");
$loginurl=$fbObject->GetLoginUrl($lparams);
header("Location: ".$loginurl);
}
?>
</html>