Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add friend button everywhere


  • alpha2
    Participant

    @neoseeyou

    Hello

    I installed a plugin for buddypress to have more privacy for each member’s profile. This way if a non login or a non friend user try to visit a profile, he will be redirect to a specific page telling him to be login or to become friend with this user.

    The problem with this situation is that the non friend user will never be able to see the “add to friend button” on the private profile (due to the redirection)

    My solution is to put the “add to friend button” into user’s posts directly. Is it possible to add this button outside the buddypress template? meaning everywhere?

    Thank you

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

  • alpha2
    Participant

    @neoseeyou

    sorry to bump but i am really stuck with these.

    Many thanks


    alpha2
    Participant

    @neoseeyou

    I tried to apply this inside the single.php file

    <?php if ( function_exists( ‘bp_add_friend_button’ ) ) : ?>
    <?php bp_add_friend_button() ?>
    <?php endif; ?>

    But nothing appears. I tried many code without luck

    If someone can help me? Thank you


    danbp
    Participant

    @danbp

    Here a button example on blog page which let you add a post author as friend.

    function bpfr_add_friend_button() {
    // fetch post author id
    $user_id = get_the_author_meta( 'ID' );
    // calling the button
    $mybutton = bp_add_friend_button( $user_id ); 
    
    // condition
    	if ( ( is_user_logged_in() && is_page( 'blog' ) ) ){
    		echo $mybutton;
    	}
    } 
    
    // create the new action hook
    add_action( 'custom_zone', 'bpfr_add_friend_button' );

    Add this code to your child-theme functions.php, or to bp-custom.php

    And here the hook to add to template (child-theme) at the appropriate place.
    <?php do_action( 'custom_zone' ); ?> to template (generally single.php of your theme)


    alpha2
    Participant

    @neoseeyou

    Thank you so much Danbp

    Work like a charm

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add friend button everywhere’ is closed to new replies.
Skip to toolbar