Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to be able to create custom login errors.

For instance if a user visits a restricted area without being logged in then I am redirecting to wp-login.php?ref=access and I would like to output Restricted area, please login to continue. or something similar.

Any idea how to do this. I found that there are filters for login_errors but I can't find anywhere else in the code this comes up, except in the login page itself.

Lastly, I really don't want to have to change any of the core files to do this either. I've spent a lot of time and energy trying to make sure that the wordpress core is completely untouched so that I can upgrade it.

Anyone have any ideas?

Thank you

Tom

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

From quick look at the login screen code (ouch):

add_action('login_head','ref_access');

function ref_access() {

    global $error;

    if( !empty($_GET['ref']) && 'access' == $_GET['ref'] )
        $error  = 'Restricted area, please login to continue.';
}
share|improve this answer
    
oh, brilliant. :) Thank you. How the hell did you figure that out?! :p Thanks a lot rarst. –  Thomas Clayson Apr 8 '11 at 9:55
    
@Thomas Clayson see the code of login_header() function. It expects error passed (which would probably require you to add and process custom action, messy) but it also checks that global $error variable which is trivial to change as you see. :) –  Rarst Apr 8 '11 at 10:11
add comment

(NOTE: This doesn't exactly answer your question.)

If I am not wrong, the login_errors filter that you are talking about is for displaying a message when a wrong username/password is entered.

So, by default, you'd be displayed this when you enter a wrong username:

ERROR: Invalid username.

And this for a wrong password:

ERROR: The password you entered for the username XXXXX is incorrect.

The thing is, you can use the login_errors filter to display a custom message:

function fake_error(){
    return 'SORRY, LOGIN DISABLED!';
}
add_filter( 'login_errors', 'fake_error' );

Generally, used as a security (through obscurity?) measure, used to prevent attacker from knowing whether he's entered a wrong username or a wrong password.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.