Skip to:
Content
Pages
Categories
Search
Top
Bottom

Activity updates only available to friends


  • handyandywilson
    Participant

    @handyandywilson

    Hey guys,

    Could you point me in the right direction: I’m looking to allow activity posts to be made visible only to users who are friends with each other. I am aware plugins exist to fulfil this but I need to create this function myself to properly customize it. Just unsure where to start.

    What hooks and/or template files should I be aware of?

    Cheers,

    Andrew

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

  • Henry Wright
    Moderator

    @henrywright

    Hi @handyandywilson

    Your first stop when customising the activity stream should be bp_parse_args(). Check out this article:

    Using bp_parse_args() to filter BuddyPress template loops


    Jonas
    Participant

    @jonaskjodt

    like Henry mentioned, you can use the bp_parse_args. You could do the following to achieve it:

    // Activity stream -> friends only

    function my_friends_only_activity_args( $args ) {
        
        if( ! bp_is_activity_directory() || !  is_user_logged_in() ) {
            return $args;
        }
        
        $user_id = get_current_user_id();
        
        $user_ids = friends_get_friend_user_ids( $user_id );
        
        array_push( $user_ids, $user_id );
        
        $args['user_id'] = $user_ids;
        
        return $args;
     
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_friends_only_activity_args' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar