BP_Groups_Invite_Template

Group invitation template loop class.

Defined (1)

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

/bp-groups/classes/class-bp-groups-invite-template.php  
  1. class BP_Groups_Invite_Template { 
  2.  
  3. /** 
  4. * @since 1.1.0 
  5. * @var int 
  6. */ 
  7. public $current_invite = -1; 
  8.  
  9. /** 
  10. * @since 1.1.0 
  11. * @var int 
  12. */ 
  13. public $invite_count; 
  14.  
  15. /** 
  16. * @since 1.1.0 
  17. * @var array 
  18. */ 
  19. public $invites; 
  20.  
  21. /** 
  22. * @since 1.1.0 
  23. * @var object 
  24. */ 
  25. public $invite; 
  26.  
  27. /** 
  28. * @since 1.1.0 
  29. * @var bool 
  30. */ 
  31. public $in_the_loop; 
  32.  
  33. /** 
  34. * @since 1.1.0 
  35. * @var int 
  36. */ 
  37. public $pag_page; 
  38.  
  39. /** 
  40. * @since 1.1.0 
  41. * @var int 
  42. */ 
  43. public $pag_num; 
  44.  
  45. /** 
  46. * @since 1.1.0 
  47. * @var string 
  48. */ 
  49. public $pag_links; 
  50.  
  51. /** 
  52. * @since 1.1.0 
  53. * @var int 
  54. */ 
  55. public $total_invite_count; 
  56.  
  57. /** 
  58. * BP_Groups_Invite_Template constructor. 
  59. * @since 1.5.0 
  60. * @param array $args 
  61. */ 
  62. public function __construct( $args = array() ) { 
  63.  
  64. // Backward compatibility with old method of passing arguments. 
  65. if ( ! is_array( $args ) || func_num_args() > 1 ) { 
  66. _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) ); 
  67.  
  68. $old_args_keys = array( 
  69. 0 => 'user_id',  
  70. 1 => 'group_id',  
  71. ); 
  72.  
  73. $args = bp_core_parse_args_array( $old_args_keys, func_get_args() ); 
  74.  
  75. $r = wp_parse_args( $args, array( 
  76. 'page' => 1,  
  77. 'per_page' => 10,  
  78. 'page_arg' => 'invitepage',  
  79. 'user_id' => bp_loggedin_user_id(),  
  80. 'group_id' => bp_get_current_group_id(),  
  81. ) ); 
  82.  
  83. $this->pag_arg = sanitize_key( $r['page_arg'] ); 
  84. $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); 
  85. $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 
  86.  
  87. $iquery = new BP_Group_Member_Query( array( 
  88. 'group_id' => $r['group_id'],  
  89. 'type' => 'first_joined',  
  90. 'per_page' => $this->pag_num,  
  91. 'page' => $this->pag_page,  
  92.  
  93. // These filters ensure we get only pending invites. 
  94. 'is_confirmed' => false,  
  95. 'inviter_id' => $r['user_id'],  
  96. ) ); 
  97.  
  98. $this->invite_data = $iquery->results; 
  99. $this->total_invite_count = $iquery->total_users; 
  100. $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) ); 
  101. $this->invite_count = count( $this->invites ); 
  102.  
  103. // If per_page is set to 0 (show all results), don't generate 
  104. // pag_links. 
  105. if ( ! empty( $this->pag_num ) ) { 
  106. $this->pag_links = paginate_links( array( 
  107. 'base' => add_query_arg( $this->pag_arg, '%#%' ),  
  108. 'format' => '',  
  109. 'total' => ceil( $this->total_invite_count / $this->pag_num ),  
  110. 'current' => $this->pag_page,  
  111. 'prev_text' => '←',  
  112. 'next_text' => '→',  
  113. 'mid_size' => 1,  
  114. 'add_args' => array(),  
  115. ) ); 
  116. } else { 
  117. $this->pag_links = ''; 
  118.  
  119. /** 
  120. * Whether or not there are invites to show. 
  121. * @since 1.1.0 
  122. * @return bool 
  123. */ 
  124. public function has_invites() { 
  125. if ( ! empty( $this->invite_count ) ) { 
  126. return true; 
  127.  
  128. return false; 
  129.  
  130. /** 
  131. * Increments up to the next invite to show. 
  132. * @since 1.1.0 
  133. * @return object 
  134. */ 
  135. public function next_invite() { 
  136. $this->current_invite++; 
  137. $this->invite = $this->invites[ $this->current_invite ]; 
  138.  
  139. return $this->invite; 
  140.  
  141. /** 
  142. * Rewinds to the first invite to show. 
  143. * @since 1.1.0 
  144. */ 
  145. public function rewind_invites() { 
  146. $this->current_invite = -1; 
  147. if ( $this->invite_count > 0 ) { 
  148. $this->invite = $this->invites[0]; 
  149.  
  150. /** 
  151. * Finishes up the invites to show. 
  152. * @since 1.1.0 
  153. * @return bool 
  154. */ 
  155. public function invites() { 
  156. $tick = intval( $this->current_invite + 1 ); 
  157. if ( $tick < $this->invite_count ) { 
  158. return true; 
  159. } elseif ( $tick == $this->invite_count ) { 
  160.  
  161. /** 
  162. * Fires right before the rewinding of invites list. 
  163. * @since 1.1.0 
  164. * @since 2.3.0 `$this` parameter added. 
  165. * @since 2.7.0 Action renamed from `loop_start`. 
  166. * @param BP_Groups_Invite_Template $this Instance of the current Invites template. 
  167. */ 
  168. do_action( 'group_invitation_loop_end', $this ); 
  169.  
  170. // Do some cleaning up after the loop 
  171. $this->rewind_invites(); 
  172.  
  173. $this->in_the_loop = false; 
  174. return false; 
  175.  
  176. /** 
  177. * Sets up the invite to show. 
  178. * @since 1.1.0 
  179. */ 
  180. public function the_invite() { 
  181. global $group_id; 
  182.  
  183. $this->in_the_loop = true; 
  184. $user_id = $this->next_invite(); 
  185.  
  186. $this->invite = new stdClass; 
  187. $this->invite->user = $this->invite_data[ $user_id ]; 
  188.  
  189. // This method previously populated the user object with 
  190. // BP_Core_User. We manually configure BP_Core_User data for 
  191. // backward compatibility. 
  192. if ( bp_is_active( 'xprofile' ) ) { 
  193. $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id ); 
  194.  
  195. $this->invite->user->avatar = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 
  196. $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ) ) ); 
  197. $this->invite->user->avatar_mini = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile photo of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) ); 
  198. $this->invite->user->email = $this->invite->user->user_email; 
  199. $this->invite->user->user_url = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login ); 
  200. $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>"; 
  201. $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) ); 
  202.  
  203. if ( bp_is_active( 'groups' ) ) { 
  204. $total_groups = BP_Groups_Member::total_group_count( $user_id ); 
  205. $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups ); 
  206.  
  207. if ( bp_is_active( 'friends' ) ) { 
  208. $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id ); 
  209.  
  210. $this->invite->user->total_blogs = null; 
  211.  
  212. // Global'ed in bp_group_has_invites() 
  213. $this->invite->group_id = $group_id; 
  214.  
  215. // loop has just started 
  216. if ( 0 == $this->current_invite ) { 
  217.  
  218. /** 
  219. * Fires if the current invite item is the first in the loop. 
  220. * @since 1.1.0 
  221. * @since 2.3.0 `$this` parameter added. 
  222. * @since 2.7.0 Action renamed from `loop_start`. 
  223. * @param BP_Groups_Invite_Template $this Instance of the current Invites template. 
  224. */ 
  225. do_action( 'group_invitation_loop_start', $this );