Skip to:
Content
Pages
Categories
Search
Top
Bottom

User favorites and user mentions feed / loop


  • @mcuk
    Participant

    @mcuk

    Hi all,

    I’m attempting to have nav tabs in the standard buddybar that displays the feed/loop for Favorites and Mentions, as seen in the pic on this page:

    Activity dropdown filters in templates

    1. I’ve managed to duplicate the activity loop on a tab with the code below, but the CSS is wrong. I’ve fiddled with the code a little as it was originally setup for blog posts and i think this is the reason the CSS i’ve written for activity loop isn’t being called. Is the hook my_profile_post() where the issue lies?

    2. I’m fine with setting up the navs and subnavs as desired, but I’m still being unsuccessful in loading a user favorites and user mentions feed/loop (want to duplicate what is shown on the subnav tabs under the default activity tab). Looked through the Buddypress code files and found and tried various things but none have worked. Any help/directions?

    (Code below thanks to Dan and Henry here: https://buddypress.org/support/topic/calling-a-post-authors-activity-stream/)

    function bpfr_post_profile_setup_nav() {
    	global $bp;
    	$parent_slug = 'test';
    	$child_slug = 'posts_sub';	
    	
    	//Add nav item
    	bp_core_new_nav_item( array(
    	'name' 					=> __( 'TEST' ),
    	'slug' 					=> $parent_slug,
    	'screen_function' 		=> 'bpfr_profile_post_screen',
    	'position' 				=> 100,
    	'default_subnav_slug' 	=> $child_slug 
    	) );
    	
    	//Add subnav item 	 
    	bp_core_new_subnav_item( array( 
    	'name' 					=> __( 'SUBTEST' ), 
    	'slug' 					=> $child_slug, 
    	'parent_url' 			=> $bp->loggedin_user->domain . $parent_slug.'/', 
    	'parent_slug' 			=> $parent_slug, 
    	'screen_function' 		=> 'bpfr_profile_post_screen'
    	) );
    }
    
    	function bpfr_profile_post_screen() {	
    		add_action( 'bp_template_content', 'bpfr_profile_post_screen_content' );
    		bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    	}
    
    	function bpfr_profile_post_screen_content() {
    		do_action( my_profile_post);
    	}
    
    add_action( 'bp_setup_nav', 'bpfr_post_profile_setup_nav' );
    
    function bpfr_get_stuff() {
    
    	$activity_id = bp_activity_get_activity_id( array(
    		'user_id' 	      => bp_loggedin_user_id(),
    		//'component'         => $bp->activity->id,
    		//'item_id'           => get_current_activity_id(),
    		//'type'              => 'activity_comment',
    		//'secondary_item_id' => $post->ID, 
    		//'type'              => $activity_post_object->action_id,
    	) );
    	
    	if ( ! $activity_id ) {
    		return '';
    	}
    // this is the activity loop, with some options.
    	if ( bp_has_activities( $activity_id . '&action=activity_update&max=5' )  ) :
    		while ( bp_activities() ) : bp_the_activity();
    			bp_get_template_part( 'activity/entry');
    		endwhile;
    	endif;
    }
    
    add_action ( 'my_profile_post', 'bpfr_get_stuff' );

    bp 2.2.3.1
    wp 4.1.2
    Website is being created locally, not online.

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Moderator

    @danbp

    you have to add a scope in bp_get_stuff function.

    if ( bp_has_activities( $activity_id . '&scope=favorites,mentions&max=5' ) ) :

    Thought you have to uncomment some of array values too. (component and item_id)

    Reference: https://codex.buddypress.org/developer/loops-reference/the-activity-stream-loop/


    @mcuk
    Participant

    @mcuk

    Thanks @danbp, adding the scope and uncommenting those args worked! (Though leaving the item_id commented doesn’t appear to make a difference. I read on one of the codex pages for another function that item_id is optional?).

    Is it normal for there to be no CSS associated with new tabs? It doesn’t seem to even show the default CSS for an activity page? If thats not normal does that mean the templates loaded are wrong or am i missing something else?

    For anyone looking to do the same as me the working code is below:

    //Function for new My Favourites tab
    function bpmc_my_favourites_setup_nav() {
    	global $bp;
    	$parent_slug = 'my_favourites';
    	$child_slug = 'favourites_sub';	
    	
    	//Add nav item
    	bp_core_new_nav_item( array(
    	'name' 					=> __( 'My Favourites' ),
    	'slug' 					=> $parent_slug,
    	'screen_function' 		=> 'bpmc_my_favourites_screen',
    	'position' 				=> 100,
    	'default_subnav_slug' 	=> $child_slug 
    	) );
    }
    
    function bpmc_my_favourites_screen() {	
    	add_action( 'bp_template_content', 'bpmc_my_favourites_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function bpmc_my_favourites_screen_content() {
    	do_action( 'my_favorites' );
    }
    
    add_action( 'bp_setup_nav', 'bpmc_my_favourites_setup_nav' );
    
    function bpmc_get_favorites() {
    	$activity_id = bp_activity_get_activity_id( array(
    		'user_id' 				=> bp_loggedin_user_id(),
    		'component'    			=> 'activity',
    		'item_id' 		  		=> 0, //optional, zero is default value
    	) );
    	
    	if ( ! $activity_id ) {
    		return '';
    	}
    
    	//Activity loop
    	if ( bp_has_activities( $activity_id . '&scope=favorites&max=10' )  ) :
    		while ( bp_activities() ) : bp_the_activity();
    			bp_get_template_part( 'activity/entry');
    		endwhile;
    	endif;
    }
    
    add_action ( 'my_favorites', 'bpmc_get_favorites' ); 
    
    ///////////////////////////////////////////////////////////////////////////////
    
    //Function for new My Mentions nav tab
    function bpmc_my_mentions_setup_nav() {
    	global $bp;
    	$parent_slug = 'my_mentions';
    	$child_slug = 'mentions_sub';	
    	
    	//Add nav item
    	bp_core_new_nav_item( array(
    	'name' => __( 'My Mentions' ),
    	'slug' => $parent_slug,
    	'screen_function' => 'bpmc_my_mentions_screen',
    	'position' => 110,
    	'default_subnav_slug' => $child_slug 
    	) );
    }
    
    function bpmc_my_mentions_screen() {	
    	add_action( 'bp_template_content', 'bpmc_my_mentions_screen_content' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function bpmc_my_mentions_screen_content() {
    	do_action( 'my_mentions' );
    }
    
    add_action( 'bp_setup_nav', 'bpmc_my_mentions_setup_nav' );
    
    function bpmc_get_mentions() {
    	$activity_id = bp_activity_get_activity_id( array(
    		'user_id'				=> bp_loggedin_user_id(),
    		'component'    			=> 'activity',
    		'item_id'				=> 0, //optional, zero is default value
    	) );
    	
    	if ( ! $activity_id ) {
    		return '';
    	}
    
    	//Activity loop
    	if ( bp_has_activities( $activity_id . '&scope=mentions&max=10' )  ) :
    		while ( bp_activities() ) : bp_the_activity();
    			bp_get_template_part( 'activity/entry');
    		endwhile;
    	endif;
    }
    
    add_action ( 'my_mentions', 'bpmc_get_mentions' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘User favorites and user mentions feed / loop’ is closed to new replies.
Skip to toolbar