/** * Returns a comma separated list of user_ids for a given user's followers. * * This can then be passed directly into the members loop querystring. * On failure, returns an integer of zero. Needed when used in a members loop to prevent SQL errors. * * Arguments include: * 'user_id' - The user ID you want to check for followers * * @param mixed $args Arguments can be passed as an associative array or as a URL argument string * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() * @return Mixed Comma-seperated string of user IDs on success. Integer zero on failure. */ function bp_get_follower_ids($args = '') { $r = wp_parse_args($args, array('user_id' => bp_displayed_user_id())); $ids = implode(',', (array) bp_follow_get_followers(array('user_id' => $r['user_id']))); $ids = empty($ids) ? 0 : $ids; return apply_filters('bp_get_follower_ids', $ids, $r['user_id']); }
/** * Filters the user suggestions query to limit by followers only. * * Only available in BP 2.1+. * * @since 1.3.0 * * @see bp_follow_user_suggestions_args() * @param array $user_query User query arguments. See {@link BP_User_Query}. */ function bp_follow_user_follow_suggestions($user_query) { if (isset(buddypress()->follow->only_friends_override)) { unset(buddypress()->follow->only_friends_override); // limit suggestions to followers $user_query['include'] = bp_follow_get_followers(array('user_id' => bp_loggedin_user_id())); } return $user_query; }
function rtmedia_api_followers($user_id) { if (empty($user_id)) { return false; } $followers = bp_follow_get_followers(array('user_id' => $user_id)); return $followers; }
/** * @group bp_follow_get_followers */ public function test_bp_follow_get_followers() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $u3 = $this->factory->user->create(); $u4 = $this->factory->user->create(); // let user 1 be followed by everyone bp_follow_start_following(array('leader_id' => $u1, 'follower_id' => $u2)); bp_follow_start_following(array('leader_id' => $u1, 'follower_id' => $u3)); bp_follow_start_following(array('leader_id' => $u1, 'follower_id' => $u4)); // get followers for user 1 bp_follow_get_followers(array('user_id' => $u1)); // assert $this->assertEqualSets(array($u2, $u3, $u4), wp_cache_get($u1, 'bp_follow_user_followers_query')); // one user stops following user 1 bp_follow_stop_following(array('leader_id' => $u1, 'follower_id' => $u4)); // make sure cache is invalidated $this->assertEmpty(wp_cache_get($u1, 'bp_follow_user_followers_query')); }
/** * Filters the user suggestions query to limit by followers only. * * Only available in BP 2.1+. * * @since 1.3.0 * * @see bp_follow_user_suggestions_args() * @param array $user_query User query arguments. See {@link BP_User_Query}. */ function bp_follow_user_follow_suggestions($user_query) { if (isset(buddypress()->follow->only_friends_override)) { unset(buddypress()->follow->only_friends_override); // limit suggestions to followers $user_query['include'] = bp_follow_get_followers(array('user_id' => bp_loggedin_user_id())); // No followers, so don't return any suggestions. if (empty($user_query['include']) && false === is_super_admin(bp_loggedin_user_id())) { $user_query['include'] = (array) 0; } } return $user_query; }