diff --git a/README.md b/README.md
index 7f8fca07..d8521379 100644
--- a/README.md
+++ b/README.md
@@ -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. |
- `state_data` - contains the default state data.
| `rtcamp.default_algorithm` | Filters default algorithm for openssl signature verification | - `default_algo` - Default algorithm.
- `algo` - Algorithm from JWT header.
| `rtcamp.google_redirect_url` | Filters the URL to which the user will be redirected post successful authentication | - `redirect_uri` - contains the URL to be redirected to. Defaults to the current URL.
+| `rtcamp.google_one_tap_show` | This filter is used to add one-tap login scripts to specific pages when `sitewide` option is disabled.
Make sure one-tap login is enabled in settings for this to work. | - `one_tap_show` - contains the boolean value for the current page. Preferred usage is with conditional tags. Defaults to `sitewide` setting.
#### Actions
diff --git a/src/Modules/OneTapLogin.php b/src/Modules/OneTapLogin.php
index 9e475f00..e4d7adac 100644
--- a/src/Modules/OneTapLogin.php
+++ b/src/Modules/OneTapLogin.php
@@ -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' ] );
@@ -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 {
+ $show_on_this_page = apply_filters(
+ 'rtcamp.google_one_tap_show',
+ ( 'sitewide' === $this->settings->one_tap_login_screen )
+ );
+
+ 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.
*
diff --git a/src/Modules/Shortcode.php b/src/Modules/Shortcode.php
index 02931959..feb8ada4 100644
--- a/src/Modules/Shortcode.php
+++ b/src/Modules/Shortcode.php
@@ -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 );
}
/**