Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/09/2015 08:30:52 AM (10 years ago)
Author:
imath
Message:

Move activity scopes adjustment in filters

Separate the hardcoded scopes away from BP_Activity_Activity::get_scope_query_sql() to manage scope adjustments within components and to allow developers to make adjustments to them if needed.

See #4988
See #6040

props r-a-y

File:
1 edited

Legend:

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

    r9315 r9325  
    868868            $scope_args = array();
    869869
    870             switch ( $scope ) {
    871                 case 'just-me' :
    872                     $scope_args = array(
    873                         'column' => 'user_id',
    874                         'value'  => $r['user_id']
    875                     );
    876 
    877                     $scope_args['override']['display_comments'] = 'stream';
    878 
    879                     // wipe out the user ID
    880                     $scope_args['override']['filter']['user_id'] = 0;
    881 
    882                     break;
    883 
    884                 case 'favorites':
    885                     $favs = bp_activity_get_user_favorites( $r['user_id'] );
    886                     if ( empty( $favs ) ) {
    887                         return $scope_args;
    888                     }
    889 
    890                     $scope_args = array(
    891                         'column'  => 'id',
    892                         'compare' => 'IN',
    893                         'value'   => (array) $favs
    894                     );
    895                     $scope_args['override']['display_comments']  = true;
    896 
    897                     // wipe out the user ID
    898                     $scope_args['override']['filter']['user_id'] = 0;
    899 
    900                     break;
    901 
    902                 case 'mentions':
    903                     // Are mentions disabled?
    904                     if ( ! bp_activity_do_mentions() ) {
    905                         return $scope_args;
    906                     }
    907 
    908                     $scope_args = array(
    909                         'column'  => 'content',
    910                         'compare' => 'LIKE',
    911 
    912                         // Start search at @ symbol and stop search at closing tag delimiter.
    913                         'value'   => '@' . bp_activity_get_user_mentionname( $r['user_id'] ) . '<'
    914                     );
    915 
    916                     // wipe out current search terms if any
    917                     // this is so the 'mentions' scope can be combined with other scopes
    918                     $scope_args['override']['search_terms'] = false;
    919 
    920                     $scope_args['override']['display_comments'] = 'stream';
    921                     $scope_args['override']['filter']['user_id'] = 0;
    922 
    923                     break;
    924 
    925                 default :
    926                     /**
    927                      * Plugins can hook here to set their activity arguments for custom scopes.
    928                      *
    929                      * This is a dynamic filter based on the activity scope. eg:
    930                      *   - 'bp_activity_set_groups_scope_args'
    931                      *   - 'bp_activity_set_friends_scope_args'
    932                      *
    933                      * To see how this filter is used, plugin devs should check out:
    934                      *   - bp_groups_filter_activity_scope() - used for 'groups' scope
    935                      *   - bp_friends_filter_activity_scope() - used for 'friends' scope
    936                      *
    937                      * @since BuddyPress (2.2.0)
    938                      *
    939                      *  @param array {
    940                      *     Activity query clauses.
    941                      *
    942                      *     @type array {
    943                      *         Activity arguments for your custom scope.
    944                      *         See {@link BP_Activity_Query::_construct()} for more details.
    945                      *     }
    946                      *     @type array $override Optional. Override existing activity arguments passed by $r.
    947                      * }
    948                      * @param array $r Current activity arguments passed in BP_Activity_Activity::get()
    949                      */
    950                     $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r );
    951                     break;
    952             }
     870            /**
     871             * Plugins can hook here to set their activity arguments for custom scopes.
     872             *
     873             * This is a dynamic filter based on the activity scope. eg:
     874             *   - 'bp_activity_set_groups_scope_args'
     875             *   - 'bp_activity_set_friends_scope_args'
     876             *
     877             * To see how this filter is used, plugin devs should check out:
     878             *   - bp_groups_filter_activity_scope() - used for 'groups' scope
     879             *   - bp_friends_filter_activity_scope() - used for 'friends' scope
     880             *
     881             * @since BuddyPress (2.2.0)
     882             *
     883             *  @param array {
     884             *     Activity query clauses.
     885             *
     886             *     @type array {
     887             *         Activity arguments for your custom scope.
     888             *         See {@link BP_Activity_Query::_construct()} for more details.
     889             *     }
     890             *     @type array $override Optional. Override existing activity arguments passed by $r.
     891             * }
     892             * @param array $r Current activity arguments passed in BP_Activity_Activity::get()
     893             */
     894            $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r );
    953895
    954896            if ( ! empty( $scope_args ) ) {
Note: See TracChangeset for help on using the changeset viewer.