WP Manifestindependent plugin directory
manifest / users / beltoft-simple-login

Simple Google Login for WooCommerce

"Continue with Google" login and registration for WooCommerce. Bricks Builder ready.

★ 0stars

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/beltoftandersen/beltoft-simple-login/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

"Continue with Google" sign-in and registration for WooCommerce customers, using Google Identity Services (the official Google button). It works with Bricks (a native element) and with page caches. No settings screen: one wp-config.php constant, plus a Google Cloud OAuth client.

Folder and text domain: simple-google-login. Repository: beltoftandersen/beltoft-simple-login.

What it does

  • Renders Google's own button where you put it:
    • after WooCommerce's standard login forms, automatically;
    • with the shortcode [sgl_google_button];
    • with the Bricks element "Google Login".
  • The button only shows to logged-out visitors, never inside the Bricks builder, and never when no client ID is configured.
  • When the visitor picks a Google account, the page posts Google's ID token to itself as a normal form post (field sgl_credential), like WooCommerce's login form. The post must come from this site (Origin, or Referer).
  • The server checks the token with Google (oauth2.googleapis.com/tokeninfo): issuer, audience = your client ID, expiry and a verified email. Each token is accepted only once.
  • It then finds the customer, or creates one, and logs them in:
    1. A user already linked to that Google account (user meta _sgl_google_sub) is logged in. A user may have several Google accounts linked; only those may sign in.
    2. Otherwise, a user with the same email is linked to this Google account and logged in. The first time, their WordPress password is replaced with a random one (filter sgl_reset_password_on_link), so from then on that account signs in with Google or a password reset.
    3. Otherwise, a new WooCommerce customer is created (first and last name from Google). This only happens if WooCommerce allows registration on My Account or at checkout (filter sgl_allow_registration).
  • The login fires wp_login in that page load, so a two-factor plugin that hooks it (WP 2FA) shows its code step first; Google sign-in never skips it. Errors show under the button (query argument sgl_error, a fixed code).
  • Only customer and subscriber accounts can use Google sign-in (filter sgl_allowed_roles). Shop managers and administrators get "Please log in with your password."
  • After login the page reloads, or goes to the button's redirect. On the checkout the automatic button returns to the checkout.

Setup

1. Google Cloud OAuth client

  1. In Google Cloud Console, open APIs & Services › Credentials › Create credentials › OAuth client ID, type Web application. Set up the OAuth consent screen first if Google asks, with your site name, support email and privacy policy URL.
  2. Under Authorized JavaScript origins, add every origin the button will appear on, for example https://example.com. Add staging too (https://staging.example.com) if it uses the same client. No paths, no trailing slash.
  3. Authorized redirect URIs are not needed: the button returns the credential to JavaScript, not by redirect.
  4. Copy the client ID (…apps.googleusercontent.com). The client secret is not used.

2. wp-config.php

define( 'SGL_CLIENT_ID', '1234567890-abc123.apps.googleusercontent.com' );

Without it the plugin does nothing: no button, and the login route answers 503.

3. Install and activate

Copy the folder to wp-content/plugins/simple-google-login/ and activate it. It requires WooCommerce (Requires Plugins: woocommerce).

4. Place the button

  • Automatic: after WooCommerce login forms (woocommerce_login_form_end). To switch this off: add_filter( 'sgl_auto_button', '__return_false' );
  • Shortcode: [sgl_google_button redirect="/a-minha-conta/" text="continue_with" theme="outline" size="large"]
    • text: continue_with, signin_with or signup_with;
    • theme: outline, filled_blue or filled_black;
    • size: small, medium or large;
    • redirect must be on this site (wp_validate_redirect).
  • Bricks: the "Google Login" element has the same four settings.

The button's language follows the page's locale.

5. Check

Log out, open a page with the button, and sign in with a Google account:

  • New email: a customer is created and logged in.
  • Email of an existing customer: that customer is logged in, and linked from then on.
  • Admin's email: refused, with "Please log in with your password."

