/** * Returns a comma separated list of user_ids for a given user's following. * * 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 a following * * @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_following_ids($args = '') { $r = wp_parse_args($args, array('user_id' => bp_displayed_user_id())); $ids = implode(',', (array) bp_follow_get_following(array('user_id' => $r['user_id']))); $ids = empty($ids) ? 0 : $ids; return apply_filters('bp_get_following_ids', $ids, $r['user_id']); }
/** * @group bp_follow_get_following */ public function test_bp_follow_get_following_no_cache() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); $u3 = $this->factory->user->create(); $u4 = $this->factory->user->create(); // let user 1 follow everyone bp_follow_start_following(array('leader_id' => $u2, 'follower_id' => $u1)); bp_follow_start_following(array('leader_id' => $u3, 'follower_id' => $u1)); bp_follow_start_following(array('leader_id' => $u4, 'follower_id' => $u1)); // get following for user 1 bp_follow_get_following(array('user_id' => $u1, 'query_args' => array('orderby' => 'id', 'order' => 'ASC'))); // we do not cache following calls with query args at the moment $this->assertEmpty(wp_cache_get($u1, 'bp_follow_user_following_query')); }
/** * Set up activity arguments for use with the 'followblogs' scope. * * For details on the syntax, see {@link BP_Activity_Query}. * * Only applicable to BuddyPress 2.2+. Older BP installs uses the code * available in /modules/blogs-backpat.php. * * @since 1.3.0 * * @param array $retval Empty array by default * @param array $filter Current activity arguments * @return array */ function filter_activity_scope($retval = array(), $filter = array()) { // Determine the user_id if (!empty($filter['user_id'])) { $user_id = $filter['user_id']; } else { $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); } // Get blogs that the user is following $following_ids = bp_follow_get_following(array('user_id' => $user_id, 'follow_type' => 'blogs')); if (empty($following_ids)) { $following_ids = array(0); } // Should we show all items regardless of sitewide visibility? $show_hidden = array(); if (!empty($user_id) && $user_id !== bp_loggedin_user_id()) { $show_hidden = array('column' => 'hide_sitewide', 'value' => 0); } // support BP Groupblog if (function_exists('bp_groupblog_init') && $following_ids !== array(0)) { global $wpdb; $bp = buddypress(); // comma-delimit the blog IDs $delimited_ids = implode(',', $following_ids); $group_ids_connected_to_blogs = $wpdb->get_col("SELECT group_id FROM {$bp->groups->table_name_groupmeta} WHERE meta_key = 'groupblog_blog_id' AND meta_value IN ( " . $delimited_ids . " )"); $clause = array('relation' => 'OR', array('relation' => 'AND', array('column' => 'component', 'value' => buddypress()->blogs->id), array('column' => 'item_id', 'compare' => 'IN', 'value' => (array) $following_ids)), array('relation' => 'AND', array('column' => 'component', 'value' => buddypress()->groups->id), array('column' => 'item_id', 'compare' => 'IN', 'value' => (array) $group_ids_connected_to_blogs), array('column' => 'type', 'value' => 'new_groupblog_post'))); // Regular follow blog clause } else { $clause = array('relation' => 'AND', array('column' => 'component', 'value' => buddypress()->blogs->id), array('column' => 'item_id', 'compare' => 'IN', 'value' => (array) $following_ids)); } $retval = array('relation' => 'AND', $clause, $show_hidden, 'override' => array('filter' => array('user_id' => 0), 'show_hidden' => true)); return $retval; }
/** * Set up a list of members the current user is following for at-mention use. * * This is intended to speed up at-mention lookups for a majority of use cases. * * @since 1.3.0 * * @see bp_activity_mentions_script() */ function bp_follow_prime_mentions_results() { if (!bp_activity_maybe_load_mentions_scripts()) { return; } // Bail out if the site has a ton of users. if (is_multisite() && wp_is_large_network('users')) { return; } $following = bp_follow_get_following(array('user_id' => bp_loggedin_user_id())); if (empty($following)) { return; } $followers_query = new BP_User_Query(array('count_total' => '', 'populate_extras' => false, 'type' => 'alphabetical', 'include' => $following)); $results = array(); foreach ($followers_query->results as $user) { $result = new stdClass(); $result->ID = $user->user_nicename; $result->image = bp_core_fetch_avatar(array('html' => false, 'item_id' => $user->ID)); $result->name = bp_core_get_user_displayname($user->ID); $results[] = $result; } wp_localize_script('bp-mentions', 'BP_Suggestions', array('friends' => $results)); }
function rtmedia_api_following($user_id) { if (empty($user_id)) { return false; } $followers = bp_follow_get_following(array('user_id' => $user_id)); return $followers; }
/** * Get friends/Following user ids * @param type $logged_user_id * @return type */ public static function get_friend_user_ids($logged_user_id) { $friend_ids = array(); if (function_exists('friends_get_friend_user_ids')) { $friend_ids = friends_get_friend_user_ids($logged_user_id); } elseif (function_exists('bp_follow_get_following')) { $friend_ids = bp_follow_get_following(array('user_id' => $logged_user_id)); } return apply_filters('fblike_activity_get_friend_ids', $friend_ids, $logged_user_id); }
/** * Set up activity arguments for use with the 'followblogs' scope. * * For details on the syntax, see {@link BP_Activity_Query}. * * Only applicable to BuddyPress 2.2+. Older BP installs uses the code * available in /modules/blogs-backpat.php. * * @since 1.3.0 * * @param array $retval Empty array by default * @param array $filter Current activity arguments * @return array */ public function filter_activity_scope($retval = array(), $filter = array()) { // Determine the user_id if (!empty($filter['user_id'])) { $user_id = $filter['user_id']; } else { $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : bp_loggedin_user_id(); } // Get activity IDs that the user is following $following_ids = bp_follow_get_following(array('user_id' => $user_id, 'follow_type' => 'activity')); // If no activity, pass largest int value to denote no blogs... sigh. if (empty($following_ids)) { $following_ids = array(0); } // Should we show all items regardless of sitewide visibility? $show_hidden = array(); if (!empty($user_id) && $user_id !== bp_loggedin_user_id()) { $show_hidden = array('column' => 'hide_sitewide', 'value' => 0); } $clause = array('relation' => 'OR', array('column' => 'id', 'compare' => 'IN', 'value' => $following_ids), array('relation' => 'AND', array('column' => 'type', 'value' => 'activity_comment'), array('column' => 'item_id', 'compare' => 'IN', 'value' => $following_ids))); $retval = array('relation' => 'AND', $clause, $show_hidden, 'override' => array('display_comments' => 'stream', 'filter' => array('user_id' => 0), 'show_hidden' => true)); return $retval; }
function bfox_bp_plans_loop_args() { global $bp; wp_parse_str(bp_ajax_querystring('reading_plans'), $args); $type = $args['scope']; if ('personal' == $type) { $args['user_id'] = $bp->loggedin_user->id; } elseif ('following' == $type) { $args['user_id'] = (array) bp_follow_get_following(array('user_id' => $bp->loggedin_user->id)); $args['is_published'] = true; } elseif ('friends' == $type) { $args['user_id'] = (array) friends_get_friend_user_ids($bp->loggedin_user->id); $args['is_published'] = true; } elseif ('groups' == $type) { $groups = groups_get_user_groups($bp->loggedin_user->id); $args['group_id'] = $groups['groups']; } else { $args['is_published'] = true; } $args['filter'] = $args['search_terms']; if (!$args['page']) { $args['page'] = 1; } if (!$args['per_page']) { $args['per_page'] = 20; } return $args; }