https://github.com/mehrshaddarzi/wp-login-gmail
Easy Login in Wordpress with Gmail
https://github.com/mehrshaddarzi/wp-login-gmail
api gmail google wordpress wordpress-plugin wordpressdevelopment
Last synced: 28 days ago
JSON representation
Easy Login in Wordpress with Gmail
- Host: GitHub
- URL: https://github.com/mehrshaddarzi/wp-login-gmail
- Owner: mehrshaddarzi
- Created: 2021-07-02T09:25:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-02T10:35:05.000Z (almost 5 years ago)
- Last Synced: 2025-04-09T07:25:07.536Z (about 1 year ago)
- Topics: api, gmail, google, wordpress, wordpress-plugin, wordpressdevelopment
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
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
````
5. add define in your wp-config.php
````php
define('WP_GMAIL_CLIENT_ID', 'xxx');
define('WP_GMAIL_CLIENT_SECRET', 'xxx');
define('WP_GMAIL_REDIRECT_PARAM', 'gmail_login_redirect');
````
6. use `wp_gmail_login_success` WordPress action for handle user register or login
````php
do_action('wp_gmail_login_success', $accessToken, $email, $name, $familyName, $gender, $locale, $avatar, $google_account_info);
````
#### Example
1.Create Button for Login Url
````php
Login With Gmail
````
2. Handle Return User Success Login With Gmail
````php
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;
}
````