Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_after_has_activities_parse_args'

Viewing 25 results - 26 through 50 (of 55 total)
  • Author
    Search Results
  • 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?

    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.

    AM77
    Participant

    Thanks @r-a-y that does work for the front page, but bp_is_component_front_page( 'activity' ) or the one I just suggested bp_is_activity_front_page() doesn’t seem to work correctly when using the activity parse args filter. The best solution I’ve got now is using ! bp_is_user() && bp_is_current_component( 'activity' ) This makes this work correctly:

    /* Display just the activity updates for who the the logged-in 
    user is following and updates from the logged in user*/
    
    function am_activity_filter( $retval ) {
       
       if ( ! bp_is_user() && bp_is_current_component( 'activity' ) ) {  
    	   $retval['scope'] = 'following,just-me'; 
    	   $retval['action'] = 'activity_update';  
       }
       
       return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'am_activity_filter' );

    The problem with this conditional bp_is_component_front_page( 'activity' ) in my activity parse args filter is activity items keep showing from everyone instead of the items from who a user is following (I’m using your master follow plugin). The items that are not supposed to display, disappear when the user refreshes the page which makes the correct items display, but they keep coming back through the ‘load newest’. Have you tried this? Nevertheless ! bp_is_user() && bp_is_current_component( 'activity' ) is the one that is working correctly for this.

    #246126
    nicolemb
    Participant

    Thanks @shanebp – This is our problem. This whole solution hinges on adding meta with the blog id to EVERYTHING that could appear in an activity stream. (We also have Activity Plus Plugin active on one site and those posts seem to be missing getting the meta added)

    Is there something we hook to in order to add meta to all activity? we tried add_action('bp_activity', 'where_activity_from', 10, 3); but it’s still not adding meta to all.

    Or is there a better way to filter activity streams to only show activity from the current site on a multisite setup?

    Here’s our latest attempt at a must-use plugin, but not all activity is shown implying the meta values are not being added:

    <?php
    
    // Add Blog ID meta to activity posts
    add_action('bp_activity', 'where_activity_from', 10, 3);
    function where_activity_from($content, $user_id, $activity_id)
    {
        bp_activity_add_meta($activity_id, '_source_blog', get_current_blog_id());
    }
    
    // Filter specific sites for activity from that site only
    function bp_after_has_activities_parse_args_func($r)
    {
        $blog_id = get_current_blog_id();
        global $wpdb;
        $sql = $wpdb->prepare("SELECT activity_id FROM " . $wpdb->base_prefix . "bp_activity_meta WHERE meta_key=%s AND meta_value=%d", '_source_blog', $blog_id);
    
        $ids = array_values($wpdb->get_col($sql));
        if (empty($ids)) {
            $r['in'] = '-1';
        } else {
            $r['in'] = $ids;
        }
        return $r;
    }
    
    if (get_current_blog_id() !== 1) {
        add_filter('bp_after_has_activities_parse_args', 'bp_after_has_activities_parse_args_func');
    }
    #244036

    In reply to: filter activity loop

    Angelo Rocha
    Participant

    Works fine with a little change:

    function omni_filter_activity( $retval ) {
        $retval['action'] = 'bbp_reply_create,bbp_topic_create'; // change scope per action
        return $retval;
    } add_filter( 'bp_after_has_activities_parse_args', 'omni_filter_activity' );
    #243867

    In reply to: filter activity loop

    shanebp
    Moderator

    Try:

    function angelo_filter_activity( $retval ) {
        
        $retval['scope'] = 'bbp_reply_create,bbp_topic_create';
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'angelo_filter_activity' );
    #242974
    danbp
    Participant

    @djsteveb,

    i wouldn’t remove the whole action hook, as other functionnalities from other plugins, can use it. Filtering is even better.

    bp_parse_{component}_args is intended to filter template loops.

    If you remove an {activity} type with this function, it will remove that activity from each activity feed (swa, profile and group). Something like an all or nothing thing.

    bp_parse return values. So if you want to remove something, you have to list what you want to keep to show, and not what to remove !

    Here a snippet, listing all existing BP activity types (2.2.x). Simply comment or remove the type you don’t want.

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

    IMPORTANT: copy/paste to bp-custom.php or child-theme functions.php. Used as-is will do nothing ! You have to remove the type you don’t want from the list….

    Third party plugins (like bbPress) use also activity types. Easiest way to get the right type name is to check xxxx_bp_activity table in DB and search for it in the Type column.


    @umar007
    , removing friendship_created will solve your question.

    @djsteveb
    , remove new_avatar ! 😉

    danbp
    Participant

    @tomnikkola,

    as you discovered already, the CSS trick is a poor solution.
    Two solution are on hand.
    A first one, which applies to all activity feeds.
    Basically the below snippet handles globally the activties output. You simply remove the activity(ies) you don’t want to see from the list. Note that almost all activity types are listed.
    Add it to child functions.php or to bp-custom.php

    function demo_parse( $retval ) {
    	// existing BP/bbP activities
    	// remove the one you wont to see from that list
    	$retval['action'] = '
    		activity_comment,
    		activity_update,
    		bbp_topic_create,
                    bbp_reply_create,
    		friendship_created,
    		joined_group,
    		last_activity,
    		new_avatar,
    		new_blog_post, 	
    		new_member,
    		updated_profile
    	';	
    
    	return $retval;
    	
    	}
    add_filter( 'bp_after_has_activities_parse_args', 'demo_parse' );

    Codex:

    Using bp_parse_args() to filter BuddyPress template loops

    The second solution, is to use a child-theme with a modified activity loop. This let you handle finer condition for each user.

    Read this tut how you can do that.

    Codex:

    Activity Loop

    r-a-y
    Keymaster

    The simple thing here is to remove all your custom code snippets that are interacting with the activity stream.

    In your original post, I see you’re using this:
    remove_filter( 'bp_after_has_activities_parse_args', 'ray_bp_display_comments_stream', 20 );

    Which means you have a function called ray_bp_display_comments_stream() somewhere which is causing the singular activity comment entries to display.

    danbp
    Participant

    @browserco,

    thank you for your help, but please, don’t give a 4 years old solution without testing it.
    At first, the snippet contains cote errors, and second, it doesn’t work with BP 2.x, as things has changed.

    You can easily modify your template loop by using bp_parse_args function.

    Here a working example (activity-update is commented – uncomment to see the difference)

    You simply have to list what to show. Anything not listed will be ignored, on all activity feeds.

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

    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' );
    #237964

    In reply to: activity

    danbp
    Participant

    Hi,

    to show only notices (aka updates) on the SWA, try this snippet (place in bp-custom.php)

    function make_swa_show_notice_only( $retval ) {	
    	
    	if ( bp_is_page( 'activity' ) ) {
    	$retval['action'] = 'activity_update';					
    	}
    	
    	return $retval;
    	
    	}
    add_filter( 'bp_after_has_activities_parse_args', 'make_swa_show_notice_only' );

    Reference: https://codex.buddypress.org/developer/using-bp_parse_args-to-filter-buddypress-template-loops/

    #236020
    danbp
    Participant

    Recently introduced function bp_parse_args allows since 2.0 to modify easely your templates. Faster and lighter than a plugin.

    Using bp_parse_args() to filter BuddyPress template loops

    As example, show only updates on the SWA (add snippet to bp-custom.php or child-theme functions.php)

    function make_swa_show_notice_only( $retval ) {	
    	
    	if ( bp_is_page( 'activity' ) ) {
    	$retval['action'] = 'activity_update';					
    	}
    	
    	return $retval;
    	
    	}
    add_filter( 'bp_after_has_activities_parse_args', 'make_swa_show_notice_only' );
Viewing 25 results - 26 through 50 (of 55 total)
Skip to toolbar