/** * @group delete */ public function test_follow_and_delete_blog() { if (!is_multisite()) { return; } // create user and blog $u = $this->factory->user->create(); $b = $this->factory->blog->create(array('title' => 'The Foo Bar Blog', 'user_id' => $u)); // make blog creator follow own blog $f = bp_follow_start_following(array('leader_id' => $b, 'follower_id' => $u, 'follow_type' => 'blogs')); // assert that follow relationship worked $this->assertTrue($f); // prime cache new BP_Follow($b, $u, 'blogs'); bp_follow_get_the_following_count(array('user_id' => $u, 'follow_type' => 'blogs')); bp_follow_get_the_followers_count(array('object_id' => $b, 'follow_type' => 'blogs')); // now delete blog wpmu_delete_blog($b); // check if cache was deleted $this->assertEmpty(wp_cache_get("{$b}:{$u}:blogs", 'bp_follow_data')); $this->assertEmpty(wp_cache_get($u, 'bp_follow_user_blogs_following_count')); $this->assertEmpty(wp_cache_get($b, 'bp_follow_blogs_followers_count')); }
/** * Add a "Following (X)" tab to the members directory. * * This is so the logged-in user can filter the members directory to only * users that the current user is following. * * @uses bp_follow_total_follow_counts() Get the following/followers counts for a user. */ function bp_follow_add_following_tab() { if (!is_user_logged_in()) { return; } $count = bp_follow_get_the_following_count(); if (empty($count)) { return; } ?> <li id="members-following"><a href="<?php echo bp_loggedin_user_domain() . BP_FOLLOWING_SLUG; ?> "><?php printf(__('Following <span>%d</span>', 'bp-follow'), $count); ?> </a></li> <?php }
/** * Get the total followers and total following counts for a user. * * You shouldn't really use this function any more. * * @see bp_follow_get_the_following_count() To grab the following count. * @see bp_follow_get_the_followers_count() To grab the followers count. * * @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. Default to '', which will query follow counts for users. * Passing a follow type such as 'blogs' will only return a 'following' * key and integer zero for the 'followers' key since a user can only follow * blogs. * } * @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' => '')); $retval = array(); $retval['following'] = bp_follow_get_the_following_count(array('user_id' => $r['user_id'], 'follow_type' => $r['follow_type'])); /** * Passing a follow type such as 'blogs' will only return a 'following' * key and integer zero for the 'followers' key since a user can only follow * blogs. */ if (!empty($r['follow_type'])) { $retval['followers'] = 0; } else { $retval['followers'] = bp_follow_get_the_followers_count(array('user_id' => $r['user_id'], 'follow_type' => $r['follow_type'])); } if (empty($r['follow_type'])) { /** * Filter the total follow counts for a user. * * @since 1.0.0 * * @param array $retval Array consisting of 'following' and 'followers' counts. * @param int $user_id The user ID. Defaults to logged-in user ID. */ $retval = apply_filters('bp_follow_total_follow_counts', $retval, $r['user_id']); } else { /** * Filter the total follow counts for a user given a specific follow type. * * @since 1.3.0 * * @param array $retval Array consisting of 'following' and 'followers' counts. Note: 'followers' * is always going to be 0, since a user can only follow a given follow type. * @param int $user_id The user ID. Defaults to logged-in user ID. */ $retval = apply_filters('bp_follow_total_follow_' . $r['follow_type'] . '_counts', $retval, $r['user_id']); } return $retval; }