I made a simple plugin from this example:
<?php
/*
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;
get_currentuserinfo();
//is there a user to check?
if(is_array($current_user->roles))
{
//check for admins
if(in_array("administrator", $current_user->roles))
return home_url("/wp-admin/?administrator");
else
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 - make sure you are fully logged out - and it will only redirect you to the /wp-admin/?administrator if you have already logged in.
What do the 10, 3 represent anyway, in this case?
From the other examples on this website and other websites - people are making reference to the $user->ID instead of the global $user_ID 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 login_redirect can work - if I can't determine the users information at the time it is called.
function my_login_redirect(){
if($user->ID){
if($user->has_cap('manage_options')) {
return home_url("/wp-admin/?administrator");
}else{
return home_url("?NOTadministrator");
}
}else{
echo "WHY DOES $user->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);
10 represents the priority your function takes among the others filtering login_redirect3 represents the number of arguments your function accepts.See: http://codex.wordpress.org/Function_Reference/add_filter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With