Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to use bp_has_activities filtering in a function


  • ljmac
    Participant

    @ljmac

    I know very well how to filter the activity loop using bp_has_activities, but how do I use it in a function? e.g. object=groups or scope=mentions

Viewing 4 replies - 1 through 4 (of 4 total)

  • danbp
    Participant

    @danbp

    hi @ljmac,

    Filter description

    bp_has_activities

    Usage example (sorry if i’m wrong) of the filter inside a function
    https://buddypress.org/support/topic/adding-favourite-posts-as-a-tab-in-buddypress/#post-236682


    ljmac
    Participant

    @ljmac

    This isn’t the kind of thing I’m looking for. What I want is just a simple way of calling a scope in the context of a function – it’s the basic stuff like this that every plug-in developer knows, but which is difficult for normal users to figure out. For example, I’ve figured out how to do it with activity types as follows:

    in_array( $activity->type, array( 'activity_comment', 'activity_update' ) )

    But how do I do it with scopes?


    danbp
    Participant

    @danbp

    Something like this ?

    function bpfr_remove_some_activity_filters( $filters, $context ) { 
    	/**
    	 * Get available filters depending on the scope.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $context The current context. 'activity', 'member',
    	 *                        'member_groups', 'group'.
    	 *
    	 * @return string HTML for <option> values.
    	 */
    	
    	if ( 'member' == $context ) {
    	
    		$remove_these = array( 'Updates', 'Posts', 'Comments' ); // case sensitive
    		
    		foreach ( $filters as $key => $val ) {
    		
    			if ( in_array( $val, $remove_these ) )
    				unset( $filters[ $key ] );
    			
    		}
    	}
    	
        return $filters; 
    } 
    add_filter( 'bp_get_activity_show_filters_options', 'bpfr_remove_some_activity_filters', 20, 2 );

    ljmac
    Participant

    @ljmac

    Thanks danbp. That’s a potentially very useful piece of code for a site-wide mod in bp-custom.php, but it still isn’t what I’m after. I need to modify a plug-in so that specific functions are restricted to either groups or mentions scopes. So I need a short snippet of code like what I posted above (which restricts the function to activity comments and updates).

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar