Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In a multisite setup, when users are visiting a blog/site that there are not a member, I would like to display a link to "HOME" that takes them to their "primary" blog.

I know how to determine if a user is or is not a member of a site with the is_current_blog_user() function. The part I am having a problem with is correctly setting the url/path of the "HOME" link to the current users "primary" blog.

Hypothetical Example:

<a href="<?php this_is_the_path_to_users_primary_blog();?>">HOME</a>

I have found the get_active_blog_for_user (http://codex.wordpress.org/Function_Reference/get_active_blog_for_user) function, and this seems to be a good place to start. But I feel as though I must be missing something, and this must be easier than I am making it.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Indeed, get_active_blog_for_user should work.

$blog = get_active_blog_for_user( get_current_user_id() );
$blog_url = $blog->domain... /* or $blog->path, together with $blog->siteurl */

Alternatively:

$blog_id = get_active_blog_for_user( get_current_user_id() )->blog_id;
// note: changed "->userblog_id" to "->blog_id" in row above to make it work.
switch_to_blog( $blog_id ); /* switch context */
$home_url = home_url();
restore_current_blog(); /* back */
share|improve this answer
    
Thank you! I was able to get to the top option to work flawlessly. I appreciate your help. –  Rachel Baker Mar 19 '12 at 13:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.