Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/Modules/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
);

Expand Down Expand Up @@ -174,7 +174,7 @@ private function markup( array $args = [] ): string {
[
'login_url' => '#',
'custom_btn_text' => '',
'forceDisplay' => false,
'force_display' => false,
]
);

Expand Down
6 changes: 2 additions & 4 deletions src/Modules/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions src/Utils/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions src/Utils/TokenVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down Expand Up @@ -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.
*
Expand Down
32 changes: 16 additions & 16 deletions templates/google-login-button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
}
?>
<div class="wp_google_login">
<div class="wp_google_login__button-container">
<a class="wp_google_login__button"
<?php
printf( ' href="%s"', esc_url( $button_url ) );
?>
>
<a class="wp_google_login__button" href="<?php echo esc_url( $button_url ); ?>">
<span class="wp_google_login__google-icon"></span>
<?php echo esc_html( $button_text ); ?>
</a>
Expand Down
2 changes: 1 addition & 1 deletion tests/php/PrivateAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions tests/php/Unit/Modules/ShortCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
],
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testCallbackWhenUserIsLoggedOut() {
[
'args' => [
[
'button_text' => __( 'Login with google', 'login-with-google' ),
'button_text' => '',
'force_display' => 'no',
'redirect_to' => null,
],
Expand Down Expand Up @@ -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/',
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Unit/Utils/GoogleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down