Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_after_has_activities_parse_args'

Viewing 25 results - 1 through 25 (of 55 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' );
    #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.

    #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.

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

    In reply to: Activities

    danbp
    Participant

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

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

    In reply to: Not show all activity

    danbp
    Participant

    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/

Viewing 25 results - 1 through 25 (of 55 total)
Skip to toolbar