function bp_blogs_total_blogs_for_user($user_id = 0) { if (empty($user_id)) { $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); } if (!($count = wp_cache_get('bp_total_blogs_for_user_' . $user_id, 'bp'))) { $count = BP_Blogs_Blog::total_blog_count_for_user($user_id); wp_cache_set('bp_total_blogs_for_user_' . $user_id, $count, 'bp'); } return $count; }
function bp_blogs_total_blogs_for_user($user_id = 0) { global $bp; if (!$user_id) { $user_id = $bp->displayed_user->id ? $bp->displayed_user->id : $bp->loggedin_user->id; } if (!($count = nxt_cache_get('bp_total_blogs_for_user_' . $user_id, 'bp'))) { $count = BP_Blogs_Blog::total_blog_count_for_user($user_id); nxt_cache_set('bp_total_blogs_for_user_' . $user_id, $count, 'bp'); } return $count; }
/** * Get the total number of blogs being tracked by BP for a specific user. * * @since BuddyPress (1.2.0) * * @param int $user_id ID of the user being queried. Default: on a user page, * the displayed user. Otherwise, the logged-in user. * @return int $count Total blog count for the user. */ function bp_blogs_total_blogs_for_user($user_id = 0) { if (empty($user_id)) { $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); } // no user ID? do not attempt to look at cache if (empty($user_id)) { return 0; } $count = wp_cache_get('bp_total_blogs_for_user_' . $user_id, 'bp'); if (false === $count) { $count = BP_Blogs_Blog::total_blog_count_for_user($user_id); wp_cache_set('bp_total_blogs_for_user_' . $user_id, $count, 'bp'); } return $count; }
/** * Get all of a user's blogs, as tracked by BuddyPress. * * Note that this is different from the WordPress function * {@link get_blogs_of_user()}; the current method returns only those * blogs that have been recorded by BuddyPress, while the WP function * does a true query of a user's blog capabilities. * * @param int $user_id Optional. ID of the user whose blogs are being * queried. Defaults to logged-in user. * @param bool $show_hidden Optional. Whether to include blogs that are not marked * public. Defaults to true when viewing one's own profile. * @return array Multidimensional results array, structured as follows: * 'blogs' - Array of located blog objects. * 'total' - A count of the total blogs for the user. */ public static function get_blogs_for_user($user_id = 0, $show_hidden = false) { global $wpdb; $bp = buddypress(); if (!$user_id) { $user_id = bp_displayed_user_id(); } // Show logged in users their hidden blogs. if (!bp_is_my_profile() && !$show_hidden) { $blogs = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.public = 1 AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id)); } else { $blogs = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT b.blog_id, b.id, bm1.meta_value as name, wb.domain, wb.path FROM {$bp->blogs->table_name} b, {$wpdb->base_prefix}blogs wb, {$bp->blogs->table_name_blogmeta} bm1 WHERE b.blog_id = wb.blog_id AND b.blog_id = bm1.blog_id AND bm1.meta_key = 'name' AND wb.deleted = 0 AND wb.spam = 0 AND wb.mature = 0 AND wb.archived = '0' AND b.user_id = %d ORDER BY b.blog_id", $user_id)); } $total_blog_count = BP_Blogs_Blog::total_blog_count_for_user($user_id); $user_blogs = array(); foreach ((array) $blogs as $blog) { $user_blogs[$blog->blog_id] = new stdClass(); $user_blogs[$blog->blog_id]->id = $blog->id; $user_blogs[$blog->blog_id]->blog_id = $blog->blog_id; $user_blogs[$blog->blog_id]->siteurl = is_ssl() ? 'https://' . $blog->domain . $blog->path : 'http://' . $blog->domain . $blog->path; $user_blogs[$blog->blog_id]->name = $blog->name; } return array('blogs' => $user_blogs, 'count' => $total_blog_count); }
function bp_blogs_total_blogs_for_user( $user_id = false ) { global $bp; if ( !$user_id ) $user_id = ( $bp->displayed_user->id ) ? $bp->displayed_user->id : $bp->loggedin_user->id; if ( !$count = wp_cache_get( 'bp_total_blogs_for_user_' . $user_id, 'bp' ) ) { $count = BP_Blogs_Blog::total_blog_count_for_user( $user_id ); wp_cache_set( 'bp_total_blogs_for_user_' . $user_id, $count, 'bp' ); } return $count; }