I need(ed) a way to redirect my users to their primary blog when they try to log into the main blog (where they are subscribers).
Search as I might, no-one seemed to have an answer beyond telling the people who asked to "search for the answer." (This has been going on for several years apparently.)
So, I present to you a simple core hack (that IMHO should be the default behavior) to redirect users to their Primary blog instead of the profile.php on the main blog (as is the default.)
Modify wp-login.php at line 485:
if ( !is_wp_error($user) ) {
// If the user can't edit posts, send them to their profile.
if ( !$user->has_cap('edit_posts') && ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
$primary = get_usermeta($user->ID , 'primary_blog'); //get primary blog ID
if ($primary && $primary != "1"){ //if the users have a primary blog, and its not the main blog... (may not be needed on all installs)
$redirect_one = get_blogaddress_by_id( $primary ); //get their primary blog
$redirect_to = $redirect_one ."wp-admin"; //tack on the wp-admin page
} else
$redirect_to = admin_url('profile.php'); // otherwise, do the "send to profile" thing that is default
}
wp_safe_redirect($redirect_to);
exit();
}
1) Anyone see a fatal problem with this? (so far it seems to be working quite well)
2) If anyone has a more elegant way to do this, please let me know.
3) For those searching desperately for a way to do this, happy hacking.