Forum Replies Created
-
AuthorPosts
-
spamis
ParticipantI am using WP Affiliate Manager and had this same problem – failed login defaulting to the WordPress login page. I found this snippet online and it worked for me with my theme’s (Divi) login page. With failed login it now stays on the same login page. The only thing I can’t get to work is there is no error message telling the user that the login failed. Anyway, you need to put the snippet it in your theme’s function.php file which is hopefully in a child theme folder. I hope this works for you.
function wpcc_front_end_login_fail( $username ) {
$referrer = $_SERVER[‘HTTP_REFERER’];
if ( !empty( $referrer ) && !strstr( $referrer,’wp-login’ ) && !strstr( $referrer,’wp-admin’ ) ) {
$referrer = esc_url( remove_query_arg( ‘login’, $referrer ) );
wp_redirect( $referrer . ‘?login=failed’ );
exit;
}
}
add_action( ‘wp_login_failed’, ‘wpcc_front_end_login_fail’ );function custom_authenticate_wpcc( $user, $username, $password ) {
if ( is_wp_error( $user ) && isset( $_SERVER[ ‘HTTP_REFERER’ ] ) && !strpos( $_SERVER[ ‘HTTP_REFERER’ ], ‘wp-admin’ ) && !strpos( $_SERVER[ ‘HTTP_REFERER’ ], ‘wp-login.php’ ) ) {
$referrer = $_SERVER[ ‘HTTP_REFERER’ ];
foreach ( $user->errors as $key => $error ) {
if ( in_array( $key, array( ’empty_password’, ’empty_username’) ) ) {
unset( $user->errors[ $key ] );
$user->errors[ ‘custom_’.$key ] = $error;
}
}
}return $user;
}
add_filter( ‘authenticate’, ‘custom_authenticate_wpcc’, 31, 3); -
AuthorPosts