diff --git a/core/um-actions-form.php b/core/um-actions-form.php index f61e0fce..2e88d857 100644 --- a/core/um-actions-form.php +++ b/core/um-actions-form.php @@ -1,7 +1,7 @@ form->add_error( 'username', __('Please enter your username or email') ); + } + + if ( isset( $args['user_login'] ) && $args['user_login'] == '' ) { + $ultimatemember->form->add_error( 'user_login', __('Please enter your username') ); + } + + if ( isset( $args['user_email'] ) && $args['user_email'] == '' ) { + $ultimatemember->form->add_error( 'user_email', __('Please enter your email') ); + } + + if ( isset( $args['username'] ) ) { + $field = 'username'; + if ( is_email( $args['username'] ) ) { + $is_email = true; + $data = get_user_by('email', $args['username'] ); + $user_name = (isset ( $data->user_login ) ) ? $data->user_login : null; + } else { + $user_name = $args['username']; + } + } else if ( isset( $args['user_email'] ) ) { + $field = 'user_email'; + $is_email = true; + $data = get_user_by('email', $args['user_email'] ); + $user_name = (isset ( $data->user_login ) ) ? $data->user_login : null; + } else { + $field = 'user_login'; + $user_name = $args['user_login']; + } + + if ( !username_exists( $user_name ) ) { + if ( $is_email ) { + $ultimatemember->form->add_error( $field, __(' Sorry, we can\'t find an account with that email address') ); + } else { + $ultimatemember->form->add_error( $field, __(' Sorry, we can\'t find an account with that username') ); + } + } else { + if ( $args['user_password'] == '' ) { + $ultimatemember->form->add_error( 'user_password', __('Please enter your password') ); + } + } + + $check = wp_authenticate_username_password( null, $user_name, $args['user_password'] ); + + if ( is_wp_error( $check ) ) { + $err = $check->get_error_code(); + switch( $err ) { + + default: + + break; + + case 'incorrect_password': + if ( username_exists( $user_name ) ) { + $ultimatemember->form->add_error( 'user_password', __('That password is incorrect. Please try again.') ); + } + break; + + } + } else { + $ultimatemember->login->auth_id = username_exists( $user_name ); + } + + } + /*** *** @login user ***/ - add_action('um_user_login', 'um_user_login', 10, 2); - function um_user_login($user_id, $args){ + add_action('um_user_login', 'um_user_login', 10); + function um_user_login($args){ global $ultimatemember; + extract( $args ); + $user_id = $ultimatemember->login->auth_id; + um_fetch_user( $user_id ); $ultimatemember->user->auto_login( $user_id ); + + $after = um_user('after_login'); + switch( $after ) { + + case 'redirect_profile': + exit( wp_redirect( um_user_profile_url() ) ); + break; + + case 'redirect_url': + exit( wp_redirect( um_user('login_redirect_url') ) ); + break; + + case 'refresh': + exit( wp_redirect( $ultimatemember->permalinks->get_current_url() ) ); + break; + + } } @@ -20,7 +118,7 @@ function um_submit_form_login($args){ global $ultimatemember; - if ( !isset($ultimatemember->form->errors) ) do_action('um_user_login', $args); + if ( !isset($ultimatemember->form->errors) ) do_action( 'um_user_login', $args ); do_action('um_user_login_extra_hook', $args ); diff --git a/core/um-actions-register.php b/core/um-actions-register.php index 70a44052..1d0b38fb 100644 --- a/core/um-actions-register.php +++ b/core/um-actions-register.php @@ -125,35 +125,35 @@ do_action("um_post_registration_global_hook", $user_id, $args); do_action("um_post_registration_{$status}_hook", $user_id, $args); - - // tracking and redirect + if ( !is_admin() ) { - if ( $status == 'approved' ) { + if ( $status == 'approved' ) { + + $ultimatemember->user->auto_login($user_id); + if ( um_user('auto_approve_act') == 'redirect_url' && um_user('auto_approve_url') !== '' ) exit( wp_redirect( um_user('auto_approve_url') ) ); + if ( um_user('auto_approve_act') == 'redirect_profile' ) exit( wp_redirect( um_user_profile_url() ) ); - $ultimatemember->user->auto_login($user_id); - if ( um_user('auto_approve_act') == 'redirect_url' && um_user('auto_approve_url') !== '' ) exit( wp_redirect( um_user('auto_approve_url') ) ); - if ( um_user('auto_approve_act') == 'redirect_profile' ) exit( wp_redirect( um_user_profile_url() ) ); + } + + if ( $status != 'approved' ) { + + if ( um_user( $status . '_action' ) == 'redirect_url' && um_user( $status . '_url' ) != '' ) { + exit( wp_redirect( um_user( $status . '_url' ) ) ); + } + + if ( um_user( $status . '_action' ) == 'show_message' && um_user( $status . '_message' ) != '' ) { + $url = $ultimatemember->permalinks->add_query( 'message', $status ); + $url = $ultimatemember->permalinks->add_query( 'uid', um_user('ID') ); + exit( wp_redirect( $url ) ); + } + + } + + do_action("track_{$status}_user_registration"); } - if ( $status != 'approved' ) { - - if ( um_user( $status . '_action' ) == 'redirect_url' && um_user( $status . '_url' ) != '' ) { - exit( wp_redirect( um_user( $status . '_url' ) ) ); - } - - if ( um_user( $status . '_action' ) == 'show_message' && um_user( $status . '_message' ) != '' ) { - $url = $ultimatemember->permalinks->add_query( 'message', $status ); - $url = $ultimatemember->permalinks->add_query( 'uid', um_user('ID') ); - exit( wp_redirect( $url ) ); - } - - } - - do_action("track_{$status}_user_registration"); - - } } /*** diff --git a/core/um-form.php b/core/um-form.php index c2a49308..a27013e0 100644 --- a/core/um-form.php +++ b/core/um-form.php @@ -86,11 +86,9 @@ class UM_Form { /* Continue based on form mode - pre-validation */ - do_action("um_submit_form_errors_hook", $this->post_form); - - do_action("um_submit_form_errors_hook__blacklist", $this->post_form); - - do_action("um_submit_form_{$this->post_form['mode']}", $this->post_form); + do_action("um_submit_form_errors_hook", $this->post_form ); + + do_action("um_submit_form_{$this->post_form['mode']}", $this->post_form ); } diff --git a/core/um-short-functions.php b/core/um-short-functions.php index 30479999..7f55e2dd 100644 --- a/core/um-short-functions.php +++ b/core/um-short-functions.php @@ -5,12 +5,18 @@ ***/ function um_get_core_page( $slug, $updated = false) { global $ultimatemember; - if ( $ultimatemember->permalinks->core[ $slug ] ) + + if ( isset( $ultimatemember->permalinks->core[ $slug ] ) ) { + $url = get_permalink( $ultimatemember->permalinks->core[ $slug ] ); - if ( $updated ) { + + if ( $updated ) $url = add_query_arg( 'updated', $updated, $url ); - } + return $url; + + } + return ''; } diff --git a/core/um-uninstall.php b/core/um-uninstall.php index 92cd759e..68a8b159 100644 --- a/core/um-uninstall.php +++ b/core/um-uninstall.php @@ -29,7 +29,7 @@ class UM_Uninstall { } - $roles = get_posts( array( 'post_type' => 'um_role', 'number' => 999 ) ); + $roles = get_posts( array( 'post_type' => 'um_role', 'numberposts' => -1 ) ); foreach( $roles as $role ) { wp_delete_post( $role->ID, 1 ); }