diff --git a/src/Modules/Block.php b/src/Modules/Block.php index 617ef9e5..b38b53c4 100644 --- a/src/Modules/Block.php +++ b/src/Modules/Block.php @@ -140,9 +140,9 @@ public function render_login_button( array $attributes ): string { ) { $markup = $this->markup( [ - 'login_url' => $this->client->authorization_url(), - 'custom_btn_text' => $attributes['buttonText'] ?? false, - 'force_display_block' => $attributes['forceDisplay'] ?? false, + 'login_url' => $this->client->authorization_url(), + 'custom_btn_text' => $attributes['buttonText'] ?? '', + 'force_display' => $force_display, ] ); @@ -174,7 +174,7 @@ private function markup( array $args = [] ): string { [ 'login_url' => '#', 'custom_btn_text' => '', - 'forceDisplay' => false, + 'force_display' => false, ] ); diff --git a/src/Modules/Shortcode.php b/src/Modules/Shortcode.php index 02931959..939790a8 100644 --- a/src/Modules/Shortcode.php +++ b/src/Modules/Shortcode.php @@ -95,12 +95,10 @@ public function init(): void { * @return string */ public function callback( $attrs = [] ): string { - $redirect_to = Helper::get_redirect_url(); - $attrs = shortcode_atts( + $attrs = shortcode_atts( [ - 'button_text' => __( 'Login with google', 'login-with-google' ), + 'button_text' => '', 'force_display' => 'no', - 'redirect_to' => $redirect_to, ], $attrs, self::TAG diff --git a/src/Utils/Helper.php b/src/Utils/Helper.php index 86b2bcd4..59b2981e 100644 --- a/src/Utils/Helper.php +++ b/src/Utils/Helper.php @@ -41,12 +41,6 @@ public static function render_template( $template_path, $variables = [], $should return ''; } - if ( ! empty( $variables ) ) { - // This will needed for provide variables to the template. - // Will skips those variables, those already defined. - extract( $variables, EXTR_SKIP ); // phpcs:ignore - } - if ( true === $should_echo ) { // Load template and output the data. diff --git a/src/Utils/TokenVerifier.php b/src/Utils/TokenVerifier.php index cf3a0ce6..9a29ba63 100644 --- a/src/Utils/TokenVerifier.php +++ b/src/Utils/TokenVerifier.php @@ -75,13 +75,11 @@ public function __construct( Settings $settings ) { * @param string $algo Algorithm. */ public static function get_supported_algorithm( string $algo = '' ) { - $find_algo = array_key_exists( $algo, self::SUPPORTED_ALGORITHMS ); - - if ( ! $find_algo ) { - return apply_filters( 'rtcamp.default_algorithm', OPENSSL_ALGO_SHA256, $algo ); + if ( isset( self::SUPPORTED_ALGORITHMS[ $algo ] ) ) { + return self::SUPPORTED_ALGORITHMS[ $algo ]; } - return self::SUPPORTED_ALGORITHMS[ $algo ]; + return apply_filters( 'rtcamp.default_algorithm', OPENSSL_ALGO_SHA256, $algo ); } /** @@ -121,7 +119,7 @@ public function base64_encode_url( $str ) { } /** - * Base64 URL Encode a string. + * Base64 URL Decode a string. * * @param string $str Input string to decode. * diff --git a/templates/google-login-button.php b/templates/google-login-button.php index c7817fca..1f36d91f 100644 --- a/templates/google-login-button.php +++ b/templates/google-login-button.php @@ -2,37 +2,37 @@ /** * Template for google login button. * - * @package RtCamp\GithubLogin + * @package RtCamp\GoogleLogin * @since 1.0.0 */ use RtCamp\GoogleLogin\Utils\Helper; -if ( isset( $custom_btn_text ) && $custom_btn_text ) { - $button_text = esc_html( $custom_btn_text ); -} else { - $button_text = ( ! empty( $button_text ) ) ? $button_text : __( 'Login with Google', 'login-with-google' ); -} +// Variables for rendering the template. +$login_url = $variables['login_url'] ?? null; +$button_text = $variables['button_text'] ?? null; +$custom_btn_text = $variables['custom_btn_text'] ?? null; if ( empty( $login_url ) ) { return; } -$button_url = $login_url; - if ( is_user_logged_in() ) { - $button_text = __( 'Log out', 'login-with-google' ); - $redirect_url = Helper::get_redirect_url(); - $button_url = wp_logout_url( $redirect_url ); + $button_text = __( 'Log out', 'login-with-google' ); + $button_url = wp_logout_url( Helper::get_redirect_url() ); +} else { + $button_url = $login_url; + + if ( ! empty( $custom_btn_text ) ) { + $button_text = $custom_btn_text; + } elseif ( empty( $button_text ) ) { + $button_text = __( 'Login with Google', 'login-with-google' ); + } } ?>
- diff --git a/tests/php/PrivateAccess.php b/tests/php/PrivateAccess.php index 3638af0c..f30ee3df 100644 --- a/tests/php/PrivateAccess.php +++ b/tests/php/PrivateAccess.php @@ -87,6 +87,6 @@ protected function get_private_property( $object, $property_name ) { */ protected function get_static_private_property( $class, $property_name ) { $properties = ( new ReflectionClass( $class ) )->getStaticProperties(); - return array_key_exists( $property_name, $properties ) ? $properties[ $property_name ] : null; + return $properties[ $property_name ] ?? null; } } diff --git a/tests/php/Unit/Modules/ShortCodeTest.php b/tests/php/Unit/Modules/ShortCodeTest.php index 0d1f270a..eec2f366 100644 --- a/tests/php/Unit/Modules/ShortCodeTest.php +++ b/tests/php/Unit/Modules/ShortCodeTest.php @@ -103,7 +103,7 @@ public function testCallbackWhenUserIsLoggedIn() { [ 'args' => [ [ - 'button_text' => __( 'Login with google', 'login-with-google' ), + 'button_text' => '', 'force_display' => 'no', 'redirect_to' => 'https://example.com/', ], @@ -137,7 +137,7 @@ public function testCallbackWhenUserIsLoggedOut() { [ 'args' => [ [ - 'button_text' => __( 'Login with google', 'login-with-google' ), + 'button_text' => '', 'force_display' => 'no', 'redirect_to' => null, ], @@ -184,7 +184,7 @@ public function testCallbackWhenUserIsLoggedOut() { [ '/some/path/templates/google-login-button.php', [ - 'button_text' => 'Login with google', + 'button_text' => '', 'force_display' => 'no', 'redirect_to' => null, 'login_url' => 'https://google.com/auth/', diff --git a/tests/php/Unit/Utils/GoogleClientTest.php b/tests/php/Unit/Utils/GoogleClientTest.php index 8a3b24bb..ae0b25d2 100644 --- a/tests/php/Unit/Utils/GoogleClientTest.php +++ b/tests/php/Unit/Utils/GoogleClientTest.php @@ -68,7 +68,7 @@ public function testCallWithEmails() { * @covers ::gt_redirect_url */ public function testCallWithOtherMethods() { - WP_Mock::expectFilterNotAdded( 'rtcamp.github_redirect_url', '' ); + WP_Mock::expectFilterNotAdded( 'rtcamp.google_redirect_url', '' ); $this->testee->__call( 'some_other_method', null ); $this->assertConditionsMet();