From f94bc5bb5037807e594f74f532ae1d668222f39a Mon Sep 17 00:00:00 2001 From: Chirag Mathur Date: Tue, 23 Jul 2024 17:14:41 +0530 Subject: [PATCH 1/2] Feat: Added code for migration to FedCM --- src/Modules/OneTapLogin.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Modules/OneTapLogin.php b/src/Modules/OneTapLogin.php index 9f45500..8a0efa2 100644 --- a/src/Modules/OneTapLogin.php +++ b/src/Modules/OneTapLogin.php @@ -86,17 +86,17 @@ public function name(): string { */ public function init(): void { if ( $this->settings->one_tap_login ) { - 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' ] ); - add_action( 'rtcamp.id_token_verified', [ $this, 'authenticate' ] ); + add_action( 'login_enqueue_scripts', array( $this, 'one_tap_scripts' ) ); + add_action( 'login_footer', array( $this, 'one_tap_prompt' ) ); + add_action( 'wp_ajax_nopriv_validate_id_token', array( $this, 'validate_token' ) ); + add_action( 'rtcamp.id_token_verified', array( $this, 'authenticate' ) ); add_action( 'init', function () { if ( ! is_user_logged_in() ) { $hook_prefix = ( 'sitewide' === $this->settings->one_tap_login_screen ) ? 'wp' : 'login'; - add_action( $hook_prefix . '_enqueue_scripts', [ $this, 'one_tap_scripts' ] ); - add_action( $hook_prefix . '_footer', [ $this, 'one_tap_prompt' ], 10000 ); + add_action( $hook_prefix . '_enqueue_scripts', array( $this, 'one_tap_scripts' ) ); + add_action( $hook_prefix . '_footer', array( $this, 'one_tap_prompt' ), 10000 ); } } ); @@ -108,8 +108,9 @@ function () { * * @return void */ - public function one_tap_prompt(): void { ?> -
+ public function one_tap_prompt(): void { + ?> +
path ) . 'assets/build/js/onetap.js' ), true ); - $data = [ + $data = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'state' => $this->google_client->state(), 'homeurl' => get_option( 'home', '' ), - ]; + ); wp_register_script( 'login-with-google-one-tap-js', trailingslashit( plugin()->url ) . 'assets/build/js/' . $filename, - [ + array( 'wp-i18n', - ], + ), filemtime( trailingslashit( plugin()->path ) . 'assets/build/js/onetap.js' ), true ); @@ -187,9 +188,9 @@ public function validate_token(): void { } wp_send_json_success( - [ + array( 'redirect' => $redirect_to, - ] + ) ); die; From d7dd905f21ac22094ac29bd7b1a9f14e7314a456 Mon Sep 17 00:00:00 2001 From: Chirag Mathur Date: Wed, 31 Jul 2024 12:41:42 +0530 Subject: [PATCH 2/2] Removed all the array shorthand changes --- src/Modules/OneTapLogin.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Modules/OneTapLogin.php b/src/Modules/OneTapLogin.php index 8a0efa2..dca7009 100644 --- a/src/Modules/OneTapLogin.php +++ b/src/Modules/OneTapLogin.php @@ -86,17 +86,17 @@ public function name(): string { */ public function init(): void { if ( $this->settings->one_tap_login ) { - add_action( 'login_enqueue_scripts', array( $this, 'one_tap_scripts' ) ); - add_action( 'login_footer', array( $this, 'one_tap_prompt' ) ); - add_action( 'wp_ajax_nopriv_validate_id_token', array( $this, 'validate_token' ) ); - add_action( 'rtcamp.id_token_verified', array( $this, 'authenticate' ) ); + 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' ] ); + add_action( 'rtcamp.id_token_verified', [ $this, 'authenticate' ] ); add_action( 'init', function () { if ( ! is_user_logged_in() ) { $hook_prefix = ( 'sitewide' === $this->settings->one_tap_login_screen ) ? 'wp' : 'login'; - add_action( $hook_prefix . '_enqueue_scripts', array( $this, 'one_tap_scripts' ) ); - add_action( $hook_prefix . '_footer', array( $this, 'one_tap_prompt' ), 10000 ); + add_action( $hook_prefix . '_enqueue_scripts', [ $this, 'one_tap_scripts' ] ); + add_action( $hook_prefix . '_footer', [ $this, 'one_tap_prompt' ], 10000 ); } } ); @@ -125,23 +125,23 @@ public function one_tap_scripts(): void { wp_enqueue_script( 'login-with-google-one-tap', 'https://accounts.google.com/gsi/client', - array(), + [], filemtime( trailingslashit( plugin()->path ) . 'assets/build/js/onetap.js' ), true ); - $data = array( + $data = [ 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'state' => $this->google_client->state(), 'homeurl' => get_option( 'home', '' ), - ); + ]; wp_register_script( 'login-with-google-one-tap-js', trailingslashit( plugin()->url ) . 'assets/build/js/' . $filename, - array( + [ 'wp-i18n', - ), + ], filemtime( trailingslashit( plugin()->path ) . 'assets/build/js/onetap.js' ), true ); @@ -188,9 +188,9 @@ public function validate_token(): void { } wp_send_json_success( - array( + [ 'redirect' => $redirect_to, - ) + ] ); die;