BP_Blogs_Blog::total_blog_count_for_user( int|null $user_id = null )

Return a count of associated blogs for a given user.

Description

Includes hidden blogs when the logged-in user is the same as the $user_id parameter, or when the logged-in user has the bp_moderate cap.

Parameters

$user_id

(Optional) ID of the user whose blogs are being queried. Defaults to logged-in user.

Default value: null

Return

(int) Blog count for the user.

Source

File: bp-blogs/classes/class-bp-blogs-blog.php

441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
public static function total_blog_count_for_user( $user_id = null ) {
    global $wpdb;
 
    $bp = buddypress();
 
    if ( !$user_id )
        $user_id = bp_displayed_user_id();
 
    // If the user is logged in return the blog count including their hidden blogs.
    if ( ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) || bp_current_user_can( 'bp_moderate' ) ) {
        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
    } else {
        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT b.blog_id) FROM {$bp->blogs->table_name} b LEFT JOIN {$wpdb->base_prefix}blogs wb ON b.blog_id = wb.blog_id WHERE wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND user_id = %d", $user_id ) );
    }
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.