Hosting notes

  • Page caches: the button markup carries nothing personal, so pages with it can be cached. The login call goes to /wp-json/, which must not be cached. The usual nginx skip rules for wp-json cover it.
  • Front proxy header limit: the login response sets the auth cookies. It deliberately doesn't call wp_clear_auth_cookie() first: that adds a dozen expiring Set-Cookie headers, and a proxy with a 4 KB header limit then answers 502 while the login actually succeeded.
  • Rate limit: 20 login attempts per IP per 10-minute window (filter sgl_max_attempts), then HTTP 429.
  • Consent / privacy: Google's script (accounts.google.com/gsi/client) loads only on pages that render the button. It may set Google's g_state cookie. List it in your cookie banner.

Filters

Filter Default Purpose
sgl_auto_button true Show the button after WooCommerce login forms
sgl_allowed_roles ['customer','subscriber'] Roles that may sign in with Google
sgl_allow_registration WooCommerce's registration settings Create new customers from Google sign-ins
sgl_reset_password_on_link true Replace the password the first time an existing account is linked
sgl_max_attempts 20 Login attempts per IP per 10 minutes

Security

Login is protected by:

  • the token checks with Google: audience = your client ID, issuer, expiry, verified email;
  • a one-time-use record of each token: Redis when a persistent object cache is present, else a transient;
  • a same-site check: the request must be application/json, with Origin or Referer on this host. That stops another site from logging a visitor in (login CSRF);
  • the per-IP rate limit.

Troubleshooting

Editing the Bricks element

Select Google login in the Builder structure tree. Content controls its wording preset, Google theme, size and redirect. Style → Layout → Width / Max. width controls its width; use Width 100% and a Max. width such as 300px for a narrower responsive button. Google's supported rendered width is 200–400 px. Size controls the button height, not its width. The Builder shows a placeholder; the real Google button appears on the frontend for logged-out visitors.

If a full-access administrator sees a missing-capabilities message on an older plugin version, update to 1.3.3 and reload the Builder tab. Older versions registered after Bricks loaded its element controls and permission catalogue. Registration now happens after Bricks initializes its base classes but before its element-load pass, with an idempotent pre-load fallback. No role/capability grants are required.

The button reserves its space while Google's script loads. Hidden checkout steps defer rendering until they have a measurable width. Temporary Google markup stays hidden until the loaded iframe has dimensions and page fonts have settled. Opening the same step again at the same width reuses the existing iframe. Width limits remain Google's 200–400 px; center its outer Bricks element with native margins when the form is wider.

Browser verification

Install development dependencies with npm ci, then set SGL_TEST_URL to an authorized guest page containing the button and run npm run test:browser. For a multistep checkout, also set SGL_TEST_OPEN_STEP to its forward button text, SGL_TEST_BUTTON to the specific Google host selector, and SGL_TEST_CONTAINER to the surrounding layout container. Set SGL_TEST_ALIGNMENT=left to verify left alignment instead of centering. The suite uses the real Google SDK with delayed and blocked requests, checks four widths, resizing and the three button sizes, and never signs in or submits checkout. Results and screenshots stay in ignored .artifacts/.

Set SGL_TEST_MAX_WIDTH=300 to assert a native 300 px width cap. tests/bricks-registration.php runs through WP-CLI with an authorized editor and an existing Google element: wp --user=<editor> eval-file tests/bricks-registration.php <post-id> <element-id>. It checks early registration, retained controls, root CSS bindings and a permission-checked layout dry run without saving a page or changing permissions.

Symptom Cause
No button at all SGL_CLIENT_ID missing, the visitor is logged in, or you're in the Bricks builder
"The Google button could not load…" The browser or an extension blocked accounts.google.com
Google shows "origin not allowed" / error 400 The site's origin isn't in the OAuth client's Authorized JavaScript origins
"Google sign-in failed." The token was invalid or already used, the client ID doesn't match, or the post did not come from this site
"Registration is disabled." WooCommerce registration is off for both My Account and checkout
"This account is already linked to another Google login." The email's account is linked to a different Google account
Login works on the server but the browser stays logged out (502) The proxy header limit; see Hosting notes

Authorship

Written by beltoft.net.