Advertisement
Guest User

Untitled

a guest
May 5th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. /**
  2. * Invites a friend to join a group via a POST request.
  3. *
  4. * @since BuddyPress (1.2)
  5. * @todo Audit return types
  6. */
  7. function bp_legacy_theme_ajax_invite_user() {
  8. // Bail if not a POST action
  9. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
  10. return;
  11.  
  12. check_ajax_referer( 'groups_invite_uninvite_user' );
  13.  
  14. if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
  15. return;
  16.  
  17. if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
  18. return;
  19.  
  20. if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) )
  21. return;
  22.  
  23. $group_id = (int) $_POST['group_id'];
  24. $friend_id = (int) $_POST['friend_id'];
  25.  
  26. if ( 'invite' == $_POST['friend_action'] ) {
  27. $group = groups_get_group( $group_id );
  28.  
  29. // Users who have previously requested membership do not need
  30. // another invitation created for them
  31. if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
  32. $user_status = 'is_pending';
  33.  
  34. // Create the user invitation
  35. } elseif ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
  36. $user_status = 'is_invited';
  37.  
  38. // Miscellaneous failure
  39. } else {
  40. return;
  41. }
  42.  
  43. $user = new BP_Core_User( $_POST['friend_id'] );
  44.  
  45. echo '<li id="uid-' . esc_attr( $user->id ) . '">';
  46. echo $user->avatar_thumb;
  47. echo '<h4>' . $user->user_link . '</h4>';
  48. echo '<span class="activity">' . esc_attr( $user->last_active ) . '</span>';
  49. echo '<div class="action">
  50. <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>
  51. </div>';
  52.  
  53. if ( 'is_pending' == $user_status ) {
  54. 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>';
  55. }
  56.  
  57. echo '</li>';
  58. exit;
  59.  
  60. } elseif ( 'uninvite' == $_POST['friend_action'] ) {
  61. // Users who have previously requested membership should not
  62. // have their requests deleted on the "uninvite" action
  63. if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
  64. return;
  65. }
  66.  
  67. // Remove the unsent invitation
  68. if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
  69. return;
  70. }
  71.  
  72. exit;
  73.  
  74. } else {
  75. return;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement