From 43d2fe6a45fd33dbb0a80f4e3b056fae63a54e3d Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Tue, 13 Dec 2022 16:41:35 +0200 Subject: [PATCH] - possible solution for #1091; --- includes/core/um-actions-login.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/includes/core/um-actions-login.php b/includes/core/um-actions-login.php index ec19ca6f..cc76afdb 100644 --- a/includes/core/um-actions-login.php +++ b/includes/core/um-actions-login.php @@ -59,18 +59,29 @@ function um_submit_form_errors_hook_login( $args ) { UM()->form()->add_error( 'user_password', __( 'Password is incorrect. Please try again.', 'ultimate-member' ) ); } + // Integration with 3rd-party login handlers e.g. 3rd-party reCAPTCHA etc. + $third_party_codes = apply_filters( 'um_custom_authenticate_error_codes', array() ); + // @since 4.18 replacement for 'wp_login_failed' action hook // see WP function wp_authenticate() $ignore_codes = array( 'empty_username', 'empty_password' ); $user = apply_filters( 'authenticate', null, $authenticate, $args['user_password'] ); if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes ) ) { - UM()->form()->add_error( $user->get_error_code(), __( 'Password is incorrect. Please try again.', 'ultimate-member' ) ); + if ( ! empty( $third_party_codes ) && in_array( $user->get_error_code(), $third_party_codes ) ) { + UM()->form()->add_error( $user->get_error_code(), $user->get_error_message() ); + } else { + UM()->form()->add_error( $user->get_error_code(), __( 'Password is incorrect. Please try again.', 'ultimate-member' ) ); + } } $user = apply_filters( 'wp_authenticate_user', $user, $args['user_password'] ); if ( is_wp_error( $user ) && ! in_array( $user->get_error_code(), $ignore_codes ) ) { - UM()->form()->add_error( $user->get_error_code(), __( 'Password is incorrect. Please try again.', 'ultimate-member' ) ); + if ( ! empty( $third_party_codes ) && in_array( $user->get_error_code(), $third_party_codes ) ) { + UM()->form()->add_error( $user->get_error_code(), $user->get_error_message() ); + } else { + UM()->form()->add_error( $user->get_error_code(), __( 'Password is incorrect. Please try again.', 'ultimate-member' ) ); + } } // if there is an error notify wp