Is there any WordPress login php script like this one?
This script is for signing in with WordPress.com account.
I have followed the documentation to write my script. But it did not provide me the access token when I print the access token. It shows it is null.
This is my code to implement sign in with WordPress.com account:
session_start();
$client_id = "2472";
$client_secret ="TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx";
$login_url = "https://public-api.wordpress.com/oauth2/authorize?client_id=$client_id&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&response_type=code";
function getToken(){
$curl = curl_init( "https://public-api.wordpress.com/oauth2/token" );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, array(
'client_id' => "2472",
'redirect_uri' => "http://w3.softwarecookerbd.com/wordpress.php",
'client_secret' => "TaB3JPXeuJA8XsosdkMbZnuJoybxJaBF6WmDD11WFJg8QQme9fmye6l2Kxd45cpx",
'code' => $_GET['code'], // The code from the previous request
'grant_type' => 'authorization_code'
) );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
$auth = curl_exec( $curl );
$secret = json_decode($auth);
echo "<pre>";
var_dump($secret);
exit;
$access_key = $secret->access_token;
}
if(isset($_GET["code"])&&!empty($_GET["code"])){
//$url = "https://public-api.wordpress.com/oauth2/token?client_id=$client_id&client_secret=client_secret&redirect_uri=http://w3.softwarecookerbd.com/wordpress.php&code=".$_GET['code']."&grant_type=authorization_code";
//$response = file_get_contents($url);
//echo $response;
getToken();
}else{
header("Location: ".$login_url);
}
I am not sure about the actual script that you have posted , but there are several plugins that will allow you to do that , you might want to have a look at them, and since they are open-source , if you really want to do it yourself, you can always peep at the code and see what the problem is .
Some of them that I know (and not limited only to wordpress.com, but to other services as well) are :
http://wordpress.org/extend/plugins/oa-social-login/
http://wordpress.org/extend/plugins/socialauth-wp/
http://wordpress.org/extend/plugins/ssi-sumilux/screenshots/
And if I am not wrong (maybe i am ) also the wordpress jetpack has this feature ..
http://wordpress.org/extend/plugins/jetpack/