bp_get_add_friend_button

Create the Add Friend button.

Description

(string) bp_get_add_friend_button( (int) $potential_friend_id = 0, (bool) $friend_status = false ); 

Returns (string)

HTML for the Add Friend button.

Parameters (2)

0. $potential_friend_id — Optional. (int)
The potential friend id.
1. $friend_status — Optional. (bool) => false
Not currently used.

Usage

  1. if ( !function_exists( 'bp_get_add_friend_button' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-template.php'; 
  3.  
  4. // The potential friend id. 
  5. $potential_friend_id = -1; 
  6.  
  7. // Not currently used. 
  8. $friend_status = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_get_add_friend_button($potential_friend_id, $friend_status); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-friends/bp-friends-template.php  
  1. function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) { 
  2.  
  3. if ( empty( $potential_friend_id ) ) 
  4. $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id ); 
  5.  
  6. $is_friend = bp_is_friend( $potential_friend_id ); 
  7.  
  8. if ( empty( $is_friend ) ) 
  9. return false; 
  10.  
  11. switch ( $is_friend ) { 
  12. case 'pending' : 
  13. $button = array( 
  14. 'id' => 'pending',  
  15. 'component' => 'friends',  
  16. 'must_be_logged_in' => true,  
  17. 'block_self' => true,  
  18. 'wrapper_class' => 'friendship-button pending_friend',  
  19. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  20. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),  
  21. 'link_text' => __( 'Cancel Friendship Request', buddypress ),  
  22. 'link_id' => 'friend-' . $potential_friend_id,  
  23. 'link_rel' => 'remove',  
  24. 'link_class' => 'friendship-button pending_friend requested' 
  25. ); 
  26. break; 
  27.  
  28. case 'awaiting_response' : 
  29. $button = array( 
  30. 'id' => 'awaiting_response',  
  31. 'component' => 'friends',  
  32. 'must_be_logged_in' => true,  
  33. 'block_self' => true,  
  34. 'wrapper_class' => 'friendship-button awaiting_response_friend',  
  35. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  36. 'link_href' => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',  
  37. 'link_text' => __( 'Friendship Requested', buddypress ),  
  38. 'link_id' => 'friend-' . $potential_friend_id,  
  39. 'link_rel' => 'remove',  
  40. 'link_class' => 'friendship-button awaiting_response_friend requested' 
  41. ); 
  42. break; 
  43.  
  44. case 'is_friend' : 
  45. $button = array( 
  46. 'id' => 'is_friend',  
  47. 'component' => 'friends',  
  48. 'must_be_logged_in' => true,  
  49. 'block_self' => false,  
  50. 'wrapper_class' => 'friendship-button is_friend',  
  51. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  52. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),  
  53. 'link_text' => __( 'Cancel Friendship', buddypress ),  
  54. 'link_id' => 'friend-' . $potential_friend_id,  
  55. 'link_rel' => 'remove',  
  56. 'link_class' => 'friendship-button is_friend remove' 
  57. ); 
  58. break; 
  59.  
  60. default: 
  61. $button = array( 
  62. 'id' => 'not_friends',  
  63. 'component' => 'friends',  
  64. 'must_be_logged_in' => true,  
  65. 'block_self' => true,  
  66. 'wrapper_class' => 'friendship-button not_friends',  
  67. 'wrapper_id' => 'friendship-button-' . $potential_friend_id,  
  68. 'link_href' => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),  
  69. 'link_text' => __( 'Add Friend', buddypress ),  
  70. 'link_id' => 'friend-' . $potential_friend_id,  
  71. 'link_rel' => 'add',  
  72. 'link_class' => 'friendship-button not_friends add' 
  73. ); 
  74. break; 
  75.  
  76. /** 
  77. * Filters the HTML for the add friend button. 
  78. * @since 1.1.0 
  79. * @param string $button HTML markup for add friend button. 
  80. */