bp_get_group_join_button

Return button to join a group.

Description

(false|string) bp_get_group_join_button( (bool) $group = false ); 

Returns (false|string)

Parameters (1)

0. $group — Optional. (bool) => false
Single group object.

Usage

  1. if ( !function_exists( 'bp_get_group_join_button' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-groups/bp-groups-template.php'; 
  3.  
  4. // Single group object. 
  5. $group = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_group_join_button($group); 
  9.  

Defined (1)

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

/bp-groups/bp-groups-template.php  
  1. function bp_get_group_join_button( $group = false ) { 
  2. global $groups_template; 
  3.  
  4. // Set group to current loop group if none passed. 
  5. if ( empty( $group ) ) { 
  6. $group =& $groups_template->group; 
  7.  
  8. // Don't show button if not logged in or previously banned. 
  9. if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) { 
  10. return false; 
  11.  
  12. // Group creation was not completed or status is unknown. 
  13. if ( empty( $group->status ) ) { 
  14. return false; 
  15.  
  16. // Already a member. 
  17. if ( ! empty( $group->is_member ) ) { 
  18.  
  19. // Stop sole admins from abandoning their group. 
  20. $group_admins = groups_get_group_admins( $group->id ); 
  21. if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) { 
  22. return false; 
  23.  
  24. // Setup button attributes. 
  25. $button = array( 
  26. 'id' => 'leave_group',  
  27. 'component' => 'groups',  
  28. 'must_be_logged_in' => true,  
  29. 'block_self' => false,  
  30. 'wrapper_class' => 'group-button ' . $group->status,  
  31. 'wrapper_id' => 'groupbutton-' . $group->id,  
  32. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),  
  33. 'link_text' => __( 'Leave Group', buddypress ),  
  34. 'link_class' => 'group-button leave-group',  
  35. ); 
  36.  
  37. // Not a member. 
  38. } else { 
  39.  
  40. // Show different buttons based on group status. 
  41. switch ( $group->status ) { 
  42. case 'hidden' : 
  43. return false; 
  44.  
  45. case 'public': 
  46. $button = array( 
  47. 'id' => 'join_group',  
  48. 'component' => 'groups',  
  49. 'must_be_logged_in' => true,  
  50. 'block_self' => false,  
  51. 'wrapper_class' => 'group-button ' . $group->status,  
  52. 'wrapper_id' => 'groupbutton-' . $group->id,  
  53. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),  
  54. 'link_text' => __( 'Join Group', buddypress ),  
  55. 'link_class' => 'group-button join-group',  
  56. ); 
  57. break; 
  58.  
  59. case 'private' : 
  60.  
  61. // Member has outstanding invitation - 
  62. // show an "Accept Invitation" button. 
  63. if ( $group->is_invited ) { 
  64. $button = array( 
  65. 'id' => 'accept_invite',  
  66. 'component' => 'groups',  
  67. 'must_be_logged_in' => true,  
  68. 'block_self' => false,  
  69. 'wrapper_class' => 'group-button ' . $group->status,  
  70. 'wrapper_id' => 'groupbutton-' . $group->id,  
  71. 'link_href' => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),  
  72. 'link_text' => __( 'Accept Invitation', buddypress ),  
  73. 'link_class' => 'group-button accept-invite',  
  74. ); 
  75.  
  76. // Member has requested membership but request is pending - 
  77. // show a "Request Sent" button. 
  78. } elseif ( $group->is_pending ) { 
  79. $button = array( 
  80. 'id' => 'membership_requested',  
  81. 'component' => 'groups',  
  82. 'must_be_logged_in' => true,  
  83. 'block_self' => false,  
  84. 'wrapper_class' => 'group-button pending ' . $group->status,  
  85. 'wrapper_id' => 'groupbutton-' . $group->id,  
  86. 'link_href' => bp_get_group_permalink( $group ),  
  87. 'link_text' => __( 'Request Sent', buddypress ),  
  88. 'link_class' => 'group-button pending membership-requested',  
  89. ); 
  90.  
  91. // Member has not requested membership yet - 
  92. // show a "Request Membership" button. 
  93. } else { 
  94. $button = array( 
  95. 'id' => 'request_membership',  
  96. 'component' => 'groups',  
  97. 'must_be_logged_in' => true,  
  98. 'block_self' => false,  
  99. 'wrapper_class' => 'group-button ' . $group->status,  
  100. 'wrapper_id' => 'groupbutton-' . $group->id,  
  101. 'link_href' => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),  
  102. 'link_text' => __( 'Request Membership', buddypress ),  
  103. 'link_class' => 'group-button request-membership',  
  104. ); 
  105.  
  106. break; 
  107.  
  108. /** 
  109. * Filters the HTML button for joining a group. 
  110. * @since 1.2.6 
  111. * @since 2.4.0 Added $group parameter to filter args. 
  112. * @param string $button HTML button for joining a group. 
  113. * @param object $group BuddyPress group object 
  114. */ 
  115. return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );