Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ via [wp-cli](https://developer.wordpress.org/cli/commands/config/).
| `rtcamp.google_login_state` | Filters the state to pass to the Google API. | <ul><li>`state_data` - contains the default state data.</li></ul>
| `rtcamp.default_algorithm` | Filters default algorithm for openssl signature verification | <ul><li>`default_algo` - Default algorithm.</li><li>`algo` - Algorithm from JWT header.</li></ul>
| `rtcamp.google_redirect_url` | Filters the URL to which the user will be redirected post successful authentication | <ul><li> `redirect_uri` - contains the URL to be redirected to. Defaults to the current URL.</li></ul>
| `rtcamp.google_one_tap_show` | This filter is used to add one-tap login scripts to specific pages when `sitewide` option is disabled. <br /> Make sure one-tap login is enabled in settings for this to work. | <ul><li> `one_tap_show` - contains the boolean value for the current page. Preferred usage is with conditional tags. Defaults to `sitewide` setting.</li></ul>

#### Actions

Expand Down
23 changes: 23 additions & 0 deletions src/Modules/OneTapLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function init(): void {
add_action( 'wp_enqueue_scripts', [ $this, 'one_tap_scripts' ] );
add_action( 'wp_footer', [ $this, 'one_tap_prompt' ], 10000 );
}

// Defer the custom one-tap page addition to 'wp' action to ensure all conditionals work.
add_action( 'wp', [ $this, 'maybe_add_one_tap_to_frontend' ] );

add_action( 'login_enqueue_scripts', [ $this, 'one_tap_scripts' ] );
add_action( 'login_footer', [ $this, 'one_tap_prompt' ] );
add_action( 'wp_ajax_nopriv_validate_id_token', [ $this, 'validate_token' ] );
Expand All @@ -106,6 +110,25 @@ public function init(): void {
// Add filters here.
}

/**
* Maybe add one-tap to frontend based on settings.
*
* Use this filter as per requirement to show or hide one-tap on specific pages, the filter passes a boolean value.
*
* @return void
*/
public function maybe_add_one_tap_to_frontend(): void {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @since n.e.x.t to newly added function.

$show_on_this_page = apply_filters(
Copy link
Member

@mi5t4n mi5t4n Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter doesn’t appear to be working. Even when it returns false, the file build/js/onetap.js is still being loaded on every page.

Steps to reproduce

  1. Goto the Login With Google Settings under the WP Settings menu.
  2. Populate the required credentials like Client ID and Client Secret.
  3. Checked the Create New User and Enable One Tap Login
  4. Select the Enable One Tap Login Site-Wide option
  5. Add below snippet code in Hello Dolly plugin or the in the current theme's functions.php file.
add_filter( 'rtcamp.google_one_tap_show', function( $is_allowed ) {
	return ! is_home();
});
  1. Navigate to the homepage
  2. We can still see the onetap pop-up view

Code that is probably causing the above issue

wp_register_script(
'login-with-google-one-tap-js',
trailingslashit( plugin()->url ) . 'assets/build/js/' . $filename,
[
'wp-i18n',
],
filemtime( trailingslashit( plugin()->path ) . 'assets/build/js/onetap.js' ),
true
);
wp_add_inline_script(
'login-with-google-one-tap-js',
'var TempAccessOneTap=' . json_encode( $data ), //phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode
'before'
);
wp_enqueue_script( 'login-with-google-one-tap-js' );

'rtcamp.google_one_tap_show',
( 'sitewide' === $this->settings->one_tap_login_screen )
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing, we have to version and document the newly added filter as well.

if ( $show_on_this_page ) {
add_action( 'wp_enqueue_scripts', [ $this, 'one_tap_scripts' ] );
add_action( 'wp_footer', [ $this, 'one_tap_prompt' ], 10000 );
}
}

/**
* Show one tap prompt markup.
*
Expand Down
8 changes: 4 additions & 4 deletions src/Modules/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public function init(): void {
/**
* Actions.
*/
add_filter( 'do_shortcode_tag', [ $this, 'scan_shortcode' ], 10, 3 );

// Add actions here.
/**
* Filters.
*/
// Add filters here.
*/
add_filter( 'do_shortcode_tag', [ $this, 'scan_shortcode' ], 10, 3 );
}

/**
Expand Down