/** * @group date_query */ public function test_date_query() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $u3 = $this->factory->user->create(); $u4 = $this->factory->user->create(); // follow all users at different dates bp_follow_start_following(array('leader_id' => $u2, 'follower_id' => $u1)); bp_follow_start_following(array('leader_id' => $u3, 'follower_id' => $u1, 'date_recorded' => '2001-01-01 12:00')); bp_follow_start_following(array('leader_id' => $u4, 'follower_id' => $u1, 'date_recorded' => '2005-01-01 12:00')); // 'date_query' before test $query = BP_Follow::get_following($u1, '', array('date_query' => array(array('before' => array('year' => 2004, 'month' => 1, 'day' => 1))))); $this->assertEquals(array($u3), $query); // 'date_query' range test $query = BP_Follow::get_following($u1, '', array('date_query' => array(array('after' => 'January 2nd, 2001', 'before' => array('year' => 2013, 'month' => 1, 'day' => 1), 'inclusive' => true)))); $this->assertEquals(array($u4), $query); // 'date_query' after and relative test $query = BP_Follow::get_following($u1, '', array('date_query' => array(array('after' => '1 day ago')))); $this->assertEquals(array($u2), $query); }
/** * Clear blog count cache when a blog is deleted. * * @param int $blog_id The ID of the blog being deleted */ public function clear_cache_on_blog_delete($blog_id) { // clear followers count for blog wp_cache_delete($blog_id, 'bp_follow_followers_blogs_count'); // clear queried followers for blog wp_cache_delete($blog_id, 'bp_follow_followers_blogs'); // delete each user's blog following count for those that followed the blog $users = BP_Follow::get_followers($blog_id, 'blogs'); if (!empty($users)) { foreach ($users as $user) { wp_cache_delete($user, 'bp_follow_following_blogs_count'); // clear follow relationship wp_cache_delete("{$blog_id}:{$user}:blogs", 'bp_follow_data'); } } }
$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; }
/** * Clear follow cache when a user is deleted. * * @since 1.3.0 * * @param int $user_id The ID of the user being deleted */ function bp_follow_clear_cache_on_user_delete($user_id) { // delete follow cache wp_cache_delete($user_id, 'bp_follow_following_count'); wp_cache_delete($user_id, 'bp_follow_followers_count'); wp_cache_delete($user_id, 'bp_follow_following'); wp_cache_delete($user_id, 'bp_follow_followers'); // delete each user's followers count that the user was following $users = BP_Follow::get_following($user_id); if (!empty($users)) { foreach ($users as $user) { wp_cache_delete($user, 'bp_follow_followers_count'); // clear follow relationship wp_cache_delete("{$user_id}:{$user}:", 'bp_follow_data'); } } }
/** * Removes follow relationships for all users from a user who is deleted or spammed * * @since 1.0.0 * * @uses BP_Follow::delete_all_for_user() Deletes user ID from all following / follower records */ function bp_follow_remove_data($user_id) { do_action('bp_follow_before_remove_data', $user_id); BP_Follow::delete_all_for_user($user_id); do_action('bp_follow_remove_data', $user_id); }
/** * 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; }
/** * Clear activity cache when a user is deleted. * * @param int $user_id The user ID being deleted */ public function clear_cache_on_user_delete($user_id = 0) { // delete user's blog follow count wp_cache_delete($user_id, 'bp_follow_user_activity_following_count'); // delete queried blogs that user was following wp_cache_delete($user_id, 'bp_follow_user_activity_following_query'); // delete each blog's followers count that the user was following $aids = BP_Follow::get_following($user_id, 'activity'); if (!empty($aids)) { foreach ($aids as $aid) { wp_cache_delete($aid, 'bp_follow_activity_followers_count'); } } }
/** * Inject $members_template global with follow status for each member in the * group members loop. * * Once the group members loop has queried and built a $members_template * object, fetch all of the member IDs in the object and bulk fetch the * following status for all the group members in one query. * * This is significantly more efficient that querying for every member inside * of the loop. * * @author r-a-y * @since 1.1 * * @global $members_template The members template object containing all fetched members in the loop * @uses BP_Follow::bulk_check_follow_status() Check the following status for more than one member * @param $has_members - Whether any members where actually returned in the loop * @return $has_members - Return the original $has_members param as this is a filter function. */ function bp_follow_inject_group_member_follow_status($has_members) { global $members_template; if (empty($has_members)) { return $has_members; } $user_ids = array(); foreach ((array) $members_template->members as $i => $member) { if ($member->user_id != bp_loggedin_user_id()) { $user_ids[] = $member->user_id; } $members_template->members[$i]->is_following = false; } if (empty($user_ids)) { return $has_members; } $following = BP_Follow::bulk_check_follow_status($user_ids); if (empty($following)) { return $has_members; } foreach ((array) $following as $is_following) { foreach ((array) $members_template->members as $i => $member) { if ($is_following->leader_id == $member->user_id) { $members_template->members[$i]->is_following = true; } } } return $has_members; }
/** * Get the followers count for a particular item. * * Defaults to the number of users following the logged-in user. * * @since 1.3.0 * * @param array $args See bp_follow_get_common_args() * @return int */ function bp_follow_get_the_followers_count($args = array()) { $r = bp_follow_get_common_args($args); // fetch cache $retval = wp_cache_get($r['object_id'], "bp_follow_{$r['object']}_followers_count"); // query if necessary if (false === $retval) { $retval = BP_Follow::get_followers_count($r['object_id'], $r['follow_type']); wp_cache_set($r['object_id'], $retval, "bp_follow_{$r['object']}_followers_count"); } /** * Dynamic filter for the followers count. * * Defaults to 'bp_follow_get_user_followers_count'. * * @since 1.3.0 * * @param int $retval The followers count. * @param int $object_id The object ID. Defaults to logged-in user ID. */ return apply_filters("bp_follow_get_{$r['object']}_followers_count", $retval, $r['object_id']); }