Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Customizing bp_get_displayed_user_nav()

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

  • defunct
    Participant

    @defunctlife

    Well,

    I tried remove_action on the function I found that I want to customize, but it doesn’t work apparently because bp-custom.php is being loaded before bp-friends. I tried this in my theme’s functions.php as well, but it still does not work. What am I doing wrong?

    /***
    * Create custom functions for buddypress so updates do not override customizations
    */

    function my_friends_setup_nav() {
    global $bp;

    /* Add ‘Friends’ to the main navigation */
    bp_core_new_nav_item( array( ‘name’ => sprintf( __( ‘Friends (%d)2222′, ‘buddypress’ ), friends_get_total_friend_count() ), ‘slug’ => $bp->friends->slug, ‘position’ => 60, ‘screen_function’ => ‘friends_screen_my_friends’, ‘default_subnav_slug’ => ‘my-friends’, ‘item_css_id’ => $bp->friends->id ) );

    $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . ‘/’;

    /* Add the subnav items to the friends nav item */
    bp_core_new_subnav_item( array( ‘name’ => __( ‘My Friends’, ‘buddypress’ ), ‘slug’ => ‘my-friends’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_my_friends’, ‘position’ => 10, ‘item_css_id’ => ‘friends-my-friends’ ) );
    bp_core_new_subnav_item( array( ‘name’ => __( ‘Requests’, ‘buddypress’ ), ‘slug’ => ‘requests’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_requests’, ‘position’ => 20, ‘user_has_access’ => bp_is_my_profile() ) );

    if ( $bp->current_component == $bp->friends->slug ) {
    if ( bp_is_my_profile() ) {
    $bp->bp_options_title = __( ‘My Friends’, ‘buddypress’ );
    } else {
    $bp->bp_options_avatar = bp_core_fetch_avatar( array( ‘item_id’ => $bp->displayed_user->id, ‘type’ => ‘thumb’ ) );
    $bp->bp_options_title = $bp->displayed_user->fullname;
    }
    }

    do_action( ‘my_friends_setup_nav’);
    }
    remove_action( ‘bp_setup_nav’, ‘friends_setup_nav’);
    add_action( ‘bp_setup_nav’, ‘my_friends_setup_nav’);


    Jeff Sayre
    Participant

    @jeffsayre

    I have not looked at your pasted code. But you are correct in stating that bp-custom.php loads prior to the accessory core BP files. I’d suggest the following tweaks:


    remove_action( ‘bp_setup_nav’, ‘friends_setup_nav’, 5);
    add_action( ‘bp_setup_nav’, ‘my_friends_setup_nav’);

    Basically, hooks are defaulted to a priority of 10. So, you want to make sure that friends_setup_nav is removed before your custom my_friends_setup_nav() is added.

    This is just a quick stab at guessing the proper hook firing sequence. So, if this does not work, I suggest installing my WordPress Hook Sniffer plugin.


    defunct
    Participant

    @defunctlife

    Thanks for having a look Jeff, however it didn’t help. I simply want to edit some HTML that is generated in a tab and it’s a total nightmare. Besides the fact that I wish this was generated in a template since it generates HTML, I just cannot seem to override this function: friends_setup_nav() located in bp-friends.php (line 87).

    Since that function adds it’s own action do_action( ‘friends_setup_nav’); I’m assuming I can remove it and add my own in it’s place but it doesn’t work.

    Even if I do install that plugin and find when it is fired, how does that help me? Does it just change how or where I call remove_action?

    Should I be trying to hook into something else?


    Jeff Sayre
    Participant

    @jeffsayre

    Okay, so I quickly ran WP Hook Sniffer and saw that the remove_action function does not get fired because when it is invoked, the function friends_setup_nav has not yet been added via the add_action function. Furthermore, the add_action request in your bp-custom.php file is invoked before the add_action request hooked to friends_setup_nav(). So, whereas your custom navigation code is being triggered, it is quickly replaced with the default, core friends navigation code in friends_setup_nav().

    The simple solution is to set the priority of your custom function to something greater than 10. Don’t even bother with the remove_action function as it will never work at this point in code execution.

    add_action( ‘bp_setup_nav’, ‘my_friends_setup_nav’, 11 );

    That should work!


    defunct
    Participant

    @defunctlife

    Hey Jeff,

    Yeah I had tried that already (tried 99 etc…) and nothing seems to work. Thanks for trying though, really do appreciate the time.

    I decided to take another route and override the $bp global in my functions.php

    $disp_user = $bp->displayed_user->id;
    if( bp_friend_get_total_requests_count($disp_user) > 0) {
    $bp->bp_nav .= ‘(‘.bp_friend_get_total_requests_count($disp_user).’)‘;
    }

    This doesn’t really allow for the customization I want, but I guess it will have to do for now.


    Jeff Sayre
    Participant

    @jeffsayre

    Hum. That is odd. I copied the friends_setup_nav() into bp-custom.php, just like you did, and made one minor change to the outputted text so that I would know if it took. I altered the priority as indicated above, and it worked without issue.

    I would suggest that you first get the override working as I did before you try more complex output manipulation. Once you know that it is working, you can then move on to customizing the output. I would guess that there is something else in your custom code output that is causing this not to work. Have you checked PHP’s error logs?

    Also, make sure that you are using the default BuddyPress theme and no 3rd-party plugins. Distill your operating environment down to the least common denominator when trying to adjust the output of core files. That way, once you get things working as you like, if you have issues when switching to a custom theme and/or activating a 3rd-party plugin, that it is more then likely some conflict with those items.

    what about removing and re-adding just the subnav? (or getting a bit hackery and editing $bp->bp_options_nav array)


    defunct
    Participant

    @defunctlife

    @Jeff you copied it in as my_friends_setup_nav()? Can you post your function please?


    defunct
    Participant

    @defunctlife

    @Jeff indeed it’s working now: Here is my bp-custom.php for others: http://pastie.org/1030176

    I think it wasn’t working because I had adjusted the do_action() function from within my function to do_action( ‘my_friends_setup_nav’); and I guess it needs to be left as do_action( ‘friends_setup_nav’);

    Thanks for all your help Jeff!


    Jeff Sayre
    Participant

    @jeffsayre

    Your welcome! I’m glad you got it to work.

    Hi !
    I want to do the same thing what you defunctlif but i have a problem. I created bp-custom.php file with your settings and put it in buddypress main directory and it doesn’t work :( should i put it somewhere else?

    p.s im quite noob in programming :D

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] Customizing bp_get_displayed_user_nav()’ is closed to new replies.
Skip to toolbar