Skip to content

Commit 5c0d27b

Browse files
feat: adds filter to restrict users from login
1 parent 0c4ee9c commit 5c0d27b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Modules/Login.php

+17
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ public function authenticate( $user = null ) {
139139
try {
140140
$this->gh_client->set_access_token( $code );
141141
$user = $this->gh_client->user();
142+
143+
if ( empty( $user ) || empty( $user->email ) ) {
144+
return new WP_Error( 'google_login_failed', __( 'Failed to authenticate user.', 'login-with-google' ) );
145+
}
146+
147+
/**
148+
* Filter the restricted emails.
149+
* Default to empty array.
150+
*
151+
* @param array $restricted_emails Array containing restricted emails.
152+
*/
153+
$restricted_emails = apply_filters( 'rtcamp.restrict_user', array() );
154+
155+
if ( in_array( $user->email, $restricted_emails, true ) ) {
156+
return new WP_Error( 'google_login_restricted', __( 'User restricted.', 'login-with-google' ) );
157+
}
158+
142159
$user = $this->authenticator->authenticate( $user );
143160

144161
if ( $user instanceof WP_User ) {

0 commit comments

Comments
 (0)