From d38e15953305c1bbcf912c0f4d8c2dc08d62dd29 Mon Sep 17 00:00:00 2001
From: "PrikolMen:-b" <44779902+PrikolMen@users.noreply.github.com>
Date: Sun, 4 Dec 2022 15:31:12 +0400
Subject: [PATCH] Login button on all authorization forms
I'm not a very good php developer, but visually this solution works much better
Signed-off-by: PrikolMen:-b <44779902+PrikolMen@users.noreply.github.com>
---
.../openid-connect-generic-login-form.php | 71 ++++++++-----------
1 file changed, 31 insertions(+), 40 deletions(-)
diff --git a/includes/openid-connect-generic-login-form.php b/includes/openid-connect-generic-login-form.php
index 4c76d9ca..f30a2656 100644
--- a/includes/openid-connect-generic-login-form.php
+++ b/includes/openid-connect-generic-login-form.php
@@ -42,6 +42,37 @@ class OpenID_Connect_Generic_Login_Form {
public function __construct( $settings, $client_wrapper ) {
$this->settings = $settings;
$this->client_wrapper = $client_wrapper;
+ add_action( 'login_form', array( $this, 'make_login_button' ) );
+ }
+
+ /**
+ * Create a login button (link).
+ *
+ * @param array $atts Array of optional attributes to override login buton
+ * functionality when used by shortcode.
+ *
+ * @return void
+ */
+ public function make_login_button( $atts = array() ) {
+ $atts = shortcode_atts(
+ array(
+ 'button_text' => __( 'Login with OpenID Connect', 'daggerhart-openid-connect-generic' ),
+ ),
+ $atts,
+ 'openid_connect_generic_login_button'
+ );
+
+ $text = apply_filters( 'openid-connect-generic-login-button-text', $atts['button_text'] );
+ $text = esc_html( $text );
+
+ $href = $this->client_wrapper->get_authentication_url( $atts );
+ $href = esc_url_raw( $href );
+
+ echo <<
+ {$text}
+
+HTML;
}
/**
@@ -58,9 +89,6 @@ public static function register( $settings, $client_wrapper ) {
// Alter the login form as dictated by settings.
add_filter( 'login_message', array( $login_form, 'handle_login_page' ), 99 );
- // Add a shortcode for the login button.
- add_shortcode( 'openid_connect_generic_login_button', array( $login_form, 'make_login_button' ) );
-
$login_form->handle_redirect_login_type_auto();
}
@@ -101,9 +129,6 @@ public function handle_login_page( $message ) {
$message .= $this->make_error_output( sanitize_text_field( wp_unslash( $_GET['login-error'] ) ), $error_message );
}
- // Login button is appended to existing messages in case of error.
- $message .= $this->make_login_button();
-
return $message;
}
@@ -127,40 +152,6 @@ public function make_error_output( $error_code, $error_message ) {
return wp_kses_post( ob_get_clean() );
}
- /**
- * Create a login button (link).
- *
- * @param array $atts Array of optional attributes to override login buton
- * functionality when used by shortcode.
- *
- * @return string
- */
- public function make_login_button( $atts = array() ) {
-
- $atts = shortcode_atts(
- array(
- 'button_text' => __( 'Login with OpenID Connect', 'daggerhart-openid-connect-generic' ),
- ),
- $atts,
- 'openid_connect_generic_login_button'
- );
-
- $text = apply_filters( 'openid-connect-generic-login-button-text', $atts['button_text'] );
- $text = esc_html( $text );
-
- $href = $this->client_wrapper->get_authentication_url( $atts );
- $href = esc_url_raw( $href );
-
- $login_button = <<
- {$text}
-
-HTML;
-
- return $login_button;
-
- }
-
/**
* Removes the login form from the HTML DOM
*