wordpress plugin add_filter(login_redirect does not work


Staff member
I made a simple plugin from this <a href="http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect" rel="nofollow">example</a>:

Plugin Name: Redirect on login
Plugin URI: some URI
Description: Custom Redirect on login
Author: Some Autor
Version: 1.0
Author URI: some URI

function my_login_redirect($redirect_to, $request){
global $current_user;
//is there a user to check?
    //check for admins
    if(in_array("administrator", $current_user-&gt;roles))
       return home_url("/wp-admin/?administrator");
        return home_url("?NOTadministrator");
add_filter("login_redirect", "my_login_redirect", 10, 3);


It only works if you are already logged in.

Please try it - drop the plugin code in your WordPress plugins directory - activate it - <strong>make sure you are fully logged out</strong> - and it will only redirect you to the
if you have already logged in.

What do the <strong>10, 3</strong> represent anyway, in this case?

From the other examples on this website and other websites - people are making reference to the
instead of the global
and other information - but I do not see any full code that shows a full functioning copy paste plugin using these methods. I am not asking someone to do my work for me - I just would really need to see a full working example of this.

If you have a full working example that clearly shows all of the variable and values that are needed - can you please post it here?
Thank you very much.

I'm adding another example and then going to jump off a bridge - I haven't wasted so much time on something since I first began programming.

I don't understand how <strong>login_redirect</strong> can work - if I can't determine the users information at the time it is called.

     function my_login_redirect(){


        if($user-&gt;has_cap('manage_options')) {
            return home_url("/wp-admin/?administrator");
            return home_url("?NOTadministrator");


        echo "WHY DOES $user-&gt;ID NOT HAVE ANY VALUE YET WHEN CALLING 'login_redirect'? How am I to decide where to send the user - if I do not know who the user is because - I can not get the user ID yet?!";


 add_filter('login_redirect', 'my_login_redirect', 10, 3);