Add reset password limit options

This commit is contained in:
champsupertramp
2016-04-21 20:05:23 +08:00
parent 37a2df870d
commit 42e95c084a
2 changed files with 47 additions and 4 deletions
+17 -4
View File
@@ -108,16 +108,29 @@
if ( ( !is_email( $user ) && !username_exists( $user ) ) || ( is_email( $user ) && !email_exists( $user ) ) ) {
$ultimatemember->form->add_error('username_b', __('We can\'t find an account registered with that address or username','ultimatemember') );
} else {
if ( is_email( $user ) ) {
$user_id = email_exists( $user );
} else {
$user_id = username_exists( $user );
}
$attempts = (int)get_user_meta( $user_id, 'password_rst_attempts', true );
if ( $attempts >= 3 ) {
$ultimatemember->form->add_error('username_b', __('You have reached the limit for requesting password change for this user already. Contact support if you cannot open the email','ultimatemember') );
} else {
update_user_meta( $user_id, 'password_rst_attempts', $attempts + 1 );
$is_admin = user_can( intval( $user_id ),'manage_options' );
if( um_get_option('enable_reset_password_limit') ){ // if reset password limit is set
if( um_get_option('disable_admin_reset_password_limit') && $is_admin ){
// Triggers this when a user has admin capabilities and when reset password limit is disabled for admins
}else{
$limit = um_get_option('reset_password_limit_number');
if ( $attempts >= $limit ) {
$ultimatemember->form->add_error('username_b', __('You have reached the limit for requesting password change for this user already. Contact support if you cannot open the email','ultimatemember') );
} else {
update_user_meta( $user_id, 'password_rst_attempts', $attempts + 1 );
}
}
}
}
+30
View File
@@ -476,6 +476,36 @@ $this->sections[] = array(
'off' => __('No','ultimatemember'),
),
array(
'id' => 'enable_reset_password_limit',
'type' => 'switch',
'title' => __( 'Enable the Reset Password Limit?','ultimatemember' ),
'default' => 1,
'on' => __('Yes','ultimatemember'),
'off' => __('No','ultimatemember'),
),
array(
'id' => 'reset_password_limit_number',
'type' => 'text',
'title' => __( 'Reset Password Limit','ultimatemember' ),
'desc' => __('Set the maximum reset password limit. If reached the maximum limit, user will be locked from using this.','ultimatemember'),
'default' => 3,
'validate' => 'numeric',
'required' => array('enable_reset_password_limit','=',1),
),
array(
'id' => 'disable_admin_reset_password_limit',
'type' => 'switch',
'title' => __( 'Disable the Reset Password Limit for Admins only?','ultimatemember' ),
'default' => 0,
'on' => __('Yes','ultimatemember'),
'off' => __('No','ultimatemember'),
'required' => array('enable_reset_password_limit','=',1),
),
array(
'id' => 'wpadmin_allow_ips',
'type' => 'textarea',