コード例 #1
0
 /**
  * @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);
 }
コード例 #2
0
 /**
  * Clear blog count 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_following_blogs_count');
     // delete queried blogs that user was following
     wp_cache_delete($user_id, 'bp_follow_following_blogs');
     // delete each blog's followers count that the user was following
     $blogs = BP_Follow::get_following($user_id, 'blogs');
     if (!empty($blogs)) {
         foreach ($blogs as $blog_id) {
             wp_cache_delete($blog_id, 'bp_follow_followers_blogs_count');
             // clear follow relationship
             wp_cache_delete("{$blog_id}:{$user_id}:blogs", 'bp_follow_data');
         }
     }
 }
コード例 #3
0
/**
 * 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');
        }
    }
}
コード例 #4
0
/**
 * Fetch the user IDs of all the users a particular user is following.
 *
 * @since 1.0.0
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $user_id The user ID to fetch following user IDs for.
 * }
 * @return array
 */
function bp_follow_get_following($args = '')
{
    $r = wp_parse_args($args, array('user_id' => bp_displayed_user_id()));
    return apply_filters('bp_follow_get_following', BP_Follow::get_following($r['user_id']));
}
コード例 #5
0
/**
 * Fetch all IDs that a particular user is following.
 *
 * @since 1.0.0
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $user_id The user ID to fetch following user IDs for.
 *     @type string $follow_type The follow type
 *     @type array $query_args The query args.  See $query_args parameter in
 *           {@link BP_Follow::get_following()}.
 * }
 * @return array
 */
function bp_follow_get_following($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_following_' . $r['follow_type'];
        $cachegroup = 'bp_follow_following_' . $r['follow_type'];
    } else {
        $filter = 'bp_follow_get_following';
        $cachegroup = 'bp_follow_following';
    }
    // 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_following($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);
}
コード例 #6
0
 /**
  * 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');
         }
     }
 }
コード例 #7
0
/**
 * Fetch the IDs that a particular item is following.
 *
 * @since 1.0.0
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $user_id The user ID to fetch following user IDs for.
 *     @type string $follow_type The follow type
 *     @type array $query_args The query args.  See $query_args parameter in
 *           {@link BP_Follow::get_following()}.
 * }
 * @return array
 */
function bp_follow_get_following($args = '')
{
    $r = bp_follow_get_common_args(wp_parse_args($args, array('user_id' => bp_displayed_user_id())));
    $retval = array();
    $do_query = true;
    // setup some variables based on the follow type
    if (!empty($r['follow_type'])) {
        $filter = 'bp_follow_get_following_' . $r['object'];
    } else {
        $filter = 'bp_follow_get_following';
    }
    // check for cache if 'query_args' is empty
    if (empty($r['query_args'])) {
        $retval = wp_cache_get($r['object_id'], "bp_follow_{$r['object']}_following_query");
        if (false !== $retval) {
            $do_query = false;
        }
    }
    // query if necessary
    if (true === $do_query) {
        $retval = BP_Follow::get_following($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']}_following_query");
            // cache count while we're at it
            wp_cache_set($r['object_id'], $GLOBALS['wpdb']->num_rows, "bp_follow_{$r['object']}_following_count");
        }
    }
    /**
     * Dynamic filter for following query.
     *
     * By default, the filter name is 'bp_follow_get_following', which filters
     * the displayed user's following.
     *
     * @since 1.0.0
     * @since 1.3.0 Filter is now dynamic.
     *
     * @param array $retval Array of follower IDs.
     */
    return apply_filters($filter, $retval);
}