-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow One-tap to be loaded on all pages. #9964
Conversation
Build files for 4712b9c have been deleted. |
Size Change: +231 B (+0.01%) Total Size: 1.98 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tofumatt looks good, just 2 small suggestions
assets/js/modules/sign-in-with-google/components/common/OneTapToggles.js
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I skipped the suggestion I made initially since it will be proposed as part of another issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
add_action( 'show_user_profile', $this->get_method_proxy( 'render_disconnect_profile' ) ); // This action shows the disconnect section on the users own profile page. | ||
add_action( 'edit_user_profile', $this->get_method_proxy( 'render_disconnect_profile' ) ); // This action shows the disconnect section on other users profile page to allow admins to disconnect others. | ||
|
||
add_action( 'woocommerce_login_form_start', $this->get_method_proxy( 'render_signin_button' ) ); | ||
// (Potentially) render the Sign in with Google button on all pages. | ||
add_action( 'wp_footer', $this->get_method_proxy( 'render_signin_button' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, i am not sure that this is a good approach to use this version of the sign-in button script on all pages, especially on those that don't need the sign-in button. We should better revert changes in this function and create a new method that renders just one-tap script.
Plus, there is no wp_footer
action call on the login page because it uses login_footer
instead: https://github.com/WordPress/WordPress/blob/master/wp-login.php#L448
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, shoot, good point.
Yeah, I wondered about rendering only the script, but knowing in the future we want to actually be able to render the sign-in buttons on any page and the code already checks if it's on the login pages, maybe it'd be better for now to restrict the button transformations to login pages but always render the script?
We could change the method name to something like load_siwg_script
or something instead 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code already only does button replacements on the relevant pages:
site-kit-wp/includes/Modules/Sign_In_With_Google.php
Lines 346 to 352 in 7ac6818
document.getElementsByClassName( 'login' )[0]?.insertBefore( parent, document.getElementsByClassName( 'woocommerce-form-row' )[0] ); | |
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> | |
async function handleCredentialResponse( response ) { | |
try { | |
const res = await fetch( '<?php echo esc_js( $login_uri ); ?>', { | |
method: 'POST', |
I think that's fair for now, given in the future we'll want to allow the buttons to replaced on all pages, so rather than separate them out only to combine them again later, we can leave them as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but let's not define a new div and render the button if it is neither the login page nor a woocommerce login form. Also, there is no sense in adding the redirect_to part as well because one-tap will never have that parameter on random pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that we need to skip the following blocks if it is not a login page/form:
site-kit-wp/includes/Modules/Sign_In_With_Google.php
Lines 330 to 335 in 63f3394
const parent = document.createElement( 'div' ); | |
<?php if ( $is_woo_commerce_login ) : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> | |
document.getElementsByClassName( 'login' )[0]?.insertBefore( parent, document.getElementsByClassName( 'woocommerce-form-row' )[0] ); | |
<?php else : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> | |
document.getElementById( 'login' ).insertBefore( parent, document.getElementById( 'loginform' ) ); | |
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> |
google.accounts.id.renderButton( parent, <?php echo wp_json_encode( $btn_args ); ?> ); |
site-kit-wp/includes/Modules/Sign_In_With_Google.php
Lines 364 to 368 in 63f3394
<?php if ( ! empty( $redirect_to ) ) : // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> | |
const expires = new Date(); | |
expires.setTime( expires.getTime() + 1000 * 60 * 5 ); | |
document.cookie = "<?php echo esc_js( Authenticator::COOKIE_REDIRECT_TO ); ?>=<?php echo esc_js( $redirect_to ); ?>;expires=" + expires.toUTCString() + ";path=<?php echo esc_js( Authenticator::get_cookie_path() ); ?>"; | |
<?php endif; // phpcs:ignore Generic.WhiteSpace.ScopeIndent.Incorrect ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense 👍🏻
I've made the change 🙂
(JS Tests failing is not related to my changes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. LGTM.
Summary
Addresses issue:
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist