Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/22/2014 09:46:50 PM (11 years ago)
Author:
r-a-y
Message:

Activity: Support multiple scopes in bp_has_activities().

This commit:

  • Allows the 'scope' parameter to support multiple scopes. For example, scope=friends,mentions. This can be a comma-delimited string or an array.
  • Makes the 'scope' parameter available across the bp_has_activities() stack. Previously, 'scope' was only available for use in the bp_has_activities() loop.
  • Parses scopes using the BP_Activity_Query class to handle complex conditions.
  • Allows components to declare their own custom activity scopes. Components can also override existing activity arguments by setting the 'override' key in their scope callback. For an example, see how the friends component declares the 'friends' scope in bp_friends_filter_activity_scope(). Previously, it was not possible for components or third-party plugins to declare their own scopes without doing a fair bit of workarounds.

See #4988.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-activity.php

    r9154 r9257  
    229229
    230230/**
     231 * Set up activity arguments for use with the 'friends' scope.
     232 *
     233 * For details on the syntax, see {@link BP_Activity_Query}.
     234 *
     235 * @since BuddyPress (2.2.0)
     236 *
     237 * @param array $retval Empty array by default
     238 * @param array $filter Current activity arguments
     239 * @return array
     240 */
     241function bp_friends_filter_activity_scope( $retval, $filter ) {
     242    $friends = friends_get_friend_user_ids( $filter['user_id'] );
     243
     244    if ( empty( $friends ) ) {
     245        return $retval;
     246    }
     247
     248    $retval= array(
     249        'relation' => 'AND',
     250        array(
     251            'column'  => 'user_id',
     252            'compare' => 'IN',
     253            'value'   => (array) $friends
     254        ),
     255        // we should only be able to view sitewide activity content for friends
     256        array(
     257            'column' => 'hide_sitewide',
     258            'value'  => 0
     259        ),
     260    );
     261
     262    // wipe out the user ID
     263    $retval['override']['filter']['user_id'] = 0;
     264
     265    // make sure we aren't limiting items by 'hide_sitewide' since we're already
     266    // limiting it above
     267    $scope_args['override']['show_hidden'] = true;
     268
     269    return $retval;
     270}
     271add_filter( 'bp_activity_set_friends_scope_args', 'bp_friends_filter_activity_scope', 10, 2 );
     272
     273/**
    231274 * Add activity stream items when one members accepts another members request
    232275 * for virtual friendship.
Note: See TracChangeset for help on using the changeset viewer.