BuddyDev

Search

BP Activity Shortcode Enhancement?

  • Participant
    Level: Master
    Posts: 413
    Venutius on #14348

    Hi Brajesh,

    I have a suggested new feature for your activity shortcode, what I’d like is to dynamically filter for the viewers friends and the viewers groups. I’ve actually written some initial code that does the job by editing you latest code, nice and easy to add:

    The idea is that we add new settings of my_groups and my_friends:

    
    			// Filtering
    			'user_id'          => false,    // user_id to filter on
    			'object'           => false,    // object to filter on e.g. groups, profile, status, friends
    			'action'           => false,    // action to filter on e.g. activity_update, new_forum_post, profile_updated
    			'primary_id'       => false,    // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    			'secondary_id'     => false,    // secondary object ID to filter on e.g. a post_id.
    			//My activity options
    			'my_friends'       => false,    // display friends activity feed
    			'my_groups'        => false,    // display my groups activity feed
    			// Searching
    			'search_terms'     => false,         // specify terms to search on.
    			'use_compat'       => bp_use_theme_compat_with_current_theme(),
    			'allow_posting'    => false,    // experimental, some of the themes may not support it.
    			'container_class'  => 'activity',// default container,
    			'hide_on_activity' => 1,// hide on user and group activity pages.
    			'for'              => '', // 'logged','displayed','author'.
    			'role'             => '', // use one or more role here(e.g administrator,editor etc).
    		), $atts );'
    
    Then use these to drive some dynamic lookups:
    
    

    // hide on user activity, activity directory and group activity.
    if ( $atts[‘hide_on_activity’] && ( function_exists( ‘bp_is_activity_component’ ) && bp_is_activity_component() ||
    function_exists( ‘bp_is_group_home’ ) && bp_is_group_home() ) ) {
    return ”;
    }

    if ( ! empty( $activity_for ) ) {
    unset( $atts[‘for’] );
    $atts[‘user_id’] = $this->get_user_id_for_context( $activity_for );

    if ( empty( $atts[‘user_id’] ) ) {
    return ”;
    }
    }

    //my activities
    if ( $atts[‘my_friends’] == true ) {
    $friends_ids = friends_get_friend_user_ids($atts[‘user_id’]);
    $atts[‘user_id’] = implode( “, “, $friends_ids );
    }

    if ($atts[‘my_groups’] == true ) {
    $groups_ids = BP_Groups_Member::get_group_ids( $atts[‘user_id’] );
    $groups_ids = $groups[‘groups’];
    $atts[‘primary_id’] = implode( “, “, $groups_ids );
    $atts[‘object’] = ‘groups’;
    }

    $activity_for = $atts[‘for’];

    // Fetch users for role and use their activity.
    if ( ! empty( $atts[‘role’] ) ) {
    $user_ids = $this->get_user_ids_by_roles( $atts[‘role’] );
    $atts[‘user_id’] = $user_ids;
    }`

    What do you think? just need to an a function for my_forums I reckon.

    • This topic was modified 6 years ago by Venutius.
  • Participant
    Level: Master
    Posts: 413
    Venutius on #14351

    Sorry brajesh, the backticks on the second bit of code don’t seem to be working.

  • Participant
    Level: Master
    Posts: 413
    Venutius on #14352

    Hi Brajesh,

    Shouldn’t those last few lines be as follows:

    		// Fetch users for role and use their activity.
    		if ( ! empty( $atts['role'] ) ) {
    			$user_ids        = $this->get_user_ids_by_roles( $atts['role'] );
    			$atts['user_id'] = implode( ", ", $user_ids );
    		}
  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #14353

    Hi George,
    Thank you for the suggestion about my groups/my friends. You don’t need the my_friends and my_groups as those can be accessed by scope and user_id or ‘for’ combination.

    As for the roles, you don’t need to the change any code. user_id parameter accepts both an array of user ids as well as a single user id.

    In the current form, to list all posts of a user’s groups you can use the following

    
    [activity-stream user_id=1 scope=groups]
    

    If you want to do it for the logged in user, you don’t need the user_id and instead can use this

    
    [activity-stream for=logged scope=groups]
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #14355

    H Brajesh, thanks for getting back to me, regarding the friends activity list, how would you arrange so that it displayed the activity for the friends of any logged in user? That is the key part I don’t get, would you set role=”friends” ?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #14356

    You are welcome.
    No, We use role strictly for WordPress roles and friends is not a role. We use scope for it.

    Here is the shortcode for showing the activity of friends of the logged user

    
    [activity-stream for=logged scope=friends]
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #14357

    Thanks Brajesh, sorry for not understanding the usage, for some reason I just couldn’t get it.

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #14358

    Hi George,
    No problem.

    In case of BuddyPress, friends/follower/groups will be scope for a user’s related activities.

    We have added an extra option ‘for’ to define a dynamic context(logged|displayed|author) user id.

    Can you please check if the above shortcode fetches the friends activities?

    Thank you
    Brajesh

  • Participant
    Level: Master
    Posts: 413
    Venutius on #14359

    Yep those work great.

    I’ve got one last requirement, to display the latest activity regarding my subscribed forum topics and forums. Is that doable? I take it scope would be forums and for would be logged, is there are filter to only show topics that the user have subscribed to?

  • Keymaster
    (BuddyDev Team)
    Posts: 24211
    Brajesh Singh on #14360

    Thank you for confirming George.

    I don’t think bbPress or BuddyPress activity supports that out of the box.
    As far as I found that BuddyPress does support filtering by your own topic and your own replies but I don’t see a way for otherwise.

    The activity stream shortcode is a layer above the Normal activity, It will not be able to support the forum/topic activities like above.
    Sorry about that.

You must be logged in to reply to this topic.

This topic is: not resolved