Skip to:
Content
Pages
Categories
Search
Top
Bottom

help with default activity stream tab


  • Masoud
    Participant

    @masoud1111

    hi.
    i am using latest versions of both wordpress and buddypress.and working on a food website.
    in this website , i wanted to allow only authors to post activity updates .
    (because it will be much easier for users to track their favorite chef recipes in the activity page.)
    so i’ve hide the ” personal ” submenu of activity tab : Activity > Personal (where people can post updates)
    with the help of following code in bp-custom.php :

    function bpfr_hide_tabs() {
    global $bp;
    if ( bp_is_user() && ( !current_user_can(author) || !current_user_can(administrator) ) ) {		
     bp_core_remove_subnav_item($bp->activity->slug, 'just-me');	}
    }
    add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );

    but now when i go to my profile (as a subscriber)
    i will see a 404 page.
    i’ve searched a lot and i noticed that , now that i’ve removed the default activity stream tab , i have to point it to another tab. so when a user profile is loading (or if a user clicks on activity tab),
    instead of default activity> personal . it load activity > mentions / OR / favorites / OR / … (some other submenu than personal )

    so my question is:

    how can i change the default activity stream tab
    from
    Activity > Personal
    To
    Activity > Mentions – Or to – Activity > Favorites – …

    thanks a lot for any help.

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

  • Masoud
    Participant

    @masoud1111

    is there a hook or action?
    or something i can put into a function like:

    function change_activity_default_tab()
    {
    global $bp;
    set[$bp->activity(current_action)]->mentions
    }
    

    Masoud
    Participant

    @masoud1111

    any idea?


    danbp
    Moderator

    @danbp

    Hi,

    all is explained in the doc !

    Changing Internal Configuration Settings

    Navigation API


    Masoud
    Participant

    @masoud1111

    hi @danbp
    and many thanks for your answer.

    i’ve read the docs already. but i read them again as you said.

    according to the docs, you can

    //Change the default tab opened when looking at a group (default is home):
    define( 'BP_GROUPS_DEFAULT_EXTENSION', 'members' );

    but i want to Change the default tab opened when looking at a Activity (default is Personal):

    so i put some codes (in bp-custom), to override :

    —-
    i’ve tried this (in bp-custom):
    <?php define( 'BP_ACTIVITY_DEFAULT_EXTENSION', 'mentions' ); ?>
    but i got 500 internal error.
    —-
    i’ve also tried this one (in bp-custom):

    <?php
     if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
     if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) )
     $bp->default_component = 'mentions' ;
    }
    ?>

    but i got error 500 internal again.
    —-
    and i’ve tried this one too (in bp-custom):

    function change_activity_default_tab()
    {
    global $bp;
    set[$bp->activity(current_action)]->mentions
    }
    

    and 500 internal error again.
    —-

    as i’ve read in the docs before, and i realized that it might be possible to change the Activity default extension too. (activity default tab is Personal (when you browse the prof , or click on switch from another tab to activity tab (when you click on activity tab) ) )

    so i came here for detail and get more help to solve it.

    i’d be grateful if you help me with this one too.

    thanks for your time and help.


    danbp
    Moderator

    @danbp

    @masoud1111,

    You’re talking about 2 different things: profile and groups. Let me explain you a little…

    On the buddy nav bar, navigation looks similar but doesn’t work the same way on profile and on group page. While profile navigation use nav and sub-nav, the group navigation use only sub-nav.

    Also, as documented on codex, define('BP_DEFAULT_COMPONENT', '...' ); is a constant related to a component, not a sub-nav tab. It let you define the default landing component, but not the one or other sub-nav tab. For example on profiles, the component Activity has 4 sub-nav attached to it: personnal, mentions, favorites, friends, groups

    To get one of them, you need to specify a new default tab, not another component. 🙂

    Buddybar main nav items on profile page
    Activity Profile Friends Groups Forums (if you use group forums)

    Default tab is Activity/personnal. To change it for “Friends” you use the constant:
    define('BP_DEFAULT_COMPONENT', 'friends' );

    To change the default landing tab from (Component/sub-tab). For example Activity/personnal to Activity/mentions, you define a new nav default tab with a function like this one:

    function bpex_set_member_default_nav() {
     
        bp_core_new_nav_default (
            array(
                'parent_slug'       => buddypress()->activity->id,
    	   // other "activity" sub_nav slugs : personal favorites friends groups
                'subnav_slug'       => 'mentions',
                'screen_function'   => 'bp_activity_screen_mentions'
            )
        );
    }
    add_action( 'bp_setup_nav', 'bpex_set_member_default_nav', 20 );

    For groups, it’s a similar technique, but a different syntax. The following example is a bit sophisticated, as it let you change the landing tab differently for each defined group.
    Depending each group activity or target, you can choose a different default tab.
    In this example, the kill bill group has Forum as landing tab, while Leon’s group use the group member directory.

    function bpex_custom_group_default_tab( $default_tab ){
    	/**
    	 * class_exists() is recommanded to avoid problems during updates 
    	 * or when Groups Component is deactivated
    	 */
    	if ( class_exists( 'BP_Group_Extension' ) ) : 
    	
    	$group = groups_get_current_group();//get the current group
    	
    	if( empty( $group ) ) {
    	 return $default_tab;
    	}
    		switch($group->slug){
    			
    			case 'kill-bill': // group name (use slug format)
    			$default_tab='forum';
    			break;
    			
    			case 'leon':
    			$default_tab='members';
    			break;
    			
    			default:		
    			$default_tab='home';// the default landing tab
    			break;
    			
    		}
    	
    	return $default_tab;
    	
    	endif; // end if ( class_exists( 'BP_Group_Extension' ) )
    }
    add_filter('bp_groups_default_extension','bpex_custom_group_default_tab');

    All this tested and working with BP 2.7.2 / Twenty Sixteen


    Masoud
    Participant

    @masoud1111

    @danbp
    hi.
    1 – first of all i have to thank you for your time, and complete explanation on this. i’m so grateful for that.
    ———
    2 – second, i have to apologize for my limited knowledge.
    i am at the beginning and still learning about php, DB, wordpress, and bp.
    so sorry if i had mistakes in codes.
    ———
    3 – third, i have to say that:
    i was not aware of this, that the usage of components are not the same. just like the example you said about buddy nav bar.
    in this code (which was not working) :

    <?php
     if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) {
     if ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) )
     $bp->default_component = 'mentions' ;
    }
    ?>

    my logic was : if ( !defined( 'BP_DEFAULT_COMPONENT' ) ) i use this code to understand if it’s a component or not.
    then after with this bp_is_active( 'activity' ) it will be checked , if it’s activity or not
    and with this isset( $bp->pages->activity ) to check if activity is to check whether activity is set or not.
    and if all true, then set and define a new nav default tab to mentions with this $bp->default_component = 'mentions'

    but it seems that my logic/codes are wrong from the start 🙁
    ———
    or for this code that i tried, and also went wrong:
    <?php define( 'BP_ACTIVITY_DEFAULT_EXTENSION', 'mentions' ); ?>
    my logic was, the <?php define( 'BP_ACTIVITY_DEFAULT_EXTENSION' part will force the bp, to set the default landing tab to activity.
    and with the second part , 'mentions' ); ?> it will force the Activity component to load on mentions sub-nav item.
    ———
    4 – i have to thank you for the group example. i didn’t know that set such a thing is possible.
    it was clear . i read it. and i’m trying to learn more about it.

    at last , i have to thank you again for the clear explanations.


    bbddev
    Participant

    @bbddev

    Hello,
    I tried to implement this code but without success.

    function bpex_set_member_default_nav() {
     
        bp_core_new_nav_default (
            array(
                'parent_slug'       => buddypress()->activity->id,
    	   // other "activity" sub_nav slugs : personal favorites friends groups
                'subnav_slug'       => 'friends',
                'screen_function'   => 'bp_activity_screen_friends'
            )
        );
    }
    add_action( 'bp_setup_nav', 'bpex_set_member_default_nav', 9 );

    My BuddyPress version is 3.0
    Have any change?
    I activate to the debug and I don’t receive any error


    welsh10
    Participant

    @welshlamb10

    Hi @danbp,

    Sorry to resurrect this thread.

    I’m looking at the code you provided for changing the Groups.

    Do you have any snippets or guidance for the following scenario.

    I would like to set a default BP Group per user within their user profile.

    User: Joe Bloggs
    BP Group: Joe Bloggs

    I would like to be able to select that the default group for Joe Bloggs > Joe Bloggs within his profile. Then when he posts in the Activity section his default group is that group.

    Any ideas on this or is it to bespoke?

    Thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar