Ticket #7218: 7218.groups-v3.patch
File 7218.groups-v3.patch, 119.1 KB (added by , 7 years ago) |
---|
-
src/bp-groups/bp-groups-actions.php
39 39 return; 40 40 } 41 41 42 $current_group = groups_get_current_group(); 43 $user_has_access = $current_group->user_has_access; 44 $is_visible = $current_group->is_visible; 45 $no_access_args = array(); 46 47 // The user can know about the group but doesn't have full access. 48 if ( ! $user_has_access && $is_visible ) { 49 // Always allow access to home and request-membership. 50 if ( bp_is_current_action( 'home' ) || bp_is_current_action( 'request-membership' ) ) { 51 $user_has_access = true; 52 53 // User doesn't have access, so set up redirect args. 54 } elseif ( is_user_logged_in() ) { 55 $no_access_args = array( 56 'message' => __( 'You do not have access to this group.', 'buddypress' ), 57 'root' => bp_get_group_permalink( $current_group ) . 'home/', 58 'redirect' => false 59 ); 60 } 61 } 62 63 // Protect the admin tab from non-admins. 64 if ( bp_is_current_action( 'admin' ) && ! bp_is_item_admin() ) { 65 $user_has_access = false; 66 $no_access_args = array( 67 'message' => __( 'You are not an admin of this group.', 'buddypress' ), 68 'root' => bp_get_group_permalink( $current_group ), 69 'redirect' => false 70 ); 71 } 72 73 /** 74 * Allow plugins to filter whether the current user has access to this group content. 75 * 76 * Note that if a plugin sets $user_has_access to false, it may also 77 * want to change the $no_access_args, to avoid problems such as 78 * logged-in users being redirected to wp-login.php. 79 * 80 * @since 2.1.0 81 * 82 * @param bool $user_has_access True if the user has access to the 83 * content, otherwise false. 84 * @param array $no_access_args Arguments to be passed to bp_core_no_access() in case 85 * of no access. Note that this value is passed by reference, 86 * so it can be modified by the filter callback. 87 */ 88 $user_has_access = apply_filters_ref_array( 'bp_group_user_has_access', array( $user_has_access, &$no_access_args ) ); 89 90 // If user has access, we return rather than redirect. 91 if ( $user_has_access ) { 92 return; 93 } 94 95 // Groups that the user cannot know about should return a 404 for non-members. 96 // Unset the current group so that you're not redirected 97 // to the default group tab. 98 if ( ! $is_visible ) { 99 buddypress()->groups->current_group = 0; 100 buddypress()->is_single_item = false; 101 bp_do_404(); 102 return; 103 } else { 104 bp_core_no_access( $no_access_args ); 105 } 106 42 $action = new BP_Groups_Action_Group_Access_Protection(); 43 $action->init(); 107 44 } 108 45 add_action( 'bp_actions', 'bp_groups_group_access_protection' ); 109 46 … … 115 52 * @return bool 116 53 */ 117 54 function groups_action_create_group() { 118 119 55 // If we're not at domain.org/groups/create/ then return false. 120 if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) ) 121 return false; 122 123 if ( !is_user_logged_in() ) 124 return false; 125 126 if ( !bp_user_can_create_groups() ) { 127 bp_core_add_message( __( 'Sorry, you are not allowed to create groups.', 'buddypress' ), 'error' ); 128 bp_core_redirect( bp_get_groups_directory_permalink() ); 129 } 130 131 $bp = buddypress(); 132 133 // Make sure creation steps are in the right order. 134 groups_action_sort_creation_steps(); 135 136 // If no current step is set, reset everything so we can start a fresh group creation. 137 $bp->groups->current_create_step = bp_action_variable( 1 ); 138 if ( !bp_get_groups_current_create_step() ) { 139 unset( $bp->groups->current_create_step ); 140 unset( $bp->groups->completed_create_steps ); 141 142 setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 143 setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 144 145 $reset_steps = true; 146 $keys = array_keys( $bp->groups->group_creation_steps ); 147 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . array_shift( $keys ) ) ); 148 } 149 150 // If this is a creation step that is not recognized, just redirect them back to the first screen. 151 if ( bp_get_groups_current_create_step() && empty( $bp->groups->group_creation_steps[bp_get_groups_current_create_step()] ) ) { 152 bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' ); 153 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) ); 154 } 155 156 // Fetch the currently completed steps variable. 157 if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !isset( $reset_steps ) ) 158 $bp->groups->completed_create_steps = json_decode( base64_decode( stripslashes( $_COOKIE['bp_completed_create_steps'] ) ) ); 159 160 // Set the ID of the new group, if it has already been created in a previous step. 161 if ( bp_get_new_group_id() ) { 162 $bp->groups->current_group = groups_get_group( $bp->groups->new_group_id ); 163 164 // Only allow the group creator to continue to edit the new group. 165 if ( ! bp_is_group_creator( $bp->groups->current_group, bp_loggedin_user_id() ) ) { 166 bp_core_add_message( __( 'Only the group creator may continue editing this group.', 'buddypress' ), 'error' ); 167 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) ); 168 } 169 } 170 171 // If the save, upload or skip button is hit, lets calculate what we need to save. 172 if ( isset( $_POST['save'] ) ) { 173 174 // Check the nonce. 175 check_admin_referer( 'groups_create_save_' . bp_get_groups_current_create_step() ); 176 177 if ( 'group-details' == bp_get_groups_current_create_step() ) { 178 if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) { 179 bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' ); 180 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 181 } 182 183 $new_group_id = isset( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : 0; 184 185 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) { 186 bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' ); 187 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 188 } 189 } 190 191 if ( 'group-settings' == bp_get_groups_current_create_step() ) { 192 $group_status = 'public'; 193 $group_enable_forum = 1; 194 195 if ( !isset($_POST['group-show-forum']) ) { 196 $group_enable_forum = 0; 197 } 198 199 if ( 'private' == $_POST['group-status'] ) 200 $group_status = 'private'; 201 elseif ( 'hidden' == $_POST['group-status'] ) 202 $group_status = 'hidden'; 203 204 if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) { 205 bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' ); 206 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 207 } 208 209 // Save group types. 210 if ( ! empty( $_POST['group-types'] ) ) { 211 bp_groups_set_group_type( $bp->groups->new_group_id, $_POST['group-types'] ); 212 } 213 214 /** 215 * Filters the allowed invite statuses. 216 * 217 * @since 1.5.0 218 * 219 * @param array $value Array of statuses allowed. 220 * Possible values are 'members, 221 * 'mods', and 'admins'. 222 */ 223 $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) ); 224 $invite_status = !empty( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members'; 225 226 groups_update_groupmeta( $bp->groups->new_group_id, 'invite_status', $invite_status ); 227 } 228 229 if ( 'group-invites' === bp_get_groups_current_create_step() ) { 230 if ( ! empty( $_POST['friends'] ) ) { 231 foreach ( (array) $_POST['friends'] as $friend ) { 232 groups_invite_user( array( 233 'user_id' => (int) $friend, 234 'group_id' => $bp->groups->new_group_id, 235 ) ); 236 } 237 } 238 239 groups_send_invites( bp_loggedin_user_id(), $bp->groups->new_group_id ); 240 } 241 242 /** 243 * Fires before finalization of group creation and cookies are set. 244 * 245 * This hook is a variable hook dependent on the current step 246 * in the creation process. 247 * 248 * @since 1.1.0 249 */ 250 do_action( 'groups_create_group_step_save_' . bp_get_groups_current_create_step() ); 251 252 /** 253 * Fires after the group creation step is completed. 254 * 255 * Mostly for clearing cache on a generic action name. 256 * 257 * @since 1.1.0 258 */ 259 do_action( 'groups_create_group_step_complete' ); 260 261 /** 262 * Once we have successfully saved the details for this step of the creation process 263 * we need to add the current step to the array of completed steps, then update the cookies 264 * holding the information 265 */ 266 $completed_create_steps = isset( $bp->groups->completed_create_steps ) ? $bp->groups->completed_create_steps : array(); 267 if ( !in_array( bp_get_groups_current_create_step(), $completed_create_steps ) ) 268 $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step(); 269 270 // Reset cookie info. 271 setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 272 setcookie( 'bp_completed_create_steps', base64_encode( json_encode( $bp->groups->completed_create_steps ) ), time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 273 274 // If we have completed all steps and hit done on the final step we 275 // can redirect to the completed group. 276 $keys = array_keys( $bp->groups->group_creation_steps ); 277 if ( count( $bp->groups->completed_create_steps ) == count( $keys ) && bp_get_groups_current_create_step() == array_pop( $keys ) ) { 278 unset( $bp->groups->current_create_step ); 279 unset( $bp->groups->completed_create_steps ); 280 281 setcookie( 'bp_new_group_id', false, time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 282 setcookie( 'bp_completed_create_steps', false, time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 283 284 // Once we completed all steps, record the group creation in the activity stream. 285 groups_record_activity( array( 286 'type' => 'created_group', 287 'item_id' => $bp->groups->new_group_id 288 ) ); 289 290 /** 291 * Fires after the group has been successfully created. 292 * 293 * @since 1.1.0 294 * 295 * @param int $new_group_id ID of the newly created group. 296 */ 297 do_action( 'groups_group_create_complete', $bp->groups->new_group_id ); 298 299 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 300 } else { 301 /** 302 * Since we don't know what the next step is going to be (any plugin can insert steps) 303 * we need to loop the step array and fetch the next step that way. 304 */ 305 foreach ( $keys as $key ) { 306 if ( $key == bp_get_groups_current_create_step() ) { 307 $next = 1; 308 continue; 309 } 310 311 if ( isset( $next ) ) { 312 $next_step = $key; 313 break; 314 } 315 } 316 317 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . $next_step ) ); 318 } 56 if ( ! bp_is_groups_component() || ! bp_is_current_action( 'create' ) ) { 57 return; 319 58 } 320 59 321 // Remove invitations. 322 if ( 'group-invites' === bp_get_groups_current_create_step() && ! empty( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { 323 if ( ! check_admin_referer( 'groups_invite_uninvite_user' ) ) { 324 return false; 325 } 326 327 $message = __( 'Invite successfully removed', 'buddypress' ); 328 $error = false; 329 330 if( ! groups_uninvite_user( (int) $_REQUEST['user_id'], $bp->groups->new_group_id ) ) { 331 $message = __( 'There was an error removing the invite', 'buddypress' ); 332 $error = 'error'; 333 } 334 335 bp_core_add_message( $message, $error ); 336 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/group-invites' ) ); 60 if ( ! is_user_logged_in() ) { 61 return; 337 62 } 338 63 339 // Group avatar is handled separately. 340 if ( 'group-avatar' == bp_get_groups_current_create_step() && isset( $_POST['upload'] ) ) { 341 if ( ! isset( $bp->avatar_admin ) ) { 342 $bp->avatar_admin = new stdClass(); 343 } 344 345 if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) { 346 // Normally we would check a nonce here, but the group save nonce is used instead. 347 // Pass the file to the avatar upload handler. 348 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 349 $bp->avatar_admin->step = 'crop-image'; 350 351 // Make sure we include the jQuery jCrop file for image cropping. 352 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 353 } 354 } 355 356 // If the image cropping is done, crop the image and save a full/thumb version. 357 if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) { 358 359 // Normally we would check a nonce here, but the group save nonce is used instead. 360 $args = array( 361 'object' => 'group', 362 'avatar_dir' => 'group-avatars', 363 'item_id' => $bp->groups->current_group->id, 364 'original_file' => $_POST['image_src'], 365 'crop_x' => $_POST['x'], 366 'crop_y' => $_POST['y'], 367 'crop_w' => $_POST['w'], 368 'crop_h' => $_POST['h'] 369 ); 370 371 if ( ! bp_core_avatar_handle_crop( $args ) ) { 372 bp_core_add_message( __( 'There was an error saving the group profile photo, please try uploading again.', 'buddypress' ), 'error' ); 373 } else { 374 /** 375 * Fires after a group avatar is uploaded. 376 * 377 * @since 2.8.0 378 * 379 * @param int $group_id ID of the group. 380 * @param string $type Avatar type. 'crop' or 'full'. 381 * @param array $args Array of parameters passed to the avatar handler. 382 */ 383 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args ); 384 385 bp_core_add_message( __( 'The group profile photo was uploaded successfully.', 'buddypress' ) ); 386 } 387 } 64 if ( ! bp_user_can_create_groups() ) { 65 bp_core_add_message( __( 'Sorry, you are not allowed to create groups.', 'buddypress' ), 'error' ); 66 bp_core_redirect( bp_get_groups_directory_permalink() ); 388 67 } 389 68 390 /** 391 * Filters the template to load for the group creation screen. 392 * 393 * @since 1.0.0 394 * 395 * @param string $value Path to the group creation template to load. 396 */ 397 bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) ); 69 $action = new BP_Groups_Action_Create_Group(); 70 $action->init(); 398 71 } 399 72 add_action( 'bp_actions', 'groups_action_create_group' ); 400 73 … … 406 79 * @return bool 407 80 */ 408 81 function groups_action_join_group() { 409 410 if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( 'join' ) )411 return false;82 if ( ! bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( 'join' ) ) { 83 return; 84 } 412 85 413 86 // Nonce check. 414 if ( !check_admin_referer( 'groups_join_group' ) ) 415 return false; 416 417 $bp = buddypress(); 418 419 // Skip if banned or already a member. 420 if ( !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) && !groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 421 422 // User wants to join a group that is not public. 423 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => $bp->groups->current_group->id ) ) ) { 424 if ( !groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 425 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); 426 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 427 } 428 } 429 430 // User wants to join any group. 431 if ( !groups_join_group( $bp->groups->current_group->id ) ) 432 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); 433 else 434 bp_core_add_message( __( 'You joined the group!', 'buddypress' ) ); 435 436 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 87 if ( ! check_admin_referer( 'groups_join_group' ) ) { 88 return; 437 89 } 438 90 439 /** 440 * Filters the template to load for the single group screen. 441 * 442 * @since 1.0.0 443 * 444 * @param string $value Path to the single group template to load. 445 */ 446 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 91 $action = new BP_Groups_Action_Join_Group(); 92 $action->init(); 447 93 } 448 94 add_action( 'bp_actions', 'groups_action_join_group' ); 449 95 … … 462 108 */ 463 109 function groups_action_leave_group() { 464 110 if ( ! bp_is_single_item() || ! bp_is_groups_component() || ! bp_is_current_action( 'leave-group' ) ) { 465 return false;111 return; 466 112 } 467 113 468 114 // Nonce check. 469 115 if ( ! check_admin_referer( 'groups_leave_group' ) ) { 470 return false; 471 } 472 473 // User wants to leave any group. 474 if ( groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 475 $bp = buddypress(); 476 477 // Stop sole admins from abandoning their group. 478 $group_admins = groups_get_group_admins( bp_get_current_group_id() ); 479 480 if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() ) { 481 bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' ); 482 } elseif ( ! groups_leave_group( $bp->groups->current_group->id ) ) { 483 bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' ); 484 } else { 485 bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) ); 486 } 487 488 $group = groups_get_current_group(); 489 $redirect = bp_get_group_permalink( $group ); 490 491 if ( ! $group->is_visible ) { 492 $redirect = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 493 } 494 495 bp_core_redirect( $redirect ); 116 return; 496 117 } 497 118 498 /** This filter is documented in bp-groups/bp-groups-actions.php */499 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ));119 $action = new BP_Groups_Action_Leave_Group(); 120 $action->init(); 500 121 } 501 122 add_action( 'bp_actions', 'groups_action_leave_group' ); 502 123 … … 592 213 ) ); 593 214 } 594 215 add_action( 'bp_actions', 'groups_action_group_feed' ); 595 596 /**597 * Update orphaned child groups when the parent is deleted.598 *599 * @since 2.7.0600 *601 * @param BP_Groups_Group $group Instance of the group item being deleted.602 */603 function bp_groups_update_orphaned_groups_on_group_delete( $group ) {604 // Get child groups and set the parent to the deleted parent's parent.605 $grandparent_group_id = $group->parent_id;606 $child_args = array(607 'parent_id' => $group->id,608 'show_hidden' => true,609 'per_page' => false,610 'update_meta_cache' => false,611 );612 $children = groups_get_groups( $child_args );613 $children = $children['groups'];614 615 foreach ( $children as $cgroup ) {616 $cgroup->parent_id = $grandparent_group_id;617 $cgroup->save();618 }619 }620 add_action( 'bp_groups_delete_group', 'bp_groups_update_orphaned_groups_on_group_delete', 10, 2 ); -
src/bp-groups/bp-groups-functions.php
2199 2199 add_action( 'delete_user', 'groups_remove_data_for_user' ); 2200 2200 add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' ); 2201 2201 2202 /** 2203 * Update orphaned child groups when the parent is deleted. 2204 * 2205 * @since 2.7.0 2206 * 2207 * @param BP_Groups_Group $group Instance of the group item being deleted. 2208 */ 2209 function bp_groups_update_orphaned_groups_on_group_delete( $group ) { 2210 // Get child groups and set the parent to the deleted parent's parent. 2211 $grandparent_group_id = $group->parent_id; 2212 $child_args = array( 2213 'parent_id' => $group->id, 2214 'show_hidden' => true, 2215 'per_page' => false, 2216 'update_meta_cache' => false, 2217 ); 2218 $children = groups_get_groups( $child_args ); 2219 $children = $children['groups']; 2220 2221 foreach ( $children as $cgroup ) { 2222 $cgroup->parent_id = $grandparent_group_id; 2223 $cgroup->save(); 2224 } 2225 } 2226 add_action( 'bp_groups_delete_group', 'bp_groups_update_orphaned_groups_on_group_delete', 10, 2 ); 2227 2202 2228 /** Group Types ***************************************************************/ 2203 2229 2204 2230 /** -
src/bp-groups/bp-groups-screens.php
20 20 * @since 1.0.0 21 21 */ 22 22 function groups_directory_groups_setup() { 23 if ( bp_is_groups_directory() ) { 24 bp_update_is_directory( true, 'groups' ); 23 if ( ! bp_is_groups_directory() ) { 24 return; 25 } 25 26 26 /** 27 * Fires before the loading of the Groups directory index. 28 * 29 * @since 1.1.0 30 */ 31 do_action( 'groups_directory_groups_setup' ); 27 bp_update_is_directory( true, 'groups' ); 32 28 33 /** 34 * Filters the template to load for the Groups directory index. 35 * 36 * @since 1.0.0 37 * 38 * @param string $value Path to the groups directory index template to load. 39 */ 40 bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) ); 41 } 29 /** 30 * Fires before the loading of the Groups directory index. 31 * 32 * @since 1.1.0 33 */ 34 do_action( 'groups_directory_groups_setup' ); 35 36 /** 37 * Filters the template to load for the Groups directory index. 38 * 39 * @since 1.0.0 40 * 41 * @param string $value Path to the groups directory index template to load. 42 */ 43 bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) ); 42 44 } 43 45 add_action( 'bp_screens', 'groups_directory_groups_setup', 2 ); 44 46 … … 48 50 * @since 1.0.0 49 51 */ 50 52 function groups_screen_my_groups() { 51 52 53 /** 53 54 * Fires before the loading of the My Groups page. 54 55 * … … 72 73 * @since 1.0.0 73 74 */ 74 75 function groups_screen_group_invites() { 75 $group_id = (int)bp_action_variable( 1 ); 76 77 if ( bp_is_action_variable( 'accept' ) && is_numeric( $group_id ) ) { 78 // Check the nonce. 79 if ( !check_admin_referer( 'groups_accept_invite' ) ) 80 return false; 81 82 if ( !groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) { 83 bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' ); 84 } else { 85 // Record this in activity streams. 86 $group = groups_get_group( $group_id ); 87 88 bp_core_add_message( sprintf( __( 'Group invite accepted. Visit %s.', 'buddypress' ), bp_get_group_link( $group ) ) ); 89 90 groups_record_activity( array( 91 'type' => 'joined_group', 92 'item_id' => $group->id 93 ) ); 94 } 95 96 if ( isset( $_GET['redirect_to'] ) ) { 97 $redirect_to = urldecode( $_GET['redirect_to'] ); 98 } else { 99 $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 100 } 101 102 bp_core_redirect( $redirect_to ); 103 104 } elseif ( bp_is_action_variable( 'reject' ) && is_numeric( $group_id ) ) { 105 // Check the nonce. 106 if ( !check_admin_referer( 'groups_reject_invite' ) ) 107 return false; 108 109 if ( !groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) { 110 bp_core_add_message( __( 'Group invite could not be rejected', 'buddypress' ), 'error' ); 111 } else { 112 bp_core_add_message( __( 'Group invite rejected', 'buddypress' ) ); 113 } 114 115 if ( isset( $_GET['redirect_to'] ) ) { 116 $redirect_to = urldecode( $_GET['redirect_to'] ); 117 } else { 118 $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 119 } 120 121 bp_core_redirect( $redirect_to ); 122 } 123 124 /** 125 * Fires before the loading of a users Groups > Invites template. 126 * 127 * @since 1.0.0 128 * 129 * @param int $group_id ID of the group being displayed 130 */ 131 do_action( 'groups_screen_group_invites', $group_id ); 132 133 /** 134 * Filters the template to load for a users Groups > Invites page. 135 * 136 * @since 1.0.0 137 * 138 * @param string $value Path to a users Groups > Invites page template. 139 */ 140 bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) ); 76 $screen = new BP_Groups_Screen_User_Invites(); 77 $screen->init(); 141 78 } 142 79 143 80 /** … … 146 83 * @since 1.0.0 147 84 */ 148 85 function groups_screen_group_home() { 149 150 86 if ( ! bp_is_single_item() ) { 151 return false;87 return; 152 88 } 153 89 154 90 /** … … 174 110 * @since 1.0.0 175 111 */ 176 112 function groups_screen_group_members() { 177 178 if ( !bp_is_single_item() ) 179 return false; 180 181 $bp = buddypress(); 113 if ( ! bp_is_single_item() ) { 114 return; 115 } 182 116 183 117 // Refresh the group member count meta. 184 groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id) );118 groups_update_groupmeta( bp_get_current_group_id(), 'total_member_count', groups_get_total_member_count( bp_get_current_group_id() ) ); 185 119 186 120 /** 187 121 * Fires before the loading of a group's Members page. … … 190 124 * 191 125 * @param int $id ID of the group whose members are being displayed. 192 126 */ 193 do_action( 'groups_screen_group_members', $bp->groups->current_group->id);127 do_action( 'groups_screen_group_members', bp_get_current_group_id() ); 194 128 195 129 /** 196 130 * Filters the template to load for a group's Members page. … … 208 142 * @since 1.0.0 209 143 */ 210 144 function groups_screen_group_invite() { 211 212 if ( !bp_is_single_item() ) 213 return false; 214 215 $bp = buddypress(); 216 217 if ( bp_is_action_variable( 'send', 0 ) ) { 218 219 if ( !check_admin_referer( 'groups_send_invites', '_wpnonce_send_invites' ) ) 220 return false; 221 222 if ( !empty( $_POST['friends'] ) ) { 223 foreach( (array) $_POST['friends'] as $friend ) { 224 groups_invite_user( array( 'user_id' => $friend, 'group_id' => $bp->groups->current_group->id ) ); 225 } 226 } 227 228 // Send the invites. 229 groups_send_invites( bp_loggedin_user_id(), $bp->groups->current_group->id ); 230 bp_core_add_message( __('Group invites sent.', 'buddypress') ); 231 232 /** 233 * Fires after the sending of a group invite inside the group's Send Invites page. 234 * 235 * @since 1.0.0 236 * 237 * @param int $id ID of the group whose members are being displayed. 238 */ 239 do_action( 'groups_screen_group_invite', $bp->groups->current_group->id ); 240 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 241 242 } elseif ( !bp_action_variable( 0 ) ) { 243 244 /** 245 * Filters the template to load for a group's Send Invites page. 246 * 247 * @since 1.0.0 248 * 249 * @param string $value Path to a group's Send Invites template. 250 */ 251 bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/home' ) ); 252 253 } else { 254 bp_do_404(); 145 if ( ! bp_is_single_item() ) { 146 return; 255 147 } 148 149 $screen = new BP_Groups_Screen_Send_Invites(); 150 $screen->init(); 256 151 } 257 152 258 153 /** … … 273 168 } 274 169 275 170 if ( ! check_admin_referer( 'groups_invite_uninvite_user' ) ) { 276 return false; 277 } 278 279 $friend_id = intval( bp_action_variable( 1 ) ); 280 $group_id = bp_get_current_group_id(); 281 $message = __( 'Invite successfully removed', 'buddypress' ); 282 $redirect = wp_get_referer(); 283 $error = false; 284 285 if ( ! bp_groups_user_can_send_invites( $group_id ) ) { 286 $message = __( 'You are not allowed to send or remove invites', 'buddypress' ); 287 $error = 'error'; 288 } elseif ( groups_check_for_membership_request( $friend_id, $group_id ) ) { 289 $message = __( 'The member requested to join the group', 'buddypress' ); 290 $error = 'error'; 291 } elseif ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 292 $message = __( 'There was an error removing the invite', 'buddypress' ); 293 $error = 'error'; 171 return; 294 172 } 295 173 296 bp_core_add_message( $message, $error);297 bp_core_redirect( $redirect);174 $screen = new BP_Groups_Screen_Remove_Invites(); 175 $screen->init(); 298 176 } 299 177 add_action( 'bp_screens', 'groups_remove_group_invite' ); 300 178 … … 304 182 * @since 1.0.0 305 183 */ 306 184 function groups_screen_group_request_membership() { 307 308 if ( !is_user_logged_in() ) 309 return false; 310 311 $bp = buddypress(); 312 313 if ( 'private' != $bp->groups->current_group->status ) 314 return false; 315 316 // If the user is already invited, accept invitation. 317 if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 318 if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) 319 bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) ); 320 else 321 bp_core_add_message( __( 'There was an error accepting the group invitation. Please try again.', 'buddypress' ), 'error' ); 322 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 185 if ( ! is_user_logged_in() ) { 186 return; 323 187 } 324 188 325 // If the user has submitted a request, send it. 326 if ( isset( $_POST['group-request-send']) ) { 327 328 // Check the nonce. 329 if ( !check_admin_referer( 'groups_request_membership' ) ) 330 return false; 331 332 if ( !groups_send_membership_request( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) { 333 bp_core_add_message( __( 'There was an error sending your group membership request. Please try again.', 'buddypress' ), 'error' ); 334 } else { 335 bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) ); 336 } 337 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 189 if ( 'private' !== buddypress()->groups->current_group->status ) { 190 return; 338 191 } 339 192 340 /** 341 * Fires before the loading of a group's Request Memebership page. 342 * 343 * @since 1.0.0 344 * 345 * @param int $id ID of the group currently being displayed. 346 */ 347 do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id ); 348 349 /** 350 * Filters the template to load for a group's Request Membership page. 351 * 352 * @since 1.0.0 353 * 354 * @param string $value Path to a group's Request Membership template. 355 */ 356 bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) ); 193 $screen = new BP_Groups_Screen_Request_Membership(); 194 $screen->init(); 357 195 } 358 196 359 197 /** … … 362 200 * @since 2.4.0 363 201 */ 364 202 function groups_screen_group_activity() { 365 366 203 if ( ! bp_is_single_item() ) { 367 return false;204 return; 368 205 } 369 206 370 207 /** … … 390 227 * @since 1.2.0 391 228 */ 392 229 function groups_screen_group_activity_permalink() { 393 394 if ( !bp_is_groups_component() || !bp_is_active( 'activity' ) || ( bp_is_active( 'activity' ) && !bp_is_current_action( bp_get_activity_slug() ) ) || !bp_action_variable( 0 ) )395 return false;230 if ( ! bp_is_groups_component() || ! bp_is_active( 'activity' ) || ( bp_is_active( 'activity' ) && ! bp_is_current_action( bp_get_activity_slug() ) ) || ! bp_action_variable( 0 ) ) { 231 return; 232 } 396 233 397 234 buddypress()->is_single_item = true; 398 235 … … 407 244 * @since 1.0.0 408 245 */ 409 246 function groups_screen_group_admin() { 410 if ( !bp_is_groups_component() || !bp_is_current_action( 'admin' ) ) 411 return false; 247 if ( ! bp_is_groups_component() || ! bp_is_current_action( 'admin' ) ) { 248 return; 249 } 412 250 413 if ( bp_action_variables() ) 414 return false; 251 if ( bp_action_variables() ) { 252 return; 253 } 415 254 416 255 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 417 256 } … … 422 261 * @since 1.0.0 423 262 */ 424 263 function groups_screen_group_admin_edit_details() { 264 if ( 'edit-details' !== bp_get_group_current_admin_tab() ) { 265 return; 266 } 425 267 426 if ( 'edit-details' != bp_get_group_current_admin_tab() ) 427 return false; 428 429 if ( bp_is_item_admin() ) { 430 431 $bp = buddypress(); 432 433 // If the edit form has been submitted, save the edited details. 434 if ( isset( $_POST['save'] ) ) { 435 // Check the nonce. 436 if ( !check_admin_referer( 'groups_edit_group_details' ) ) 437 return false; 438 439 $group_notify_members = isset( $_POST['group-notify-members'] ) ? (int) $_POST['group-notify-members'] : 0; 440 441 // Name and description are required and may not be empty. 442 if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) ) { 443 bp_core_add_message( __( 'Groups must have a name and a description. Please try again.', 'buddypress' ), 'error' ); 444 } elseif ( ! groups_edit_base_group_details( array( 445 'group_id' => $_POST['group-id'], 446 'name' => $_POST['group-name'], 447 'slug' => null, // @TODO: Add to settings pane? If yes, editable by site admin only, or allow group admins to do this? 448 'description' => $_POST['group-desc'], 449 'notify_members' => $group_notify_members, 450 ) ) ) { 451 bp_core_add_message( __( 'There was an error updating group details. Please try again.', 'buddypress' ), 'error' ); 452 } else { 453 bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) ); 454 } 455 456 /** 457 * Fires before the redirect if a group details has been edited and saved. 458 * 459 * @since 1.0.0 460 * 461 * @param int $id ID of the group that was edited. 462 */ 463 do_action( 'groups_group_details_edited', $bp->groups->current_group->id ); 464 465 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 466 } 467 468 /** 469 * Fires before the loading of the group admin/edit-details page template. 470 * 471 * @since 1.0.0 472 * 473 * @param int $id ID of the group that is being displayed. 474 */ 475 do_action( 'groups_screen_group_admin_edit_details', $bp->groups->current_group->id ); 476 477 /** 478 * Filters the template to load for a group's admin/edit-details page. 479 * 480 * @since 1.0.0 481 * 482 * @param string $value Path to a group's admin/edit-details template. 483 */ 484 bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) ); 268 if ( ! bp_is_item_admin() ) { 269 return; 485 270 } 271 272 $screen = new BP_Groups_Screen_Admin_Edit_Details(); 273 $screen->init(); 486 274 } 487 275 add_action( 'bp_screens', 'groups_screen_group_admin_edit_details' ); 488 276 … … 492 280 * @since 1.0.0 493 281 */ 494 282 function groups_screen_group_admin_settings() { 495 496 if ( 'group-settings' != bp_get_group_current_admin_tab() ) 497 return false; 498 499 if ( ! bp_is_item_admin() ) 500 return false; 501 502 $bp = buddypress(); 503 504 // If the edit form has been submitted, save the edited details. 505 if ( isset( $_POST['save'] ) ) { 506 $enable_forum = ( isset($_POST['group-show-forum'] ) ) ? 1 : 0; 507 508 // Checked against a whitelist for security. 509 /** This filter is documented in bp-groups/bp-groups-admin.php */ 510 $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) ); 511 $status = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public'; 512 513 // Checked against a whitelist for security. 514 /** This filter is documented in bp-groups/bp-groups-admin.php */ 515 $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) ); 516 $invite_status = isset( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members'; 517 518 // Check the nonce. 519 if ( !check_admin_referer( 'groups_edit_group_settings' ) ) 520 return false; 521 522 /* 523 * Save group types. 524 * 525 * Ensure we keep types that have 'show_in_create_screen' set to false. 526 */ 527 $current_types = bp_groups_get_group_type( bp_get_current_group_id(), false ); 528 $current_types = array_intersect( bp_groups_get_group_types( array( 'show_in_create_screen' => false ) ), (array) $current_types ); 529 if ( isset( $_POST['group-types'] ) ) { 530 $current_types = array_merge( $current_types, $_POST['group-types'] ); 531 532 // Set group types. 533 bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 534 535 // No group types checked, so this means we want to wipe out all group types. 536 } else { 537 /* 538 * Passing a blank string will wipe out all types for the group. 539 * 540 * Ensure we keep types that have 'show_in_create_screen' set to false. 541 */ 542 $current_types = empty( $current_types ) ? '' : $current_types; 543 544 // Set group types. 545 bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 546 } 547 548 if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) { 549 bp_core_add_message( __( 'There was an error updating group settings. Please try again.', 'buddypress' ), 'error' ); 550 } else { 551 bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) ); 552 } 553 554 /** 555 * Fires before the redirect if a group settings has been edited and saved. 556 * 557 * @since 1.0.0 558 * 559 * @param int $id ID of the group that was edited. 560 */ 561 do_action( 'groups_group_settings_edited', $bp->groups->current_group->id ); 562 563 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/group-settings/' ); 283 if ( 'group-settings' !== bp_get_group_current_admin_tab() ) { 284 return; 564 285 } 565 286 566 /** 567 * Fires before the loading of the group admin/group-settings page template. 568 * 569 * @since 1.0.0 570 * 571 * @param int $id ID of the group that is being displayed. 572 */ 573 do_action( 'groups_screen_group_admin_settings', $bp->groups->current_group->id ); 287 if ( ! bp_is_item_admin() ) { 288 return; 289 } 574 290 575 /** 576 * Filters the template to load for a group's admin/group-settings page. 577 * 578 * @since 1.0.0 579 * 580 * @param string $value Path to a group's admin/group-settings template. 581 */ 582 bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/home' ) ); 291 $screen = new BP_Groups_Screen_Admin_Settings(); 292 $screen->init(); 583 293 } 584 294 add_action( 'bp_screens', 'groups_screen_group_admin_settings' ); 585 295 … … 589 299 * @since 1.0.0 590 300 */ 591 301 function groups_screen_group_admin_avatar() { 592 593 if ( 'group-avatar' != bp_get_group_current_admin_tab() ) 594 return false; 595 596 // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here. 597 if ( ! bp_is_item_admin() || bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) 598 return false; 599 600 $bp = buddypress(); 601 602 // If the group admin has deleted the admin avatar. 603 if ( bp_is_action_variable( 'delete', 1 ) ) { 604 605 // Check the nonce. 606 check_admin_referer( 'bp_group_avatar_delete' ); 607 608 if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group' ) ) ) { 609 bp_core_add_message( __( 'The group profile photo was deleted successfully!', 'buddypress' ) ); 610 } else { 611 bp_core_add_message( __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 'error' ); 612 } 613 } 614 615 if ( ! isset( $bp->avatar_admin ) ) { 616 $bp->avatar_admin = new stdClass(); 617 } 618 619 $bp->avatar_admin->step = 'upload-image'; 620 621 if ( !empty( $_FILES ) ) { 622 623 // Check the nonce. 624 check_admin_referer( 'bp_avatar_upload' ); 625 626 // Pass the file to the avatar upload handler. 627 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 628 $bp->avatar_admin->step = 'crop-image'; 629 630 // Make sure we include the jQuery jCrop file for image cropping. 631 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 632 } 633 302 if ( 'group-avatar' !== bp_get_group_current_admin_tab() ) { 303 return; 634 304 } 635 305 636 // If the image cropping is done, crop the image and save a full/thumb version. 637 if ( isset( $_POST['avatar-crop-submit'] ) ) { 638 639 // Check the nonce. 640 check_admin_referer( 'bp_avatar_cropstore' ); 641 642 $args = array( 643 'object' => 'group', 644 'avatar_dir' => 'group-avatars', 645 'item_id' => $bp->groups->current_group->id, 646 'original_file' => $_POST['image_src'], 647 'crop_x' => $_POST['x'], 648 'crop_y' => $_POST['y'], 649 'crop_w' => $_POST['w'], 650 'crop_h' => $_POST['h'] 651 ); 652 653 if ( !bp_core_avatar_handle_crop( $args ) ) { 654 bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' ); 655 } else { 656 /** 657 * Fires after a group avatar is uploaded. 658 * 659 * @since 2.8.0 660 * 661 * @param int $group_id ID of the group. 662 * @param string $type Avatar type. 'crop' or 'full'. 663 * @param array $args Array of parameters passed to the avatar handler. 664 */ 665 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args ); 666 bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) ); 667 } 306 // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here. 307 if ( ! bp_is_item_admin() || bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) { 308 return; 668 309 } 669 310 670 /** 671 * Fires before the loading of the group Change Avatar page template. 672 * 673 * @since 1.0.0 674 * 675 * @param int $id ID of the group that is being displayed. 676 */ 677 do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id ); 678 679 /** 680 * Filters the template to load for a group's Change Avatar page. 681 * 682 * @since 1.0.0 683 * 684 * @param string $value Path to a group's Change Avatar template. 685 */ 686 bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) ); 311 $screen = new BP_Groups_Screen_Admin_Avatar(); 312 $screen->init(); 687 313 } 688 314 add_action( 'bp_screens', 'groups_screen_group_admin_avatar' ); 689 315 … … 693 319 * @since 2.4.0 694 320 */ 695 321 function groups_screen_group_admin_cover_image() { 696 if ( 'group-cover-image' != bp_get_group_current_admin_tab() ) {697 return false;322 if ( 'group-cover-image' !== bp_get_group_current_admin_tab() ) { 323 return; 698 324 } 699 325 700 326 // If the logged-in user doesn't have permission or if cover image uploads are disabled, then stop here. 701 327 if ( ! bp_is_item_admin() || ! bp_group_use_cover_image_header() ) { 702 return false;328 return; 703 329 } 704 330 705 331 /** … … 728 354 * @since 1.0.0 729 355 */ 730 356 function groups_screen_group_admin_manage_members() { 731 732 if ( 'manage-members' != bp_get_group_current_admin_tab() ) 733 return false; 734 735 if ( ! bp_is_item_admin() ) 736 return false; 737 738 $bp = buddypress(); 739 740 if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) && bp_action_variable( 3 ) ) { 741 if ( bp_is_action_variable( 'promote', 1 ) && ( bp_is_action_variable( 'mod', 2 ) || bp_is_action_variable( 'admin', 2 ) ) && is_numeric( bp_action_variable( 3 ) ) ) { 742 $user_id = bp_action_variable( 3 ); 743 $status = bp_action_variable( 2 ); 744 745 // Check the nonce first. 746 if ( !check_admin_referer( 'groups_promote_member' ) ) 747 return false; 748 749 // Promote a user. 750 if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) ) 751 bp_core_add_message( __( 'There was an error when promoting that user. Please try again.', 'buddypress' ), 'error' ); 752 else 753 bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) ); 754 755 /** 756 * Fires before the redirect after a group member has been promoted. 757 * 758 * @since 1.0.0 759 * 760 * @param int $user_id ID of the user being promoted. 761 * @param int $id ID of the group user is promoted within. 762 */ 763 do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id ); 764 765 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 766 } 357 if ( 'manage-members' !== bp_get_group_current_admin_tab() ) { 358 return; 767 359 } 768 360 769 if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) ) { 770 if ( bp_is_action_variable( 'demote', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 771 $user_id = bp_action_variable( 2 ); 772 773 // Check the nonce first. 774 if ( !check_admin_referer( 'groups_demote_member' ) ) 775 return false; 776 777 // Stop sole admins from abandoning their group. 778 $group_admins = groups_get_group_admins( $bp->groups->current_group->id ); 779 if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id ) 780 bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' ); 781 782 // Demote a user. 783 elseif ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) ) 784 bp_core_add_message( __( 'There was an error when demoting that user. Please try again.', 'buddypress' ), 'error' ); 785 else 786 bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) ); 787 788 /** 789 * Fires before the redirect after a group member has been demoted. 790 * 791 * @since 1.0.0 792 * 793 * @param int $user_id ID of the user being demoted. 794 * @param int $id ID of the group user is demoted within. 795 */ 796 do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id ); 797 798 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 799 } 800 801 if ( bp_is_action_variable( 'ban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 802 $user_id = bp_action_variable( 2 ); 803 804 // Check the nonce first. 805 if ( !check_admin_referer( 'groups_ban_member' ) ) 806 return false; 807 808 // Ban a user. 809 if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) ) 810 bp_core_add_message( __( 'There was an error when banning that user. Please try again.', 'buddypress' ), 'error' ); 811 else 812 bp_core_add_message( __( 'User banned successfully', 'buddypress' ) ); 813 814 /** 815 * Fires before the redirect after a group member has been banned. 816 * 817 * @since 1.0.0 818 * 819 * @param int $user_id ID of the user being banned. 820 * @param int $id ID of the group user is banned from. 821 */ 822 do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id ); 823 824 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 825 } 826 827 if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 828 $user_id = bp_action_variable( 2 ); 829 830 // Check the nonce first. 831 if ( !check_admin_referer( 'groups_unban_member' ) ) 832 return false; 833 834 // Remove a ban for user. 835 if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) ) 836 bp_core_add_message( __( 'There was an error when unbanning that user. Please try again.', 'buddypress' ), 'error' ); 837 else 838 bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) ); 839 840 /** 841 * Fires before the redirect after a group member has been unbanned. 842 * 843 * @since 1.0.0 844 * 845 * @param int $user_id ID of the user being unbanned. 846 * @param int $id ID of the group user is unbanned from. 847 */ 848 do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id ); 849 850 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 851 } 852 853 if ( bp_is_action_variable( 'remove', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 854 $user_id = bp_action_variable( 2 ); 855 856 // Check the nonce first. 857 if ( !check_admin_referer( 'groups_remove_member' ) ) 858 return false; 859 860 // Remove a user. 861 if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) ) 862 bp_core_add_message( __( 'There was an error removing that user from the group. Please try again.', 'buddypress' ), 'error' ); 863 else 864 bp_core_add_message( __( 'User removed successfully', 'buddypress' ) ); 865 866 /** 867 * Fires before the redirect after a group member has been removed. 868 * 869 * @since 1.2.6 870 * 871 * @param int $user_id ID of the user being removed. 872 * @param int $id ID of the group the user is removed from. 873 */ 874 do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id ); 875 876 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 877 } 361 if ( ! bp_is_item_admin() ) { 362 return; 878 363 } 879 364 880 /** 881 * Fires before the loading of a group's manage members template. 882 * 883 * @since 1.0.0 884 * 885 * @param int $id ID of the group whose manage members page is being displayed. 886 */ 887 do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id ); 888 889 /** 890 * Filters the template to load for a group's manage members page. 891 * 892 * @since 1.0.0 893 * 894 * @param string $value Path to a group's manage members template. 895 */ 896 bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) ); 365 $screen = new BP_Groups_Screen_Admin_Manage_Members(); 366 $screen->init(); 897 367 } 898 368 add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' ); 899 369 … … 903 373 * @since 1.0.0 904 374 */ 905 375 function groups_screen_group_admin_requests() { 906 $bp = buddypress();907 908 376 if ( 'membership-requests' != bp_get_group_current_admin_tab() ) { 909 return false; 910 } 911 912 if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) ) { 913 return false; 377 return; 914 378 } 915 379 916 $request_action = (string) bp_action_variable( 1 ); 917 $membership_id = (int) bp_action_variable( 2 ); 918 919 if ( !empty( $request_action ) && !empty( $membership_id ) ) { 920 if ( 'accept' == $request_action && is_numeric( $membership_id ) ) { 921 922 // Check the nonce first. 923 if ( !check_admin_referer( 'groups_accept_membership_request' ) ) 924 return false; 925 926 // Accept the membership request. 927 if ( !groups_accept_membership_request( $membership_id ) ) 928 bp_core_add_message( __( 'There was an error accepting the membership request. Please try again.', 'buddypress' ), 'error' ); 929 else 930 bp_core_add_message( __( 'Group membership request accepted', 'buddypress' ) ); 931 932 } elseif ( 'reject' == $request_action && is_numeric( $membership_id ) ) { 933 /* Check the nonce first. */ 934 if ( !check_admin_referer( 'groups_reject_membership_request' ) ) 935 return false; 936 937 // Reject the membership request. 938 if ( !groups_reject_membership_request( $membership_id ) ) 939 bp_core_add_message( __( 'There was an error rejecting the membership request. Please try again.', 'buddypress' ), 'error' ); 940 else 941 bp_core_add_message( __( 'Group membership request rejected', 'buddypress' ) ); 942 } 943 944 /** 945 * Fires before the redirect if a group membership request has been handled. 946 * 947 * @since 1.0.0 948 * 949 * @param int $id ID of the group that was edited. 950 * @param string $request_action Membership request action being performed. 951 * @param int $membership_id The key of the action_variables array that you want. 952 */ 953 do_action( 'groups_group_request_managed', $bp->groups->current_group->id, $request_action, $membership_id ); 954 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/' ); 380 if ( ! bp_is_item_admin() || ( 'public' == buddypress()->groups->current_group->status ) ) { 381 return; 955 382 } 956 383 957 /** 958 * Fires before the loading of the group membership request page template. 959 * 960 * @since 1.0.0 961 * 962 * @param int $id ID of the group that is being displayed. 963 */ 964 do_action( 'groups_screen_group_admin_requests', $bp->groups->current_group->id ); 965 966 /** 967 * Filters the template to load for a group's membership request page. 968 * 969 * @since 1.0.0 970 * 971 * @param string $value Path to a group's membership request template. 972 */ 973 bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/home' ) ); 384 $screen = new BP_Groups_Screen_Admin_Requests(); 385 $screen->init(); 974 386 } 975 387 add_action( 'bp_screens', 'groups_screen_group_admin_requests' ); 976 388 … … 980 392 * @since 1.0.0 981 393 */ 982 394 function groups_screen_group_admin_delete_group() { 983 984 if ( 'delete-group' != bp_get_group_current_admin_tab() ) 985 return false; 986 987 if ( ! bp_is_item_admin() && !bp_current_user_can( 'bp_moderate' ) ) 988 return false; 989 990 $bp = buddypress(); 991 992 if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) { 993 994 // Check the nonce first. 995 if ( !check_admin_referer( 'groups_delete_group' ) ) { 996 return false; 997 } 998 999 /** 1000 * Fires before the deletion of a group from the Delete Group page. 1001 * 1002 * @since 1.5.0 1003 * 1004 * @param int $id ID of the group being deleted. 1005 */ 1006 do_action( 'groups_before_group_deleted', $bp->groups->current_group->id ); 1007 1008 // Group admin has deleted the group, now do it. 1009 if ( !groups_delete_group( $bp->groups->current_group->id ) ) { 1010 bp_core_add_message( __( 'There was an error deleting the group. Please try again.', 'buddypress' ), 'error' ); 1011 } else { 1012 bp_core_add_message( __( 'The group was deleted successfully.', 'buddypress' ) ); 1013 1014 /** 1015 * Fires after the deletion of a group from the Delete Group page. 1016 * 1017 * @since 1.0.0 1018 * 1019 * @param int $id ID of the group being deleted. 1020 */ 1021 do_action( 'groups_group_deleted', $bp->groups->current_group->id ); 1022 1023 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 1024 } 1025 1026 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 395 if ( 'delete-group' !== bp_get_group_current_admin_tab() ) { 396 return; 1027 397 } 1028 398 1029 /** 1030 * Fires before the loading of the Delete Group page template. 1031 * 1032 * @since 1.0.0 1033 * 1034 * @param int $id ID of the group that is being displayed. 1035 */ 1036 do_action( 'groups_screen_group_admin_delete_group', $bp->groups->current_group->id ); 399 if ( ! bp_is_item_admin() && ! bp_current_user_can( 'bp_moderate' ) ) { 400 return; 401 } 1037 402 1038 /** 1039 * Filters the template to load for the Delete Group page. 1040 * 1041 * @since 1.0.0 1042 * 1043 * @param string $value Path to the Delete Group template. 1044 */ 1045 bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/home' ) ); 403 $screen = new BP_Groups_Screen_Admin_Delete(); 404 $screen->init(); 1046 405 } 1047 406 add_action( 'bp_screens', 'groups_screen_group_admin_delete_group' ); 1048 407 … … 1052 411 * @since 1.0.0 1053 412 */ 1054 413 function groups_screen_notification_settings() { 1055 1056 if ( !$group_invite = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_invite', true ) ) 1057 $group_invite = 'yes'; 1058 1059 if ( !$group_update = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_group_updated', true ) ) 1060 $group_update = 'yes'; 1061 1062 if ( !$group_promo = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_admin_promotion', true ) ) 1063 $group_promo = 'yes'; 1064 1065 if ( !$group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) ) 1066 $group_request = 'yes'; 1067 1068 if ( ! $group_request_completed = bp_get_user_meta( bp_displayed_user_id(), 'notification_membership_request_completed', true ) ) { 1069 $group_request_completed = 'yes'; 1070 } 1071 ?> 1072 1073 <table class="notification-settings" id="groups-notification-settings"> 1074 <thead> 1075 <tr> 1076 <th class="icon"></th> 1077 <th class="title"><?php _ex( 'Groups', 'Group settings on notification settings page', 'buddypress' ) ?></th> 1078 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 1079 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 1080 </tr> 1081 </thead> 1082 1083 <tbody> 1084 <tr id="groups-notification-settings-invitation"> 1085 <td></td> 1086 <td><?php _ex( 'A member invites you to join a group', 'group settings on notification settings page','buddypress' ) ?></td> 1087 <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-yes" value="yes" <?php checked( $group_invite, 'yes', true ) ?>/><label for="notification-groups-invite-yes" class="bp-screen-reader-text"><?php 1088 /* translators: accessibility text */ 1089 _e( 'Yes, send email', 'buddypress' ); 1090 ?></label></td> 1091 <td class="no"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-no" value="no" <?php checked( $group_invite, 'no', true ) ?>/><label for="notification-groups-invite-no" class="bp-screen-reader-text"><?php 1092 /* translators: accessibility text */ 1093 _e( 'No, do not send email', 'buddypress' ); 1094 ?></label></td> 1095 </tr> 1096 <tr id="groups-notification-settings-info-updated"> 1097 <td></td> 1098 <td><?php _ex( 'Group information is updated', 'group settings on notification settings page', 'buddypress' ) ?></td> 1099 <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-yes" value="yes" <?php checked( $group_update, 'yes', true ) ?>/><label for="notification-groups-group-updated-yes" class="bp-screen-reader-text"><?php 1100 /* translators: accessibility text */ 1101 _e( 'Yes, send email', 'buddypress' ); 1102 ?></label></td> 1103 <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-no" value="no" <?php checked( $group_update, 'no', true ) ?>/><label for="notification-groups-group-updated-no" class="bp-screen-reader-text"><?php 1104 /* translators: accessibility text */ 1105 _e( 'No, do not send email', 'buddypress' ); 1106 ?></label></td> 1107 </tr> 1108 <tr id="groups-notification-settings-promoted"> 1109 <td></td> 1110 <td><?php _ex( 'You are promoted to a group administrator or moderator', 'group settings on notification settings page', 'buddypress' ) ?></td> 1111 <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-yes" value="yes" <?php checked( $group_promo, 'yes', true ) ?>/><label for="notification-groups-admin-promotion-yes" class="bp-screen-reader-text"><?php 1112 /* translators: accessibility text */ 1113 _e( 'Yes, send email', 'buddypress' ); 1114 ?></label></td> 1115 <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-no" value="no" <?php checked( $group_promo, 'no', true ) ?>/><label for="notification-groups-admin-promotion-no" class="bp-screen-reader-text"><?php 1116 /* translators: accessibility text */ 1117 _e( 'No, do not send email', 'buddypress' ); 1118 ?></label></td> 1119 </tr> 1120 <tr id="groups-notification-settings-request"> 1121 <td></td> 1122 <td><?php _ex( 'A member requests to join a private group for which you are an admin', 'group settings on notification settings page', 'buddypress' ) ?></td> 1123 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php 1124 /* translators: accessibility text */ 1125 _e( 'Yes, send email', 'buddypress' ); 1126 ?></label></td> 1127 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php 1128 /* translators: accessibility text */ 1129 _e( 'No, do not send email', 'buddypress' ); 1130 ?></label></td> 1131 </tr> 1132 <tr id="groups-notification-settings-request-completed"> 1133 <td></td> 1134 <td><?php _ex( 'Your request to join a group has been approved or denied', 'group settings on notification settings page', 'buddypress' ) ?></td> 1135 <td class="yes"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-yes" value="yes" <?php checked( $group_request_completed, 'yes', true ) ?>/><label for="notification-groups-membership-request-completed-yes" class="bp-screen-reader-text"><?php 1136 /* translators: accessibility text */ 1137 _e( 'Yes, send email', 'buddypress' ); 1138 ?></label></td> 1139 <td class="no"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-no" value="no" <?php checked( $group_request_completed, 'no', true ) ?>/><label for="notification-groups-membership-request-completed-no" class="bp-screen-reader-text"><?php 1140 /* translators: accessibility text */ 1141 _e( 'No, do not send email', 'buddypress' ); 1142 ?></label></td> 1143 </tr> 1144 1145 <?php 1146 1147 /** 1148 * Fires at the end of the available group settings fields on Notification Settings page. 1149 * 1150 * @since 1.0.0 1151 */ 1152 do_action( 'groups_screen_notification_settings' ); ?> 1153 1154 </tbody> 1155 </table> 1156 1157 <?php 414 $screen = new BP_Groups_Screen_User_Settings_Notifications(); 415 $screen->init(); 1158 416 } 1159 417 add_action( 'bp_notification_settings', 'groups_screen_notification_settings' ); 1160 418 -
new file src/bp-groups/classes/class-bp-groups-action-create-group.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Catch and process group creation form submissions. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_action_create_group() 19 */ 20 class BP_Groups_Action_Create_Group { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $bp = buddypress(); 28 29 // Make sure creation steps are in the right order. 30 groups_action_sort_creation_steps(); 31 32 // If no current step is set, reset everything so we can start a fresh group creation. 33 $bp->groups->current_create_step = bp_action_variable( 1 ); 34 if ( ! bp_get_groups_current_create_step() ) { 35 unset( $bp->groups->current_create_step ); 36 unset( $bp->groups->completed_create_steps ); 37 38 setcookie( 'bp_new_group_id', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 39 setcookie( 'bp_completed_create_steps', false, time() - 1000, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 40 41 $reset_steps = true; 42 $keys = array_keys( $bp->groups->group_creation_steps ); 43 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . array_shift( $keys ) ) ); 44 } 45 46 // If this is a creation step that is not recognized, just redirect them back to the first screen. 47 if ( bp_get_groups_current_create_step() && empty( $bp->groups->group_creation_steps[bp_get_groups_current_create_step()] ) ) { 48 bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' ); 49 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) ); 50 } 51 52 // Fetch the currently completed steps variable. 53 if ( isset( $_COOKIE['bp_completed_create_steps'] ) && ! isset( $reset_steps ) ) { 54 $bp->groups->completed_create_steps = json_decode( base64_decode( stripslashes( $_COOKIE['bp_completed_create_steps'] ) ) ); 55 } 56 57 // Set the ID of the new group, if it has already been created in a previous step. 58 if ( bp_get_new_group_id() ) { 59 $bp->groups->current_group = groups_get_group( $bp->groups->new_group_id ); 60 61 // Only allow the group creator to continue to edit the new group. 62 if ( ! bp_is_group_creator( $bp->groups->current_group, bp_loggedin_user_id() ) ) { 63 bp_core_add_message( __( 'Only the group creator may continue editing this group.', 'buddypress' ), 'error' ); 64 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create' ) ); 65 } 66 } 67 68 // If the save, upload or skip button is hit, lets calculate what we need to save. 69 if ( isset( $_POST['save'] ) ) { 70 // Check the nonce. 71 check_admin_referer( 'groups_create_save_' . bp_get_groups_current_create_step() ); 72 73 if ( 'group-details' == bp_get_groups_current_create_step() ) { 74 if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) { 75 bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' ); 76 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 77 } 78 79 $new_group_id = isset( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : 0; 80 81 if ( ! $bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) { 82 bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' ); 83 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 84 } 85 } 86 87 if ( 'group-settings' == bp_get_groups_current_create_step() ) { 88 $group_status = 'public'; 89 $group_enable_forum = 1; 90 91 if ( ! isset($_POST['group-show-forum']) ) { 92 $group_enable_forum = 0; 93 } 94 95 if ( 'private' == $_POST['group-status'] ) { 96 $group_status = 'private'; 97 } elseif ( 'hidden' == $_POST['group-status'] ) { 98 $group_status = 'hidden'; 99 } 100 101 if ( ! $bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) { 102 bp_core_add_message( __( 'There was an error saving group details. Please try again.', 'buddypress' ), 'error' ); 103 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . bp_get_groups_current_create_step() ) ); 104 } 105 106 // Save group types. 107 if ( ! empty( $_POST['group-types'] ) ) { 108 bp_groups_set_group_type( $bp->groups->new_group_id, $_POST['group-types'] ); 109 } 110 111 /** 112 * Filters the allowed invite statuses. 113 * 114 * @since 1.5.0 115 * 116 * @param array $value Array of statuses allowed. 117 * Possible values are 'members, 118 * 'mods', and 'admins'. 119 */ 120 $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) ); 121 $invite_status = !empty( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members'; 122 123 groups_update_groupmeta( $bp->groups->new_group_id, 'invite_status', $invite_status ); 124 } 125 126 if ( 'group-invites' === bp_get_groups_current_create_step() ) { 127 if ( ! empty( $_POST['friends'] ) ) { 128 foreach ( (array) $_POST['friends'] as $friend ) { 129 groups_invite_user( array( 130 'user_id' => (int) $friend, 131 'group_id' => $bp->groups->new_group_id, 132 ) ); 133 } 134 } 135 136 groups_send_invites( bp_loggedin_user_id(), $bp->groups->new_group_id ); 137 } 138 139 /** 140 * Fires before finalization of group creation and cookies are set. 141 * 142 * This hook is a variable hook dependent on the current step 143 * in the creation process. 144 * 145 * @since 1.1.0 146 */ 147 do_action( 'groups_create_group_step_save_' . bp_get_groups_current_create_step() ); 148 149 /** 150 * Fires after the group creation step is completed. 151 * 152 * Mostly for clearing cache on a generic action name. 153 * 154 * @since 1.1.0 155 */ 156 do_action( 'groups_create_group_step_complete' ); 157 158 /** 159 * Once we have successfully saved the details for this step of the creation process 160 * we need to add the current step to the array of completed steps, then update the cookies 161 * holding the information 162 */ 163 $completed_create_steps = isset( $bp->groups->completed_create_steps ) ? $bp->groups->completed_create_steps : array(); 164 if ( ! in_array( bp_get_groups_current_create_step(), $completed_create_steps ) ) { 165 $bp->groups->completed_create_steps[] = bp_get_groups_current_create_step(); 166 } 167 168 // Reset cookie info. 169 setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 170 setcookie( 'bp_completed_create_steps', base64_encode( json_encode( $bp->groups->completed_create_steps ) ), time()+60*60*24, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 171 172 // If we have completed all steps and hit done on the final step we 173 // can redirect to the completed group. 174 $keys = array_keys( $bp->groups->group_creation_steps ); 175 if ( count( $bp->groups->completed_create_steps ) == count( $keys ) && bp_get_groups_current_create_step() == array_pop( $keys ) ) { 176 unset( $bp->groups->current_create_step ); 177 unset( $bp->groups->completed_create_steps ); 178 179 setcookie( 'bp_new_group_id', false, time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 180 setcookie( 'bp_completed_create_steps', false, time() - 3600, COOKIEPATH, COOKIE_DOMAIN, is_ssl() ); 181 182 // Once we completed all steps, record the group creation in the activity stream. 183 groups_record_activity( array( 184 'type' => 'created_group', 185 'item_id' => $bp->groups->new_group_id 186 ) ); 187 188 /** 189 * Fires after the group has been successfully created. 190 * 191 * @since 1.1.0 192 * 193 * @param int $new_group_id ID of the newly created group. 194 */ 195 do_action( 'groups_group_create_complete', $bp->groups->new_group_id ); 196 197 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) ); 198 } else { 199 /** 200 * Since we don't know what the next step is going to be (any plugin can insert steps) 201 * we need to loop the step array and fetch the next step that way. 202 */ 203 foreach ( $keys as $key ) { 204 if ( $key == bp_get_groups_current_create_step() ) { 205 $next = 1; 206 continue; 207 } 208 209 if ( isset( $next ) ) { 210 $next_step = $key; 211 break; 212 } 213 } 214 215 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . $next_step ) ); 216 } 217 } 218 219 // Remove invitations. 220 if ( 'group-invites' === bp_get_groups_current_create_step() && ! empty( $_REQUEST['user_id'] ) && is_numeric( $_REQUEST['user_id'] ) ) { 221 if ( ! check_admin_referer( 'groups_invite_uninvite_user' ) ) { 222 return false; 223 } 224 225 $message = __( 'Invite successfully removed', 'buddypress' ); 226 $error = false; 227 228 if ( ! groups_uninvite_user( (int) $_REQUEST['user_id'], $bp->groups->new_group_id ) ) { 229 $message = __( 'There was an error removing the invite', 'buddypress' ); 230 $error = 'error'; 231 } 232 233 bp_core_add_message( $message, $error ); 234 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/group-invites' ) ); 235 } 236 237 // Group avatar is handled separately. 238 if ( 'group-avatar' == bp_get_groups_current_create_step() && isset( $_POST['upload'] ) ) { 239 if ( ! isset( $bp->avatar_admin ) ) { 240 $bp->avatar_admin = new stdClass(); 241 } 242 243 if ( ! empty( $_FILES ) && isset( $_POST['upload'] ) ) { 244 // Normally we would check a nonce here, but the group save nonce is used instead. 245 // Pass the file to the avatar upload handler. 246 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 247 $bp->avatar_admin->step = 'crop-image'; 248 249 // Make sure we include the jQuery jCrop file for image cropping. 250 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 251 } 252 } 253 254 // If the image cropping is done, crop the image and save a full/thumb version. 255 if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) { 256 257 // Normally we would check a nonce here, but the group save nonce is used instead. 258 $args = array( 259 'object' => 'group', 260 'avatar_dir' => 'group-avatars', 261 'item_id' => $bp->groups->current_group->id, 262 'original_file' => $_POST['image_src'], 263 'crop_x' => $_POST['x'], 264 'crop_y' => $_POST['y'], 265 'crop_w' => $_POST['w'], 266 'crop_h' => $_POST['h'] 267 ); 268 269 if ( ! bp_core_avatar_handle_crop( $args ) ) { 270 bp_core_add_message( __( 'There was an error saving the group profile photo, please try uploading again.', 'buddypress' ), 'error' ); 271 } else { 272 /** 273 * Fires after a group avatar is uploaded. 274 * 275 * @since 2.8.0 276 * 277 * @param int $group_id ID of the group. 278 * @param string $type Avatar type. 'crop' or 'full'. 279 * @param array $args Array of parameters passed to the avatar handler. 280 */ 281 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args ); 282 283 bp_core_add_message( __( 'The group profile photo was uploaded successfully.', 'buddypress' ) ); 284 } 285 } 286 } 287 288 /** 289 * Filters the template to load for the group creation screen. 290 * 291 * @since 1.0.0 292 * 293 * @param string $value Path to the group creation template to load. 294 */ 295 bp_core_load_template( apply_filters( 'groups_template_create_group', 'groups/create' ) ); 296 } 297 } 298 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-action-group-access-protection.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Protect access to single groups. 15 * 16 * @since 3.0.0 17 * 18 * @see bp_groups_group_access_protection() 19 */ 20 class BP_Groups_Action_Group_Access_Protection { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $current_group = groups_get_current_group(); 28 $user_has_access = $current_group->user_has_access; 29 $is_visible = $current_group->is_visible; 30 $no_access_args = array(); 31 32 // The user can know about the group but doesn't have full access. 33 if ( ! $user_has_access && $is_visible ) { 34 // Always allow access to home and request-membership. 35 if ( bp_is_current_action( 'home' ) || bp_is_current_action( 'request-membership' ) ) { 36 $user_has_access = true; 37 38 // User doesn't have access, so set up redirect args. 39 } elseif ( is_user_logged_in() ) { 40 $no_access_args = array( 41 'message' => __( 'You do not have access to this group.', 'buddypress' ), 42 'root' => bp_get_group_permalink( $current_group ) . 'home/', 43 'redirect' => false 44 ); 45 } 46 } 47 48 // Protect the admin tab from non-admins. 49 if ( bp_is_current_action( 'admin' ) && ! bp_is_item_admin() ) { 50 $user_has_access = false; 51 $no_access_args = array( 52 'message' => __( 'You are not an admin of this group.', 'buddypress' ), 53 'root' => bp_get_group_permalink( $current_group ), 54 'redirect' => false 55 ); 56 } 57 58 /** 59 * Allow plugins to filter whether the current user has access to this group content. 60 * 61 * Note that if a plugin sets $user_has_access to false, it may also 62 * want to change the $no_access_args, to avoid problems such as 63 * logged-in users being redirected to wp-login.php. 64 * 65 * @since 2.1.0 66 * 67 * @param bool $user_has_access True if the user has access to the 68 * content, otherwise false. 69 * @param array $no_access_args Arguments to be passed to bp_core_no_access() in case 70 * of no access. Note that this value is passed by reference, 71 * so it can be modified by the filter callback. 72 */ 73 $user_has_access = apply_filters_ref_array( 'bp_group_user_has_access', array( $user_has_access, &$no_access_args ) ); 74 75 // If user has access, we return rather than redirect. 76 if ( $user_has_access ) { 77 return; 78 } 79 80 // Groups that the user cannot know about should return a 404 for non-members. 81 // Unset the current group so that you're not redirected 82 // to the default group tab. 83 if ( ! $is_visible ) { 84 buddypress()->groups->current_group = 0; 85 buddypress()->is_single_item = false; 86 bp_do_404(); 87 return; 88 } else { 89 bp_core_no_access( $no_access_args ); 90 } 91 } 92 } 93 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-action-join-group.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Catch and process "Join Group" button clicks. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_action_join_group() 19 */ 20 class BP_Groups_Action_Join_Group { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 // Skip if banned or already a member. 28 if ( ! groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) && !groups_is_user_banned( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 29 30 // User wants to join a group that is not public. 31 if ( bp_current_user_can( 'groups_join_group', array( 'group_id' => bp_get_current_group_id() ) ) ) { 32 if ( ! groups_check_user_has_invite( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 33 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); 34 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); 35 } 36 } 37 38 // User wants to join any group. 39 if ( ! groups_join_group( bp_get_current_group_id() ) ) { 40 bp_core_add_message( __( 'There was an error joining the group.', 'buddypress' ), 'error' ); 41 } else { 42 bp_core_add_message( __( 'You joined the group!', 'buddypress' ) ); 43 } 44 45 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); 46 } 47 48 /** 49 * Filters the template to load for the single group screen. 50 * 51 * @since 1.0.0 52 * 53 * @param string $value Path to the single group template to load. 54 */ 55 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 56 } 57 } 58 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-action-leave-group.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Catch and process "Leave Group" button clicks. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_action_leave_group() 19 */ 20 class BP_Groups_Action_Leave_Group { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 28 // Stop sole admins from abandoning their group. 29 $group_admins = groups_get_group_admins( bp_get_current_group_id() ); 30 31 if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() ) { 32 bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' ); 33 } elseif ( ! groups_leave_group( bp_get_current_group_id() ) ) { 34 bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' ); 35 } else { 36 bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) ); 37 } 38 39 $group = groups_get_current_group(); 40 $redirect = bp_get_group_permalink( $group ); 41 42 if ( ! $group->is_visible ) { 43 $redirect = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 44 } 45 46 bp_core_redirect( $redirect ); 47 } 48 49 /** This filter is documented in bp-groups/bp-groups-actions.php */ 50 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 51 } 52 } 53 No newline at end of file -
src/bp-groups/classes/class-bp-groups-component.php
127 127 'filters', 128 128 'screens', 129 129 'widgets', 130 'activity',131 130 'template', 132 131 'adminbar', 133 132 'functions', 134 133 'notifications' 135 134 ); 136 135 136 // Conditional includes. 137 137 if ( is_admin() ) { 138 138 $includes[] = 'admin'; 139 139 } 140 if ( bp_is_active( 'activity' ) ) { 141 $includes[] = 'activity'; 142 } 140 143 141 144 parent::includes( $includes ); 142 145 } -
new file src/bp-groups/classes/class-bp-groups-screen-admin-avatar.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of a group's Change Avatar page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_avatar() 19 */ 20 class BP_Groups_Screen_Admin_Avatar { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $bp = buddypress(); 28 29 // If the group admin has deleted the admin avatar. 30 if ( bp_is_action_variable( 'delete', 1 ) ) { 31 // Check the nonce. 32 check_admin_referer( 'bp_group_avatar_delete' ); 33 34 if ( bp_core_delete_existing_avatar( array( 'item_id' => bp_get_current_group_id(), 'object' => 'group' ) ) ) { 35 bp_core_add_message( __( 'The group profile photo was deleted successfully!', 'buddypress' ) ); 36 } else { 37 bp_core_add_message( __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 'error' ); 38 } 39 } 40 41 if ( ! isset( $bp->avatar_admin ) ) { 42 $bp->avatar_admin = new stdClass(); 43 } 44 45 $bp->avatar_admin->step = 'upload-image'; 46 47 if ( ! empty( $_FILES ) ) { 48 // Check the nonce. 49 check_admin_referer( 'bp_avatar_upload' ); 50 51 // Pass the file to the avatar upload handler. 52 if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) { 53 $bp->avatar_admin->step = 'crop-image'; 54 55 // Make sure we include the jQuery jCrop file for image cropping. 56 add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' ); 57 } 58 } 59 60 // If the image cropping is done, crop the image and save a full/thumb version. 61 if ( isset( $_POST['avatar-crop-submit'] ) ) { 62 // Check the nonce. 63 check_admin_referer( 'bp_avatar_cropstore' ); 64 65 $args = array( 66 'object' => 'group', 67 'avatar_dir' => 'group-avatars', 68 'item_id' => bp_get_current_group_id(), 69 'original_file' => $_POST['image_src'], 70 'crop_x' => $_POST['x'], 71 'crop_y' => $_POST['y'], 72 'crop_w' => $_POST['w'], 73 'crop_h' => $_POST['h'] 74 ); 75 76 if ( ! bp_core_avatar_handle_crop( $args ) ) { 77 bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' ); 78 } else { 79 /** 80 * Fires after a group avatar is uploaded. 81 * 82 * @since 2.8.0 83 * 84 * @param int $group_id ID of the group. 85 * @param string $type Avatar type. 'crop' or 'full'. 86 * @param array $args Array of parameters passed to the avatar handler. 87 */ 88 do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args ); 89 bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) ); 90 } 91 } 92 93 /** 94 * Fires before the loading of the group Change Avatar page template. 95 * 96 * @since 1.0.0 97 * 98 * @param int $id ID of the group that is being displayed. 99 */ 100 do_action( 'groups_screen_group_admin_avatar', bp_get_current_group_id() ); 101 102 /** 103 * Filters the template to load for a group's Change Avatar page. 104 * 105 * @since 1.0.0 106 * 107 * @param string $value Path to a group's Change Avatar template. 108 */ 109 bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) ); 110 } 111 } 112 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-admin-delete.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of the Delete Group page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_delete_group() 19 */ 20 class BP_Groups_Screen_Admin_Delete { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) { 28 // Check the nonce first. 29 if ( ! check_admin_referer( 'groups_delete_group' ) ) { 30 return; 31 } 32 33 /** 34 * Fires before the deletion of a group from the Delete Group page. 35 * 36 * @since 1.5.0 37 * 38 * @param int $id ID of the group being deleted. 39 */ 40 do_action( 'groups_before_group_deleted', bp_get_current_group_id() ); 41 42 // Group admin has deleted the group, now do it. 43 if ( !groups_delete_group( bp_get_current_group_id() ) ) { 44 bp_core_add_message( __( 'There was an error deleting the group. Please try again.', 'buddypress' ), 'error' ); 45 } else { 46 bp_core_add_message( __( 'The group was deleted successfully.', 'buddypress' ) ); 47 48 /** 49 * Fires after the deletion of a group from the Delete Group page. 50 * 51 * @since 1.0.0 52 * 53 * @param int $id ID of the group being deleted. 54 */ 55 do_action( 'groups_group_deleted', bp_get_current_group_id() ); 56 57 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 58 } 59 60 bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) ); 61 } 62 63 /** 64 * Fires before the loading of the Delete Group page template. 65 * 66 * @since 1.0.0 67 * 68 * @param int $id ID of the group that is being displayed. 69 */ 70 do_action( 'groups_screen_group_admin_delete_group', bp_get_current_group_id() ); 71 72 /** 73 * Filters the template to load for the Delete Group page. 74 * 75 * @since 1.0.0 76 * 77 * @param string $value Path to the Delete Group template. 78 */ 79 bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/home' ) ); 80 } 81 } 82 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-admin-edit-details.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of a group's admin/edit-details page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_edit_details() 19 */ 20 class BP_Groups_Screen_Admin_Edit_Details { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 // If the edit form has been submitted, save the edited details. 28 if ( isset( $_POST['save'] ) ) { 29 // Check the nonce. 30 if ( ! check_admin_referer( 'groups_edit_group_details' ) ) 31 return false; 32 33 $group_notify_members = isset( $_POST['group-notify-members'] ) ? (int) $_POST['group-notify-members'] : 0; 34 35 // Name and description are required and may not be empty. 36 if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) ) { 37 bp_core_add_message( __( 'Groups must have a name and a description. Please try again.', 'buddypress' ), 'error' ); 38 } elseif ( ! groups_edit_base_group_details( array( 39 'group_id' => $_POST['group-id'], 40 'name' => $_POST['group-name'], 41 'slug' => null, // @TODO: Add to settings pane? If yes, editable by site admin only, or allow group admins to do this? 42 'description' => $_POST['group-desc'], 43 'notify_members' => $group_notify_members, 44 ) ) ) { 45 bp_core_add_message( __( 'There was an error updating group details. Please try again.', 'buddypress' ), 'error' ); 46 } else { 47 bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) ); 48 } 49 50 /** 51 * Fires before the redirect if a group details has been edited and saved. 52 * 53 * @since 1.0.0 54 * 55 * @param int $id ID of the group that was edited. 56 */ 57 do_action( 'groups_group_details_edited', bp_get_current_group_id() ); 58 59 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 60 } 61 62 /** 63 * Fires before the loading of the group admin/edit-details page template. 64 * 65 * @since 1.0.0 66 * 67 * @param int $id ID of the group that is being displayed. 68 */ 69 do_action( 'groups_screen_group_admin_edit_details', bp_get_current_group_id() ); 70 71 /** 72 * Filters the template to load for a group's admin/edit-details page. 73 * 74 * @since 1.0.0 75 * 76 * @param string $value Path to a group's admin/edit-details template. 77 */ 78 bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) ); 79 } 80 } 81 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-admin-manage-members.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handles actions related to member management on the group admin. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_manage_members() 19 */ 20 class BP_Groups_Screen_Admin_Manage_Members { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) && bp_action_variable( 3 ) ) { 28 if ( bp_is_action_variable( 'promote', 1 ) && ( bp_is_action_variable( 'mod', 2 ) || bp_is_action_variable( 'admin', 2 ) ) && is_numeric( bp_action_variable( 3 ) ) ) { 29 $user_id = bp_action_variable( 3 ); 30 $status = bp_action_variable( 2 ); 31 32 // Check the nonce first. 33 if ( ! check_admin_referer( 'groups_promote_member' ) ) { 34 return; 35 } 36 37 // Promote a user. 38 if ( ! groups_promote_member( $user_id, bp_get_current_group_id(), $status ) ) { 39 bp_core_add_message( __( 'There was an error when promoting that user. Please try again.', 'buddypress' ), 'error' ); 40 } else { 41 bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) ); 42 } 43 44 /** 45 * Fires before the redirect after a group member has been promoted. 46 * 47 * @since 1.0.0 48 * 49 * @param int $user_id ID of the user being promoted. 50 * @param int $id ID of the group user is promoted within. 51 */ 52 do_action( 'groups_promoted_member', $user_id, bp_get_current_group_id() ); 53 54 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 55 } 56 } 57 58 if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) ) { 59 if ( bp_is_action_variable( 'demote', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 60 $user_id = bp_action_variable( 2 ); 61 62 // Check the nonce first. 63 if ( ! check_admin_referer( 'groups_demote_member' ) ) { 64 return; 65 } 66 67 // Stop sole admins from abandoning their group. 68 $group_admins = groups_get_group_admins( bp_get_current_group_id() ); 69 if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id ) { 70 bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' ); 71 72 // Demote a user. 73 } elseif ( ! groups_demote_member( $user_id, bp_get_current_group_id() ) ) { 74 bp_core_add_message( __( 'There was an error when demoting that user. Please try again.', 'buddypress' ), 'error' ); 75 } else { 76 bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) ); 77 } 78 79 /** 80 * Fires before the redirect after a group member has been demoted. 81 * 82 * @since 1.0.0 83 * 84 * @param int $user_id ID of the user being demoted. 85 * @param int $id ID of the group user is demoted within. 86 */ 87 do_action( 'groups_demoted_member', $user_id, bp_get_current_group_id() ); 88 89 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 90 } 91 92 if ( bp_is_action_variable( 'ban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 93 $user_id = bp_action_variable( 2 ); 94 95 // Check the nonce first. 96 if ( ! check_admin_referer( 'groups_ban_member' ) ) { 97 return; 98 } 99 100 // Ban a user. 101 if ( ! groups_ban_member( $user_id, bp_get_current_group_id() ) ) { 102 bp_core_add_message( __( 'There was an error when banning that user. Please try again.', 'buddypress' ), 'error' ); 103 } else { 104 bp_core_add_message( __( 'User banned successfully', 'buddypress' ) ); 105 } 106 107 /** 108 * Fires before the redirect after a group member has been banned. 109 * 110 * @since 1.0.0 111 * 112 * @param int $user_id ID of the user being banned. 113 * @param int $id ID of the group user is banned from. 114 */ 115 do_action( 'groups_banned_member', $user_id, bp_get_current_group_id() ); 116 117 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 118 } 119 120 if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 121 $user_id = bp_action_variable( 2 ); 122 123 // Check the nonce first. 124 if ( ! check_admin_referer( 'groups_unban_member' ) ) { 125 return; 126 } 127 128 // Remove a ban for user. 129 if ( ! groups_unban_member( $user_id, bp_get_current_group_id() ) ) { 130 bp_core_add_message( __( 'There was an error when unbanning that user. Please try again.', 'buddypress' ), 'error' ); 131 } else { 132 bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) ); 133 } 134 135 /** 136 * Fires before the redirect after a group member has been unbanned. 137 * 138 * @since 1.0.0 139 * 140 * @param int $user_id ID of the user being unbanned. 141 * @param int $id ID of the group user is unbanned from. 142 */ 143 do_action( 'groups_unbanned_member', $user_id, bp_get_current_group_id() ); 144 145 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 146 } 147 148 if ( bp_is_action_variable( 'remove', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) { 149 $user_id = bp_action_variable( 2 ); 150 151 // Check the nonce first. 152 if ( ! check_admin_referer( 'groups_remove_member' ) ) { 153 return; 154 } 155 156 // Remove a user. 157 if ( !groups_remove_member( $user_id, bp_get_current_group_id() ) ) { 158 bp_core_add_message( __( 'There was an error removing that user from the group. Please try again.', 'buddypress' ), 'error' ); 159 } else { 160 bp_core_add_message( __( 'User removed successfully', 'buddypress' ) ); 161 } 162 163 /** 164 * Fires before the redirect after a group member has been removed. 165 * 166 * @since 1.2.6 167 * 168 * @param int $user_id ID of the user being removed. 169 * @param int $id ID of the group the user is removed from. 170 */ 171 do_action( 'groups_removed_member', $user_id, bp_get_current_group_id() ); 172 173 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' ); 174 } 175 } 176 177 /** 178 * Fires before the loading of a group's manage members template. 179 * 180 * @since 1.0.0 181 * 182 * @param int $id ID of the group whose manage members page is being displayed. 183 */ 184 do_action( 'groups_screen_group_admin_manage_members', bp_get_current_group_id() ); 185 186 /** 187 * Filters the template to load for a group's manage members page. 188 * 189 * @since 1.0.0 190 * 191 * @param string $value Path to a group's manage members template. 192 */ 193 bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) ); 194 } 195 } 196 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-admin-requests.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of Admin > Membership Requests. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_requests() 19 */ 20 class BP_Groups_Screen_Admin_Requests { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $request_action = (string) bp_action_variable( 1 ); 28 $membership_id = (int) bp_action_variable( 2 ); 29 30 if ( ! empty( $request_action ) && ! empty( $membership_id ) ) { 31 if ( 'accept' == $request_action && is_numeric( $membership_id ) ) { 32 // Check the nonce first. 33 if ( ! check_admin_referer( 'groups_accept_membership_request' ) ) { 34 return; 35 } 36 37 // Accept the membership request. 38 if ( ! groups_accept_membership_request( $membership_id ) ) { 39 bp_core_add_message( __( 'There was an error accepting the membership request. Please try again.', 'buddypress' ), 'error' ); 40 } else { 41 bp_core_add_message( __( 'Group membership request accepted', 'buddypress' ) ); 42 } 43 44 } elseif ( 'reject' == $request_action && is_numeric( $membership_id ) ) { 45 // Check the nonce first. 46 if ( ! check_admin_referer( 'groups_reject_membership_request' ) ) { 47 return; 48 } 49 50 // Reject the membership request. 51 if ( ! groups_reject_membership_request( $membership_id ) ) { 52 bp_core_add_message( __( 'There was an error rejecting the membership request. Please try again.', 'buddypress' ), 'error' ); 53 } else { 54 bp_core_add_message( __( 'Group membership request rejected', 'buddypress' ) ); 55 } 56 } 57 58 /** 59 * Fires before the redirect if a group membership request has been handled. 60 * 61 * @since 1.0.0 62 * 63 * @param int $id ID of the group that was edited. 64 * @param string $request_action Membership request action being performed. 65 * @param int $membership_id The key of the action_variables array that you want. 66 */ 67 do_action( 'groups_group_request_managed', bp_get_current_group_id(), $request_action, $membership_id ); 68 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/' ); 69 } 70 71 /** 72 * Fires before the loading of the group membership request page template. 73 * 74 * @since 1.0.0 75 * 76 * @param int $id ID of the group that is being displayed. 77 */ 78 do_action( 'groups_screen_group_admin_requests', bp_get_current_group_id() ); 79 80 /** 81 * Filters the template to load for a group's membership request page. 82 * 83 * @since 1.0.0 84 * 85 * @param string $value Path to a group's membership request template. 86 */ 87 bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/home' ) ); 88 } 89 } 90 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-admin-settings.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of a group's admin/group-settings page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_admin_settings() 19 */ 20 class BP_Groups_Screen_Admin_Settings { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 // If the edit form has been submitted, save the edited details. 28 if ( isset( $_POST['save'] ) ) { 29 $enable_forum = ( isset( $_POST['group-show-forum'] ) ) ? 1 : 0; 30 31 // Checked against a whitelist for security. 32 /** This filter is documented in bp-groups/bp-groups-admin.php */ 33 $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) ); 34 $status = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public'; 35 36 // Checked against a whitelist for security. 37 /** This filter is documented in bp-groups/bp-groups-admin.php */ 38 $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) ); 39 $invite_status = isset( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members'; 40 41 // Check the nonce. 42 if ( ! check_admin_referer( 'groups_edit_group_settings' ) ) { 43 return; 44 } 45 46 /* 47 * Save group types. 48 * 49 * Ensure we keep types that have 'show_in_create_screen' set to false. 50 */ 51 $current_types = bp_groups_get_group_type( bp_get_current_group_id(), false ); 52 $current_types = array_intersect( bp_groups_get_group_types( array( 'show_in_create_screen' => false ) ), (array) $current_types ); 53 if ( isset( $_POST['group-types'] ) ) { 54 $current_types = array_merge( $current_types, $_POST['group-types'] ); 55 56 // Set group types. 57 bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 58 59 // No group types checked, so this means we want to wipe out all group types. 60 } else { 61 /* 62 * Passing a blank string will wipe out all types for the group. 63 * 64 * Ensure we keep types that have 'show_in_create_screen' set to false. 65 */ 66 $current_types = empty( $current_types ) ? '' : $current_types; 67 68 // Set group types. 69 bp_groups_set_group_type( bp_get_current_group_id(), $current_types ); 70 } 71 72 if ( ! groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) { 73 bp_core_add_message( __( 'There was an error updating group settings. Please try again.', 'buddypress' ), 'error' ); 74 } else { 75 bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) ); 76 } 77 78 /** 79 * Fires before the redirect if a group settings has been edited and saved. 80 * 81 * @since 1.0.0 82 * 83 * @param int $id ID of the group that was edited. 84 */ 85 do_action( 'groups_group_settings_edited', bp_get_current_group_id() ); 86 87 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/group-settings/' ); 88 } 89 90 /** 91 * Fires before the loading of the group admin/group-settings page template. 92 * 93 * @since 1.0.0 94 * 95 * @param int $id ID of the group that is being displayed. 96 */ 97 do_action( 'groups_screen_group_admin_settings', bp_get_current_group_id() ); 98 99 /** 100 * Filters the template to load for a group's admin/group-settings page. 101 * 102 * @since 1.0.0 103 * 104 * @param string $value Path to a group's admin/group-settings template. 105 */ 106 bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/home' ) ); 107 } 108 } 109 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-remove-invites.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Process group invitation removal requests. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_remove_group_invite() 19 */ 20 class BP_Groups_Screen_Remove_Invites { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $friend_id = intval( bp_action_variable( 1 ) ); 28 $group_id = bp_get_current_group_id(); 29 $message = __( 'Invite successfully removed', 'buddypress' ); 30 $redirect = wp_get_referer(); 31 $error = false; 32 33 if ( ! bp_groups_user_can_send_invites( $group_id ) ) { 34 $message = __( 'You are not allowed to send or remove invites', 'buddypress' ); 35 $error = 'error'; 36 } elseif ( groups_check_for_membership_request( $friend_id, $group_id ) ) { 37 $message = __( 'The member requested to join the group', 'buddypress' ); 38 $error = 'error'; 39 } elseif ( ! groups_uninvite_user( $friend_id, $group_id ) ) { 40 $message = __( 'There was an error removing the invite', 'buddypress' ); 41 $error = 'error'; 42 } 43 44 bp_core_add_message( $message, $error ); 45 bp_core_redirect( $redirect ); 46 } 47 } 48 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-request-membership.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of a group's Request Membership page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_request_membership() 19 */ 20 class BP_Groups_Screen_Request_Membership { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 // If the user is already invited, accept invitation. 28 if ( groups_check_user_has_invite( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 29 if ( groups_accept_invite( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 30 bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) ); 31 } else { 32 bp_core_add_message( __( 'There was an error accepting the group invitation. Please try again.', 'buddypress' ), 'error' ); 33 } 34 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); 35 } 36 37 // If the user has submitted a request, send it. 38 if ( isset( $_POST['group-request-send']) ) { 39 // Check the nonce. 40 if ( ! check_admin_referer( 'groups_request_membership' ) ) { 41 return; 42 } 43 44 if ( ! groups_send_membership_request( bp_loggedin_user_id(), bp_get_current_group_id() ) ) { 45 bp_core_add_message( __( 'There was an error sending your group membership request. Please try again.', 'buddypress' ), 'error' ); 46 } else { 47 bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) ); 48 } 49 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); 50 } 51 52 /** 53 * Fires before the loading of a group's Request Memebership page. 54 * 55 * @since 1.0.0 56 * 57 * @param int $id ID of the group currently being displayed. 58 */ 59 do_action( 'groups_screen_group_request_membership', bp_get_current_group_id() ); 60 61 /** 62 * Filters the template to load for a group's Request Membership page. 63 * 64 * @since 1.0.0 65 * 66 * @param string $value Path to a group's Request Membership template. 67 */ 68 bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) ); 69 } 70 } 71 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-send-invites.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the display of a group's Send Invites page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_invite() 19 */ 20 class BP_Groups_Screen_Send_Invites { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( bp_is_action_variable( 'send', 0 ) ) { 28 if ( ! check_admin_referer( 'groups_send_invites', '_wpnonce_send_invites' ) ) { 29 return; 30 } 31 32 if ( ! empty( $_POST['friends'] ) ) { 33 foreach( (array) $_POST['friends'] as $friend ) { 34 groups_invite_user( array( 'user_id' => $friend, 'group_id' => bp_get_current_group_id() ) ); 35 } 36 } 37 38 // Send the invites. 39 groups_send_invites( bp_loggedin_user_id(), bp_get_current_group_id() ); 40 bp_core_add_message( __('Group invites sent.', 'buddypress') ); 41 42 /** 43 * Fires after the sending of a group invite inside the group's Send Invites page. 44 * 45 * @since 1.0.0 46 * 47 * @param int $id ID of the group whose members are being displayed. 48 */ 49 do_action( 'groups_screen_group_invite', bp_get_current_group_id() ); 50 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) ); 51 52 } elseif ( ! bp_action_variable( 0 ) ) { 53 54 /** 55 * Filters the template to load for a group's Send Invites page. 56 * 57 * @since 1.0.0 58 * 59 * @param string $value Path to a group's Send Invites template. 60 */ 61 bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/home' ) ); 62 63 } else { 64 bp_do_404(); 65 } 66 } 67 } 68 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-user-invites.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Handle the loading of a user's Groups > Invites page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_group_invites() 19 */ 20 class BP_Groups_Screen_User_Invites { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 $group_id = (int) bp_action_variable( 1 ); 28 29 if ( bp_is_action_variable( 'accept' ) && is_numeric( $group_id ) ) { 30 // Check the nonce. 31 if ( ! check_admin_referer( 'groups_accept_invite' ) ) { 32 return; 33 } 34 35 if ( ! groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) { 36 bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' ); 37 } else { 38 // Record this in activity streams. 39 $group = groups_get_group( $group_id ); 40 41 bp_core_add_message( sprintf( __( 'Group invite accepted. Visit %s.', 'buddypress' ), bp_get_group_link( $group ) ) ); 42 43 groups_record_activity( array( 44 'type' => 'joined_group', 45 'item_id' => $group->id 46 ) ); 47 } 48 49 if ( isset( $_GET['redirect_to'] ) ) { 50 $redirect_to = urldecode( $_GET['redirect_to'] ); 51 } else { 52 $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 53 } 54 55 bp_core_redirect( $redirect_to ); 56 57 } elseif ( bp_is_action_variable( 'reject' ) && is_numeric( $group_id ) ) { 58 // Check the nonce. 59 if ( ! check_admin_referer( 'groups_reject_invite' ) ) { 60 return; 61 } 62 63 if ( ! groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) { 64 bp_core_add_message( __( 'Group invite could not be rejected', 'buddypress' ), 'error' ); 65 } else { 66 bp_core_add_message( __( 'Group invite rejected', 'buddypress' ) ); 67 } 68 69 if ( isset( $_GET['redirect_to'] ) ) { 70 $redirect_to = urldecode( $_GET['redirect_to'] ); 71 } else { 72 $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() ); 73 } 74 75 bp_core_redirect( $redirect_to ); 76 } 77 78 /** 79 * Fires before the loading of a users Groups > Invites template. 80 * 81 * @since 1.0.0 82 * 83 * @param int $group_id ID of the group being displayed 84 */ 85 do_action( 'groups_screen_group_invites', $group_id ); 86 87 /** 88 * Filters the template to load for a users Groups > Invites page. 89 * 90 * @since 1.0.0 91 * 92 * @param string $value Path to a users Groups > Invites page template. 93 */ 94 bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) ); 95 } 96 } 97 No newline at end of file -
new file src/bp-groups/classes/class-bp-groups-screen-user-settings-notifications.php
new file mode 100644
- + 1 <?php 2 /** 3 * BuddyPress Groups Classes. 4 * 5 * @package BuddyPress 6 * @subpackage GroupsClasses 7 * @since 3.0.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * Render the group settings fields on the Notification Settings page. 15 * 16 * @since 3.0.0 17 * 18 * @see groups_screen_notification_settings() 19 */ 20 class BP_Groups_Screen_User_Settings_Notifications { 21 /** 22 * Init method. 23 * 24 * @since 3.0.0 25 */ 26 public function init() { 27 if ( ! $group_invite = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_invite', true ) ) { 28 $group_invite = 'yes'; 29 } 30 31 if ( ! $group_update = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_group_updated', true ) ) { 32 $group_update = 'yes'; 33 } 34 35 if ( ! $group_promo = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_admin_promotion', true ) ) { 36 $group_promo = 'yes'; 37 } 38 39 if ( ! $group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) ) { 40 $group_request = 'yes'; 41 } 42 43 if ( ! $group_request_completed = bp_get_user_meta( bp_displayed_user_id(), 'notification_membership_request_completed', true ) ) { 44 $group_request_completed = 'yes'; 45 } 46 ?> 47 48 <table class="notification-settings" id="groups-notification-settings"> 49 <thead> 50 <tr> 51 <th class="icon"></th> 52 <th class="title"><?php _ex( 'Groups', 'Group settings on notification settings page', 'buddypress' ) ?></th> 53 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th> 54 <th class="no"><?php _e( 'No', 'buddypress' )?></th> 55 </tr> 56 </thead> 57 58 <tbody> 59 <tr id="groups-notification-settings-invitation"> 60 <td></td> 61 <td><?php _ex( 'A member invites you to join a group', 'group settings on notification settings page','buddypress' ) ?></td> 62 <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-yes" value="yes" <?php checked( $group_invite, 'yes', true ) ?>/><label for="notification-groups-invite-yes" class="bp-screen-reader-text"><?php 63 /* translators: accessibility text */ 64 _e( 'Yes, send email', 'buddypress' ); 65 ?></label></td> 66 <td class="no"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-no" value="no" <?php checked( $group_invite, 'no', true ) ?>/><label for="notification-groups-invite-no" class="bp-screen-reader-text"><?php 67 /* translators: accessibility text */ 68 _e( 'No, do not send email', 'buddypress' ); 69 ?></label></td> 70 </tr> 71 <tr id="groups-notification-settings-info-updated"> 72 <td></td> 73 <td><?php _ex( 'Group information is updated', 'group settings on notification settings page', 'buddypress' ) ?></td> 74 <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-yes" value="yes" <?php checked( $group_update, 'yes', true ) ?>/><label for="notification-groups-group-updated-yes" class="bp-screen-reader-text"><?php 75 /* translators: accessibility text */ 76 _e( 'Yes, send email', 'buddypress' ); 77 ?></label></td> 78 <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-no" value="no" <?php checked( $group_update, 'no', true ) ?>/><label for="notification-groups-group-updated-no" class="bp-screen-reader-text"><?php 79 /* translators: accessibility text */ 80 _e( 'No, do not send email', 'buddypress' ); 81 ?></label></td> 82 </tr> 83 <tr id="groups-notification-settings-promoted"> 84 <td></td> 85 <td><?php _ex( 'You are promoted to a group administrator or moderator', 'group settings on notification settings page', 'buddypress' ) ?></td> 86 <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-yes" value="yes" <?php checked( $group_promo, 'yes', true ) ?>/><label for="notification-groups-admin-promotion-yes" class="bp-screen-reader-text"><?php 87 /* translators: accessibility text */ 88 _e( 'Yes, send email', 'buddypress' ); 89 ?></label></td> 90 <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-no" value="no" <?php checked( $group_promo, 'no', true ) ?>/><label for="notification-groups-admin-promotion-no" class="bp-screen-reader-text"><?php 91 /* translators: accessibility text */ 92 _e( 'No, do not send email', 'buddypress' ); 93 ?></label></td> 94 </tr> 95 <tr id="groups-notification-settings-request"> 96 <td></td> 97 <td><?php _ex( 'A member requests to join a private group for which you are an admin', 'group settings on notification settings page', 'buddypress' ) ?></td> 98 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php 99 /* translators: accessibility text */ 100 _e( 'Yes, send email', 'buddypress' ); 101 ?></label></td> 102 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php 103 /* translators: accessibility text */ 104 _e( 'No, do not send email', 'buddypress' ); 105 ?></label></td> 106 </tr> 107 <tr id="groups-notification-settings-request-completed"> 108 <td></td> 109 <td><?php _ex( 'Your request to join a group has been approved or denied', 'group settings on notification settings page', 'buddypress' ) ?></td> 110 <td class="yes"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-yes" value="yes" <?php checked( $group_request_completed, 'yes', true ) ?>/><label for="notification-groups-membership-request-completed-yes" class="bp-screen-reader-text"><?php 111 /* translators: accessibility text */ 112 _e( 'Yes, send email', 'buddypress' ); 113 ?></label></td> 114 <td class="no"><input type="radio" name="notifications[notification_membership_request_completed]" id="notification-groups-membership-request-completed-no" value="no" <?php checked( $group_request_completed, 'no', true ) ?>/><label for="notification-groups-membership-request-completed-no" class="bp-screen-reader-text"><?php 115 /* translators: accessibility text */ 116 _e( 'No, do not send email', 'buddypress' ); 117 ?></label></td> 118 </tr> 119 120 <?php 121 122 /** 123 * Fires at the end of the available group settings fields on Notification Settings page. 124 * 125 * @since 1.0.0 126 */ 127 do_action( 'groups_screen_notification_settings' ); ?> 128 129 </tbody> 130 </table> 131 132 <?php 133 } 134 } 135 No newline at end of file