BuddyDev

Search

[Resolved] How to add custom buttons to buddypress profile page

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #33755

    Hello

    Please how can I add two new custom buttons to the buddypress profiles page (bp_is_profile) were the other buttons are displayed like the public message and private message buttons. This buttons will be custom links to any page and should only appear in the profile header of the current logged in user. The buttons will have text and links below

    1. Write a new article — This button will link to https://www.website.com/publish/

    2. Post a free advert — This button will link to https://www.website.com/advertise/

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33763

    Hello Tosin,

    Thank you for posting. Please try the follwoing code it will add two on loggedin user profile with “BuddyPress Nouveau” template active

    
    
    /**
     * Add two buttons
     *
     * @param array $buttons Buttons.
     *
     * @return array
     */
    function buddydev_add_custom_buttons( $buttons ) {
    
    	if ( ! bp_is_my_profile() ) {
    		return $buttons;
    	}
    
    	$buttons['new_article'] = array(
    		'id'                => 'buddydev_new_article',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'button_element'    => 'a',
    		'link_text'         => __( 'Write a new article' ),
    		'button_attr'       => array(
    			'href'  => esc_url( 'https://www.website.com/publish/' ),
    			'title' => __( 'Write a new article' ),
    		)
    	);
    
    	$buttons['new_advert'] = array(
    		'id'                => 'buddydev_new_advert',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'button_element'    => 'a',
    		'link_text'         => __( 'Post a free advert' ),
    		'button_attr'       => array(
    			'href'  => esc_url( 'https://www.website.com/advertise/' ),
    			'title' => __( 'Post a free advert' ),
    		)
    	);
    
    	return $buttons;
    }
    
    add_filter( 'bp_nouveau_get_members_buttons', 'buddydev_add_custom_buttons' );
    
    

    Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #33768

    Thanks for the feedback but im using the legacy template

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #33771

    The code did not work for legacy template

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33772

    Hello Tosin,

    Try the following code.

    
    /**
     * Add custom button on user own profile
     */
    function buddydev_add_custom_buttons() {
    
    	if ( ! bp_is_my_profile() ) {
    		return;
    	}
    
    	$new_article_button_args = array(
    		'id'                => 'buddydev_new_article',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'block_self'        => false,
    		'link_href'         => esc_url( 'https://www.website.com/publish/' ),
    		'link_text'         => __( 'Write a new article' ),
    	);
    
    	$new_advert_button_args = array(
    		'id'                => 'buddydev_new_advert',
    		'component'         => 'members',
    		'must_be_logged_in' => true,
    		'block_self'        => false,
    		'link_href'         => esc_url( 'https://www.website.com/advertise/' ),
    		'link_text'         => __( 'Post a free advert' ),
    	);
    
    	echo bp_get_button( $new_article_button_args );
    	echo bp_get_button( $new_advert_button_args );
    }
    
    add_action( 'bp_member_header_actions', 'buddydev_add_custom_buttons' );
    
    

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #33779

    This also did not work

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33784

    Hello Tosin,

    Please make sure in your “member-header.php” template has this action “bp_member_header_actions”. This is working for me.

    https://tinyurl.com/y5wwuhos

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #33787

    YES YES YES It worked perfectly there was a caching problem with my site so that’s why the changes did not reflect before.

    Thank you so much

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #33788

    Hello Tosin,

    Thank you for the acknowledgement. I am glad I could help.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved