Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is bp-friends-template.php editable?

  • Avatar of terraling
    terraling
    Participant

    @terraling

    I looked through the docs about the new template system and I don’t think this falls within that, but, anyway, is there some way to override bp-friends-template.php (or similar files, for that matter) by having a copy in an appropriate sub-directory in my theme? Or some other way that doesn’t involve making changes to the core?

    Thanks.

Viewing 22 replies - 1 through 22 (of 22 total)
  • Avatar of Hugo
    Hugo
    Moderator

    @hnla

    bp-friends-template.php is not an actual template file you don’t override it it’s a core file.

    You need to explain what you are trying to do.

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    As @hnla said, bp-friends-template.php isn’t a template file so you can’t override it. Some parts of it may be filterable (look for the apply_filters() function) so you may be able to modify parts of it’s output via your theme’s functions.php. Again though – it all depends on what you want to do.

    Avatar of terraling
    terraling
    Participant

    @terraling

    In this instance I want to change the text for some of the buttons generated, e.g. the ‘Add Friend’ button etc.

    I know that one way to do it is to use a translation file, but that sort of seemed like overkill to just change a few small instances of text.

    But is that the recommended solution? I don’t mind dropping a function into my functions.php, although I may need a few pointers on how if it’s possible.

    Thanks for your feedback.

    Avatar of terraling
    terraling
    Participant

    @terraling

    Taking a quick look at the bp-friends-template.php file it would also be able to change some other things, such as the class names that are added to the buttons, though it’s not a deal-breaker.

    				$button = array(
    					'id'                => 'not_friends',
    					'component'         => 'friends',
    					'must_be_logged_in' => true,
    					'block_self'        => true,
    					'wrapper_class'     => 'friendship-button not_friends',
    					'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    					'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
    					'link_text'         => __( 'Add Friend', 'buddypress' ),
    					'link_title'        => __( 'Add Friend', 'buddypress' ),
    					'link_id'           => 'friend-' . $potential_friend_id,
    					'link_rel'          => 'add',
    					'link_class'        => 'friendship-button not_friends add'
    				);
    
    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    No don’t change tokens , class & ID’s are best left alone many are there as specific hooks for ajax firing / JS functionality, we went through an exercise of unbinding tokens from markup to allow for more flexibility for devs in re-factoring markup without upsetting functionality but tokens ought to be retained, you can add your own though or add classes to body tag.

    Avatar of terraling
    terraling
    Participant

    @terraling

    Yeah, I just wanted to add some classes that I’m already using elsewhere in my theme if it’s straightforward to do, hence the question about whether it is possible to edit the bp-friends-template.php file.

    The answer to that is no, but can I override the above code somewhere else such as functions.php? If yes, an example of how would be really helpful.

    Thanks again…

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    As Hugo said you could always add classes to the body element. You would do it like this:

    //add class to body element
    function add_to_body_class( $classes ) {
    	$classes[] = 'custom_class_name_goes_here';
    	return $classes;
    }
    add_filter( 'body_class', 'add_to_body_class' );
    Avatar of terraling
    terraling
    Participant

    @terraling

    Sorry, we seem to be talking at cross purposes. Adding body classes doesn’t do anything useful for me, I wanted to add classes to the html generated for the button, either add to wrapper_class or link_class above, and at the same time (more importantly) change the link_text from __( ‘Add Friend’, buddypress) to something else.

    I had hoped it would be as simple as reproducing the code from bp-friends-template.php in another location in my theme folder to overwrite the original, but from your replies it appears that such a thing is not possible.

    Thanks anyway for your help.

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Well there is a filter on the button assembly in that file
    return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) );
    so you could do this:

    
    function my_add_friend_link_text($button) {
    $button['link_text'] = 'new button text';
    return $button;
    }
    add_filter('bp_get_add_friend_button', 'my_add_friend_link_text');
    

    Not necessarily suggesting this as the best approach though.

    Avatar of terraling
    terraling
    Participant

    @terraling

    Can’t hurt though, right?!

    Thanks for the tip, I’ll play around with it and if I encounter any issues I’ll revert to creating a translation file…

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Bear in mind with that $button array it’s run through a switch statement to determine which state the button is in ‘is_friend()’ and which args to pass.

    Avatar of funmi omoba
    funmi omoba
    Participant

    @funmi-omoba

    @hnla,

    thank for the above code, please how can i use it to target Cancel Friendship button alone

    I have tried the below code with no luck.

    function my_add_friend_link_text($button) {
    $button['link_text'] = 'Unfriend';
    if($button['id']!='is_friend');
    return $button;
    }
    add_filter('bp_get_add_friend_button', 'my_add_friend_link_text');

    Note: Your code above changed both add friend and cancel friend button to the same thing.

    Regards

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Ah well my code wasn’t that tested might need to pick up the $args instead, have a look at the core function.

    Avatar of meg@info
    meg@info
    Participant

    @megainfo

    Hi @funmi-omoba, check this example of code, he may help you

    function bp_new_link_class_get_add_friend_button( $button ) {
            // add new css classes to the button   
     	$button['link_class'] .= ' new-button-class2 new-button-class2 ';
    
    	switch($button['id']){
    		case 'not_friends' :
    			$button['link_class'] .= ' btn-add-friend';
    			break;
    		case 'pending' :
    			$button['link_class'] .= ' btn-pending-rel';
    			break;
    
    		case 'is_friend' :
    			$button['link_class'] .= ' btn-remove-friend';
    			break;
    
    		default :
    			$button['link_class'] .= '';
    			break;
    		default: 
    
    			break;
    	}
    	return $button;
    }
    add_filter( 'bp_get_add_friend_button', 'bp_new_link_class_get_add_friend_button' , 1);
    

    Regards,

    Avatar of funmi omoba
    funmi omoba
    Participant

    @funmi-omoba

    @megainfo, have had a look through your code but still no luck as its not working. Any help from anyone will be highly appreciated. I just want to filter is_button text to another text.

    @terraling,any new development?

    Thanks

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    You needed to persevere with what you were trying as that’s no more than I was/am doing but it’s not for me :)

    You lookm like you set the button text then checked if the button id wasn’t ‘is_friend’ then returned the $button.

    This works:

    
    function my_add_friend_link_text($button) {
    if( 'is_friend' == $button['id'] ):
     $button['link_text'] = 'Unfriend';
     return $button;
    else:
     return $button;
    endif;
    }
    add_filter('bp_get_add_friend_button', 'my_add_friend_link_text');
    
    Avatar of terraling
    terraling
    Participant

    @terraling

    Sorry @funmi-omoba, I didn’t quite get your question, but here is the code I added to my functions.php based on earlier answers:

    function my_add_friend_link_text($button) {
    	switch ( $button['id'] ) {
    		case 'pending' :
    			$button['link_text'] = 'x Pending';
    			$button['link_title'] = 'Cancel friend request';
    			$button['link_class'] .= ' btn btn-xs btn-warning';
    		break;
    
    		case 'is_friend' :
    			$button['link_text'] = '- Unfriend';
    			$button['link_class'] .= ' btn btn-xs btn-danger';
    		break;
    
    		default:
    			$button['link_text'] = '+ Friend';
    			$button['link_title'] = 'Send friend request';
    			$button['link_class'] .= ' btn btn-xs btn-success';
    	}
    	return $button;
    }
    add_filter('bp_get_add_friend_button', 'my_add_friend_link_text');
    

    I’m changing the link text, changing the title, and adding additional classes (I’m using bootstrap and wanted the buttons styled the same as elsewhere, though that means deleting the generic button styling from buddypress.css)

    Hope that helps.

    Avatar of terraling
    terraling
    Participant

    @terraling

    I’m trying to finesse this a little further and I’m hitting the bumpers, don’t know if you have any further insights @hnla or whether you’ve run out of patience with this one (understandable).

    One of the things I don’t like about how the friendship buttons work is that for pending it doesn’t differentiate who originated the request (although that is recorded in the bp_friends table in the db), so that the person who originated the request will see ‘Cancel friendship request’ when viewing the other’s profile, but vice versa, too. If the recipient of the request presses the button they get a ‘Friendship request cannot be cancelled’-type message, whereas it seems more appropriate that they shouldn’t see the button at all, or that it should be disabled.

    Hooking in to ‘bp_get_add_friend_button’ I have been able to alter $button as above, but I would like to be able to get in earlier (or reproduce the relevant part of bp-friends-template.php) to be able to add some logic for the case=’pending’ to check whether the current user was the initiator of the friendship request or not, and if they were the recipient of the request, disable the button.

    Any advice..? Thanks…

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    Not necessarily following this without a test case in front of me but are you able to produce a good use case for this behaviour, would we all ( the BP core app ) benefit from the change and then are you able to edit the core files to achieve it? In which case might be a cause for a patch to core?

    Avatar of terraling
    terraling
    Participant

    @terraling

    Case?

    John sends a friend request to Lucy.

    Lucy receives an email notification which invites her to check out John’s profile.

    When she does she sees a ‘Cancel Friendship Request’ button. She also sees how fond John is of gerbils and she quickly hits the button, but gets an error message ‘Friendship request cannot be cancelled’.

    She can’t cancel it because she didn’t initiate it.

    It seems logically there might be 3 options:

    1. she sees no button (likewise when John appears on the member directory list);
    2. she sees a button which takes her to her friend requests page where she can accept or reject it; or,
    3. she is able to accept/reject it then and there.

    These options become more user friendly but harder to implement.

    I would have thought 1. is, ahem, fairly straightforward, and wouldn’t break anything anywhere else.

    It would be helpful if check_is_friend in bp-friends-classes.php returned not just ‘pending’, ‘is_friend’, or ‘not_friends’ but differentiated ‘pending’ according to whether the current user had initiated it or not.

    But now I’m getting a little out of my depth…

    Avatar of funmi omoba
    funmi omoba
    Participant

    @funmi-omoba

    @hnla, you are a life safer… Thumbs up. Exactly what I am looking for

    Regards

    Avatar of Hugo
    Hugo
    Moderator

    @hnla

    @terraling version also works if you want more exacting control.

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

You must be logged in to reply to this topic.