Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_after_has_activities_parse_args'

Viewing 25 results - 26 through 50 (of 73 total)
  • Author
    Search Results
  • #260312

    In reply to: Activities

    danbp
    Moderator

    Hi @mei-ling,

    it’s not an issue but how it works ! 😉

    You can filter the activity stream and remove the activities you don’t want to be showed.

    Add this snippet to bp-custom.php or your child-theme functions.php

    function bpex_bp_activity_types( $retval ) {
       if ( bp_is_active( 'activity' ) ) {
    
    // list of all BP activity types  - remove or comment those you won't show.
    	$retval['action'] = '
    		activity_comment,
    		activity_update,
    		// bbp_topic_create,
    		// bbp_reply_create,
    		friendship_created,
    		created_group,
    		joined_group,
    		last_activity,
    		new_avatar,
    		new_blog_post, 	
    		new_blog_comment,
    		new_member,
    		updated_profile
    	';	
    
    	return $retval;
    	
    	}
    }
    add_filter( 'bp_after_has_activities_parse_args', 'bpex_bp_activity_types' );

    You might also remove bbpress activities from the activity filter. You can use this (goes to same file as previous)

    function bpex_remove_bbp_activities_dropdown_labels() {
       if ( bp_is_active( 'activity' ) ) {
    
             // Remove forum filters in site wide activity streams
            remove_action( 'bp_activity_filter_options',        array( bbpress()->extend->buddypress->activity , 'activity_filter_options'   ), 10 );
         
             // Remove forum filters in single member activity streams
             remove_action( 'bp_member_activity_filter_options', array( bbpress()->extend->buddypress->activity , 'activity_filter_options'   ), 10 );
     
             // Remove forum filters in single group activity streams
             remove_action( 'bp_group_activity_filter_options',  array( bbpress()->extend->buddypress->activity , 'activity_filter_options'   ), 10 );
       }      
    }
    add_action( 'bp_init', 'bpex_remove_bbp_activities_dropdown_labels', 9 );

    Codex references:

    Using bp_parse_args() to filter BuddyPress template loops

    bp-custom.php

    #260002
    davidtuttle
    Participant

    Topic is resolved. Comments were being restricted in them folders function.php. I added check for bp_is_group_single. Current code:

    //Restrict access to BP to logged-in users only
    function my_filter_activity( $loop ) {

    // added 10/19/16 D.T. – show all comments in single group home page
    if ( !bp_is_group_home() )
    $loop[‘scope’] = ‘just-me,friends’;

    return $loop;
    }
    add_filter( ‘bp_after_has_activities_parse_args’, ‘my_filter_activity’ );

    davidtuttle
    Participant

    Hi,

    I am using WP 4.6.1 in a network site, directory install using a Divi child theme. I have BuddyPress 2.6.2 with BuddyBlock, BuddyPress Cover Photo, BuddyPress Group Email Subscription and BuddyPress Group Tags. No bbPress.

    I would like to make all posts and comments in a group visible to anyone who joins the group. At the moment group members can only see the posts and comments of their friends.

    This implies that if a new member wants to see all the activity in a group, they have to send friend requests to everyone in the group.

    I believe this should be done in bp-custom.php with code something like the following. I don’t know if I should be using the ‘has_groups’ or ‘has_activites’ loop or some other loop. I confirmed that bp_is_group_single does target the page in question because I could change the per_page entries successfully.

    function make_all_group_comments_visible( $loop ) 
    {
     if ( bp_is_group_single() ) {
    		 $loop['??????'] = '????';
    	 }
      return $loop;
    }
    add_filter( 'bp_after_has_activities_parse_args','make_all_group_comments_visible');

    Thanks for any suggestions,

    David Tuttle

    HDcms
    Participant

    Hello,

    The ultimate goal is to mask the content and selector when a member arrives on the page of a public group to which it has not acceded. In fact he will see just the top of the page, and description button to join group

    screenshot:
    https://framapic.org/j4FYWFvZmHVI/sOyIzEz0Gl7F.png

    The idea is to reach over activities and other menu group visited oblige to register if he sees that description, avatar and the button to join

    I found bp_group_is_member to test ()
    http://buddypress.wp-a2z.org/oik_api/bp_group_is_member/
    If I do not put any argument, I understand that it will test whether the member is party group (and I add the condition to be displayed in a group?

    I have an error message:
    « Fatal error: Call to undefined function bp_group_is_member() in /var/www/../wp-content/plugins/bp-custom.php on line 3 »

    What I found to achieve the goal:

    if ( !bp_group_is_member() || bp_is_active('groups') )
     {add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activity_types_non-membre' );}
     
    function my_bp_activity_types_non-membre( $retval ) {
        $retval['action'] = array(        
            //'activity_comment',
    	//'activity_update',
    	//'created_group',
    	//'friendship_created', nouv relation entre membre
    	//'joined_group',
    	//'last_activity',
    	//'new_avatar',
    	//'new_blog_comment',
            //'new_blog_post',
    	//'new_member',
    	//'updated_profile',
    	//'rtmedia_update'       
        ); 
        return $retval;

    Regards

    #258221
    ruess
    Participant

    Super helpful and very hard to find. Just so we keep this archived (as the vital code is on a blog), I’m going to repeat it below:

    function my_bp_activities_include_activity_types( $retval ) {
        // only allow the following activity types to be shown
        $retval['action'] = array(
            'activity_update',
            'activity_comment',
            'new_blog_post',
            'new_blog_comment',
            'friendship_created',
            'created_group',
        );
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_include_activity_types' );
    Jeremy Pry
    Participant

    Thanks all for the quick replies. I don’t mean to ignore all of your helpful questions and suggestions, but those may not be needed anymore.

    After getting a chance to speak with a colleague who’s been out of the office for a while, I was able to identify the problem here. A function from a custom plugin was filtering both the bp_before_has_activities_parse_args and bp_after_has_activities_parse_args filters, and the specific problem was that it was setting $args['include'] to an empty string. This removed the comment ID that was supposed to be part of the query, and resulted in the wrong query. We don’t know why it was doing this in the first place, but it has been corrected and the infinite loop has been fixed.

    Regardless, it may be beneficial to include some checking in this code to prevent the possibility of an infinite loop even for edge cases like this.

    #254815
    Jonas
    Participant

    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' );
    IdleWanderer
    Participant

    Hi there,

    For a while back I got lots of help in this forum on how to filter the activity stream for specific pages using parse_args. It has been great so far, but I have come across a small issue with some of the terms I want filtered.

    Basically, this is what I want and what am doing so far:
    If a user writes about a specific species of animal, whatever the user wrote will come up on the activity stream for that particular species, as long as the name of the species is mentioned. Now, this I can do (thanks to help in here), but a few animals have a species name with an apostrophe in it, and that’s where my problem arises.

    Here’s an example of what I want done:

    function my_bp_activities_search_term_on_page_3431( $retval ) {
        // Add search term for correct page
        if ( is_page(3431) ) {
             $filter_query[] = array(
            'relation' => 'OR',
            array(
                'column'  => 'content',
                'value'   => 'keast's tube-nosed fruit bat',
                'compare' => 'LIKE'
            ),
            array(
                'column'  => 'content',
                'value'   => 'keast's tube-nosed bat',
                'compare' => 'LIKE'
            ),
            array(
                'column'  => 'content',
                'value'   => 'nyctimene keasti',
                'compare' => 'LIKE'
            ),
        );
        $retval['filter_query'] = $filter_query;
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_search_term_on_page_3431' );

    Of couse, this gives me an errer. I looked the issue up on google, and it seemed that the problem would be fixed by writing it like this:

    'value' => 'keast\'s tube-nosed fruit bat',

    Now, when doing this I no longer get the fatal error, but if I write “keast’s tube-nosed fruit bat” in the activity stream, it won’t show where it should.

    So, how can I solve this and have “keast’s tube-nosed fruit bat” show?

    Thanks!

    #253585

    In reply to: Not show all activity

    danbp
    Moderator

    Please read first BP’s documentation:

    Using bp_parse_args() to filter BuddyPress template loops

    Many topics with same question where already resolved.
    https://buddypress.org/support/search/bp_after_has_activities_parse_args/

    Night Hawk
    Participant

    Really, I don’t know why, but is not working…

    I add it like this in my themes faction.php

     add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
       $retval['action'] = array(
            'activity_update',
            'activity_comment',
            'updated_profile',
        );
        return $retval;
    } );
    

    but nothing works.

    Henry Wright
    Moderator

    @mlao,

    Sorry for the delay in getting back to you. So it looks like we will need to add our actions instead of removing them. Here’s where the fun part begins. You’ll need to find a list of all the action types you want in your stream and add them to the following snippet:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        $retval['action'] = array(
            'activity_update',
            'activity_comment',
            'another_action_here_etc',
        );
        return $retval;
    } );

    Obviously, don’t include updated_profile or new_avatar.

    Henry Wright
    Moderator

    Do you mind doing a little debugging for me? If you paste the following code into your theme’s functions.php file (make sure this is done on your testing install). Then visit the activity stream. You should see some output dumped on the screen. Can you copy that and paste it here?

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        var_dump( $retval['action'] );
        return $retval;
    } );
    Night Hawk
    Participant
    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        // Convert $retval['action'] into an array.
        $parts = explode( ',', $retval['action'] );
    
        // Remove new_avatar items.
        if ( ( $key = array_search( 'new_avatar', $parts ) ) !== false ) {
            unset( $parts[$key] );
        }
    
    // Remove updated_profile.
    if ( ( $key = array_search( 'updated_profile', $parts ) ) !== false ) {
        unset( $parts[$key] );
    }
    
        // Convert $parts back into a comma separated string.
        $retval['action'] = implode( ',', $parts );
    
        return $retval;
    } );
    Henry Wright
    Moderator

    To stop “profile photo updated” updates being displayed in your activity stream, try this:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        // Convert $retval['action'] into an array.
        $parts = explode( ',', $retval['action'] );
    
        // Remove new_avatar items.
        if ( ( $key = array_search( 'new_avatar', $parts ) ) !== false ) {
            unset( $parts[$key] );
        }
    
        // Convert $parts back into a comma separated string.
        $retval['action'] = implode( ',', $parts );
    
        return $retval;
    } );

    Please note I haven’t tested.

    #252785
    BackpackersUnion
    Participant

    @sharmavishal Thanks for the suggestion! “BuddyPress Wall” goes beyond what I’m looking for and seems to have quite a few unhappy users (Even most of the 5 star reviews are issues). So, I’m afraid it will cause more issues than it would solve.

    I’ve found a tutorial here using bp_parse_args() to create an activity loop with ‘Personal’ and ‘Friends Activity’ only, but not a way to isolate the loop into its own subnav tab “All” (The code currently effects all activity loops universally [i.e. Friends, Personal, Mentions, Favorites, Site wide, all become Friends+Personal loops]).

    Here’s the code to filter the activity loop into Friends+Personal,

    function my_filter_activity( $loop ) {
        
        $loop['scope'] = 'just-me,friends';
     
        return $loop;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_filter_activity' );

    The next step would be isolating the loop into an ‘All’ activity subnav tab/button.

    Any ideas?

    #251715
    @mcuk
    Participant

    Hi all,

    I’m looking to have the option within the #activity-filter-by drop down in the activity stream where I can filter updates for a search term (e.g. MYWORD).

    I’ve added: <option value="-2"><?php _e( 'MYWORD', 'buddypress' ); ?></option> into members\single\activity.php in child theme.

    I’ve also got the working code below in my bp-custom.php:

    function bptest( $retval ) {
    
        if ( bp_is_user_activity() ) {
            $retval['search_terms'] = 'MYWORD';
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'bptest' );

    How can i link the two, so that ONLY WHEN the option is selected in the drop down, the code in bp-custom takes effect and at all other times, there is no filter active?

    Many thanks.

    WP 4.2.2
    BP 2.5.1

    Henry Wright
    Moderator

    I don’t have enough data set up on my local install to test, but you could try this:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        $filter_query[] = array(
            'relation' => 'OR',
            array(
                'column'  => 'content',
                'value'   => 'philippine tube-nosed fruit bat',
                'compare' => 'LIKE'
            ),
            array(
                'column'  => 'content',
                'value'   => 'nyctimene rabori',
                'compare' => 'LIKE'
            )
        );
        $filter_query[] = array(
            array(
                'column'  => 'content',
                'value'   => 'sea lion',
                'compare' => 'NOT LIKE'
            )
        );
        $retval['filter_query'] = $filter_query;
        return $retval;
    } );
    IdleWanderer
    Participant

    I tried it, but it din’t work. At least it didn’t stop the filter rules already set up, like they did when I tried before.. So only words with lion shows up, but also sea lion.. Even with the code set up exactly like yours. Like this:

    function my_bp_activities_search_term_on_page_241( $retval ) {
        // Add search term for correct page
        if ( is_page(241) ) {
             $filter_query[] = array(
            'relation' => 'OR',
            array(
        'column'  => 'content',
        'value'   => 'lion',
        'compare' => 'LIKE',
        array(
            'column'  => 'content',
            'value'   => 'sea lion',
            'compare' => 'NOT LIKE'
        )
    ),
               array(
        'column'  => 'content',
        'value'   => 'lion',
        'compare' => 'LIKE',
        array(
            'column'  => 'content',
            'value'   => 'sea lion',
            'compare' => 'NOT LIKE'
        )
      ),
    );
        $retval['filter_query'] = $filter_query;
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_search_term_on_page_241' );
    Henry Wright
    Moderator

    Ah, that’s not quite how to use it. You should filter inside the function you’re hooking to bp_after_has_activities_parse_args. For example:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        $filter_query[] = array(
            'relation' => 'OR',
            array(
                'column'  => 'content',
                'value'   => 'philippine tube-nosed fruit bat',
                'compare' => 'LIKE'
            ),
            array(
                'column'  => 'content',
                'value'   => 'nyctimene rabori',
                'compare' => 'LIKE'
            )
        );
        $retval['filter_query'] = $filter_query;
        return $retval;
    } );
    IdleWanderer
    Participant

    Okay, so what I tried now didn’t work, but that’s because I really do not know what I am doing. I’m just testing the waters with what I learned from the search terms and the code you just posted. I ended up having my functions.php file looking like this:

    $filter_query[92] = array(
        'relation' => 'OR',
        array(
            'column'  => 'content',
            'value'   => 'philippine tube-nosed fruit bat',
            'compare' => 'LIKE'
        ),
        array(
            'column'  => 'content',
            'value'   =>  'nyctimene rabori',
            'compare' => 'LIKE'
        )
    );
    
    function my_bp_activities_search_term_on_page_92( $retval ) {
        // Add search term for correct page
        if ( is_page(92) ) {
            $retval['filter_query'] = $filter_query[92];
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_search_term_on_page_92' );

    And that clearly did not work, so what will work?

    IdleWanderer
    Participant

    Thanks! I think I got it now!

    I just added this to my functions.php:

    function my_bp_activities_search_term_on_page_92( $retval ) {
        // Add search term for correct page
        if ( bp_is_page(92) ) {
            $retval['search_term'] = 'philippine tube-nosed fruit bat';
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_search_term_on_page_92' );

    Do you think this will work? I do not have any ways to test if it actually works yet.. Another thing, how do I add multiple search terms? Everytime I tried adding another one I got an error, I tried doing this: $retval['search_term'] = 'philippine tube-nosed fruit bat', 'philippine tube-nosed bat', 'nyctimene rabori';

    Henry Wright
    Moderator

    You can add a custom function to the bp_after_has_activities_parse_args filter hook like this:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        // Change search-term to your own search term.
        $retval['search_terms'] = 'search-term';
        return $retval;
    } );
    #248867
    iwishiknew
    Participant

    I figured it out. This will help everyone who has this question:

    function omni_filter_activity( $retval ) {
        $retval['action'] = 'activity_update'; // change scope per action
        return $retval;
    } add_filter( 'bp_after_has_activities_parse_args', 'omni_filter_activity' );
    #247877
    Andrew
    Participant

    Thanks Henry. I’ve got more info on this to help the core team fix this issue.

    I think all WordPress conditionals are not working correctly inside the bp_after_has_activities_parse_args filter. Only BuddyPress conditionals are working inside it.

    I also have custom member pages too using bp_after_has_members_parse_args, but WordPress conditionals inside that are all working fine, example:

    // filter member pages
    function cm_members_filter( $retval ) {
    
    	if ( is_page('custom-page-3') ) {
    		$retval['per_page'] = 1;
    	}	
    	
    	if ( is_page('custom-page-4') ) {
    		$retval['per_page'] = 5;
    	}	
    	
    	if ( is_search() ) {  
    		$retval['per_page'] = 3;
    	}	
    		
        return $retval;
    }
    add_filter( 'bp_after_has_members_parse_args', 'cm_members_filter' );

    It is just the activity parse args that is having problems with WordPress conditionals. I can provide further info to help figure out why WordPress conditionals don’t work correctly inside bp_after_has_activities_parse_args, it has something to do with the way ajax is used on the load more button to load more items:

    If I remove activity ajax features by removing <div class=”activity”></div> or by removing bp-templates/bp-legacy/js/buddypress.min.js. The load more button now works like a pagination next page button (similar to the members directory pagination). This makes the WordPress conditionals work fine and all my custom activity pages are now filtering correctly.

    So to conclude, WordPress conditionals are working OK inside bp_after_has_members_parse_args, but they are not working correctly inside bp_after_has_activities_parse_args unless the activity ajax is removed.

    #247854
    Henry Wright
    Moderator

    Ah OK, cool. In that case you may also be interested to hear about bp_parse_args(). I think it’s a better way of doing what you want. This approach will also handle the loop pagination for you. For example:

    function my_func( $ret ) {
        // Your custom stuff here. 
        return $ret;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_func' );

    See the Using bp_parse_args() to filter BuddyPress template loops article for a complete guide.

Viewing 25 results - 26 through 50 (of 73 total)
Skip to toolbar