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-groups/bp-groups-activity.php

    r9204 r9257  
    235235
    236236/**
     237 * Set up activity arguments for use with the 'groups' scope.
     238 *
     239 * @since BuddyPress (2.2.0)
     240 *
     241 * @param array $retval Empty array by default
     242 * @param array $filter Current activity arguments
     243 * @return array
     244 */
     245function bp_groups_filter_activity_scope( $retval, $filter ) {
     246    $groups = groups_get_user_groups( $filter['user_id'] );
     247
     248    if ( empty( $groups['groups'] ) ) {
     249        return $retval;
     250    }
     251
     252    $retval= array(
     253        'relation' => 'AND',
     254        array(
     255            'column' => 'component',
     256            'value'  => buddypress()->groups->id
     257        ),
     258        array(
     259            'column'  => 'item_id',
     260            'compare' => 'IN',
     261            'value'   => (array) $groups['groups']
     262        ),
     263    );
     264
     265    // wipe out the user ID
     266    $retval['override']['filter']['user_id'] = 0;
     267
     268    return $retval;
     269}
     270add_filter( 'bp_activity_set_groups_scope_args', 'bp_groups_filter_activity_scope', 10, 2 );
     271
     272/**
    237273 * Record an activity item related to the Groups component.
    238274 *
Note: See TracChangeset for help on using the changeset viewer.