/** * Get the total followers and total following counts for a user. * * @since 1.0.0 * * @param array $args { * Array of arguments. * @type int $user_id The user ID to grab follow counts for. * } * @return array [ followers => int, following => int ] */ function bp_follow_total_follow_counts($args = '') { $r = wp_parse_args($args, array('user_id' => bp_loggedin_user_id())); $count = false; /* try to get locally-cached values first */ // logged-in user if ($r['user_id'] == bp_loggedin_user_id() && is_user_logged_in()) { global $bp; if (!empty($bp->loggedin_user->total_follow_counts)) { $count = $bp->loggedin_user->total_follow_counts; } // displayed user } elseif ($r['user_id'] == bp_displayed_user_id() && bp_is_user()) { global $bp; if (!empty($bp->displayed_user->total_follow_counts)) { $count = $bp->displayed_user->total_follow_counts; } } // no cached value, so query for it if ($count === false) { $count = BP_Follow::get_counts($r['user_id']); } return apply_filters('bp_follow_total_follow_counts', $count, $r['user_id']); }
$output .= '<div class="clearfix">'; $output .= '<ul data-max-slides="' . $max_slides . '" data-min-slides="' . $min_slides . '" data-item-width="' . $item_width . '" class="gears-carousel-standard bp-members-carousel">'; while (bp_members()) { bp_the_member(); $output .= '<li class="carousel-item">'; $name = bp_get_member_name(); $permalink = bp_get_member_permalink(); $last_active = bp_get_member_last_active(); $output .= '<a class="members-name" href="' . esc_url($permalink) . '" title="' . esc_attr($name) . '">'; $output .= esc_attr($name); $output .= '</a>'; $output .= '<a href="' . esc_url($permalink) . '" title="' . esc_attr($name) . '">'; $output .= bp_get_member_avatar(array('type' => 'full')); $output .= '</a>'; if (class_exists('BP_Follow')) { if (method_exists('BP_Follow', 'get_counts')) { $follow_count = BP_Follow::get_counts(bp_get_member_user_id()); $follow_label = $follow_count['followers'] == 1 ? 'Follower' : 'Followers'; $output .= '<p><strong>' . $follow_count['followers'] . ' ' . $follow_label . '</strong></p>'; } } $output .= '</li>'; } $output .= '</ul>'; $output .= '</div>'; echo $output; } } else { echo $this->bp_not_installed; }
/** * Get the total followers and total following counts for a user. * * @since 1.0.0 * * @param array $args { * Array of arguments. * @type int $user_id The user ID to grab follow counts for. * @type string $follow_type The follow type * } * @return array [ followers => int, following => int ] */ function bp_follow_total_follow_counts($args = '') { $r = wp_parse_args($args, array('user_id' => bp_loggedin_user_id(), 'follow_type' => '')); $counts = BP_Follow::get_counts($r['user_id'], $r['follow_type']); if (empty($r['follow_type'])) { $retval = apply_filters('bp_follow_total_follow_counts', $counts, $r['user_id']); } else { $retval = apply_filters('bp_follow_total_follow_' . $r['follow_type'] . '_counts', $counts, $r['user_id']); } return $retval; }