Skip to:
Content
Pages
Categories
Search
Top
Bottom

Solved – How to use bp Nouveau theme hooks?


  • tatiana_k
    Participant

    @tatiana_k

    The previous buddypress theme used actions, for example do_action( ‘bp_after_profile_content’ ).
    Now there’re hooks instead, for example bp_nouveau_xprofile_hook( ‘after’, ‘loop_content’ );

    And I cannot find any information how these hooks can be used.
    What function do I have to use instead of add_action now?

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

  • Varun Dubey
    Participant

    @vapvarun

    You can compare the template files for both
    https://github.com/buddypress/BuddyPress/tree/master/src/bp-templates


    tatiana_k
    Participant

    @tatiana_k

    As you can see I have already compared it.
    In first case I used add_action() function.
    What function should I use with the second one?


    tatiana_k
    Participant

    @tatiana_k

    Here’s the solution how to use Nouveau theme hooks.
    It’s a bit complicated, but I’ve not found a way easier. And no other instructions.

    1. Find the hook you need.
    2. Search through the buddypress files and find the function with the same name (hook is a function, so find the source).
    In my example it’s function bp_nouveau_xprofile_hook($when = ”, $suffix = ”) {} (code reference page)
    3. Write down the array with all $hook components.
    Here they are bp/after/profile/loop_content
    I’d like to say that the pattern is
    bp/first-argument-in-hook/hook-name-from-function/second-argument-in-hook
    but here I had to change xprofile to profile, so the source code is still essential.
    4. Merge the array with _ (bp_after_profile_loop_content)
    5. Congratulations! We’ve got a custom action name and can continue with add_action().

    Honestly, I don’t understand why it has to be so complicated now, but here we are.


    kristifers
    Participant

    @kristifers

    Can someone please post some more examples of how to do this?


    Mad-As-A-Writer
    Participant

    @tinytiger

    Just wanted to say a HUGE thank you to @tatiana_k, using your tutorial I was able to find the bp_nouveau_member_hook( 'before', 'header_meta' ); hook in the Buddyboss member-header.php and in that I added an action to insert a profile field “tagline” below a user’s name on their profile. So before, a profile showed the avatar and Name, then on the next line the @mentionname but now it shows Avatar, Name, TAGLINE FROM PROFILE FIELD, @mentionname etc.

    My code:

    /*Add profile field 'tagline' to member profile, below member name*/
    add_action( 'bp_before_member_header_meta' , 'insert_tagline_in_profile' );
    function insert_tagline_in_profile(){
        $webdata = bp_get_member_profile_data( 'field=Tagline' );
    	if( $webdata != false )
    	echo '<div class="member-tagline">' . $webdata . '</div>';
        }

    Note, if you are using a profile field like Favourite Quote, you would replace Tagline in the field above with your field, ie ‘field=Favourite Quote’.

    Thanks to Tatiana I was able to realise I needed bp_before_member_header_meta as the hook, by adding bp / before (from the bp_nouveaux function) / member (because it’s inside the member section) / header_meta (from the bp_nouveaux function).

    If you want another example, I was able to use it to display the same field in the Activity Feed, but in this case I ended up adding the code directly to a template file copied into my child functions.php instead of using the hook, because I wanted the data nested in with the name etc instead of on the line below, but in case it helps anyone, the code to add a profile field below the user info in the activity feed is:

    /*add Tagline to activity feed user info using nouveau loop - no good for me as it
    inserts after the user header instead of inside it*/
    add_action( 'bp_before_activity_activity_content' , 'insert_tagline_in_feed' );
    function insert_tagline_in_feed(){
        $profile_id = bp_get_activity_user_id();
          $tagline_data = xprofile_get_field_data( 'Tagline', $profile_id);
          if( $tagline_data != false ){
              echo '<div class="activity-tagline">' . $tagline_data . '</div>';
          }
        }

    Once again my heartfelt thanks!


    Marek
    Participant

    @marekmaurizio

    You must have some problems to implement hooks like this.

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