bp_dtheme_ajax_invite_user

Invites a friend to join a group via a POST request.

Description

bp_dtheme_ajax_invite_user(); 

Usage

  1. if ( !function_exists( 'bp_dtheme_ajax_invite_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-themes/bp-default/_inc/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_dtheme_ajax_invite_user(); 
  7.  

Defined (1)

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

/bp-themes/bp-default/_inc/ajax.php  
  1. function bp_dtheme_ajax_invite_user() { 
  2. // Bail if not a POST action 
  3. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 
  4. return; 
  5.  
  6. check_ajax_referer( 'groups_invite_uninvite_user' ); 
  7.  
  8. if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] ) 
  9. return; 
  10.  
  11. if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) ) 
  12. return; 
  13.  
  14. if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) ) 
  15. return; 
  16.  
  17. $group_id = (int) $_POST['group_id']; 
  18. $friend_id = (int) $_POST['friend_id']; 
  19.  
  20. if ( 'invite' == $_POST['friend_action'] ) { 
  21. $group = groups_get_group( $group_id ); 
  22.  
  23. // Users who have previously requested membership do not need 
  24. // another invitation created for them 
  25. if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 
  26. $user_status = 'is_pending'; 
  27.  
  28. // Create the user invitation 
  29. } else if ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) { 
  30. $user_status = 'is_invited'; 
  31.  
  32. // Miscellaneous failure 
  33. } else { 
  34. return; 
  35.  
  36. $user = new BP_Core_User( $_POST['friend_id'] ); 
  37.  
  38. echo '<li id="uid-' . $user->id . '">'; 
  39. echo $user->avatar_thumb; 
  40. echo '<h4>' . $user->user_link . '</h4>'; 
  41. echo '<span class="activity">' . esc_attr( $user->last_active ) . '</span>'; 
  42. echo '<div class="action"> 
  43. <a class="button remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . $_POST['group_id'] . '/invites/remove/' . $user->id, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', buddypress ) . '</a> 
  44. </div>'; 
  45.  
  46. if ( 'is_pending' == $user_status ) { 
  47. echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', buddypress ), $user->user_link ) . '</p>'; 
  48.  
  49. echo '</li>'; 
  50. exit; 
  51.  
  52. } elseif ( 'uninvite' == $_POST['friend_action'] ) { 
  53. // Users who have previously requested membership should not 
  54. // have theirrequestsdeleted on the "uninvite" action 
  55. if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) { 
  56. return; 
  57.  
  58. // Remove the unsent invitation 
  59. if ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 
  60. return; 
  61.  
  62. exit; 
  63.  
  64. } else { 
  65. return;