<?php
/*
Plugin Name: Simple Login Redirect
Plugin URI: https://premium.wpmudev.org/support/
Description: A simple mu-plugin that redirects users to their subsite on login.
Version: 0.0.1
Author: James Morris - WPMU DEV
Author URI: https://premium.wpmudev.org/profile/jrmorris77
Network: true
*/
function my_login_redirect( $redirect_to, $request, $current_user ) {
$current_user = wp_get_current_user();
if ( $current_user ) {
$user_id = $current_user->ID;
}
if ( isset( $user_id ) ) {
// Get the blogs of this user
$user_blogs = get_blogs_of_user( $user_id );
// Get the URL of the blog
foreach ( $user_blogs AS $user_blog ) {
if ( !isset( $userblogid ) ) {
$userblogid = $user_blog->userblog_id;
return $user_blog->domain;
}
}
// If user has no blog, return to the homepage.
} else {
return home_url();
}
}
add_filter( "login_redirect", "my_login_redirect", 10, 3 );
?>