[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Groups Screen Functions 4 * 5 * Screen functions are the controllers of BuddyPress. They will execute when 6 * their specific URL is caught. They will first save or manipulate data using 7 * business functions, then pass on the user to a template file. 8 * 9 * @package BuddyPress 10 * @subpackage GroupsScreens 11 * @since 1.5.0 12 */ 13 14 // Exit if accessed directly. 15 defined( 'ABSPATH' ) || exit; 16 17 /** 18 * Handle the display of the Groups directory index. 19 * 20 * @since 1.0.0 21 */ 22 function groups_directory_groups_setup() { 23 if ( bp_is_groups_directory() ) { 24 bp_update_is_directory( true, 'groups' ); 25 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' ); 32 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 } 42 } 43 add_action( 'bp_screens', 'groups_directory_groups_setup', 2 ); 44 45 /** 46 * Handle the loading of the My Groups page. 47 * 48 * @since 1.0.0 49 */ 50 function groups_screen_my_groups() { 51 52 /** 53 * Fires before the loading of the My Groups page. 54 * 55 * @since 1.1.0 56 */ 57 do_action( 'groups_screen_my_groups' ); 58 59 /** 60 * Filters the template to load for the My Groups page. 61 * 62 * @since 1.0.0 63 * 64 * @param string $value Path to the My Groups page template to load. 65 */ 66 bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) ); 67 } 68 69 /** 70 * Handle the loading of a user's Groups > Invites page. 71 * 72 * @since 1.0.0 73 */ 74 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' ) ); 141 } 142 143 /** 144 * Handle the loading of a single group's page. 145 * 146 * @since 1.0.0 147 */ 148 function groups_screen_group_home() { 149 150 if ( ! bp_is_single_item() ) { 151 return false; 152 } 153 154 /** 155 * Fires before the loading of a single group's page. 156 * 157 * @since 1.0.0 158 */ 159 do_action( 'groups_screen_group_home' ); 160 161 /** 162 * Filters the template to load for a single group's page. 163 * 164 * @since 1.0.0 165 * 166 * @param string $value Path to a single group's template to load. 167 */ 168 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 169 } 170 171 /** 172 * Handle the display of a group's Members page. 173 * 174 * @since 1.0.0 175 */ 176 function groups_screen_group_members() { 177 178 if ( !bp_is_single_item() ) 179 return false; 180 181 $bp = buddypress(); 182 183 // 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 ) ); 185 186 /** 187 * Fires before the loading of a group's Members page. 188 * 189 * @since 1.0.0 190 * 191 * @param int $id ID of the group whose members are being displayed. 192 */ 193 do_action( 'groups_screen_group_members', $bp->groups->current_group->id ); 194 195 /** 196 * Filters the template to load for a group's Members page. 197 * 198 * @since 1.0.0 199 * 200 * @param string $value Path to a group's Members template. 201 */ 202 bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) ); 203 } 204 205 /** 206 * Handle the display of a group's Send Invites page. 207 * 208 * @since 1.0.0 209 */ 210 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(); 255 } 256 } 257 258 /** 259 * Process group invitation removal requests. 260 * 261 * Note that this function is only used when JS is disabled. Normally, clicking 262 * Remove Invite removes the invitation via AJAX. 263 * 264 * @since 2.0.0 265 */ 266 function groups_remove_group_invite() { 267 if ( ! bp_is_group_invites() ) { 268 return; 269 } 270 271 if ( ! bp_is_action_variable( 'remove', 0 ) || ! is_numeric( bp_action_variable( 1 ) ) ) { 272 return; 273 } 274 275 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'; 294 } 295 296 bp_core_add_message( $message, $error ); 297 bp_core_redirect( $redirect ); 298 } 299 add_action( 'bp_screens', 'groups_remove_group_invite' ); 300 301 /** 302 * Handle the display of a group's Request Membership page. 303 * 304 * @since 1.0.0 305 */ 306 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 ) ); 323 } 324 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 ) ); 338 } 339 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' ) ); 357 } 358 359 /** 360 * Handle the loading of a single group's activity. 361 * 362 * @since 2.4.0 363 */ 364 function groups_screen_group_activity() { 365 366 if ( ! bp_is_single_item() ) { 367 return false; 368 } 369 370 /** 371 * Fires before the loading of a single group's activity page. 372 * 373 * @since 2.4.0 374 */ 375 do_action( 'groups_screen_group_activity' ); 376 377 /** 378 * Filters the template to load for a single group's activity page. 379 * 380 * @since 2.4.0 381 * 382 * @param string $value Path to a single group's template to load. 383 */ 384 bp_core_load_template( apply_filters( 'groups_screen_group_activity', 'groups/single/activity' ) ); 385 } 386 387 /** 388 * Handle the display of a single group activity item. 389 * 390 * @since 1.2.0 391 */ 392 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; 396 397 buddypress()->is_single_item = true; 398 399 /** This filter is documented in bp-groups/bp-groups-screens.php */ 400 bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) ); 401 } 402 add_action( 'bp_screens', 'groups_screen_group_activity_permalink' ); 403 404 /** 405 * Handle the display of a group's Admin pages. 406 * 407 * @since 1.0.0 408 */ 409 function groups_screen_group_admin() { 410 if ( !bp_is_groups_component() || !bp_is_current_action( 'admin' ) ) 411 return false; 412 413 if ( bp_action_variables() ) 414 return false; 415 416 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' ); 417 } 418 419 /** 420 * Handle the display of a group's admin/edit-details page. 421 * 422 * @since 1.0.0 423 */ 424 function groups_screen_group_admin_edit_details() { 425 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' ) ); 485 } 486 } 487 add_action( 'bp_screens', 'groups_screen_group_admin_edit_details' ); 488 489 /** 490 * Handle the display of a group's admin/group-settings page. 491 * 492 * @since 1.0.0 493 */ 494 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/' ); 564 } 565 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 ); 574 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' ) ); 583 } 584 add_action( 'bp_screens', 'groups_screen_group_admin_settings' ); 585 586 /** 587 * Handle the display of a group's Change Avatar page. 588 * 589 * @since 1.0.0 590 */ 591 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 634 } 635 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 } 668 } 669 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' ) ); 687 } 688 add_action( 'bp_screens', 'groups_screen_group_admin_avatar' ); 689 690 /** 691 * Handle the display of a group's Change cover image page. 692 * 693 * @since 2.4.0 694 */ 695 function groups_screen_group_admin_cover_image() { 696 if ( 'group-cover-image' != bp_get_group_current_admin_tab() ) { 697 return false; 698 } 699 700 // If the logged-in user doesn't have permission or if cover image uploads are disabled, then stop here. 701 if ( ! bp_is_item_admin() || ! bp_group_use_cover_image_header() ) { 702 return false; 703 } 704 705 /** 706 * Fires before the loading of the group Change cover image page template. 707 * 708 * @since 2.4.0 709 * 710 * @param int $id ID of the group that is being displayed. 711 */ 712 do_action( 'groups_screen_group_admin_cover_image', bp_get_current_group_id() ); 713 714 /** 715 * Filters the template to load for a group's Change cover image page. 716 * 717 * @since 2.4.0 718 * 719 * @param string $value Path to a group's Change cover image template. 720 */ 721 bp_core_load_template( apply_filters( 'groups_template_group_admin_cover_image', 'groups/single/home' ) ); 722 } 723 add_action( 'bp_screens', 'groups_screen_group_admin_cover_image' ); 724 725 /** 726 * This function handles actions related to member management on the group admin. 727 * 728 * @since 1.0.0 729 */ 730 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 } 767 } 768 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 } 878 } 879 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' ) ); 897 } 898 add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' ); 899 900 /** 901 * Handle the display of Admin > Membership Requests. 902 * 903 * @since 1.0.0 904 */ 905 function groups_screen_group_admin_requests() { 906 $bp = buddypress(); 907 908 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; 914 } 915 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/' ); 955 } 956 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' ) ); 974 } 975 add_action( 'bp_screens', 'groups_screen_group_admin_requests' ); 976 977 /** 978 * Handle the display of the Delete Group page. 979 * 980 * @since 1.0.0 981 */ 982 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() ) ); 1027 } 1028 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 ); 1037 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' ) ); 1046 } 1047 add_action( 'bp_screens', 'groups_screen_group_admin_delete_group' ); 1048 1049 /** 1050 * Render the group settings fields on the Notification Settings page. 1051 * 1052 * @since 1.0.0 1053 */ 1054 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 1158 } 1159 add_action( 'bp_notification_settings', 'groups_screen_notification_settings' ); 1160 1161 /** Theme Compatibility *******************************************************/ 1162 1163 new BP_Groups_Theme_Compat();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Apr 1 01:00:58 2018 | Cross-referenced by PHPXref 0.7.1 |