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 new action hook when user logs in #76

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
23 changes: 21 additions & 2 deletions inc/classes/class-google-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class Google_Auth {
*/
protected $_redirect_to = '';

/**
* @var \WP_User
*/
protected $_user = false;

/**
* @var boolean
*/
protected $_is_logged = false;
/**
* Google_Auth constructor.
*/
Expand All @@ -41,7 +50,7 @@ protected function __construct() {

$this->_client = $this->_get_client();

add_filter( 'authenticate', [ $this, 'authenticate_user' ] );
$this->_is_logged = add_filter( 'authenticate', [ $this, 'authenticate_user' ] );
add_filter( 'login_redirect', [ $this, 'get_login_redirect' ] );
add_filter( 'registration_redirect', [ $this, 'get_login_redirect' ] );
add_filter( 'allowed_redirect_hosts', [ $this, 'maybe_whitelist_subdomain' ] );
Expand Down Expand Up @@ -396,6 +405,8 @@ public function authenticate_user( $user = null ) {
// We found the user.
if ( ! empty( $user ) && $user instanceof \WP_User ) {

$this->_user = $user;

if ( ! $is_mu_site ) {
return $user;
}
Expand Down Expand Up @@ -428,6 +439,7 @@ public function authenticate_user( $user = null ) {
if ( empty( $user ) || ! $user instanceof \WP_User ) {
$user_id = $this->_create_user( $user_info );
$user = get_user_by( 'id', $user_id );
$this->_user = $user;
}

if ( $is_mu_site ) {
Expand All @@ -446,7 +458,14 @@ public function authenticate_user( $user = null ) {
*
* @return string Redirect to URL.
*/
public function get_login_redirect( $redirect_to ) {
public function get_login_redirect( $redirect_to, $requested_redirect_to, $user ) {
if($this->_user instanceof \WP_User && $this->_is_logged){
/**
* This hook provides access to user after login from this plugin.
* @param \WP_User $user logged in.
*/
do_action('wp_google_login_user_loggedin', $user);
}
return ( ! empty( $this->_redirect_to ) ) ? $this->_redirect_to : $redirect_to;
}

Expand Down