Skip to content

Commit

Permalink
Add action 'openid-connect-generic-register-login-form' to
Browse files Browse the repository at this point in the history
make it possible to grab the login form object and trigger
it from other pages, such as the WooCommerce checkout page.
  • Loading branch information
Christian Grothoff committed Oct 17, 2020
1 parent 7560701 commit 97e36e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions includes/openid-connect-generic-login-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );

Expand Down
33 changes: 33 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 97e36e2

Please sign in to comment.