Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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(
'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