The MU forums have moved to WordPress.org

Best way to get users primary blog? (3 posts)

  1. delayedinsanity
    Member
    Posted 14 years ago #

    Is this the best way of getting this information? It seems the user data isn't available in the global space anywhere I can see by default, but I could be wrong about that.

    $user = wp_get_current_user();
    $addr = get_blogaddress_by_id($user->primary_blog);

    It's only two lines, can't go wrong with that... though if there's a function that does this already, why duplicate right?

  2. dsader
    Member
    Posted 14 years ago #

    Same circus, new clowns:

    $user = wp_get_current_user();
    $details = get_active_blog_for_user( $user->ID );
    $addr = $details->siteurl;

    $details includes the following:

    stdClass Object
    (
        [blog_id] => 63
        [site_id] => 1
        [domain] => domain.tld
        [path] => /
        [registered] => 2006-05-10 00:56:29
        [last_updated] => 2009-09-03 02:52:54
        [public] => 1
        [archived] => 0
        [mature] => 0
        [spam] => 0
        [deleted] => 0
        [lang_id] => 0
        [blogname] => Pingo Lingo
        [siteurl] => http://domain.site.tld
        [post_count] => 1222
    )

    $details->blogname being quite useful. get_active_blog_for_user has the bonus effect of double checking that the current user is a member of at least the dashboard blog and eventually spits out their primary_blog as that if they have no other blog.

  3. delayedinsanity
    Member
    Posted 14 years ago #

    Thanks dsader. :) Learning as I go.

About this Topic

  • Started 14 years ago by delayedinsanity
  • Latest reply from delayedinsanity