| 337 | // Process invitation actions |
| 338 | if ( ! empty( $_POST['bp-groups-invite-action'] ) ) { |
| 339 | |
| 340 | foreach ( $_POST['bp-groups-invite-action'] as $user_id => $action ) { |
| 341 | switch ( $action ) { |
| 342 | case 'remove': |
| 343 | // Remove the invitation |
| 344 | $result = groups_uninvite_user( $user_id, $group_id ); |
| 345 | // Store the success or failure |
| 346 | if ( $result ) { |
| 347 | $success_removed_invite[] = $user_id; |
| 348 | } else { |
| 349 | $error_removed_invite[] = $user_id; |
| 350 | } |
| 351 | break; |
| 352 | case 'resend': |
| 353 | // This can't work at the moment, because sending invites is tied to the logged-in user id |
| 354 | break; |
| 355 | case 'send': |
| 356 | // This can't work at the moment, because sending invites is tied to the logged-in user id |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | // Destroy the variables to prevent confusion |
| 361 | unset( $action, $user_id ); |
| 362 | } |
| 363 | |
| 364 | // Process invitation actions |
| 365 | if ( ! empty( $_POST['bp-groups-mem-req-action'] ) ) { |
| 366 | |
| 367 | foreach ( $_POST['bp-groups-mem-req-action'] as $membership_id => $action ) { |
| 368 | switch ( $action ) { |
| 369 | case 'accept': |
| 370 | // Accept the request |
| 371 | $result = groups_accept_membership_request( $membership_id ); |
| 372 | // Store the success or failure |
| 373 | if ( $result ) { |
| 374 | $success_accepted_mem_req[] = $membership_id; |
| 375 | } else { |
| 376 | $error_accepted_mem_req[] = $membership_id; |
| 377 | } |
| 378 | break; |
| 379 | case 'reject': |
| 380 | // Reject the request |
| 381 | $result = groups_reject_membership_request( $membership_id ); |
| 382 | // Store the success or failure |
| 383 | if ( $result ) { |
| 384 | $success_rejected_mem_req[] = $membership_id; |
| 385 | } else { |
| 386 | $error_rejected_mem_req[] = $membership_id; |
| 387 | } break; |
| 388 | } |
| 389 | } |
| 390 | // Destroy the variables to prevent confusion |
| 391 | unset( $action, $membership_id ); |
| 392 | } |
| 393 | |
| 426 | if ( !empty( $success_removed_invite ) ) { |
| 427 | $success_removed_invite = implode( ',', array_filter( $success_removed_invite, 'urlencode' ) ); |
| 428 | $redirect_to = add_query_arg( 'success_removed_invite', $success_removed_invite, $redirect_to ); |
| 429 | } |
| 430 | |
| 431 | if ( !empty( $error_removed_invite ) ) { |
| 432 | $error_removed_invite = implode( ',', array_filter( $error_removed_invite, 'urlencode' ) ); |
| 433 | $redirect_to = add_query_arg( 'error_removed_invite', $error_removed_invite, $redirect_to ); |
| 434 | } |
| 435 | |
| 436 | if ( !empty( $success_accepted_mem_req ) ) { |
| 437 | $success_accepted_mem_req = implode( ',', array_filter( $success_accepted_mem_req, 'urlencode' ) ); |
| 438 | $redirect_to = add_query_arg( 'success_accepted_mem_req', $success_accepted_mem_req, $redirect_to ); |
| 439 | } |
| 440 | |
| 441 | if ( !empty( $error_accepted_mem_req ) ) { |
| 442 | $error_accepted_mem_req = implode( ',', array_filter( $error_accepted_mem_req, 'urlencode' ) ); |
| 443 | $redirect_to = add_query_arg( 'error_accepted_mem_req', $error_accepted_mem_req, $redirect_to ); |
| 444 | } |
| 445 | |
| 446 | if ( !empty( $success_rejected_mem_req ) ) { |
| 447 | $success_rejected_mem_req = implode( ',', array_filter( $success_rejected_mem_req, 'urlencode' ) ); |
| 448 | $redirect_to = add_query_arg( 'success_rejected_mem_req', $success_rejected_mem_req, $redirect_to ); |
| 449 | } |
| 450 | |
| 451 | if ( !empty( $error_rejected_mem_req ) ) { |
| 452 | $error_rejected_mem_req = implode( ',', array_filter( $error_rejected_mem_req, 'urlencode' ) ); |
| 453 | $redirect_to = add_query_arg( 'error_rejected_mem_req', $error_rejected_mem_req, $redirect_to ); |
| 454 | } |
| 988 | * Renders the Invitations metabox on single group pages. |
| 989 | * |
| 990 | * @since BuddyPress (2.1.0) |
| 991 | * |
| 992 | * @param BP_Groups_Group $item The BP_Groups_Group object for the current |
| 993 | * group. |
| 994 | */ |
| 995 | function bp_groups_admin_edit_metabox_invites_requests( $item ) { |
| 996 | $current_invite_page = isset( $_GET[ 'invites_page' ] ) ? absint( $_GET[ 'invites_page' ] ) : 1; |
| 997 | $invitee_query = new BP_Group_Member_Query( array( |
| 998 | 'group_id' => $item->id, |
| 999 | 'type' => 'alphabetical', |
| 1000 | 'is_confirmed' => false, |
| 1001 | 'inviter_id' => 'any', // Finds all non-zero entries -- invitations |
| 1002 | 'per_page' => 10, |
| 1003 | 'page' => $current_invite_page, |
| 1004 | ) ); |
| 1005 | |
| 1006 | $invited_users = $invitee_query->results; |
| 1007 | $pagination['invites'] = bp_groups_admin_create_invite_pagination_links( $invitee_query, 'invites' ); |
| 1008 | ?> |
| 1009 | <div id="bp-group-invitations-list" class="bp-group-admin-paginated-list"> |
| 1010 | <h4><?php _ex( 'Outstanding Invitations', 'Outstanding invitations header in group admin', 'buddypress' ); ?></h4> |
| 1011 | |
| 1012 | <?php if ( ! empty( $invited_users ) ) : ?> |
| 1013 | |
| 1014 | <div class="bp-group-admin-pagination table-top"> |
| 1015 | <?php echo $pagination['invites']; ?> |
| 1016 | </div> |
| 1017 | |
| 1018 | <table class="widefat bp-group-invitations"> |
| 1019 | <thead> |
| 1020 | <tr> |
| 1021 | <th scope="col" class="uid-column"><?php _ex( 'ID', 'Group invitation recipient user_id in group admin', 'buddypress' ) ?></th> |
| 1022 | <th scope="col" class="uname-column"><?php _ex( 'Name', 'Group invitation recipient name in group admin', 'buddypress' ) ?></th> |
| 1023 | <th scope="col" class="inviter-name-column"><?php _ex( 'Invited By', 'Username of group invitation sender in group admin', 'buddypress' ) ?></th> |
| 1024 | <th scope="col" class="invitation-action-column"><?php _ex( 'Actions', 'Invitation actions in group admin', 'buddypress' ) ?></th> |
| 1025 | </tr> |
| 1026 | </thead> |
| 1027 | |
| 1028 | <tbody> |
| 1029 | |
| 1030 | <?php foreach ( $invited_users as $invite ) : ?> |
| 1031 | <tr> |
| 1032 | <th scope="row" class="uid-column"><?php echo esc_html( $invite->ID ); ?></th> |
| 1033 | |
| 1034 | <td class="uname-column"> |
| 1035 | <a style="float: left;" href="<?php echo bp_core_get_userlink( $invite->ID, false, true ); ?>"><?php |
| 1036 | echo bp_core_fetch_avatar( array( |
| 1037 | 'item_id' => $invite->ID, |
| 1038 | 'width' => '32', |
| 1039 | 'height' => '32' |
| 1040 | ) ); ?></a> |
| 1041 | |
| 1042 | <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invite->ID ); ?></span> |
| 1043 | </td> |
| 1044 | |
| 1045 | <td class="inviter-name-column"> |
| 1046 | <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $invite->inviter_id ); ?></span> |
| 1047 | </td> |
| 1048 | <td class="invitation-action-column"> |
| 1049 | <label style="margin: 8px; float: left;"><input type="radio" name="bp-groups-invite-action[<?php echo $invite->ID; ?>]" value="remove">Remove</label> |
| 1050 | |
| 1051 | <?php /* This can't be done at the moment, because sending invitations is tied to the logged-in user's id. ?> |
| 1052 | <?php if ( ! $invite->invite_sent ) : ?> |
| 1053 | <label style="margin: 8px; float: left;"><input type="radio" name="bp-groups-invite-action[<?php echo $invite->ID; ?>]" value="send">Send</label> |
| 1054 | <?php else : ?> |
| 1055 | <label style="margin: 8px; float: left;"><input type="radio" name="bp-groups-invite-action[<?php echo $invite->ID; ?>]" value="resend">Re-send</label> |
| 1056 | <?php endif; ?> |
| 1057 | <?php */ ?> |
| 1058 | </td> |
| 1059 | </tr> |
| 1060 | |
| 1061 | <?php endforeach; ?> |
| 1062 | |
| 1063 | </tbody> |
| 1064 | </table> |
| 1065 | |
| 1066 | <div class="bp-group-admin-pagination table-bottom"> |
| 1067 | <?php echo $pagination['invites']; ?> |
| 1068 | </div> |
| 1069 | |
| 1070 | <?php else : ?> |
| 1071 | |
| 1072 | <p class="bp-groups-no-outstanding-invites description"><?php _e( 'No outstanding invitations', 'buddypress' ) ?></p> |
| 1073 | |
| 1074 | <?php endif; ?> |
| 1075 | |
| 1076 | </div><!-- #bp-group-invitations-list --> |
| 1077 | |
| 1078 | <?php |
| 1079 | |
| 1080 | $current_req_page = isset( $_GET[ 'mem_req_page' ] ) ? absint( $_GET[ 'mem_req_page' ] ) : 1; |
| 1081 | $request_query = new BP_Group_Member_Query( array( |
| 1082 | 'group_id' => $item->id, |
| 1083 | 'type' => 'alphabetical', |
| 1084 | 'is_confirmed' => false, |
| 1085 | 'inviter_id' => 0, // inviter_id = 0 and is_confirmed = 0 are requests |
| 1086 | 'per_page' => 10, |
| 1087 | 'page' => $current_req_page, |
| 1088 | ) ); |
| 1089 | |
| 1090 | $mem_req_users = $request_query->results; |
| 1091 | $pagination['mem_req'] = bp_groups_admin_create_invite_pagination_links( $request_query, 'mem_req' ); |
| 1092 | ?> |
| 1093 | <div id="bp-group-requests-list" class="bp-group-admin-paginated-list"> |
| 1094 | <h4><?php _ex( 'Membership Requests', 'Membership requests header in group admin', 'buddypress' ); ?></h4> |
| 1095 | |
| 1096 | <?php if ( ! empty( $mem_req_users ) ) : ?> |
| 1097 | |
| 1098 | <div class="bp-group-admin-pagination table-top"> |
| 1099 | <?php echo $pagination['mem_req']; ?> |
| 1100 | </div> |
| 1101 | |
| 1102 | <table class="widefat bp-group-mem-requests"> |
| 1103 | <thead> |
| 1104 | <tr> |
| 1105 | <th scope="col" class="uid-column"><?php _ex( 'ID', 'Group invitation recipient user_id in group admin', 'buddypress' ) ?></th> |
| 1106 | <th scope="col" class="uname-column"><?php _ex( 'Name', 'Group invitation recipient name in group admin', 'buddypress' ) ?></th> |
| 1107 | <th scope="col" class="mem-req-action-column"><?php _ex( 'Actions', 'Membership request actions in group admin', 'buddypress' ) ?></th> |
| 1108 | </tr> |
| 1109 | </thead> |
| 1110 | |
| 1111 | <tbody> |
| 1112 | |
| 1113 | <?php foreach ( $mem_req_users as $mem_req ) : ?> |
| 1114 | <tr> |
| 1115 | <th scope="row" class="uid-column"><?php echo esc_html( $mem_req->ID ); ?></th> |
| 1116 | |
| 1117 | <td class="uname-column"> |
| 1118 | <a style="float: left;" href="<?php echo bp_core_get_userlink( $mem_req->ID, false, true ); ?>"><?php |
| 1119 | echo bp_core_fetch_avatar( array( |
| 1120 | 'item_id' => $mem_req->ID, |
| 1121 | 'width' => '32', |
| 1122 | 'height' => '32' |
| 1123 | ) ); ?></a> |
| 1124 | |
| 1125 | <span style="margin: 8px; float: left;"><?php echo bp_core_get_userlink( $mem_req->ID ); ?></span> |
| 1126 | </td> |
| 1127 | |
| 1128 | <td class="mem-req-action-column"> |
| 1129 | <label style="margin: 8px; float: left;"><input type="radio" name="bp-groups-mem-req-action[<?php echo $mem_req->membership_id; ?>]" value="accept">Accept</label> |
| 1130 | <label style="margin: 8px; float: left;"><input type="radio" name="bp-groups-mem-req-action[<?php echo $mem_req->membership_id; ?>]" value="reject">Reject</label> |
| 1131 | </td> |
| 1132 | </tr> |
| 1133 | |
| 1134 | <?php endforeach; ?> |
| 1135 | |
| 1136 | </tbody> |
| 1137 | </table> |
| 1138 | |
| 1139 | <div class="bp-group-admin-pagination table-bottom"> |
| 1140 | <?php echo $pagination['mem_req']; ?> |
| 1141 | </div> |
| 1142 | |
| 1143 | <?php else : ?> |
| 1144 | |
| 1145 | <p class="bp-groups-no-outstanding-requests description"><?php _e( 'No outstanding membership requests', 'buddypress' ) ?></p> |
| 1146 | |
| 1147 | <?php endif; ?> |
| 1148 | |
| 1149 | </div><!-- #bp-group-requests-list --> |
| 1150 | <?php |
| 1151 | } |
| 1152 | |
| 1153 | /** |
| 1213 | * Create pagination links out of a BP_Group_Member_Query. |
| 1214 | * |
| 1215 | * This function is intended to create pagination links for use under the |
| 1216 | * Manage Unconfirmed Members section of the Groups Admin Dashboard pages. It is a stopgap |
| 1217 | * measure until a more general pagination solution is in place for BuddyPress. |
| 1218 | * Plugin authors should not use this function, as it is likely to be |
| 1219 | * deprecated soon. |
| 1220 | * |
| 1221 | * @since BuddyPress (2.1.0) |
| 1222 | * |
| 1223 | * @param BP_Group_Member_Query $query A BP_Group_Member_Query object. |
| 1224 | * @param string $type mem_req|invites. |
| 1225 | * @return string Pagination links HTML. |
| 1226 | */ |
| 1227 | function bp_groups_admin_create_invite_pagination_links( BP_Group_Member_Query $query, $type ) { |
| 1228 | $pagination = ''; |
| 1229 | |
| 1230 | if ( ! in_array( $type, array( 'invites', 'mem_req' ) ) ) { |
| 1231 | return $pagination; |
| 1232 | } |
| 1233 | |
| 1234 | // The key used to paginate this member type in the $_GET global |
| 1235 | $qs_key = $type . '_page'; |
| 1236 | $url_base = remove_query_arg( array( $qs_key, 'updated', 'success_modified' ), $_SERVER['REQUEST_URI'] ); |
| 1237 | |
| 1238 | $page = isset( $_GET[ $qs_key ] ) ? absint( $_GET[ $qs_key ] ) : 1; |
| 1239 | $per_page = 10; // @todo Make this customizable? |
| 1240 | |
| 1241 | // Don't show anything if there's no pagination |
| 1242 | if ( 1 === $page && $query->total_users <= $per_page ) { |
| 1243 | return $pagination; |
| 1244 | } |
| 1245 | |
| 1246 | $current_page_start = ( ( $page - 1 ) * $per_page ) + 1; |
| 1247 | $current_page_end = $page * $per_page > intval( $query->total_users ) ? $query->total_users : $page * $per_page; |
| 1248 | |
| 1249 | $pag_links = paginate_links( array( |
| 1250 | 'base' => add_query_arg( $qs_key, '%#%', $url_base ), |
| 1251 | 'format' => '', |
| 1252 | 'prev_text' => __( '«', 'buddypress' ), |
| 1253 | 'next_text' => __( '»', 'buddypress' ), |
| 1254 | 'total' => ceil( $query->total_users / $per_page ), |
| 1255 | 'current' => $page, |
| 1256 | ) ); |
| 1257 | |
| 1258 | $viewing_text = sprintf( |
| 1259 | __( 'Viewing %1$s - %2$s of %3$s', 'buddypress' ), |
| 1260 | number_format_i18n( $current_page_start ), |
| 1261 | number_format_i18n( $current_page_end ), |
| 1262 | sprintf( _n( '%s member', '%s members', $query->total_users, 'buddypress' ), $query->total_users ) |
| 1263 | ); |
| 1264 | |
| 1265 | $pagination .= '<span class="bp-group-admin-pagination-viewing">' . $viewing_text . '</span>'; |
| 1266 | $pagination .= '<span class="bp-group-admin-pagination-links">' . $pag_links . '</span>'; |
| 1267 | |
| 1268 | return $pagination; |
| 1269 | } |
| 1270 | |
| 1271 | /** |