WP Manifestindependent plugin directory
manifest / users / wp-login-gmail

Login With Gmail

Easy Login in Wordpress with Gmail

by Mehrshad Darzi · github.com/mehrshaddarzi/wp-login-gmail · website

1stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/mehrshaddarzi/wp-login-gmail/archive/refs/heads/master.zip

Readme

WordPress Login With Gmail

How To install Plugin?

  1. run composer update in dir
  2. install plugin in wordpress.
  3. Create Google Client ID and Client Secret by this article:
    https://code.tutsplus.com/tutorials/create-a-google-login-page-in-php--cms-33214

4.Set Authorised redirect URIs in Google Developer:

https://site.com/?gmail_login_redirect=yes
  1. add define in your wp-config.php

    define('WP_GMAIL_CLIENT_ID', 'xxx');
    define('WP_GMAIL_CLIENT_SECRET', 'xxx');
    define('WP_GMAIL_REDIRECT_PARAM', 'gmail_login_redirect');
  2. use wp_gmail_login_success WordPress action for handle user register or login

    do_action('wp_gmail_login_success', $accessToken, $email, $name, $familyName, $gender, $locale, $avatar, $google_account_info);

Example

1.Create Button for Login Url

<a href="<?php echo WP_Gmail_Login::getAuthUrl(); ?>">Login With Gmail</a>
  1. Handle Return User Success Login With Gmail

    add_action('wp_gmail_login_success', 'login_with_gmail', 10, 4);
    function login_with_gmail($accessToken, $email, $name, $familyName)
    {
     $user_id = email_exists($email);
     if ($user_id === false) {
    
         $data = array(
             'user_email' => $email,
             'first_name' => $name,
             'show_admin_bar_front' => false
         );
         $user_id = wp_insert_user( $data );
     }
    
     // Automatic SignIn
     wp_set_current_user($user_id);
     wp_set_auth_cookie($user_id, true);
    
     // Redirect To Home Page Again
     wp_redirect(home_url());
     exit;
    }

Read the full README on GitHub →