且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 wordpress 登录

更新时间:2023-12-02 09:02:58

我不确定您发布的实际脚本,但是有几个插件可以让您做到这一点,您可能想看看看看他们,而且因为他们是开源的,如果你真的想自己做,你可以随时偷看代码,看看有什么问题.

我所知道的其中一些(不仅限于 wordpress.com,还包括其他服务)是:

http://wordpress.org/extend/plugins/oa-social-login/

http://wordpress.org/extend/plugins/socialauth-wp/

http://wordpress.org/extend/plugins/ssi-sumilux/screenshots/

如果我没记错的话(也许我是),wordpress jetpack 也有这个功能..

http://wordpress.org/extend/plugins/jetpack/

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/