WordPress plugin to login/register with google
Login with google provides seamless experience for users to login in to WordPress sites using their google account. No need to manually create accounts, no need to remember quirky passwords. Just one click and land into the site!
- Clone this repository.
- Run
composer install --no-dev
from inside the cloned directory. - Upload the directory to
wp-content/plugins
directory. - Activate the plugin from WordPress dashboard.
These browsers are supported. Note, for example, that One Tap Login is not supported in Safari.
-
You will need to register a new application at https://console.cloud.google.com/apis/dashboard
-
Authorization callback URL
should be likehttps://yourdomain.com/wp-login.php
, wherehttps://yourdomain.com
will be replaced by your site URL. -
Once you create the app, you will receive the
Client ID
andClient Secret
, add these credentials inSettings > Login with google
settings page in their respective fields. -
Create new user
enables new user registration irrespective ofMembership
settings inSettings > General
; as sometimes enabling user registration can lead to lots of spam users. Plugin will take this setting as first priority and membership setting as second priority, so if any one of them is enabled, new users will be registered by this plugin after successful authorization. -
Whitelisted Domains
allows users from specific domains (domain in email) to get registered on site. This will prevent unwanted registration on website. For Example: If you want users only from your organization (myorg.com
) to get registered on the website, you entermyorg.com
in whitelisted domains. Users with google email likeabc@myorg.com
will be able to register on website. Contrary to this, users with emails likesomething@gmail.com
would not be able to register here.
Above mentioned settings can also be configured via PHP constants by defining them in wp-config.php file.
Refer following list of constants.
Type | Description | |
---|---|---|
WP_GOOGLE_LOGIN_CLIENT_ID | String | Google client ID of your application. |
WP_GOOGLE_LOGIN_SECRET | String | Secret key of your application |
WP_GOOGLE_LOGIN_USER_REGISTRATION | Boolean | (Optional) Set True If you want to enable new user registration. By default, user registration defers to Settings > General Settings > Membership if constant is not set. |
WP_GOOGLE_LOGIN_WHITELIST_DOMAINS | String | (Optional) Domain name, if you want to restrict login with your custom domain. By default, It will allow all domains. You can whitelist multiple domains. |
These constants can also be configured via wp-cli.
Note: If you have defined the constant in wp-config.php file, corresponding settings field will be disable (locked for editing) on the settings page.
Filter | Description | Parameters |
---|---|---|
rtcamp.google_scope |
This filter can be used to filter existing scope used in Google Sign in. You can ask for additional permission while user logs in. |
|
rtcamp.google_login_modules |
Filter out active modules before modules are initialized. |
|
rtcamp.google_login_button_display |
This filter is useful where we want to forcefully display login button, even when user is already logged-in in system. |
|
rtcamp.google_default_redirect |
Filter the default redirect URL in case redirect_to param is not available. Default to admin URL. |
|
rtcamp.google_register_user |
Check if we need to register the user. |
|
rtcamp.google_client_args |
Filter the arguments for sending in query. This is useful in cases for example: choosing the correct prompt. |
|
rtcamp.google_login_state |
Filters the state to pass to the Google API. |
|
rtcamp.default_algorithm |
Filters default algorithm for openssl signature verification |
|
Action | Description | Parameters |
---|---|---|
rtcamp.google_login_services |
Define any additional services. |
|
rtcamp.google_user_authenticated |
Fires once the user has been authenticated via Google OAuth. |
|
rtcamp.id_token_verified |
Do something when token has been verified successfully. If we are here that means ID token has been verified. |
|
rtcamp.google_user_logged_in |
Fires once the user has been authenticated. |
|
rtcamp.google_user_created |
Fires once the user has been registered successfully. |
|
rtcamp.login_with_google_exception |
Fires when an exception is raised during token verification. |
|
You can add the google login button to any page/post using shortcode: google_login
Example:
[google_login button_text="Google Login" force_display="yes" /]
Supported attributes for shortcode
Parameter | Description | Values | Default |
---|---|---|---|
button_text | Text to show for login button | string | Login with google |
force_display | Whether to display button when user is already logged in | yes/no | no |
redirect_to | URL where user should be redirected post login | URL | wp-admin |
Before creating a new issue, do browse through the existing issues for resolution or upcoming fixes.
If you still need to log an issue, making sure to include as much detail as you can, including clear steps to reproduce your issue if possible.
Want to contribute a new feature? Start a conversation by logging an issue.
Once you're ready to send a pull request, please run through the following checklist:
-
Browse through the existing issues for anything related to what you want to work on. If you don't find any related issues, open a new one.
-
Fork this repository.
-
Create a branch from
develop
for each issue you'd like to address and commit your changes. -
Push the code changes from your local clone to your fork.
-
Open a pull request and that's it! We'll with feedback as soon as possible (Isn't collaboration a great thing? π)
-
Once your pull request has passed final code review and tests, it will be merged into
develop
and be in the pipeline for the next release. Props to you! π
Unit tests can be run with simple command composer tests:unit
.
Please note that you'll need to do composer install
(need to install dev dependencies) for running
unit tests.
You should have PHP CLI > 7.1 installed. If you have Xdebug enabled with php, code coverage report will be
generated at /tmp/report/html
WordPress >= 5.5.0
PHP >= 7.4
This library is released under "GPL 2.0 or later" License.