[ 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 6.3.0 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 * @since 3.0.0 513 */ 514 function bp_nouveau_get_groups_directory_nav_items() { 515 $nav_items = array(); 516 517 $nav_items['all'] = array( 518 'component' => 'groups', 519 'slug' => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope 520 'li_class' => array( 'selected' ), 521 'link' => bp_get_groups_directory_permalink(), 522 'text' => __( 'All Groups', 'buddypress' ), 523 'count' => bp_get_total_group_count(), 524 'position' => 5, 525 ); 526 527 if ( is_user_logged_in() ) { 528 529 $my_groups_count = bp_get_total_group_count_for_user( bp_loggedin_user_id() ); 530 531 // If the user has groups create a nav item 532 if ( $my_groups_count ) { 533 $nav_items['personal'] = array( 534 'component' => 'groups', 535 'slug' => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope 536 'li_class' => array(), 537 'link' => bp_loggedin_user_domain() . bp_get_groups_slug() . '/my-groups/', 538 'text' => __( 'My Groups', 'buddypress' ), 539 'count' => $my_groups_count, 540 'position' => 15, 541 ); 542 } 543 544 // If the user can create groups, add the create nav 545 if ( bp_user_can_create_groups() ) { 546 $nav_items['create'] = array( 547 'component' => 'groups', 548 'slug' => 'create', // slug is used because BP_Core_Nav requires it, but it's the scope 549 'li_class' => array( 'no-ajax', 'group-create', 'create-button' ), 550 'link' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ), 551 'text' => __( 'Create a Group', 'buddypress' ), 552 'count' => false, 553 'position' => 999, 554 ); 555 } 556 } 557 558 // Check for the deprecated hook : 559 $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_groups_directory_group_filter', 'groups', 20 ); 560 561 if ( ! empty( $extra_nav_items ) ) { 562 $nav_items = array_merge( $nav_items, $extra_nav_items ); 563 } 564 565 /** 566 * Use this filter to introduce your custom nav items for the groups directory. 567 * 568 * @since 3.0.0 569 * 570 * @param array $nav_items The list of the groups directory nav items. 571 */ 572 return apply_filters( 'bp_nouveau_get_groups_directory_nav_items', $nav_items ); 573 } 574 575 /** 576 * Get Dropdown filters for the groups component 577 * 578 * @since 3.0.0 579 * 580 * @param string $context 'directory' or 'user' 581 * 582 * @return array the filters 583 */ 584 function bp_nouveau_get_groups_filters( $context = '' ) { 585 if ( empty( $context ) ) { 586 return array(); 587 } 588 589 $action = ''; 590 if ( 'user' === $context ) { 591 $action = 'bp_member_group_order_options'; 592 } elseif ( 'directory' === $context ) { 593 $action = 'bp_groups_directory_order_options'; 594 } 595 596 /** 597 * Recommended, filter here instead of adding an action to 'bp_member_group_order_options' 598 * or 'bp_groups_directory_order_options' 599 * 600 * @since 3.0.0 601 * 602 * @param array the members filters. 603 * @param string the context. 604 */ 605 $filters = apply_filters( 'bp_nouveau_get_groups_filters', array( 606 'active' => __( 'Last Active', 'buddypress' ), 607 'popular' => __( 'Most Members', 'buddypress' ), 608 'newest' => __( 'Newly Created', 'buddypress' ), 609 'alphabetical' => __( 'Alphabetical', 'buddypress' ), 610 ), $context ); 611 612 if ( $action ) { 613 return bp_nouveau_parse_hooked_options( $action, $filters ); 614 } 615 616 return $filters; 617 } 618 619 /** 620 * Catch the arguments for buttons 621 * 622 * @since 3.0.0 623 * 624 * @param array $button The arguments of the button that BuddyPress is about to create. 625 * 626 * @return array An empty array to stop the button creation process. 627 */ 628 function bp_nouveau_groups_catch_button_args( $button = array() ) { 629 /** 630 * Globalize the arguments so that we can use it 631 * in bp_nouveau_get_groups_buttons(). 632 */ 633 bp_nouveau()->groups->button_args = $button; 634 635 // return an empty array to stop the button creation process 636 return array(); 637 } 638 639 /** 640 * Catch the content hooked to the 'bp_group_header_meta' action 641 * 642 * @since 3.0.0 643 * 644 * @return string|bool HTML Output if hooked. False otherwise. 645 */ 646 function bp_nouveau_get_hooked_group_meta() { 647 ob_start(); 648 649 /** 650 * Fires after inside the group header item meta section. 651 * 652 * @since 1.2.0 653 */ 654 do_action( 'bp_group_header_meta' ); 655 656 $output = ob_get_clean(); 657 658 if ( ! empty( $output ) ) { 659 return $output; 660 } 661 662 return false; 663 } 664 665 /** 666 * Display the Widgets of Group extensions into the default front page? 667 * 668 * @since 3.0.0 669 * 670 * @return bool True to display. False otherwise. 671 */ 672 function bp_nouveau_groups_do_group_boxes() { 673 $group_settings = bp_nouveau_get_appearance_settings(); 674 675 return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_boxes'] ); 676 } 677 678 /** 679 * Display description of the Group into the default front page? 680 * 681 * @since 3.0.0 682 * 683 * @return bool True to display. False otherwise. 684 */ 685 function bp_nouveau_groups_front_page_description() { 686 $group_settings = bp_nouveau_get_appearance_settings(); 687 688 // This check is a problem it needs to be used in templates but returns true even if not on the front page 689 // return false on this if we are not displaying the front page 'bp_is_group_home()' 690 // This may well be a bad approach to re-think ~hnla. 691 // @todo 692 return ! empty( $group_settings['group_front_page'] ) && ! empty( $group_settings['group_front_description'] ) && bp_is_group_home(); 693 } 694 695 /** 696 * Add sections to the customizer for the groups component. 697 * 698 * @since 3.0.0 699 * 700 * @param array $sections the Customizer sections to add. 701 * 702 * @return array the Customizer sections to add. 703 */ 704 function bp_nouveau_groups_customizer_sections( $sections = array() ) { 705 return array_merge( $sections, array( 706 'bp_nouveau_group_front_page' => array( 707 'title' => __( 'Group front page', 'buddypress' ), 708 'panel' => 'bp_nouveau_panel', 709 'priority' => 20, 710 'description' => __( 'Configure the default front page for groups.', 'buddypress' ), 711 ), 712 'bp_nouveau_group_primary_nav' => array( 713 'title' => __( 'Group navigation', 'buddypress' ), 714 'panel' => 'bp_nouveau_panel', 715 'priority' => 40, 716 'description' => __( 'Customize the navigation menu for groups. See your changes by navigating to a group in the live-preview window.', 'buddypress' ), 717 ), 718 ) ); 719 } 720 721 /** 722 * Add settings to the customizer for the groups component. 723 * 724 * @since 3.0.0 725 * 726 * @param array $settings Optional. The settings to add. 727 * 728 * @return array the settings to add. 729 */ 730 function bp_nouveau_groups_customizer_settings( $settings = array() ) { 731 return array_merge( $settings, array( 732 'bp_nouveau_appearance[group_front_page]' => array( 733 'index' => 'group_front_page', 734 'capability' => 'bp_moderate', 735 'sanitize_callback' => 'absint', 736 'transport' => 'refresh', 737 'type' => 'option', 738 ), 739 'bp_nouveau_appearance[group_front_boxes]' => array( 740 'index' => 'group_front_boxes', 741 'capability' => 'bp_moderate', 742 'sanitize_callback' => 'absint', 743 'transport' => 'refresh', 744 'type' => 'option', 745 ), 746 'bp_nouveau_appearance[group_front_description]' => array( 747 'index' => 'group_front_description', 748 'capability' => 'bp_moderate', 749 'sanitize_callback' => 'absint', 750 'transport' => 'refresh', 751 'type' => 'option', 752 ), 753 'bp_nouveau_appearance[group_nav_display]' => array( 754 'index' => 'group_nav_display', 755 'capability' => 'bp_moderate', 756 'sanitize_callback' => 'absint', 757 'transport' => 'refresh', 758 'type' => 'option', 759 ), 760 'bp_nouveau_appearance[group_nav_tabs]' => array( 761 'index' => 'group_nav_tabs', 762 'capability' => 'bp_moderate', 763 'sanitize_callback' => 'absint', 764 'transport' => 'refresh', 765 'type' => 'option', 766 ), 767 'bp_nouveau_appearance[group_subnav_tabs]' => array( 768 'index' => 'group_subnav_tabs', 769 'capability' => 'bp_moderate', 770 'sanitize_callback' => 'absint', 771 'transport' => 'refresh', 772 'type' => 'option', 773 ), 774 'bp_nouveau_appearance[groups_create_tabs]' => array( 775 'index' => 'groups_create_tabs', 776 'capability' => 'bp_moderate', 777 'sanitize_callback' => 'absint', 778 'transport' => 'refresh', 779 'type' => 'option', 780 ), 781 'bp_nouveau_appearance[group_nav_order]' => array( 782 'index' => 'group_nav_order', 783 'capability' => 'bp_moderate', 784 'sanitize_callback' => 'bp_nouveau_sanitize_nav_order', 785 'transport' => 'refresh', 786 'type' => 'option', 787 ), 788 'bp_nouveau_appearance[groups_layout]' => array( 789 'index' => 'groups_layout', 790 'capability' => 'bp_moderate', 791 'sanitize_callback' => 'absint', 792 'transport' => 'refresh', 793 'type' => 'option', 794 ), 795 'bp_nouveau_appearance[groups_dir_tabs]' => array( 796 'index' => 'groups_dir_tabs', 797 'capability' => 'bp_moderate', 798 'sanitize_callback' => 'absint', 799 'transport' => 'refresh', 800 'type' => 'option', 801 ), 802 ) ); 803 } 804 805 /** 806 * Add controls for the settings of the customizer for the groups component. 807 * 808 * @since 3.0.0 809 * 810 * @param array $controls Optional. The controls to add. 811 * 812 * @return array the controls to add. 813 */ 814 function bp_nouveau_groups_customizer_controls( $controls = array() ) { 815 return array_merge( $controls, array( 816 'group_front_page' => array( 817 'label' => __( 'Enable custom front pages for groups.', 'buddypress' ), 818 'section' => 'bp_nouveau_group_front_page', 819 'settings' => 'bp_nouveau_appearance[group_front_page]', 820 'type' => 'checkbox', 821 ), 822 'group_front_boxes' => array( 823 'label' => __( 'Enable widget region for group homepages. When enabled, the site admin can add widgets to group pages via the Widgets panel.', 'buddypress' ), 824 'section' => 'bp_nouveau_group_front_page', 825 'settings' => 'bp_nouveau_appearance[group_front_boxes]', 826 'type' => 'checkbox', 827 ), 828 'group_front_description' => array( 829 'label' => __( "Display the group description in the body of the group's front page.", 'buddypress' ), 830 'section' => 'bp_nouveau_group_front_page', 831 'settings' => 'bp_nouveau_appearance[group_front_description]', 832 'type' => 'checkbox', 833 ), 834 'group_nav_display' => array( 835 'label' => __( 'Display the group navigation vertically.', 'buddypress' ), 836 'section' => 'bp_nouveau_group_primary_nav', 837 'settings' => 'bp_nouveau_appearance[group_nav_display]', 838 'type' => 'checkbox', 839 ), 840 'group_nav_tabs' => array( 841 'label' => __( 'Use tab styling for primary navigation.', 'buddypress' ), 842 'section' => 'bp_nouveau_group_primary_nav', 843 'settings' => 'bp_nouveau_appearance[group_nav_tabs]', 844 'type' => 'checkbox', 845 ), 846 'group_subnav_tabs' => array( 847 'label' => __( 'Use tab styling for secondary navigation.', 'buddypress' ), 848 'section' => 'bp_nouveau_group_primary_nav', 849 'settings' => 'bp_nouveau_appearance[group_subnav_tabs]', 850 'type' => 'checkbox', 851 ), 852 'groups_create_tabs' => array( 853 'label' => __( 'Use tab styling for the group creation process.', 'buddypress' ), 854 'section' => 'bp_nouveau_group_primary_nav', 855 'settings' => 'bp_nouveau_appearance[groups_create_tabs]', 856 'type' => 'checkbox', 857 ), 858 'group_nav_order' => array( 859 'class' => 'BP_Nouveau_Nav_Customize_Control', 860 'label' => __( 'Reorder the primary navigation for a group.', 'buddypress' ), 861 'section' => 'bp_nouveau_group_primary_nav', 862 'settings' => 'bp_nouveau_appearance[group_nav_order]', 863 'type' => 'group', 864 ), 865 'groups_layout' => array( 866 'label' => _x( 'Groups', 'Customizer control label', 'buddypress' ), 867 'section' => 'bp_nouveau_loops_layout', 868 'settings' => 'bp_nouveau_appearance[groups_layout]', 869 'type' => 'select', 870 'choices' => bp_nouveau_customizer_grid_choices(), 871 ), 872 'members_group_layout' => array( 873 'label' => __( 'Group > Members', 'buddypress' ), 874 'section' => 'bp_nouveau_loops_layout', 875 'settings' => 'bp_nouveau_appearance[members_group_layout]', 876 'type' => 'select', 877 'choices' => bp_nouveau_customizer_grid_choices(), 878 ), 879 'group_dir_layout' => array( 880 'label' => __( 'Use column navigation for the Groups directory.', 'buddypress' ), 881 'section' => 'bp_nouveau_dir_layout', 882 'settings' => 'bp_nouveau_appearance[groups_dir_layout]', 883 'type' => 'checkbox', 884 ), 885 'group_dir_tabs' => array( 886 'label' => __( 'Use tab styling for Groups directory navigation.', 'buddypress' ), 887 'section' => 'bp_nouveau_dir_layout', 888 'settings' => 'bp_nouveau_appearance[groups_dir_tabs]', 889 'type' => 'checkbox', 890 ), 891 ) ); 892 } 893 894 /** 895 * Add the default group front template to the front template hierarchy. 896 * 897 * @since 3.0.0 898 * 899 * @param array $templates Optional. The list of templates for the front.php template part. 900 * @param BP_Groups_Group $group Optional. The group object. 901 * 902 * @return array The same list with the default front template if needed. 903 */ 904 function bp_nouveau_group_reset_front_template( $templates = array(), $group = null ) { 905 if ( empty( $group->id ) ) { 906 return $templates; 907 } 908 909 $use_default_front = bp_nouveau_get_appearance_settings( 'group_front_page' ); 910 911 // Setting the front template happens too early, so we need this! 912 if ( is_customize_preview() ) { 913 $use_default_front = bp_nouveau_get_temporary_setting( 'group_front_page', $use_default_front ); 914 } 915 916 if ( ! empty( $use_default_front ) ) { 917 array_push( $templates, 'groups/single/default-front.php' ); 918 } 919 920 /** 921 * Filters the BuddyPress Nouveau template hierarchy after resetting front template for groups. 922 * 923 * @since 3.0.0 924 * 925 * @param array $templates Array of templates. 926 */ 927 return apply_filters( '_bp_nouveau_group_reset_front_template', $templates ); 928 } 929 930 /** 931 * Locate a single group template into a specific hierarchy. 932 * 933 * @since 3.0.0 934 * 935 * @param string $template Optional. The template part to get (eg: activity, members...). 936 * 937 * @return string The located template. 938 */ 939 function bp_nouveau_group_locate_template_part( $template = '' ) { 940 $current_group = groups_get_current_group(); 941 $bp_nouveau = bp_nouveau(); 942 943 if ( ! $template || empty( $current_group->id ) ) { 944 return ''; 945 } 946 947 // Use a global to avoid requesting the hierarchy for each template 948 if ( ! isset( $bp_nouveau->groups->current_group_hierarchy ) ) { 949 $bp_nouveau->groups->current_group_hierarchy = array( 950 'groups/single/%s-id-' . (int) $current_group->id . '.php', 951 'groups/single/%s-slug-' . sanitize_file_name( $current_group->slug ) . '.php', 952 ); 953 954 /** 955 * Check for group types and add it to the hierarchy 956 */ 957 if ( bp_groups_get_group_types() ) { 958 $current_group_type = bp_groups_get_group_type( $current_group->id ); 959 if ( ! $current_group_type ) { 960 $current_group_type = 'none'; 961 } 962 963 $bp_nouveau->groups->current_group_hierarchy[] = 'groups/single/%s-group-type-' . sanitize_file_name( $current_group_type ) . '.php'; 964 } 965 966 $bp_nouveau->groups->current_group_hierarchy = array_merge( $bp_nouveau->groups->current_group_hierarchy, array( 967 'groups/single/%s-status-' . sanitize_file_name( $current_group->status ) . '.php', 968 'groups/single/%s.php' 969 ) ); 970 } 971 972 // Init the templates 973 $templates = array(); 974 975 // Loop in the hierarchy to fill it for the requested template part 976 foreach ( $bp_nouveau->groups->current_group_hierarchy as $part ) { 977 $templates[] = sprintf( $part, sanitize_file_name( $template ) ); 978 } 979 980 /** 981 * Filters the found template parts for the group template part locating functionality. 982 * 983 * @since 3.0.0 984 * 985 * @param array $templates Array of found templates. 986 */ 987 return bp_locate_template( apply_filters( 'bp_nouveau_group_locate_template_part', $templates ), false, true ); 988 } 989 990 /** 991 * Load a single group template part 992 * 993 * @since 3.0.0 994 * 995 * @param string $template Optional. The template part to get (eg: activity, members...). 996 * 997 * @return string HTML output. 998 */ 999 function bp_nouveau_group_get_template_part( $template = '' ) { 1000 $located = bp_nouveau_group_locate_template_part( $template ); 1001 1002 if ( false !== $located ) { 1003 $slug = str_replace( '.php', '', $located ); 1004 $name = null; 1005 1006 /** 1007 * Let plugins adding an action to bp_get_template_part get it from here. 1008 * 1009 * This is a variable hook that is dependent on the template part slug. 1010 * 1011 * @since 3.0.0 1012 * 1013 * @param string $slug Template part slug requested. 1014 * @param string $name Template part name requested. 1015 */ 1016 do_action( 'get_template_part_' . $slug, $slug, $name ); 1017 1018 load_template( $located, true ); 1019 } 1020 1021 return $located; 1022 } 1023 1024 /** 1025 * Are we inside the Current group's default front page sidebar? 1026 * 1027 * @since 3.0.0 1028 * 1029 * @return bool True if in the group's home sidebar. False otherwise. 1030 */ 1031 function bp_nouveau_group_is_home_widgets() { 1032 return ( true === bp_nouveau()->groups->is_group_home_sidebar ); 1033 } 1034 1035 /** 1036 * Filter the Latest activities Widget to only keep the one of the group displayed 1037 * 1038 * @since 3.0.0 1039 * 1040 * @param array $args Optional. The Activities Template arguments. 1041 * 1042 * @return array The Activities Template arguments. 1043 */ 1044 function bp_nouveau_group_activity_widget_overrides( $args = array() ) { 1045 return array_merge( $args, array( 1046 'object' => 'groups', 1047 'primary_id' => bp_get_current_group_id(), 1048 ) ); 1049 } 1050 1051 /** 1052 * Filter the Groups widget to only keep the displayed group. 1053 * 1054 * @since 3.0.0 1055 * 1056 * @param array $args Optional. The Groups Template arguments. 1057 * 1058 * @return array The Groups Template arguments. 1059 */ 1060 function bp_nouveau_group_groups_widget_overrides( $args = array() ) { 1061 return array_merge( $args, array( 1062 'include' => bp_get_current_group_id(), 1063 ) ); 1064 } 1065 1066 /** 1067 * Filter the Members widgets to only keep members of the displayed group. 1068 * 1069 * @since 3.0.0 1070 * 1071 * @param array $args Optional. The Members Template arguments. 1072 * 1073 * @return array The Members Template arguments. 1074 */ 1075 function bp_nouveau_group_members_widget_overrides( $args = array() ) { 1076 $group_members = groups_get_group_members( array( 'exclude_admins_mods' => false ) ); 1077 1078 if ( empty( $group_members['members'] ) ) { 1079 return $args; 1080 } 1081 1082 return array_merge( $args, array( 1083 'include' => wp_list_pluck( $group_members['members'], 'ID' ), 1084 ) ); 1085 } 1086 1087 /** 1088 * Init the Group's default front page filters as we're in the sidebar 1089 * 1090 * @since 3.0.0 1091 */ 1092 function bp_nouveau_groups_add_home_widget_filters() { 1093 add_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 ); 1094 add_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 ); 1095 add_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 ); 1096 1097 /** 1098 * Fires after BuddyPress Nouveau groups have added their home widget filters. 1099 * 1100 * @since 3.0.0 1101 */ 1102 do_action( 'bp_nouveau_groups_add_home_widget_filters' ); 1103 } 1104 1105 /** 1106 * Remove the Group's default front page filters as we're no more in the sidebar 1107 * 1108 * @since 3.0.0 1109 */ 1110 function bp_nouveau_groups_remove_home_widget_filters() { 1111 remove_filter( 'bp_nouveau_activity_widget_query', 'bp_nouveau_group_activity_widget_overrides', 10, 1 ); 1112 remove_filter( 'bp_before_has_groups_parse_args', 'bp_nouveau_group_groups_widget_overrides', 10, 1 ); 1113 remove_filter( 'bp_before_has_members_parse_args', 'bp_nouveau_group_members_widget_overrides', 10, 1 ); 1114 1115 /** 1116 * Fires after BuddyPress Nouveau groups have removed their home widget filters. 1117 * 1118 * @since 3.0.0 1119 */ 1120 do_action( 'bp_nouveau_groups_remove_home_widget_filters' ); 1121 } 1122 1123 /** 1124 * Get the hook, nonce, and eventually a specific template for Core Group's create screens. 1125 * 1126 * @since 3.0.0 1127 * 1128 * @param string $id Optional. The screen id 1129 * 1130 * @return mixed An array containing the hook dynamic part, the nonce, and eventually a specific template. 1131 * False if it's not a core create screen. 1132 */ 1133 function bp_nouveau_group_get_core_create_screens( $id = '' ) { 1134 // screen id => dynamic part of the hooks, nonce & specific template to use. 1135 $screens = array( 1136 'group-details' => array( 1137 'hook' => 'group_details_creation_step', 1138 'nonce' => 'groups_create_save_group-details', 1139 'template' => 'groups/single/admin/edit-details', 1140 ), 1141 'group-settings' => array( 1142 'hook' => 'group_settings_creation_step', 1143 'nonce' => 'groups_create_save_group-settings', 1144 ), 1145 'group-avatar' => array( 1146 'hook' => 'group_avatar_creation_step', 1147 'nonce' => 'groups_create_save_group-avatar', 1148 ), 1149 'group-cover-image' => array( 1150 'hook' => 'group_cover_image_creation_step', 1151 'nonce' => 'groups_create_save_group-cover-image', 1152 ), 1153 'group-invites' => array( 1154 'hook' => 'group_invites_creation_step', 1155 'nonce' => 'groups_create_save_group-invites', 1156 'template' => 'common/js-templates/invites/index', 1157 ), 1158 ); 1159 1160 if ( isset( $screens[ $id ] ) ) { 1161 return $screens[ $id ]; 1162 } 1163 1164 return false; 1165 } 1166 1167 /** 1168 * Get the hook and nonce for Core Group's manage screens. 1169 * 1170 * @since 3.0.0 1171 * 1172 * @param string $id Optional. The screen id 1173 * 1174 * @return mixed An array containing the hook dynamic part and the nonce. 1175 * False if it's not a core manage screen. 1176 */ 1177 function bp_nouveau_group_get_core_manage_screens( $id = '' ) { 1178 // screen id => dynamic part of the hooks & nonce. 1179 $screens = array( 1180 'edit-details' => array( 'hook' => 'group_details_admin', 'nonce' => 'groups_edit_group_details' ), 1181 'group-settings' => array( 'hook' => 'group_settings_admin', 'nonce' => 'groups_edit_group_settings' ), 1182 'group-avatar' => array(), 1183 'group-cover-image' => array( 'hook' => 'group_settings_cover_image', 'nonce' => '' ), 1184 'manage-members' => array( 'hook' => 'group_manage_members_admin', 'nonce' => '' ), 1185 'membership-requests' => array( 'hook' => 'group_membership_requests_admin', 'nonce' => '' ), 1186 'delete-group' => array( 'hook' => 'group_delete_admin', 'nonce' => 'groups_delete_group' ), 1187 ); 1188 1189 if ( isset( $screens[ $id ] ) ) { 1190 return $screens[ $id ]; 1191 } 1192 1193 return false; 1194 } 1195 1196 /** 1197 * Register notifications filters for the groups component. 1198 * 1199 * @since 3.0.0 1200 */ 1201 function bp_nouveau_groups_notification_filters() { 1202 $notifications = array( 1203 array( 1204 'id' => 'new_membership_request', 1205 'label' => __( 'Pending Group membership requests', 'buddypress' ), 1206 'position' => 55, 1207 ), 1208 array( 1209 'id' => 'membership_request_accepted', 1210 'label' => __( 'Accepted Group membership requests', 'buddypress' ), 1211 'position' => 65, 1212 ), 1213 array( 1214 'id' => 'membership_request_rejected', 1215 'label' => __( 'Rejected Group membership requests', 'buddypress' ), 1216 'position' => 75, 1217 ), 1218 array( 1219 'id' => 'member_promoted_to_admin', 1220 'label' => __( 'Group Administrator promotions', 'buddypress' ), 1221 'position' => 85, 1222 ), 1223 array( 1224 'id' => 'member_promoted_to_mod', 1225 'label' => __( 'Group Moderator promotions', 'buddypress' ), 1226 'position' => 95, 1227 ), 1228 array( 1229 'id' => 'group_invite', 1230 'label' => __( 'Group invitations', 'buddypress' ), 1231 'position' => 105, 1232 ), 1233 ); 1234 1235 foreach ( $notifications as $notification ) { 1236 bp_nouveau_notifications_register_filter( $notification ); 1237 } 1238 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 19 01:01:32 2021 | Cross-referenced by PHPXref 0.7.1 |