admin管理员组文章数量:1122832
I am modifying my wp-login.php but from within functions.php (in order not to hack the core).
I need to disable one WP_error with code: authentication_failed.
if i hack the core and modify wp-login.php at the code:
foreach ( $wp_error->get_error_codes() as $code ) {
$severity = $wp_error->get_error_data( $code );
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
if ( 'message' == $severity )
$messages .= ' ' . $error_message . "<br />\n";
else
$errors .= ' ' . $error_message . "<br />\n";
}
}
to:
foreach ( $wp_error->get_error_codes() as $code ) {
$severity = $wp_error->get_error_data( $code );
if($code !=='authentication_failed'){ <======= ADDED
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
if ( 'message' == $severity )
$messages .= ' ' . $error_message . "<br />\n";
else
$errors .= ' ' . $error_message . "<br />\n";
}
}
}
It works. But I don't want to hack the core, is there a way to disable it from functions.php?
I am modifying my wp-login.php but from within functions.php (in order not to hack the core).
I need to disable one WP_error with code: authentication_failed.
if i hack the core and modify wp-login.php at the code:
foreach ( $wp_error->get_error_codes() as $code ) {
$severity = $wp_error->get_error_data( $code );
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
if ( 'message' == $severity )
$messages .= ' ' . $error_message . "<br />\n";
else
$errors .= ' ' . $error_message . "<br />\n";
}
}
to:
foreach ( $wp_error->get_error_codes() as $code ) {
$severity = $wp_error->get_error_data( $code );
if($code !=='authentication_failed'){ <======= ADDED
foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
if ( 'message' == $severity )
$messages .= ' ' . $error_message . "<br />\n";
else
$errors .= ' ' . $error_message . "<br />\n";
}
}
}
It works. But I don't want to hack the core, is there a way to disable it from functions.php?
Share Improve this question asked Mar 16, 2015 at 20:06 ccotccot 1493 silver badges12 bronze badges1 Answer
Reset to default 0You can use the pluggable function wp_authenticate to override the core.
https://developer.wordpress.org/reference/functions/wp_authenticate/
Important caution: Test this code on a sandbox before deploying live!
function wp_authenticate($username, $password) {
$username = sanitize_user($username);
$password = trim($password);
$user = apply_filters( 'authenticate', null, $username, $password );
if ( $user == null ) {
$user = new WP_Error( 'authentication_failed', __( '<strong>ERROR</strong>: Invalid username or incorrect password.' ) );
}
$ignore_codes = array( 'authentication_failed' );
if ( is_wp_error( $user ) && !in_array( $user->get_error_code(), $ignore_codes ) ) {
do_action( 'wp_login_failed', $username );
}
return $user;
}
add_action( 'init', 'wp_authenticate' );
本文标签: functionsdisable WPerror authenticationfailed
版权声明:本文标题:functions - disable WP_error: authentication_failed 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736306652a1933034.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论