Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action 'openid-connect-generic-register-login-form' #241

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
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' ) );

}
);
Comment on lines +379 to +399
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example leads me to believe that there is an attempt to get the login form which should already be available by using the openid_connect_generic_login_button shortcode.

```

### User Meta Data

This plugin stores meta data about the user for both practical and debugging purposes.
Expand Down