Helping you Build Your Own Social Network!

Faster, better and easier!

How to target a subnav item in a function?

(8 posts) (2 voices)

  1. Hi all!

    I’m trying to write a simple function for the admin section of a new theme that will add_action if a user tries to visit any uri related to groups (then adapt it for members, activity, etc.)

    Using $bp->current_component == ('groups') works fine for top-level stuff, but I haven't figured out how to target subnavs like this:

    http://example.com/members/username/activity/groups/

    Can anyone clue me in on how to specify a member profile subnav item?

    I’ve been searching the codex but haven’t found what I’m looking for (yet…)

    (The next challenge will be to learn how to filter out group activity from the stream if the function is triggered. Oh fun!)

    Posted 1 year ago #
  2. Hi Patrick,
    For the specific thing, say you want to trigger it on membersname/activity/groups
    You can use the following thing

    if($bp->current_component==BP_ACTIVITY_SLUG && $bp->current_action==BP_GROUPS_SLUG)
    //do something

    a slight explanation
    //$bp->current_action, points to the componentname/action name
    //$bp->action_variables;//it's an array and contains any other chunk of url for example if the url is membername/gallery/my-test-gallery/some-photo-here, $bp->current_component is "gallery", $bp->current_action is "my-test-gallery", $bp->action_variables[0] is "some-photo-here", I hope that gives you an idea about these

    I am not sure what you will need to generalize it or how you want to generalize it. If you can explain a little more, I am sure we can have better way :)

    Posted 1 year ago #
  3. Hi Brajesh, thanks for replying so quickly!

    Adding $bp->current_action did the trick for the subnavs... I thought I had tried that, but maybe not ;-)

    What I'm doing is enhancing the privacy features of my BuddyBuilder theme for the next update. As it is now, site admins can select to show/hide components/pages/posts depending on is_user_logged_in status and display a not-logged-in message to users who try to access those urls.

    I've added a 3rd option to redirect to an admin-defined url to each component if not logged in, and would like to now give each of those options more "reach".

    For example, if an admin selects to hide everything group-related from not-logged-in users, the following should be hidden:

    Groups directory & groups list in member profiles (DONE with: $bp->current_component==BP_GROUPS_SLUG)
    Group activity in member subnav (DONE with: $bp->current_component==BP_ACTIVITY_SLUG && $bp->current_action==BP_GROUPS_SLUG)
    All group activity in stream (need filters here)

    Thanks for your help!

    Posted 1 year ago #
  4. ooh wow, that's a cool feature you are adding to the theme. looking forward to it.
    I am glad, I could help a little in figuring our the things :)

    Posted 1 year ago #
  5. Thanks Brajesh!

    I'll be sure to update my earlier thread when the next version is ready:
    http://buddydev.com/forums/topic/my-new-years-gift-to-all-members-of-buddydev#post-6101

    Posted 1 year ago #
  6. :)
    sure, I look forward to that. Please do let me know if you need any assistance anytime :)

    Posted 1 year ago #
  7. @sbrajesh

    OK, I'll take you up on that offer!

    Do you have an idea how to make the user "Profile" tab the default landing tab instead of "Activity"?

    :-)

    EDIT: I've tried the following in bp-custom.php (not a good idea in a theme) and it works to re-order the tabs, but doesn't change the default landing tab.

    function change_profile_tab_order() {
    global $bp;
    
    $bp->bp_nav['profile']['position'] = 10;
    $bp->bp_nav['activity']['position'] = 20;
    $bp->bp_nav['friends']['position'] = 30;
    $bp->bp_nav['groups']['position'] = 40;
    $bp->bp_nav['blogs']['position'] = 50;
    $bp->bp_nav['messages']['position'] = 60;
    $bp->bp_nav['settings']['position'] = 70;
    }
    add_action( 'bp_setup_nav', 'change_profile_tab_order', 999 );
    Posted 1 year ago #
  8. Oh yeah, this default tab thing is something I've been messing with for awhile. I filed a ticket for it 7 weeks ago and was informed by djpaul that it can't be done in functions.php 'cuz it gets loaded too late. Unless you have a brilliant workaround, that is...

    http://trac.buddypress.org/ticket/3007

    Posted 1 year ago #

Reply

You must log in to post.