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

Login With Gmail

Easy Login in Wordpress with Gmail

★ 1stars

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/mehrshaddarzi/wp-login-gmail/archive/refs/heads/master.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

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;
    }