/** * 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'); } } }
/** * Fetch the IDs of all the followers of a particular item. * * @since 1.0.0 * * @param array $args { * Array of arguments. * @type int $user_id The user ID to get followers for. * @type string $follow_type The follow type * @type array $query_args The query args. See $query_args parameter in * {@link BP_Follow::get_followers()}. * } * @return array */ function bp_follow_get_followers($args = '') { $r = wp_parse_args($args, array('user_id' => bp_displayed_user_id(), 'follow_type' => '', 'query_args' => array())); $retval = array(); $do_query = true; // setup some variables based on the follow type if (!empty($r['follow_type'])) { $filter = 'bp_follow_get_followers_' . $r['follow_type']; $cachegroup = 'bp_follow_followers_' . $r['follow_type']; } else { $filter = 'bp_follow_get_followers'; $cachegroup = 'bp_follow_followers'; } // check for cache if 'query_args' is empty if (empty($r['query_args'])) { $retval = wp_cache_get($r['user_id'], $cachegroup); if (false !== $retval) { $do_query = false; } } // query if necessary if (true === $do_query) { $retval = BP_Follow::get_followers($r['user_id'], $r['follow_type'], $r['query_args']); // cache if no extra query args - we only cache default args for now if (empty($r['query_args'])) { wp_cache_set($r['user_id'], $retval, $cachegroup); } } return apply_filters($filter, $retval); }
/** * Fetch the user IDs of all the followers of a particular user. * * @since 1.0.0 * * @param array $args { * Array of arguments. * @type int $user_id The user ID to get followers for. * } * @return array */ function bp_follow_get_followers($args = '') { $r = wp_parse_args($args, array('user_id' => bp_displayed_user_id())); return apply_filters('bp_follow_get_followers', BP_Follow::get_followers($r['user_id'])); }
/** * Fetch the IDs for the followers of a particular item. * * @since 1.0.0 * * @param array $args { * Array of arguments. * @type int $user_id The user ID to get followers for. * @type string $follow_type The follow type * @type array $query_args The query args. See $query_args parameter in * {@link BP_Follow::get_followers()}. * } * @return array */ function bp_follow_get_followers($args = '') { $r = bp_follow_get_common_args(wp_parse_args($args, array('user_id' => bp_displayed_user_id()))); $retval = array(); $do_query = true; // Set up filter name if (!empty($r['follow_type'])) { $filter = 'bp_follow_get_followers_' . $r['object']; } else { $filter = 'bp_follow_get_followers'; } // check for cache if 'query_args' is empty if (empty($r['query_args'])) { $retval = wp_cache_get($r['object_id'], "bp_follow_{$r['object']}_followers_query"); if (false !== $retval) { $do_query = false; } } // query if necessary if (true === $do_query) { $retval = BP_Follow::get_followers($r['object_id'], $r['follow_type'], $r['query_args']); // cache if no extra query args - we only cache default args for now if (empty($r['query_args'])) { wp_cache_set($r['object_id'], $retval, "bp_follow_{$r['object']}_followers_query"); // cache count while we're at it wp_cache_set($r['object_id'], $GLOBALS['wpdb']->num_rows, "bp_follow_{$r['object']}_followers_count"); } } /** * Dynamic filter for followers query. * * By default, the filter name is 'bp_follow_get_followers', which filters * the displayed user's followers. * * @since 1.0.0 * @since 1.3.0 Filter is now dynamic. * * @param array $retval Array of follower IDs. */ return apply_filters($filter, $retval); }