diff --git a/includes/openid-connect-generic-login-form.php b/includes/openid-connect-generic-login-form.php index 401b463c..aff7c9f8 100644 --- a/includes/openid-connect-generic-login-form.php +++ b/includes/openid-connect-generic-login-form.php @@ -61,6 +61,9 @@ static public function register( $settings, $client_wrapper ) { // Alter the login form as dictated by settings. add_filter( 'login_message', array( $login_form, 'handle_login_page' ), 99 ); + // Allow extensions to hook the login form. + do_action( 'openid-connect-generic-register-login-form', $login_form ); + // Add a shortcode for the login button. add_shortcode( 'openid_connect_generic_login_button', array( $login_form, 'make_login_button' ) ); diff --git a/readme.md b/readme.md index 565e00f6..55752671 100644 --- a/readme.md +++ b/readme.md @@ -37,6 +37,7 @@ Much of the documentation can be found on the Settings > OpenID Connect Generic - [openid-connect-generic-user-update](#openid-connect-generic-user-update) - [openid-connect-generic-update-user-using-current-claim](#openid-connect-generic-update-user-using-current-claim) - [openid-connect-generic-redirect-user-back](#openid-connect-generic-redirect-user-back) + - [openid-connect-generic-register-login-form](#openid-connect-generic-register-login-form) ## Installation @@ -366,6 +367,38 @@ add_action('openid-connect-generic-redirect-user-back', function( $redirect_url, }, 10, 2); ``` + +#### `openid-connect-generic-register-login-form` + +Allow user to add the login form to various pages, such as WooCommerce's checkout page. It will fire +whenever the plugin is loaded and pass the login form to the callback. + +Provides 1 argument: the login form instance. + +``` +add_action ('openid-connect-generic-register-login-form', + function ( $login_form ) { + + // show login form at the shopping cart (if not logged in) + add_action( 'woocommerce_before_checkout_billing_form', + function () use ( $login_form ) { + $user = wp_get_current_user (); + if (0 == $user->ID) { + // ID 0 is used to indicate user is not logged in. + // Re-use filter logic to generate login page + print ( $login_form->handle_login_page ('') ); + } + }); + + // Add action to set cookie to redirect back to current + // (checkout) page after OIDC provided the data + add_action( 'woocommerce_before_checkout_billing_form', + array( $login_form, 'handle_redirect_cookie' ) ); + + } +); +``` + ### User Meta Data This plugin stores meta data about the user for both practical and debugging purposes.