wp-includes/ms-functions.php:45Gets one of a user's active blogs.
$user_idintWP_Site|object|null|falsefunction get_active_blog_for_user( $user_id ) { $blogs = get_blogs_of_user( $user_id ); if ( empty( $blogs ) ) { return null; } if ( ! is_multisite() ) { return $blogs[ get_current_blog_id() ]; } $primary = null; $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); $first_blog = current( $blogs ); if ( false !== $primary_blog ) { if ( ! isset( $blogs[ $primary_blog ] ) ) { update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); $primary = get_site( $first_blog->userblog_id ); } else { $primary = get_site( $primary_blog ); } } else { // TODO: Review this call to add_user_to_blog too - to get here the user must have a role on this blog? $result = add_user_to_blog( $first_blog->userblog_id, $user_id, 'subscriber' ); if ( ! is_wp_error( $result ) ) { update_user_meta( $user_id, 'primary_blog', $first_blog->userblog_id ); $primary = $first_blog; } } if ( ( ! is_object( $primary ) ) || ( '1' === $primary->archived || '1' === $primary->spam || '1' === $primary->deleted ) ) { $blogs = get_blogs_of_user( $user_id, true ); // If a user's primary blog is shut down, check their other blogs. $ret = false; if ( is_array( $blogs ) && count( $blogs ) > 0 ) { $current_network_id = get_current_network_id(); foreach ( (array) $blogs as $blog_id => $blog ) { if ( $blog->site_id !== $current_network_id ) { continue; } $details = get_site( $blog_id ); if ( is_object( $details ) && '0' === $details->archived && '0' === $details->spam && '0' === $details->deleted ) { $ret = $details; if ( (int) get_user_meta( $user_id, 'primary_blog', true ) !== $blog_id ) { update_user_meta( $user_id, 'primary_blog', $blog_id ); } if ( ! get_user_meta( $user_id, 'source_domain', true ) ) { update_user_meta( $user_id, 'source_domain', $details->domain ); } break; } } } else { return null; } return $ret; } else { return $primary; }}Introduced in MU (3.0.0). One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
WP_Site|void to WP_Site|object|null|false.verified against sourcesrc/wp-includes/ms-functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.