Skip to content

Commit fa029d6

Browse files
committed
Fix errant log in message (missing password) for some users.
1 parent 1c52131 commit fa029d6

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

readme.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
**Tags:** user, registration, activation, email
55
**Requires at least:** 3.5
66
**Tested up to:** 3.8
7-
**Stable tag:** 1.2.1
7+
**Stable tag:** 1.2.2
88

99
Require users to enter an activation code to access the site the first time. The activation code is emailed upon user registration.
1010

@@ -31,6 +31,9 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
3131

3232
## Changelog ##
3333

34+
### 1.2.2 ###
35+
* Fix errant error message displaying on log in screen for some users
36+
3437
### 1.2.1 ###
3538
* Fix fatal error with new user registration email
3639

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: NateJacobs
44
Tags: user, registration, activation, email
55
Requires at least: 3.5
66
Tested up to: 3.8
7-
Stable tag: 1.2.1
7+
Stable tag: 1.2.2
88

99
Require users to enter an activation code to access the site the first time. The activation code is emailed upon user registration.
1010

@@ -27,6 +27,9 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc
2727

2828
== Changelog ==
2929

30+
= 1.2.2 =
31+
* Fix errant error message displaying on log in screen for some users
32+
3033
= 1.2.1 =
3134
* Fix fatal error with new user registration email
3235

user-activation-email.php

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Plugin Name: User Activation Email
55
* Plugin URI: https://github.com/NateJacobs/User-Activation-Email
66
* Description: Add an activation code to the new user email sent once a user registers. The user must enter this activation code in addition to a username and password to log in successfully the first time.
7-
* Version: 1.2.1
7+
* Version: 1.2.2
88
* License: GPL V2
99
* Author: Nate Jacobs <nate@natejacobs.org>
1010
* Author URI: http://natejacobs.org
@@ -82,49 +82,65 @@ public function activate()
8282
*/
8383
public function check_user_activation_code( $user, $user_login, $password )
8484
{
85+
// get the error class ready
86+
$error = new \WP_Error();
87+
8588
$activation_code = '';
8689

87-
// get user data by login
90+
// first check if either of the two fields are empty
91+
if ( empty( $user_login ) || empty( $password ) )
92+
{
93+
// figure out which one
94+
if ( empty( $user_login ) )
95+
$error->add( 'empty_username', __( 'The username field is empty.', 'user-activation-email' ) );
96+
97+
if ( empty( $password ) )
98+
$error->add( 'empty_password', __( 'The password field is empty.', 'user-activation-email' ) );
99+
100+
// remove the ability to authenticate
101+
remove_action( 'authenticate', 'wp_authenticate_username_password', 20 );
102+
103+
// return appropriate error
104+
return $error;
105+
}
106+
88107
$user_info = get_user_by( 'login', $user_login );
89-
90-
// if the user has entered something in the user name box
91-
if ( $user_info )
108+
109+
// if the object is empty, meaning an invalid username
110+
if( empty( $user_info ) )
111+
{
112+
// add the error message for invalid username
113+
$error->add( 'incorrect user', __( 'Username does not exist', 'user-activation-email' ) );
114+
115+
// remove the ability to authenticate
116+
remove_action( 'authenticate', 'wp_authenticate_username_password', 20 );
117+
118+
// return appropriate error
119+
return $error;
120+
}
121+
else
92122
{
93123
// get the custom user meta defined during registration
94124
$activation_code = get_user_meta( $user_info->ID, $this->user_meta, true );
95125
}
96-
if ( empty( $user_login ) || empty($password) )
126+
127+
if( $activation_code == 'active' )
97128
{
98-
if ( empty($username) )
99-
$user = new WP_Error( 'empty_username', __( '<strong>ERROR</strong>: The username field is empty.', 'user-activation-email' ) );
100-
101-
if ( empty($password) )
102-
$user = new WP_Error( 'empty_password', __( '<strong>ERROR</strong>: The password field is empty.', 'user-activation-email' ) );
129+
return $user;
130+
exit;
103131
}
104132
else
105133
{
106-
if ( $activation_code == 'active' )
107-
{
108-
return $user;
109-
exit;
110-
}
111-
112-
if ( !isset($_POST['activation-code'] ) )
113-
{
114-
$_POST['activation-code'] = false;
115-
}
116-
117-
// if the activation code entered by the user is not identical to the activation code
118-
// stored in the *_usermeta table then deny access
119-
if ( $_POST['activation-code'] !== $activation_code )
134+
if( $_POST['activation-code'] !== $activation_code )
120135
{
121136
// register a new error with the error message set above
122137
$user = new WP_Error( 'access_denied', __( 'Sorry, that activation code does not match. Please try again. You can find the activation code in your welcome email.', 'user-activation-email' ) );
123138
// deny access to login and send back to login page
124139
remove_filter( 'authenticate', 'wp_authenticate_username_password', 20 );
140+
141+
return $user;
125142
}
126-
}
127-
return $user;
143+
}
128144
}
129145

130146
/**

0 commit comments

Comments
 (0)