[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Groups functions 4 * 5 * @since 3.0.0 6 * @version 7.2.1 7 */ 8 9 // Exit if accessed directly. 10 defined( 'ABSPATH' ) || exit; 11 12 /** 13 * Provide a convenience function to add markup wrapper for message strings 14 * 15 * @param string $message The message text string 16 * @param string $type The message type - 'error, 'info', 'warning', success' 17 * 18 * @return string 19 * 20 * @since 3.0 21 */ 22 function bp_nouveau_message_markup_wrapper( $message, $type ) { 23 if ( ! $message ) { 24 return false; 25 } 26 27 $message = '<div class=" ' . esc_attr( "bp-feedback {$type}" ) . '"><span class="bp-icon" aria-hidden="true"></span><p>' . esc_html( $message ) . '</p></div>'; 28 29 return $message; 30 } 31 32 /** 33 * Register Scripts for the Groups component 34 * 35 * @since 3.0.0 36 * 37 * @param array $scripts Optional. The array of scripts to register. 38 * 39 * @return array The same array with the specific groups scripts. 40 */ 41 function bp_nouveau_groups_register_scripts( $scripts = array() ) { 42 if ( ! isset( $scripts['bp-nouveau'] ) ) { 43 return $scripts; 44 } 45 46 return array_merge( $scripts, array( 47 'bp-nouveau-group-invites' => array( 48 'file' => 'js/buddypress-group-invites%s.js', 49 'dependencies' => array( 'bp-nouveau', 'json2', 'wp-backbone' ), 50 'footer' => true, 51 ), 52 ) ); 53 } 54 55 /** 56 * Enqueue the groups scripts 57 * 58 * @since 3.0.0 59 */ 60 function bp_nouveau_groups_enqueue_scripts() { 61 // Neutralize Ajax when using BuddyPress Groups & member widgets on default front page 62 if ( bp_is_group_home() && bp_nouveau_get_appearance_settings( 'group_front_page' ) ) { 63 wp_add_inline_style( 'bp-nouveau', ' 64 #group-front-widgets #groups-list-options, 65 #group-front-widgets #members-list-options { 66 display: none; 67 } 68 ' ); 69 } 70 71 if ( bp_is_group_invites() || ( bp_is_group_create() && bp_is_group_creation_step( 'group-invites' ) ) ) { 72 wp_enqueue_script( 'bp-nouveau-group-invites' ); 73 } 74 75 if ( bp_rest_api_is_available() && bp_is_group_admin_page() && bp_is_group_admin_screen( 'manage-members' ) ) { 76 wp_enqueue_script( 'bp-group-manage-members' ); 77 wp_localize_script( 78 'bp-group-manage-members', 79 'bpGroupManageMembersSettings', 80 bp_groups_get_group_manage_members_script_data( bp_get_current_group_id() ) 81 ); 82 } 83 } 84 85 /** 86 * Can all members be invited to join any group? 87 * 88 * @since 3.0.0 89 * 90 * @param bool $default False to allow. True to disallow. 91 * 92 * @return bool 93 */ 94 function bp_nouveau_groups_disallow_all_members_invites( $default = false ) { 95 /** 96 * Filter to remove the All members nav, returning true 97 * 98 * @since 3.0.0 99 * 100 * @param bool $default True to disable the nav. False otherwise. 101 */ 102 return apply_filters( 'bp_nouveau_groups_disallow_all_members_invites', $default ); 103 } 104 105 /** 106 * Localize the strings needed for the Group's Invite UI 107 * 108 * @since 3.0.0 109 * 110 * @param array $params Associative array containing the JS Strings needed by scripts 111 * 112 * @return array The same array with specific strings for the Group's Invite UI if needed. 113 */ 114 function bp_nouveau_groups_localize_scripts( $params = array() ) { 115 if ( ! bp_is_group_invites() && ! ( bp_is_group_create() && bp_is_group_creation_step( 'group-invites' ) ) ) { 116 return $params; 117 } 118 119 $show_pending = bp_group_has_invites( array( 'user_id' => 'any' ) ) && ! bp_is_group_create(); 120 121 // Init the Group invites nav 122 $invites_nav = array( 123 'members' => array( 124 'id' => 'members', 125 'caption' => __( 'All Members', 'buddypress' ), 126 'order' => 5, 127 ), 128 'invited' => array( 129 'id' => 'invited', 130 'caption' => __( 'Pending Invites', 'buddypress' ), 131 'order' => 90, 132 'hide' => (int) ! $show_pending, 133 ), 134 'invites' => array( 135 'id' => 'invites', 136 'caption' => __( 'Send Invites', 'buddypress' ), 137 'order' => 100, 138 'hide' => 1, 139 'href' => '#send-invites-editor', 140 ), 141 ); 142 143 if ( bp_is_active( 'friends' ) ) { 144 $invites_nav['friends'] = array( 145 'id' => 'friends', 146 'caption' => __( 'My Friends', 'buddypress' ), 147 'order' => 0, 148 ); 149 150 if ( true === bp_nouveau_groups_disallow_all_members_invites() ) { 151 unset( $invites_nav['members'] ); 152 } 153 } 154 155 $params['group_invites'] = array( 156 'nav' => bp_sort_by_key( $invites_nav, 'order', 'num' ), 157 'loading' => __( 'Loading members. Please wait.', 'buddypress' ), 158 'invites_form' => __( 'Use the "Send" button to send your invite or the "Cancel" button to abort.', 'buddypress' ), 159 'invites_form_reset' => __( 'Group invitations cleared. Please use one of the available tabs to select members to invite.', 'buddypress' ), 160 'invites_sending' => __( 'Sending group invitations. Please wait.', 'buddypress' ), 161 162 /* translators: %s: member name */ 163 'removeUserInvite' => __( 'Cancel invitation %s', 'buddypress' ), 164 'group_id' => ! bp_get_current_group_id() ? bp_get_new_group_id() : bp_get_current_group_id(), 165 'is_group_create' => bp_is_group_create(), 166 'nonces' => array( 167 'uninvite' => wp_create_nonce( 'groups_invite_uninvite_user' ), 168 'send_invites' => wp_create_nonce( 'groups_send_invites' ) 169 ), 170 ); 171 172 return $params; 173 } 174 175 /** 176 * @since 3.0.0 177 */ 178 function bp_nouveau_groups_get_inviter_ids( $user_id, $group_id ) { 179 if ( empty( $user_id ) || empty( $group_id ) ) { 180 return false; 181 } 182 183 return BP_Nouveau_Group_Invite_Query::get_inviter_ids( $user_id, $group_id ); 184 } 185 186 /** 187 * @since 3.0.0 188 */ 189 function bp_nouveau_prepare_group_potential_invites_for_js( $user ) { 190 $bp = buddypress(); 191 192 $response = array( 193 'id' => intval( $user->ID ), 194 'name' => $user->display_name, 195 'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array( 196 'item_id' => $user->ID, 197 'object' => 'user', 198 'type' => 'thumb', 199 'width' => 50, 200 'height' => 50, 201 'html' => false ) 202 ) ), 203 ); 204 205 // Do extra queries only if needed 206 if ( ! empty( $bp->groups->invites_scope ) && 'invited' === $bp->groups->invites_scope ) { 207 $response['is_sent'] = (bool) groups_check_user_has_invite( $user->ID, bp_get_current_group_id() ); 208 209 $inviter_ids = bp_nouveau_groups_get_inviter_ids( $user->ID, bp_get_current_group_id() ); 210 211 foreach ( $inviter_ids as $inviter_id ) { 212 $class = false; 213 214 if ( bp_loggedin_user_id() === (int) $inviter_id ) { 215 $class = 'group-self-inviter'; 216 } 217 218 $response['invited_by'][] = array( 219 'avatar' => htmlspecialchars_decode( bp_core_fetch_avatar( array( 220 'item_id' => $inviter_id, 221 'object' => 'user', 222 'type' => 'thumb', 223 'width' => 50, 224 'height' => 50, 225 'html' => false, 226 'class' => $class, 227 ) ) ), 228 'user_link' => bp_core_get_userlink( $inviter_id, false, true ), 229 'user_name' => bp_core_get_username( $inviter_id ), 230 ); 231 } 232 233 if ( bp_is_item_admin() ) { 234 $response['can_edit'] = true; 235 } else { 236 $response['can_edit'] = in_array( bp_loggedin_user_id(), $inviter_ids, true ); 237 } 238 } 239 240 /** 241 * Filters the response value for potential group invite data for use with javascript. 242 * 243 * @since 3.0.0 244 * 245 * @param array $response Array of invite data. 246 * @param WP_User $user User object. 247 */ 248 return apply_filters( 'bp_nouveau_prepare_group_potential_invites_for_js', $response, $user ); 249 } 250 251 /** 252 * @since 3.0.0 253 */ 254 function bp_nouveau_get_group_potential_invites( $args = array() ) { 255 $r = bp_parse_args( $args, array( 256 'group_id' => bp_get_current_group_id(), 257 'type' => 'alphabetical', 258 'per_page' => 20, 259 'page' => 1, 260 'search_terms' => false, 261 'member_type' => false, 262 'user_id' => 0, 263 'is_confirmed' => true, 264 ) ); 265 266 if ( empty( $r['group_id'] ) ) { 267 return false; 268 } 269 270 // Check the current user's access to the group. 271 if ( ! bp_groups_user_can_send_invites( $r['group_id'] ) ) { 272 return false; 273 } 274 275 /* 276 * If it's not a friend request and users can restrict invites to friends, 277 * make sure they are not displayed in results. 278 */ 279 if ( ! $r['user_id'] && bp_is_active( 'friends' ) && bp_is_active( 'settings' ) && ! bp_nouveau_groups_disallow_all_members_invites() ) { 280 $r['meta_query'] = array( 281 array( 282 'key' => '_bp_nouveau_restrict_invites_to_friends', 283 'compare' => 'NOT EXISTS', 284 ), 285 ); 286 } 287 288 $query = new BP_Nouveau_Group_Invite_Query( $r ); 289 290 $response = new stdClass(); 291 292 $response->meta = array( 'total_page' => 0, 'current_page' => 0 ); 293 $response->users = array(); 294 295 if ( ! empty( $query->results ) ) { 296 $response->users = $query->results; 297 298 if ( ! empty( $r['per_page'] ) ) { 299 $response->meta = array( 300 'total_page' => ceil( (int) $query->total_users / (int) $r['per_page'] ), 301 'page' => (int) $r['page'], 302 ); 303 } 304 } 305 306 return $response; 307 } 308 309 /** 310 * @since 3.0.0 311 */ 312 function bp_nouveau_group_invites_create_steps( $steps = array() ) { 313 if ( bp_is_active( 'friends' ) && isset( $steps['group-invites'] ) ) { 314 // Simply change the name 315 $steps['group-invites']['name'] = _x( 'Invite', 'Group invitations menu title', 'buddypress' ); 316 return $steps; 317 } 318 319 // Add the create step if friends component is not active 320 $steps['group-invites'] = array( 321 'name' => _x( 'Invite', 'Group invitations menu title', 'buddypress' ), 322 'position' => 30, 323 ); 324 325 return $steps; 326 } 327 328 /** 329 * @since 3.0.0 330 */ 331 function bp_nouveau_group_setup_nav() { 332 if ( ! bp_is_group() || ! bp_groups_user_can_send_invites() ) { 333 return; 334 } 335 336 // Simply change the name 337 if ( bp_is_active( 'friends' ) ) { 338 $bp = buddypress(); 339 340 $bp->groups->nav->edit_nav( 341 array( 'name' => _x( 'Invite', 'Group invitations menu title', 'buddypress' ) ), 342 'send-invites', 343 bp_get_current_group_slug() 344 ); 345 346 // Create the Subnav item for the group 347 } else { 348 $current_group = groups_get_current_group(); 349 $group_link = bp_get_group_permalink( $current_group ); 350 351 bp_core_new_subnav_item( array( 352 'name' => _x( 'Invite', 'Group invitations menu title', 'buddypress' ), 353 'slug' => 'send-invites', 354 'parent_url' => $group_link, 355 'parent_slug' => $current_group->slug, 356 'screen_function' => 'groups_screen_group_invite', 357 'item_css_id' => 'invite', 358 'position' => 70, 359 'user_has_access' => $current_group->user_has_access, 360 'no_access_url' => $group_link, 361 ) ); 362 } 363 } 364 365 /** 366 * Includes a message into the sent invitation email. 367 * 368 * @since 3.0.0 369 * @deprecated 6.3.0 370 * 371 * @param string $message The message to send with the invite 372 */ 373 function bp_nouveau_groups_invites_custom_message( $message = '' ) { 374 _deprecated_function( __FUNCTION__, '6.3.0' ); 375 376 if ( empty( $message ) ) { 377 return $message; 378 } 379 380 $bp = buddypress(); 381 382 if ( empty( $bp->groups->invites_message ) ) { 383 return $message; 384 } 385 386 $message = str_replace( '---------------------', " 387 ---------------------\n 388 " . $bp->groups->invites_message . "\n 389 --------------------- 390 ", $message ); 391 392 return $message; 393 } 394 395 /** 396 * Format a Group for a json reply 397 * 398 * @since 3.0.0 399 */ 400 function bp_nouveau_prepare_group_for_js( $item ) { 401 if ( empty( $item->id ) ) { 402 return array(); 403 } 404 405 $item_avatar_url = bp_core_fetch_avatar( array( 406 'item_id' => $item->id, 407 'object' => 'group', 408 'type' => 'thumb', 409 'html' => false 410 ) ); 411 412 return array( 413 'id' => $item->id, 414 'name' => $item->name, 415 'avatar_url' => $item_avatar_url, 416 'object_type' => 'group', 417 'is_public' => ( 'public' === $item->status ), 418 ); 419 } 420 421 /** 422 * Group invites restriction settings navigation. 423 * 424 * @since 3.0.0 425 */ 426 function bp_nouveau_groups_invites_restriction_nav() { 427 $slug = bp_get_settings_slug(); 428 $user_domain = bp_loggedin_user_domain(); 429 430 if ( bp_displayed_user_domain() ) { 431 $user_domain = bp_displayed_user_domain(); 432 } 433 434 bp_core_new_subnav_item( array( 435 'name' => _x( 'Group Invites', 'Group invitations main menu title', 'buddypress' ), 436 'slug' => 'invites', 437 'parent_url' => trailingslashit( $user_domain . $slug ), 438 'parent_slug' => $slug, 439 'screen_function' => 'bp_nouveau_groups_screen_invites_restriction', 440 'item_css_id' => 'invites', 441 'position' => 70, 442 'user_has_access' => bp_core_can_edit_settings(), 443 ), 'members' ); 444 } 445 446 /** 447 * Group invites restriction settings Admin Bar navigation. 448 * 449 * @since 3.0.0 450 * 451 * @param array $wp_admin_nav The list of settings admin subnav items. 452 * 453 * @return array The list of settings admin subnav items. 454 */ 455 function bp_nouveau_groups_invites_restriction_admin_nav( $wp_admin_nav ) { 456 // Setup the logged in user variables. 457 $settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() ); 458 459 // Add the "Group Invites" subnav item. 460 $wp_admin_nav[] = array( 461 'parent' => 'my-account-' . buddypress()->settings->id, 462 'id' => 'my-account-' . buddypress()->settings->id . '-invites', 463 'title' => _x( 'Group Invites', 'Group invitations main menu title', 'buddypress' ), 464 'href' => trailingslashit( $settings_link . 'invites/' ), 465 ); 466 467 return $wp_admin_nav; 468 } 469 470 /** 471 * Group invites restriction screen. 472 * 473 * @since 3.0.0 474 */ 475 function bp_nouveau_groups_screen_invites_restriction() { 476 // Redirect if no invites restriction settings page is accessible. 477 if ( 'invites' !== bp_current_action() || ! bp_is_active( 'friends' ) ) { 478 bp_do_404(); 479 return; 480 } 481 482 if ( isset( $_POST['member-group-invites-submit'] ) ) { 483 // Nonce check. 484 check_admin_referer( 'bp_nouveau_group_invites_settings' ); 485 486 if ( bp_is_my_profile() || bp_current_user_can( 'bp_moderate' ) ) { 487 if ( empty( $_POST['account-group-invites-preferences'] ) ) { 488 bp_delete_user_meta( bp_displayed_user_id(), '_bp_nouveau_restrict_invites_to_friends' ); 489 } else { 490 bp_update_user_meta( bp_displayed_user_id(), '_bp_nouveau_restrict_invites_to_friends', (int) $_POST['account-group-invites-preferences'] ); 491 } 492 493 bp_core_add_message( __( 'Group invites preferences saved.', 'buddypress' ) ); 494 } else { 495 bp_core_add_message( __( 'You are not allowed to perform this action.', 'buddypress' ), 'error' ); 496 } 497 498 bp_core_redirect( trailingslashit( bp_displayed_user_domain() . bp_get_settings_slug() ) . 'invites/' ); 499 } 500 501 /** 502 * Filters the template to load for the Group Invites settings screen. 503 * 504 * @since 3.0.0 505 * 506 * @param string $template Path to the Group Invites settings screen template to load. 507 */ 508 bp_core_load_template( apply_filters( 'bp_nouveau_groups_screen_invites_restriction', 'members/single/settings/group-invites' ) ); 509 } 510 511 /** 512 * Makes sure the BP REST API groups/invites endpoint respects invite restrictions. 513 * 514 * @since 7.2.1 515 * 516 * @param bool|WP_Error $retval Whether the request can continue. 517 * @param WP_REST_Request $request The request sent to the API. 518 * @return bool|WP_Error 519 */ 520 function bp_nouveau_restrict_rest_group_invite_to_friends( $retval, $request ) { 521 if ( true === $retval && bp_is_active( 'friends' ) ) { 522 $group_id = $request->get_param( 'group_id' ); 523 $user_id = $request->get_param( 'user_id' ); 524 $inviter_id = $request->get_param( 'inviter_id' ); 525 526 if ( ! $inviter_id ) { 527 $inviter_id = bp_loggedin_user_id(); 528 } 529 530 if ( bp_nouveau_groups_get_group_invites_setting( $user_id ) && 'is_friend' !== BP_Friends_Friendship::check_is_friend( $inviter_id, $user_id ) ) { 531 $retval = new WP_Error( 532 'bp_rest_group_invite_cannot_create_item', 533 __( 'Sorry, you are not allowed to create the invitation as requested.', 'buddypress' ), 534 array( 535 'status' => rest_authorization_required_code(), 536 ) 537 ); 538 } 539 } 540 541 return $retval; 542 } 543 add_filter( 'bp_rest_group_invites_create_item_permissions_check', 'bp_nouveau_restrict_rest_group_invite_to_friends', 10, 2 ); 544 545 /** 546 * @since 3.0.0 547 */ 548 function bp_nouveau_get_groups_directory_nav_items() { 549 $nav_items = array(); 550 551 $nav_items['all'] = array( 552 'component' => 'groups', 553 'slug' => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope 554 'li_class' => array( 'selected' ), 555 'link' => bp_get_groups_directory_permalink(), 556 'text' => __( 'All Groups', 'buddypress' ), 557 'count' => bp_get_total_group_count(), 558 'position' => 5, 559 ); 560 561 if ( is_user_logged_in() ) { 562 563 $my_groups_count = bp_get_total_group_count_for_user( bp_loggedin_user_id() ); 564 565 // If the user has groups create a nav item 566 if ( $my_groups_count ) { 567 $nav_items['personal'] = array( 568 'component' => 'groups', 569 'slug' => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope 570 'li_class' => array(), 571 'link' => bp_loggedin_user_domain() . bp_get_groups_slug() . '/my-groups/', 572 'text' => __( 'My Groups', 'buddypress' ), 573 'count' => $my_groups_count, 574 'position' => 15, 575 ); 576 } 577 578 // If the user can create groups, add the create nav 579 if ( bp_user_can_create_groups() ) { 580 $nav_items['create'] = array( 581 'component' => 'groups', 582 'slug' => 'create', // slug is used because BP_Core_Nav requires it, but it's the scope 583 'li_class' => array( 'no-ajax', 'group-create', 'create-button' ), 584 'link' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ), 585 'text' => __( 'Create a Group', 'buddypress' ), 586 'count' => false, 587 'position' => 999, 588 ); 589 } 590 } 591 592 // Check for the deprecated hook : 593 $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_groups_directory_group_filter', 'groups', 20 ); 594 595 if ( ! empty( $extra_nav_items ) ) { 596 $nav_items = array_merge( $nav_items, $extra_nav_items ); 597 } 598 599 /** 600 * Use this filter to introduce your custom nav items for the groups directory. 601 * 602 * @since 3.0.0 603 * 604 * @param array $nav_items The list of the groups directory nav items. 605 */ 606 return apply_filters( 'bp_nouveau_get_groups_directory_nav_items', $nav_items ); 607 } 608 609 /** 610 * Get Dropdown filters for the groups component 611 * 612 * @since 3.0.0 613 * 614 * @param string $context 'directory' or 'user' 615 * 616 * @return array the filters 617 */ 618 function bp_nouveau_get_groups_filters( $context = '' ) { 619 if ( empty( $context ) ) { 620 return array(); 621 } 622 623 $action = ''; 624 if ( 'user' === $context ) { 625 $action = 'bp_member_group_order_options'; 626 } elseif ( 'directory' === $context ) { 627 $action = 'bp_groups_directory_order_options'; 628 } 629 630 /** 631 * Recommended, filter here instead of adding an action to 'bp_member_group_order_options' 632 * or 'bp_groups_directory_order_options' 633 * 634 * @since 3.0.0 635 * 636 * @param array the members filters. 637 * @param string the context. 638 */ 639 $filters = apply_filters( 'bp_nouveau_get_groups_filters', array( 640 'active' => __( 'Last Active', 'buddypress' ), 641 'popular' => __( 'Most Members', 'buddypress' ), 642 'newest' => __( 'Newly Created', 'buddypress' ), 643 'alphabetical' => __( 'Alphabetical', 'buddypress' ), 644 ), $context ); 645 646 if ( $action ) { 647 return bp_nouveau_parse_hooked_options( $action, $filters ); 648 } 649 650 return $filters; 651 } 652 653 /** 654 * Catch the arguments for buttons 655 * 656 * @since 3.0.0 657 * 658 * @param array $button The arguments of the button that BuddyPress is about to create. 659 * 660 * @return array An empty array to stop the button creation process. 661 */ 662 function bp_nouveau_groups_catch_button_args( $button = array() ) { 663 /** 664 * Globalize the arguments so that we can use it 665 * in bp_nouveau_get_groups_buttons(). 666 */ 667 bp_nouveau()->groups->button_args = $button; 668 669 // return an empty array to stop the button creation process 670 return array(); 671 } 672 673 /** 674 * Catch the content hooked to the 'bp_group_header_meta' action 675 * 676 * @since 3.0.0 677 * 678 * @return string|bool HTML Output if hooked. False otherwise. 679 */ 680 function bp_nouveau_get_hooked_group_meta() { 681 ob_start(); 682 683 /** 684 * Fires after inside the group header item meta section. 685 * 686 * @since 1.2.0 687 */ 688 do_action( 'bp_group_header_meta' ); 689 690 $output = ob_get_clean(); 691 692 if ( ! empty( $output ) ) { 693 return $output; 694 } 695 696 return false; 697 } 698 699 /** 700 * Display the Widgets of Group extensions into the default front page? 701 * 702 * @since 3.0.0 703 * 704 * @return bool True to display. False otherwise. 705 */ 706 function bp_nouveau_groups_do_group_boxes() { 707 $group_settings = bp_nouveau_get_appearance_settings(); 708 709 return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_boxes'] ); 710 } 711 712 /** 713 * Display description of the Group into the default front page? 714 * 715 * @since 3.0.0 716 * 717 * @return bool True to display. False otherwise. 718 */ 719 function bp_nouveau_groups_front_page_description() { 720 $group_settings = bp_nouveau_get_appearance_settings(); 721 722 // This check is a problem it needs to be used in templates but returns true even if not on the front page 723 // return false on this if we are not displaying the front page 'bp_is_group_home()' 724 // This may well be a bad approach to re-think ~hnla. 725 // @todo 726 return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_description'] ) && bp_is_group_home(); 727 } 728 729 /** 730 * Add sections to the customizer for the groups component. 731 * 732 * @since 3.0.0 733 * 734 * @param array $sections the Customizer sections to add. 735 * 736 * @return array the Customizer sections to add. 737 */ 738 function bp_nouveau_groups_customizer_sections( $sections = array() ) { 739 return array_merge( $sections, array( 740 'bp_nouveau_group_front_page' => array( 741 'title' => __( 'Group front page', 'buddypress' ), 742 'panel' => 'bp_nouveau_panel', 743 'priority' => 20, 744 'description' => __( 'Configure the default front page for groups.', 'buddypress' ), 745 ), 746 'bp_nouveau_group_primary_nav' => array( 747 'title' => __( 'Group navigation', 'buddypress' ), 748 'panel' => 'bp_nouveau_panel', 749 'priority' => 40, 750 'description' => __( 'Customize the navigation menu for groups. See your changes by navigating to a group in the live-preview window.', 'buddypress' ), 751 ), 752 ) ); 753 } 754 755 /** 756 * Add settings to the customizer for the groups component. 757 * 758 * @since 3.0.0 759 * 760 * @param array $settings Optional. The settings to add. 761 * 762 * @return array the settings to add. 763 */ 764 function bp_nouveau_groups_customizer_settings( $settings = array() ) { 765 return array_merge( $settings, array( 766 'bp_nouveau_appearance[group_front_page]' => array( 767 'index' => 'group_front_page', 768 'capability' => 'bp_moderate', 769 'sanitize_callback' => 'absint', 770 'transport' => 'refresh', 771 'type' => 'option', 772 ), 773 'bp_nouveau_appearance[group_front_boxes]' => array( 774 'index' => 'group_front_boxes', 775 'capability' => 'bp_moderate', 776 'sanitize_callback' => 'absint', 777 'transport' => 'refresh', 778 'type' => 'option', 779 ), 780 'bp_nouveau_appearance[group_front_description]' => array( 781 'index' => 'group_front_description', 782 'capability' => 'bp_moderate', 783 'sanitize_callback' => 'absint', 784 'transport' => 'refresh', 785 'type' => 'option', 786 ), 787 'bp_nouveau_appearance[group_nav_display]' => array( 788 'index' => 'group_nav_display', 789 'capability' => 'bp_moderate', 790 'sanitize_callback' => 'absint', 791 'transport' => 'refresh', 792 'type' => 'option', 793 ), 794 'bp_nouveau_appearance[group_nav_tabs]' => array( 795 'index' => 'group_nav_tabs', 796 'capability' => 'bp_moderate', 797 'sanitize_callback' => 'absint', 798 'transport' => 'refresh', 799 'type' => 'option', 800 ), 801 'bp_nouveau_appearance[group_subnav_tabs]' => array( 802 'index' => 'group_subnav_tabs', 803 'capability' => 'bp_moderate', 804 'sanitize_callback' => 'absint', 805 'transport' => 'refresh', 806 'type' => 'option', 807 ), 808 'bp_nouveau_appearance[groups_create_tabs]' => array( 809 'index' => 'groups_create_tabs', 810 'capability' => 'bp_moderate', 811 'sanitize_callback' => 'absint', 812 'transport' => 'refresh', 813 'type' => 'option', 814 ), 815 'bp_nouveau_appearance[group_nav_order]' => array( 816 'index' => 'group_nav_order', 817 'capability' => 'bp_moderate', 818 'sanitize_callback' => 'bp_nouveau_sanitize_nav_order', 819 'transport' => 'refresh', 820 'type' => 'option', 821 ), 822 'bp_nouveau_appearance[groups_layout]' => array( 823 'index' => 'groups_layout', 824 'capability' => 'bp_moderate', 825 'sanitize_callback' => 'absint', 826 'transport' => 'refresh', 827 'type' => 'option', 828 ), 829 'bp_nouveau_appearance[groups_dir_tabs]' => array( 830 'index' => 'groups_dir_tabs', 831 'capability' => 'bp_moderate', 832 'sanitize_callback' => 'absint', 833 'transport' => 'refresh', 834 'type' => 'option', 835 ), 836 ) ); 837 } 838 839 /** 840 * Add controls for the settings of the customizer for the groups component. 841 * 842 * @since 3.0.0 843 * 844 * @param array $controls Optional. The controls to add. 845 * 846 * @return array the controls to add. 847 */ 848 function bp_nouveau_groups_customizer_controls( $controls = array() ) { 849 return array_merge( $controls, array( 850 'group_front_page' => array( 851 'label' => __( 'Enable custom front pages for groups.', 'buddypress' ), 852 'section' => 'bp_nouveau_group_front_page', 853 'settings' => 'bp_nouveau_appearance[group_front_page]', 854 'type' => 'checkbox', 855 ), 856 'group_front_boxes' => array( 857 'label' => __( 'Enable widget region for group homepages. When enabled, the site admin can add widgets to group pages via the Widgets panel.', 'buddypress' ), 858 'section' => 'bp_nouveau_group_front_page', 859 'settings' => 'bp_nouveau_appearance[group_front_boxes]', 860 'type' => 'checkbox', 861 ), 862 'group_front_description' => array( 863 'label' => __( "Display the group description in the body of the group's front page.", 'buddypress' ), 864 'section' => 'bp_nouveau_group_front_page', 865 'settings' => 'bp_nouveau_appearance[group_front_description]', 866 'type' => 'checkbox', 867 ), 868 'group_nav_display' => array( 869 'label' => __( 'Display the group navigation vertically.', 'buddypress' ), 870 'section' => 'bp_nouveau_group_primary_nav', 871 'settings' => 'bp_nouveau_appearance[group_nav_display]', 872 'type' => 'checkbox', 873 ), 874 'group_nav_tabs' => array( 875 'label' => __( 'Use tab styling for primary navigation.', 'buddypress' ), 876 'section' => 'bp_nouveau_group_primary_nav', 877 'settings' => 'bp_nouveau_appearance[group_nav_tabs]', 878 'type' => 'checkbox', 879 ), 880 'group_subnav_tabs' => array( 881 'label' => __( 'Use tab styling for secondary navigation.', 'buddypress' ), 882 'section' => 'bp_nouveau_group_primary_nav', 883 'settings' => 'bp_nouveau_appearance[group_subnav_tabs]', 884 'type' => 'checkbox', 885 ), 886 'groups_create_tabs' => array( 887 'label' => __( 'Use tab styling for the group creation process.', 'buddypress' ), 888 'section' => 'bp_nouveau_group_primary_nav', 889 'settings' => 'bp_nouveau_appearance[groups_create_tabs]', 890 'type' => 'checkbox', 891 ), 892 'group_nav_order' => array( 893 'class' => 'BP_Nouveau_Nav_Customize_Control', 894 'label' => __( 'Reorder the primary navigation for a group.', 'buddypress' ), 895 'section' => 'bp_nouveau_group_primary_nav', 896 'settings' => 'bp_nouveau_appearance[group_nav_order]', 897 'type' => 'group', 898 ), 899 'groups_layout' => array( 900 'label' => _x( 'Groups', 'Customizer control label', 'buddypress' ), 901 'section' => 'bp_nouveau_loops_layout', 902 'settings' => 'bp_nouveau_appearance[groups_layout]', 903 'type' => 'select', 904 'choices' => bp_nouveau_customizer_grid_choices(), 905 ), 906 'members_group_layout' => array( 907 'label' => __( 'Group > Members', 'buddypress' ), 908 'section' => 'bp_nouveau_loops_layout', 909 'settings' => 'bp_nouveau_appearance[members_group_layout]', 910 'type' => 'select', 911 'choices' => bp_nouveau_customizer_grid_choices(), 912 ), 913 'group_dir_layout' => array( 914 'label' => __( 'Use column navigation for the Groups directory.', 'buddypress' ), 915 'section' => 'bp_nouveau_dir_layout', 916 'settings' => 'bp_nouveau_appearance[groups_dir_layout]', 917 'type' => 'checkbox', 918 ), 919 'group_dir_tabs' => array( 920 'label' => __( 'Use tab styling for Groups directory navigation.', 'buddypress' ), 921 'section' => 'bp_nouveau_dir_layout', 922 'settings' => 'bp_nouveau_appearance[groups_dir_tabs]', 923 'type' => 'checkbox', 924 ), 925 ) ); 926 } 927 928 /** 929 * Add the default group front template to the front template hierarchy. 930 * 931 * @since 3.0.0 932 * 933 * @param array $templates Optional. The list of templates for the front.php template part. 934 * @param BP_Groups_Group $group Optional. The group object. 935 * 936 * @return array The same list with the default front template if needed. 937 */ 938 function bp_nouveau_group_reset_front_template( $templates = array(), $group = null ) { 939 if ( empty( $group->id ) ) { 940 return $templates; 941 } 942 943 $use_default_front = bp_nouveau_get_appearance_settings( 'group_front_page' ); 944 945 // Setting the front template happens too early, so we need this! 946 if ( is_customize_preview() ) { 947 $use_default_front = bp_nouveau_get_temporary_setting( 'group_front_page', $use_default_front ); 948 } 949 950 if ( ! empty( $use_default_front ) ) { 951 array_push( $templates, 'groups/single/default-front.php' ); 952 } 953 954 /** 955 * Filters the BuddyPress Nouveau template hierarchy after resetting front template for groups. 956 * 957 * @since 3.0.0 958 * 959 * @param array $templates Array of templates. 960 */ 961 return apply_filters( '_bp_nouveau_group_reset_front_template', $templates ); 962 } 963 964 /** 965 * Locate a single group template into a specific hierarchy. 966 * 967 * @since 3.0.0 968 * 969 * @param string $template Optional. The template part to get (eg: activity, members...). 970 * 971 * @return string The located template. 972 */ 973 function bp_nouveau_group_locate_template_part( $template = '' ) { 974 $current_group = groups_get_current_group(); 975 $bp_nouveau = bp_nouveau(); 976 977 if ( ! $template || empty( $current_group->id ) ) { 978 return ''; 979 } 980 981 // Use a global to avoid requesting the hierarchy for each template 982 if ( ! isset( $bp_nouveau->groups->current_group_hierarchy ) ) { 983 $bp_nouveau->groups->current_group_hierarchy = array( 984 'groups/single/%s-id-' . (int) $current_group->id . '.php', 985 'groups/single/%s-slug-' . sanitize_file_name( $current_group->slug ) . '.php', 986 ); 987 988 /** 989 * Check for group types and add it to the hierarchy 990 */ 991 if ( bp_groups_get_group_types() ) { 992 $current_group_type = bp_groups_get_group_type( $current_group->id ); 993 if ( ! $current_group_type ) { 994 $current_group_type = 'none'; 995 } 996 997 $bp_nouveau->groups->current_group_hierarchy[] = 'groups/single/%s-group-type-' . sanitize_file_name( $current_group_type ) . '.php'; 998 } 999 1000 $bp_nouveau->groups->current_group_hierarchy = array_merge( $bp_nouveau->groups->current_group_hierarchy, array( 1001 'groups/single/%s-status-' . sanitize_file_name( $current_group->status ) . '.php', 1002 'groups/single/%s.php' 1003 ) ); 1004 } 1005 1006 // Init the templates 1007 $templates = array(); 1008 1009 // Loop in the hierarchy to fill it for the requested template part 1010 foreach ( $bp_nouveau->groups->current_group_hierarchy as $part ) { 1011 $templates[] = sprintf( $part, sanitize_file_name( $template ) ); 1012 } 1013 1014 /** 1015 * Filters the found template parts for the group template part locating functionality. 1016 * 1017 * @since 3.0.0 1018 * 1019 * @param array $templates Array of found templates. 1020 */ 1021 return bp_locate_template( apply_filters( 'bp_nouveau_group_locate_template_part', $templates ), false, true ); 1022 } 1023 1024 /** 1025 * Load a single group template part 1026 * 1027 * @since 3.0.0 1028 * 1029 * @param string $template Optional. The template part to get (eg: activity, members...). 1030 * 1031 * @return string HTML output. 1032 */ 1033 function bp_nouveau_group_get_template_part( $template = '' ) { 1034 $located = bp_nouveau_group_locate_template_part( $template ); 1035 1036 if ( false !== $located ) { 1037 $slug = str_replace( '.php', '', $located ); 1038 $name = null; 1039 1040 /** 1041 * Let plugins adding an action to bp_get_template_part get it from here. 1042 * 1043 * This is a variable hook that is dependent on the template part slug. 1044 * 1045 * @since 3.0.0 1046 * 1047 * @param string $slug Template part slug requested. 1048 * @param string $name Template part name requested. 1049 */ 1050 do_action( 'get_template_part_' . $slug, $slug, $name ); 1051 1052 load_template( $located, true ); 1053 } 1054 1055 return $located; 1056 } 1057 1058 /** 1059 * Are we inside the Current group's default front page sidebar? 1060 * 1061 * @since 3.0.0 1062 * 1063 * @return bool True if in the group's home sidebar. False otherwise. 1064 */ 1065 function bp_nouveau_group_is_home_widgets() { 1066 return ( true === bp_nouveau()->groups->is_group_home_sidebar ); 1067 } 1068 1069 /** 1070 * Filter the Latest activities Widget to only keep the one of the group displayed 1071 * 1072 * @since 3.0.0 1073 * 1074 * @param array $args Optional. The Activities Template arguments. 1075 * 1076 * @return array The Activities Template arguments. 1077 */ 1078 function bp_nouveau_group_activity_widget_overrides( $args = array() ) { 1079 return array_merge( $args, array( 1080 'object' => 'groups', 1081 'primary_id' => bp_get_current_group_id(), 1082 ) ); 1083 } 1084 1085 /** 1086 * Filter the Groups widget to only keep the displayed group. 1087 * 1088 * @since 3.0.0 1089 * 1090 * @param array $args Optional. The Groups Template arguments. 1091 * 1092 * @return array The Groups Template arguments. 1093 */ 1094 function bp_nouveau_group_groups_widget_overrides( $args = array() ) { 1095 return array_merge( $args, array( 1096 'include' => bp_get_current_group_id(), 1097 ) ); 1098 } 1099 1100 /** 1101 * Filter the Members widgets to only keep members of the displayed group. 1102 * 1103 * @since 3.0.0 1104 * 1105 * @param array $args Optional. The Members Template arguments. 1106 * 1107 * @return array The Members Template arguments. 1108 */ 1109 function bp_nouveau_group_members_widget_overrides( $args = array() ) { 1110 $group_members = groups_get_group_members( array( 'exclude_admins_mods' => false ) ); 1111 1112 if ( empty( $group_members['members'] ) ) { 1113 return $args; 1114 } 1115 1116 return array_merge( $args, array( 1117 'include' => wp_list_pluck( $group_members['members'], 'ID' ), 1118 ) ); 1119 } 1120 1121 /** 1122 * Init the Group's default front page filters as we're in the sidebar 1123 * 1124 * @since 3.0.0 1125 */ 1126 function bp_nouveau_groups_add_home_widget_filters() { 1127 add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 ); 1128 add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 ); 1129 add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 ); 1130 1131 /** 1132 * Fires after BuddyPress Nouveau groups have added their home widget filters. 1133 * 1134 * @since 3.0.0 1135 */ 1136 do_action( 'bp_nouveau_groups_add_home_widget_filters' ); 1137 } 1138 1139 /** 1140 * Remove the Group's default front page filters as we're no more in the sidebar 1141 * 1142 * @since 3.0.0 1143 */ 1144 function bp_nouveau_groups_remove_home_widget_filters() { 1145 remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 ); 1146 remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 ); 1147 remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 ); 1148 1149 /** 1150 * Fires after BuddyPress Nouveau groups have removed their home widget filters. 1151 * 1152 * @since 3.0.0 1153 */ 1154 do_action( 'bp_nouveau_groups_remove_home_widget_filters' ); 1155 } 1156 1157 /** 1158 * Get the hook, nonce, and eventually a specific template for Core Group's create screens. 1159 * 1160 * @since 3.0.0 1161 * 1162 * @param string $id Optional. The screen id 1163 * 1164 * @return mixed An array containing the hook dynamic part, the nonce, and eventually a specific template. 1165 * False if it's not a core create screen. 1166 */ 1167 function bp_nouveau_group_get_core_create_screens( $id = '' ) { 1168 // screen id => dynamic part of the hooks, nonce & specific template to use. 1169 $screens = array( 1170 'group-details' => array( 1171 'hook' => 'group_details_creation_step', 1172 'nonce' => 'groups_create_save_group-details', 1173 'template' => 'groups/single/admin/edit-details', 1174 ), 1175 'group-settings' => array( 1176 'hook' => 'group_settings_creation_step', 1177 'nonce' => 'groups_create_save_group-settings', 1178 ), 1179 'group-avatar' => array( 1180 'hook' => 'group_avatar_creation_step', 1181 'nonce' => 'groups_create_save_group-avatar', 1182 ), 1183 'group-cover-image' => array( 1184 'hook' => 'group_cover_image_creation_step', 1185 'nonce' => 'groups_create_save_group-cover-image', 1186 ), 1187 'group-invites' => array( 1188 'hook' => 'group_invites_creation_step', 1189 'nonce' => 'groups_create_save_group-invites', 1190 'template' => 'common/js-templates/invites/index', 1191 ), 1192 ); 1193 1194 if ( isset( $screens[ $id ] ) ) { 1195 return $screens[ $id ]; 1196 } 1197 1198 return false; 1199 } 1200 1201 /** 1202 * Get the hook and nonce for Core Group's manage screens. 1203 * 1204 * @since 3.0.0 1205 * 1206 * @param string $id Optional. The screen id 1207 * 1208 * @return mixed An array containing the hook dynamic part and the nonce. 1209 * False if it's not a core manage screen. 1210 */ 1211 function bp_nouveau_group_get_core_manage_screens( $id = '' ) { 1212 // screen id => dynamic part of the hooks & nonce. 1213 $screens = array( 1214 'edit-details' => array( 'hook' => 'group_details_admin', 'nonce' => 'groups_edit_group_details' ), 1215 'group-settings' => array( 'hook' => 'group_settings_admin', 'nonce' => 'groups_edit_group_settings' ), 1216 'group-avatar' => array(), 1217 'group-cover-image' => array( 'hook' => 'group_settings_cover_image', 'nonce' => '' ), 1218 'manage-members' => array( 'hook' => 'group_manage_members_admin', 'nonce' => '' ), 1219 'membership-requests' => array( 'hook' => 'group_membership_requests_admin', 'nonce' => '' ), 1220 'delete-group' => array( 'hook' => 'group_delete_admin', 'nonce' => 'groups_delete_group' ), 1221 ); 1222 1223 if ( isset( $screens[ $id ] ) ) { 1224 return $screens[ $id ]; 1225 } 1226 1227 return false; 1228 } 1229 1230 /** 1231 * Register notifications filters for the groups component. 1232 * 1233 * @since 3.0.0 1234 */ 1235 function bp_nouveau_groups_notification_filters() { 1236 $notifications = array( 1237 array( 1238 'id' => 'new_membership_request', 1239 'label' => __( 'Pending Group membership requests', 'buddypress' ), 1240 'position' => 55, 1241 ), 1242 array( 1243 'id' => 'membership_request_accepted', 1244 'label' => __( 'Accepted Group membership requests', 'buddypress' ), 1245 'position' => 65, 1246 ), 1247 array( 1248 'id' => 'membership_request_rejected', 1249 'label' => __( 'Rejected Group membership requests', 'buddypress' ), 1250 'position' => 75, 1251 ), 1252 array( 1253 'id' => 'member_promoted_to_admin', 1254 'label' => __( 'Group Administrator promotions', 'buddypress' ), 1255 'position' => 85, 1256 ), 1257 array( 1258 'id' => 'member_promoted_to_mod', 1259 'label' => __( 'Group Moderator promotions', 'buddypress' ), 1260 'position' => 95, 1261 ), 1262 array( 1263 'id' => 'group_invite', 1264 'label' => __( 'Group invitations', 'buddypress' ), 1265 'position' => 105, 1266 ), 1267 ); 1268 1269 foreach ( $notifications as $notification ) { 1270 bp_nouveau_notifications_register_filter( $notification ); 1271 } 1272 } 1273 1274 /** 1275 * Makes sure the Nouveau specific behavior about Group invites visibility is applied to the REST API. 1276 * 1277 * @since 7.2.1 1278 * 1279 * @param true|WP_Error $retval Whether the current user can list invites. 1280 * @param WP_REST_Request $request The request sent to the API. 1281 * @return true|WP_Error Whether the current user can list invites. 1282 */ 1283 function bp_nouveau_rest_group_invites_get_items_permissions_check( $retval, $request ) { 1284 if ( is_wp_error( $retval ) ) { 1285 $group_id = (int) $request['group_id']; 1286 1287 if ( groups_is_user_member( bp_loggedin_user_id(), $group_id ) ) { 1288 $retval = true; 1289 } 1290 } 1291 1292 return $retval; 1293 } 1294 add_filter( 'bp_rest_group_invites_get_items_permissions_check', 'bp_nouveau_rest_group_invites_get_items_permissions_check', 10, 2 );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sat Apr 17 01:01:43 2021 | Cross-referenced by PHPXref 0.7.1 |