Skip to content

Instantly share code, notes, and snippets.

@nciske
Created June 9, 2012 13:15
Show Gist options
  • Save nciske/2900933 to your computer and use it in GitHub Desktop.
Save nciske/2900933 to your computer and use it in GitHub Desktop.
Custom Login Error Plugin
<?php
/*
Plugin Name: Custom Login Error
Plugin URI: http://www.thoughtrefinery.com/
Description: Customize error messages on login form
Version: 0.1
Author: Nick Ciske | Thought Refinery
Author URI: http://www.thoughtrefinery.com/
*/
// Quick hack to change authentication messages written for thew MSP WordPress User Group
// https://groups.google.com/forum/?fromgroups#!topic/mpls-stpaul-wordpress/sISiHS6qizo
//drop old filter
remove_filter('authenticate', 'custom_authenticate_username_password', 20, 3);
//add new filter
add_filter('authenticate', 'custom_authenticate_username_password', 30, 3);
//copied from WP 3.3.2 core files
function custom_authenticate_username_password($user, $username, $password) {
if ( is_a($user, 'WP_User') ) { return $user; }
if ( empty($username) || empty($password) ) {
$error = new WP_Error();
if ( empty($username) )
$error->add('empty_username', __('<strong>ERROR</strong>: The USERNAME field is empty.'));
if ( empty($password) )
$error->add('empty_password', __('<strong>ERROR</strong>: The PASSWORD field is empty.'));
return $error;
}
$userdata = get_user_by('login', $username);
if ( !$userdata )
return new WP_Error('invalid_username', sprintf(__('<strong>ERROR</strong>: Invalid USERNAME. <a href="%s" title="Password Lost and Found">Lost your password</a>?'), wp_lostpassword_url()));
if ( is_multisite() ) {
// Is user marked as spam?
if ( 1 == $userdata->spam)
return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Your account has been marked as a spammer.'));
// Is a user's blog marked as spam?
if ( !is_super_admin( $userdata->ID ) && isset($userdata->primary_blog) ) {
$details = get_blog_details( $userdata->primary_blog );
if ( is_object( $details ) && $details->spam == 1 )
return new WP_Error('blog_suspended', __('Site Suspended.'));
}
}
$userdata = apply_filters('wp_authenticate_user', $userdata, $password);
if ( is_wp_error($userdata) )
return $userdata;
if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) )
return new WP_Error( 'incorrect_password', sprintf( __( '<strong>ERROR</strong>: The PASSWORD you entered for the username <strong>%1$s</strong> is incorrect. <a href="%2$s" title="Password Lost and Found">Lost your password</a>?' ),
$username, wp_lostpassword_url() ) );
$user = new WP_User($userdata->ID);
return $user;
}
@saas786
Copy link

saas786 commented Nov 15, 2012

What do you mean by drop old filter

remove_filter('authenticate', 'custom_authenticate_username_password', 20, 3);?????

do you mean
remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3); ??????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment