PHP code example of revolution / socialite-wordpress

1. Go to this page and download the library: Download revolution/socialite-wordpress library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

revolution / socialite-wordpress example snippets


    'wordpress' => [
        // Endpoint for WordPress.com
        // 'host'          => env('WORDPRESS_HOST', 'https://public-api.wordpress.com/oauth2'),
        // 'api_me'        => env('WORDPRESS_API_ME', 'https://public-api.wordpress.com/rest/v1.1/me'),

        // Endpoint for Self-hosted WordPress
        'host'   => env('WORDPRESS_HOST'),
        'api_me' => env('WORDPRESS_API_ME', env('WORDPRESS_HOST') . '/me/'),

        'client_id'     => env('WORDPRESS_CLIENT_ID'),
        'client_secret' => env('WORDPRESS_CLIENT_SECRET'),
        'redirect'      => env('WORDPRESS_REDIRECT'),
    ],

Route::get('login', [SocialiteController::class, 'login']);
Route::get('callback', [SocialiteController::class, 'callback']);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Socialite;

class SocialiteController extends Controller
{
    public function login()
    {
        return Socialite::driver('wordpress')->redirect();
    }

    public function callback()
    {
        $user = Socialite::driver('wordpress')->user();
        dd($user);
    }
}