Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_after_has_activities_parse_args'

Viewing 25 results - 1 through 25 (of 66 total)
  • Author
    Search Results
  • #331880
    teeboy4real
    Participant

    I had the option Allow activity stream commenting on posts and comments disabled I also have some code in custom.php file. I am not sure if it could have any effect

    /* Disable comment for all activity but still enable @mention autosuggestion. */
    function disable_activity_comments($can_comment, $activity) {
        // Disable comments
        $can_comment = false;
        return $can_comment;
    }
    add_filter('bp_activity_can_comment', 'disable_activity_comments', 10, 2);
    
    /* Hide comment from activity page */ 
    add_action( 'bp_after_has_activities_parse_args', function ( $r ) {
        if ( bp_is_activity_directory() || bp_is_single_activity() ) {
            $r['display_comments'] = false;
        }
        return $r;
    } );
    
    // Exclude activity updates from subscribers who are not logged in on the activity directory page.
    function hide_new_member_activities_from_unlogged_users( $args ) {
        if ( ! is_user_logged_in() ) {
            $args['action'] = array(
                'activity_comment',
                'activity_update',
                'last_activity',
                'new_avatar',
                'new_blog_comment',
                'new_blog_post',
    			'new_classified',
                'updated_profile'
            );
        }
        return $args;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'hide_new_member_activities_from_unlogged_users' );
    
    #312216
    Prashant Singh
    Participant
    function ps_mine_activity_args( $args ) {
     
        if ( ! bp_is_activity_directory() || ! is_user_logged_in() || ! empty( $args['scope'] ) ) {
            return $args;
        }
     
        $user_id = get_current_user_id();
     
        $args['user_id'] = $user_id;
     
        return $args;
    
    }
    add_filter( 'bp_after_has_activities_parse_args', 'ps_mine_activity_args' );

    Please put the above given code in your bp-custom.php file or in your child theme’s functions.php file.

    Hope that it will show only logged-in user’s activities in the sitewide activity stream.

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

    This is what is suggested around the forums, but as soon as this is added, the filter by options stop working.

    Same goes for bp_after_has_activities_parse_args when setting parameters for followers/freinds only. Is there something missing?

    kobrakai75
    Participant

    Hi all

    After a lot of searching around I found a solution for a friends only activity stream.

    The following function works and I am only seeing updates from friends:

    function buddydev_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 );
        
        //include users own too?
        array_push( $user_ids, $user_id );
        
        $args['user_id'] = $user_ids;
        
        //print_r($args);
        return $args;
     
    }
    
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_friends_only_activity_args' );

    However, the mentions tab on my activity stream now displays the message “Sorry, there was no activity found.” If I remove the function I can see all the mentions again.

    Mentions are still working fine on user profiles.

    Any ideas what is causing this?

    WordPress 5.2.2
    BuddyPress 4.4.0

    #306721
    colingdi
    Participant

    That helped a lot, I’ve now got it filtering for the users activity on just their profile page. So we’re halfway there. Using your links I’m to the point where I have this code:

    function my_filter_after_has_activities_parse_args( $r ) {
            $r['per_page'] = 10;
            if (bp_is_my_profile()) {
            $r['per_page'] = 3;
            $r['scope'] = "just-me";
            } else if (bp_is_user_profile()) {
            $r['per_page'] = 3;
            //$r['scope'] = "just-me"; - I'll work out the code for just-them after I get the function calling
            }
            
            return $r;
        }
        add_filter( 'bp_after_has_activities_parse_args', 'my_filter_after_has_activities_parse_args' );

    When I run this code on a normal users profile I get nothing changed (the final bp_is_user_profile() doesn’t fire). I’m on the site.com/members/user page and it’s the ‘home.php’ template that’s calling all of this so I’m at a loss as to why I’m getting no joy.

    #306698
    Henry Wright
    Moderator

    Try using bp_parse_args(). Here is an example:

    
    function my_filter_after_has_activities_parse_args( $r ) {
        $r['per_page'] = 3;
        // Do something else here
        return $r;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_filter_after_has_activities_parse_args' );
    

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

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

    This is what is suggested around the forums, but as soon as this is added, the filter by options stop working.

    Same goes for bp_after_has_activities_parse_args when setting parameters for followers/freinds only. Is there something missing?

    #305947
    btees
    Participant

    Got it sorted.

    I set up a new search-form.php in my child theme:

    <div class="<?php bp_nouveau_search_container_class(); ?> bp-search" data-bp-search="<?php bp_nouveau_search_object_data_attr() ;?>">
    <form action="" method="get" class="bp-dir-search-form" id="<?php bp_nouveau_search_selector_id( 'search-form' ); ?>">
    <select onchange="this.form.submit()" id="<?php bp_nouveau_search_selector_id( 'search' ); ?>" name="<?php bp_nouveau_search_selector_name(); ?>">
    		  <option value="" disabled selected>Filter by Industry</option>
    		  <option value="">All</option>
      <?php  $result = $wpdb->get_results ( "SELECT * FROM wp_bp_xprofile_fields WHERE id='2'" );
      foreach ( $result as $print );
      $options = $wpdb->get_results ( "SELECT * FROM wp_bp_xprofile_fields WHERE parent_id='$print->id'" );
          foreach ( $options as $option )   { ;?>
        	
        <option class="<?php echo $option->name;?>" name ="field_<?php echo $print->id;?>_match_any[]"value="<?php echo $option->name;?>"><?php echo $option->name;?></option>
              <?php } ;?> 
    		</select>
    </form>
    </div>
    

    And then Ravi over at BuddyDev figured out how to change what the search applies to:

    // Activity Search by Category
    
    function buddydev_filter_activities_query_args( $r ) {
    
    	$searched_category = empty( $r[ 'search_terms' ] ) ? false : $r[ 'search_terms' ];
    
    	if ( ! $searched_category ) {
    		return $r;
    	}
    
    	$r['search_terms'] = false;
    
    	if ( empty( $r['meta_query'] ) ) {
    		$r['meta_query'] = array(
    			array(
    				'key'     => 'bpcat',
    				'value'   => $searched_category,
    			)
    		);
    	} else {
    		array_push( $r['meta_query'], array(
    			'key'     => 'bpcat',
    			'value'   => $searched_category,
    		) );
    	}
    
    	return $r;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'buddydev_filter_activities_query_args' );
    #302927
    mrjanvier
    Participant

    Dear,

    I tried but it didn’t work. I made a bp-custom.php map in: wp-content/plugins/bp-custom.php –> In the map bp-custom.php i placed a file bp-custom.php
    I used notedpadd ++ as a editor to place the code you give me and copied it to my server. Once installed, i can’t enter my site. It gives an error:
    Warning: require …
    Fatal error: require(): Failed opening .. class-buddypress.php on line 226

    This looks strange, cause the code filled in notepadd ++ goes only to line 11.

    I filled it in as:
    <?php
    function bp_activities_user_friends_scope( $retval ) {

    if ( bp_is_activity_directory() ) {
    $retval[‘scope’] = ‘friends’;
    }

    return $retval;
    }
    add_filter( ‘bp_after_has_activities_parse_args’, ‘bp_activities_user_friends_scope’ );
    ?>

    did I do something wrong?

    Big thank for youre help

    #302754
    shanebp
    Moderator

    You can use the scope argument for that.
    Try this in your theme > functions.php or in bp-custom.php

    function bp_activities_user_friends_scope( $retval ) {
    
        if ( bp_is_activity_directory() ) {
            $retval['scope'] = 'friends';
        }
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'bp_activities_user_friends_scope' );
    #276634
    groston
    Participant

    I did not develop, but help support, the http://www.EmbraceCreatives.com website. I have stumbled across three issues with the site, but I believe all are closely related.

    Issue 1: The default settings for the News Feed are too inclusive and the News Feed gets clogged with uninteresting stuff. To address this issue, I received some help form this forum which resulted in my adding the following code to …/wp-content/themes/social-portfolio/functions.php. (Yes, this does belong in social-portfolio-child, but when I added it there, it did not function. It would require too much time and effort to address fix this problem, which just means that I have to be careful should we update the theme.)

    function ec_filter_activity( $activity_object ) {
      $activity_object['action'] = array( 'item1', 'item2');
      return $activity_object;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'ec_filter_activity');

    The good news is that this code does limit the items shown in the News Feed to those in the item list. However, the dropdown filter, which allows filtering by activity type, no longer functions. Selecting any value causes the page to refresh, but the items displayed are not changed. Also note that removing the code shown in Issue 2 below does not change this behavior.

    Issue 2: Part of the customization is to allow site members to post portfolios of their work. This was implemented as a custom component called gallery and there are two activities associated with this component. The first thing I did was register these activities (as the developer had failed to do so). Next, I added the following code to …/wp-content/plugins/embrace-creatives/include/components/gallery/gallery-component.php

    function setup_actions() { /*other lines from this function omitted for clarity */
        add_action( 'bp_activity_filter_options', array( $this, 'display_activity_actions' ) );  /* added */
    }
    
    public function display_activity_actions() {  /* newly added function */
    ?>
        <option value="<?php echo 'portfolio_published'; ?>"><?php _e('Portfolio Published'); ?></option>
        <option value="<?php echo 'project_published'; ?>"><?php _e('Project Published'); ?></option>
    <?php  }

    The good news is that these two actions are shown in the dropdown mentioned above. However, whereas the dropdown functions properly with regard to all other activities, it does not function for these two newly added ones (when this code is active and the code from Issue 1 is disabled).

    Issue 3: The list of activities shown in the dropdown filter should match the list specified under Issue 1. While I think that I may have figured out how to add activities to this filter (see Issue 2), I do not know how to remove ones on the list, or better yet, simply specify only the ones that should be included.

    We would truly appreciate any assistance you can provide. I would be more than willing to jump onto a phone call or even provide access to our clone site if someone wants to jump in.

    asokaaso2
    Participant

    Using ‘bp_after_has_activities_parse_args’, I am trying to create a post scheduler on buddypress (Will be glad if there’s an existing one) where if the publish date is greater than the date today, it will not show on the user who is viewing the profile. On the ‘bp_after_has_activities_parse_args’ filter, I saw a value that says ‘date_query’ I’m not sure if it’s the one I’m looking for. Do you have any idea how can I do this? Much appreciated if someone can help me since I’m new to Buddypress.

    #275382
    groston
    Participant

    r-a-y,

    This is blather to try to trick the ‘Duplicate reply detected’ nonsense.

    Thanks for the reply – seem like the right approach, but… Following is my code:

    function ec_filter_activity( $activity_object ) {
      $activity_object['action'] = array( 'item1', 'item2');
      return $activity_object;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'ec_filter_activity');

    When I load the activity feed, I get this warning (in the debug.log file):

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'ec_filter_activity' not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 286

    I do not understand why this error is appearing – can you offer some guidance?

    p.s. The site is the MVP for the company. If there is decent adoption, the next release will be a custom app, so moving the code into a plugin is not really needed.

    #274937
    groston
    Participant

    I would like to prevent certain types of activities from appearing in the global feed. I have found a number of articles that discuss this, but many are quite old (prior versions) and (to a novice), many seem to be incomplete.

    Based on my reading, it seems that the clean way to do this is to add some code to the file functions.php in themes/child-theme. Based on my reading, and just for testing purposes, I added the following code:

    function ec_filter_activity( $activity_object ) {
      $activity_object['action'] = array( 'activity_comment' , 'activity_update');
      $activity_object['per_page'] = 8;
      return $activity_object;
    }
    add_action( 'bp_after_has_activities_parse_args', 'ec_filter_activity');

    However, when I reloaded the page with the activity feed, the following appeared in debug.log:

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘ec_filter_activity’ not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 286

    Can you please help me figure out what I am doing wrong. I suspect that if I can get past this error, I can make the filtering work…

    Thanks

    #271229

    In reply to: Activities

    HDcms
    Participant

    Hello @danbp

    PHP Warning: Illegal offset type in /home…./wp-content/plugins/buddypress/bp-activity/bp-activity-functions.php on line 734

    I found where the error came from:

    add_filter( 'bp_after_has_activities_parse_args', 'activites_affiche_infos' );
    function activites_affiche_infos( $retval ) {
     //  if ( bp_is_active( 'activity' ) ) {
       $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;	
    //	}
    }

    I feel that this function does not work anymore with the latest version of buddypress. If I disable it, => all works
    I activate it by trying several solutions and nothing else works !!
    I tried your code without success either

    @ +
    An “old” member of your BP site

    #271202
    HDcms
    Participant

    Hi,
    I feel that this function does not work anymore with the latest version of buddypress. If I disable it, => all works
    I activate it by trying several solutions and nothing else works !!

    add_filter( 'bp_after_has_activities_parse_args', 'activites_affiche_infos' );
    function activites_affiche_infos( $retval ) {
     //  if ( bp_is_active( 'activity' ) ) {
       $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;	
    //	}
    }
    #271134
    HDcms
    Participant

    Hello

    [17-Feb-2018 11:37:41 UTC] PHP Warning: Illegal offset type in /home…./wp-content/plugins/buddypress/bp-activity/bp-activity-functions.php on line 734

    I found where the error came from:

    add_filter( 'bp_after_has_activities_parse_args', 'activites_affiche_infos' );
    function activites_affiche_infos( $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' // ajout important sinon on perd l'affichage des médiaq                
        ); 
        return $retval;
    }

    IF you can tell me the mistake !?

    For the other, it’s the mailster plugin

    [24-Feb-2018 00:59:35 UTC] PHP Warning:  mysqli_query(): Error reading result set's header in /home/../wp-includes/wp-db.php on line 1924
    [24-Feb-2018 01:56:20 UTC] PHP Warning:  mysqli_query(): MySQL server has gone away in /home/../wp-includes/wp-db.php on line 1924
    #266780
    Henry Wright
    Moderator

    Try this:

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
        $retval['display_comments'] = 'stream';
        return $retval;
    } );

    Please note I haven’t tested.

    #266609
    slimmyweight
    Participant

    Hi Henry,

    Thanks for the reply,

    I’m not a programmer I have basic programming knowledge at best. I’ve tried pasting

    // Fetch only the last five entries for all activity loops
    function my_bp_activities_per_page_5( $retval ) {
        $retval['per_page'] = 5;
     
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_per_page_5' );
    

    at the top of my current code and it is still the same showing an fatal error message and allowing me to view the admins profile.

    Have I put the code in the wrong place, or is it even possible for me to comprehend what I need to do without knowing php?

    Thanks

    #266608
    Henry Wright
    Moderator

    I recommend using the bp_after_has_activities_parse_args filter to modify the activity stream (remove admin items). Check out this helpful article:

    Using bp_parse_args() to filter BuddyPress template loops

    kodacollider
    Participant

    I had to disable activity update comments from displaying as their own items entirely to fix this, but it looks like doing so did. I used the code from this thread.

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

    Weird issue all around.

    truelux
    Participant

    I have the following code in my functions.php file

    add_filter( 'bp_after_has_activities_parse_args', function( $retval ) {
       $retval['action'] = array(
            'activity_update',
            'activity_comment',
    		'friendship_created',
    		'rtmedia_update',
    		'new_member',
    		'created_group',
    		'joined_group',
        );
        return $retval;
    } );

    It works great… BUT when I try to filter the buddypress stream everything appears. There is no filtering ability. Is this the right function to use?

    Humiges
    Participant

    Dear @danbp,

    I have seen and tried the solution you kindly provided at: “I am trying to remove activity comments as separate entries” on: https://buddypress.org/support/topic/i-am-trying-to-remove-activity-comments-as-separate-entries/

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

    This is awesome, until I found out that it also removes them in @-mentions – the …/activity/mentions/ posts … please, is there any way I can keep those under …/activity/mentions/ ??

    Thanks a lot :))

    #263372
    Mr3k
    Participant

    Hello,

    I’ve a question on filter activity items. I’ve found that I can filter on for example user_id and then give several ids, and at the same time give a object as for example “groups”. This filter is now applied that it only shows the ids AND object “groups”. Is there anyway to use like the union instead. So the ids OR “groups”?

    The code I use:

    function 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 );
        
        //include users own too?
        array_push( $user_ids, $user_id );
        
        $args['user_id'] = $user_ids;
        $args['object'] = 'groups';
    
        //print_r($args);
        return $args;
     
    }
    add_filter( 'bp_after_has_activities_parse_args', 'friends_only_activity_args' );

    Thanks for any suggestion!

    #260610
    tronix-ex
    Participant

    @danbp thanks for your response I’ve used the below code as per the suggested link but still it dosen’t work.

    function my_bp_activities_per_page_5_on_user_activity( $retval ) {
        // only fetch the last five entries if we're on a user's activity page
        if ( bp_is_user_activity() ) {
    	$retval['action'] = 'bbp_reply_create, bbp_topic_create, activity_update';
    	$retval['object'] = 'profile, status';
     } 
        return $retval;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'my_bp_activities_per_page_5_on_user_activity' );
Viewing 25 results - 1 through 25 (of 66 total)
Skip to toolbar