BP_Groups_Component
Creates our Groups component.
Description
Source
File: bp-groups/classes/class-bp-groups-component.php
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | class BP_Groups_Component extends BP_Component { /** * Auto-join group when non group member performs group activity. * * @since BuddyPress 1.5.0 * @var bool */ public $auto_join ; /** * The group being currently accessed. * * @since BuddyPress 1.5.0 * @var BP_Groups_Group */ public $current_group ; /** * Default group extension. * * @since BuddyPress 1.6.0 * @todo Is this used anywhere? Is this a duplicate of $default_extension? * @var string */ var $default_component ; /** * Default group extension. * * @since BuddyPress 1.6.0 * @var string */ public $default_extension ; /** * Illegal group names/slugs. * * @since BuddyPress 1.5.0 * @var array */ public $forbidden_names ; /** * Group creation/edit steps (e.g. Details, Settings, Avatar, Invites). * * @since BuddyPress 1.5.0 * @var array */ public $group_creation_steps ; /** * Types of group statuses (Public, Private, Hidden). * * @since BuddyPress 1.5.0 * @var array */ public $valid_status ; /** * Group types. * * @see bp_groups_register_group_type() * * @since BuddyPress 2.6.0 * @var array */ public $types = array (); /** * Current directory group type. * * @see groups_directory_groups_setup() * * @since BuddyPress 2.7.0 * @var string */ public $current_directory_type = '' ; /** * Start the groups component creation process. * * @since BuddyPress 1.5.0 */ public function __construct() { parent::start( 'groups' , __( 'Social Groups' , 'buddyboss' ), buddypress()->plugin_dir, array ( 'adminbar_myaccount_order' => 70, 'search_query_arg' => 'groups_search' , ) ); } /** * Include Groups component files. * * @since BuddyPress 1.5.0 * * @see BP_Component::includes() for a description of arguments. * * @param array $includes See BP_Component::includes() for a description. */ public function includes( $includes = array () ) { $includes = array ( 'cache' , 'filters' , 'widgets' , 'template' , 'adminbar' , 'functions' , 'notifications' ); // Conditional includes. if ( bp_is_active( 'activity' ) ) { $includes [] = 'activity' ; } if ( is_admin() ) { $includes [] = 'admin' ; } parent::includes( $includes ); } /** * Late includes method. * * Only load up certain code when on specific pages. * * @since BuddyPress 3.0.0 */ public function late_includes() { // Bail if PHPUnit is running. if ( defined( 'BP_TESTS_DIR' ) ) { return ; } if ( bp_is_groups_component() ) { // Authenticated actions. if ( is_user_logged_in() && in_array( bp_current_action(), array ( 'create' , 'join' , 'leave-group' ), true ) ) { require $this ->path . 'bp-groups/actions/' . bp_current_action() . '.php' ; } // Actions - RSS feed handler. if ( bp_is_active( 'activity' ) && bp_is_current_action( 'feed' ) ) { require $this ->path . 'bp-groups/actions/feed.php' ; } // Actions - Random group handler. if ( isset( $_GET [ 'random-group' ] ) ) { require $this ->path . 'bp-groups/actions/random.php' ; } // Screens - Directory. if ( bp_is_groups_directory() ) { require $this ->path . 'bp-groups/screens/directory.php' ; } // Screens - User profile integration. if ( bp_is_user() ) { require $this ->path . 'bp-groups/screens/user/my-groups.php' ; if ( bp_is_current_action( 'invites' ) ) { require $this ->path . 'bp-groups/screens/user/invites.php' ; } } // Single group. if ( bp_is_group() ) { // Actions - Access protection. require $this ->path . 'bp-groups/actions/access.php' ; // Public nav items. if ( in_array( bp_current_action(), array ( 'home' , 'request-membership' , 'activity' , 'members' , 'photos' , 'albums' , 'send-invites' , 'subgroups' ), true ) ) { require $this ->path . 'bp-groups/screens/single/' . bp_current_action() . '.php' ; } if ( in_array( bp_get_group_current_members_tab(), array ( 'all-members' , 'leaders' ), true ) ) { require $this ->path . 'bp-groups/screens/single/members/' . bp_get_group_current_members_tab() . '.php' ; } // Admin nav items. if ( bp_is_item_admin() && is_user_logged_in() ) { require $this ->path . 'bp-groups/screens/single/admin.php' ; if ( in_array( bp_get_group_current_admin_tab(), array ( 'edit-details' , 'group-settings' , 'group-avatar' , 'group-cover-image' , 'manage-members' , 'membership-requests' , 'delete-group' ), true ) ) { require $this ->path . 'bp-groups/screens/single/admin/' . bp_get_group_current_admin_tab() . '.php' ; } } } // Theme compatibility. new BP_Groups_Theme_Compat(); } } /** * Set up component global data. * * The BP_GROUPS_SLUG constant is deprecated, and only used here for * backwards compatibility. * * @since BuddyPress 1.5.0 * * @see BP_Component::setup_globals() for a description of arguments. * * @param array $args See BP_Component::setup_globals() for a description. */ public function setup_globals( $args = array () ) { $bp = buddypress(); // Define a slug, if necessary. if ( ! defined( 'BP_GROUPS_SLUG' ) ) { define( 'BP_GROUPS_SLUG' , $this ->id ); } // Global tables for groups component. $global_tables = array ( 'table_name' => $bp ->table_prefix . 'bp_groups' , 'table_name_members' => $bp ->table_prefix . 'bp_groups_members' , 'table_name_groupmeta' => $bp ->table_prefix . 'bp_groups_groupmeta' ); // Metadata tables for groups component. $meta_tables = array ( 'group' => $bp ->table_prefix . 'bp_groups_groupmeta' , ); // Fetch the default directory title. $default_directory_titles = bp_core_get_directory_page_default_titles(); $default_directory_title = $default_directory_titles [ $this ->id]; // All globals for groups component. // Note that global_tables is included in this array. $args = array ( 'slug' => BP_GROUPS_SLUG, 'root_slug' => isset( $bp ->pages->groups->slug ) ? $bp ->pages->groups->slug : BP_GROUPS_SLUG, 'has_directory' => true, 'directory_title' => isset( $bp ->pages->groups->title ) ? $bp ->pages->groups->title : $default_directory_title , 'notification_callback' => 'groups_format_notifications' , 'search_string' => __( 'Search Groups…' , 'buddyboss' ), 'global_tables' => $global_tables , 'meta_tables' => $meta_tables , ); parent::setup_globals( $args ); /* Single Group Globals **********************************************/ // Are we viewing a single group? if ( bp_is_groups_component() && ( ( $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) || ( $group_id = BP_Groups_Group::get_id_by_previous_slug( bp_current_action() ) ) ) ) { $bp ->is_single_item = true; /** * Filters the current PHP Class being used. * * @since BuddyPress 1.5.0 * * @param string $value Name of the class being used. */ $current_group_class = apply_filters( 'bp_groups_current_group_class' , 'BP_Groups_Group' ); if ( $current_group_class == 'BP_Groups_Group' ) { $this ->current_group = groups_get_group( $group_id ); } else { /** * Filters the current group object being instantiated from previous filter. * * @since BuddyPress 1.5.0 * * @param object $value Newly instantiated object for the group. */ $this ->current_group = apply_filters( 'bp_groups_current_group_object' , new $current_group_class ( $group_id ) ); } // When in a single group, the first action is bumped down one because of the // group name, so we need to adjust this and set the group name to current_item. $bp ->current_item = bp_current_action(); $bp ->current_action = bp_action_variable( 0 ); array_shift ( $bp ->action_variables ); // Using "item" not "group" for generic support in other components. if ( bp_current_user_can( 'bp_moderate' ) ) { bp_update_is_item_admin( true, 'groups' ); } else { bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this ->current_group->id ), 'groups' ); } // If the user is not an admin, check if they are a moderator. if ( ! bp_is_item_admin() ) { bp_update_is_item_mod ( groups_is_user_mod ( bp_loggedin_user_id(), $this ->current_group->id ), 'groups' ); } // Check once if the current group has a custom front template. $this ->current_group->front_template = bp_groups_get_front_template( $this ->current_group ); // Initialize the nav for the groups component. $this ->nav = new BP_Core_Nav( $this ->current_group->id ); // Set current_group to 0 to prevent debug errors. } else { $this ->current_group = 0; } // Set group type if available. if ( bp_is_groups_directory() && bp_is_current_action( bp_get_groups_group_type_base() ) && bp_action_variable() ) { $matched_types = bp_groups_get_group_types( array ( 'has_directory' => true, 'directory_slug' => bp_action_variable(), ) ); // Set 404 if we do not have a valid group type. if ( empty ( $matched_types ) ) { bp_do_404(); return ; } // Set our directory type marker. $this ->current_directory_type = reset( $matched_types ); } // Set up variables specific to the group creation process. if ( bp_is_groups_component() && bp_is_current_action( 'create' ) && bp_user_can_create_groups() && isset( $_COOKIE [ 'bp_new_group_id' ] ) ) { $bp ->groups->new_group_id = (int) $_COOKIE [ 'bp_new_group_id' ]; } /** * Filters the list of illegal groups names/slugs. * * @since BuddyPress 1.0.0 * * @param array $value Array of illegal group names/slugs. */ $this ->forbidden_names = apply_filters( 'groups_forbidden_names' , array ( 'my-groups' , 'create' , 'invites' , 'send-invites' , 'forum' , 'delete' , 'add' , 'admin' , 'request-membership' , 'members' , 'settings' , 'avatar' , $this ->slug, $this ->root_slug, ) ); // If the user was attempting to access a group, but no group by that name was found, 404. if ( bp_is_groups_component() && empty ( $this ->current_group ) && empty ( $this ->current_directory_type ) && bp_current_action() && ! in_array( bp_current_action(), $this ->forbidden_names ) ) { bp_do_404(); return ; } /** * Filters the preconfigured groups creation steps. * * @since BuddyPress 1.1.0 * * @param array $value Array of preconfigured group creation steps. */ $this ->group_creation_steps = apply_filters( 'groups_create_group_steps' , array ( 'group-details' => array ( 'name' => __( 'Details' , 'buddyboss' ), 'position' => 0 ), 'group-settings' => array ( 'name' => __( 'Settings' , 'buddyboss' ), 'position' => 10 ) ) ); // If avatar uploads are not disabled, add avatar option. $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads(); if ( ! $disabled_avatar_uploads && $bp ->avatar->show_avatars ) { $this ->group_creation_steps[ 'group-avatar' ] = array ( 'name' => __( 'Photo' , 'buddyboss' ), 'position' => 20 ); } if ( bp_group_use_cover_image_header() ) { $this ->group_creation_steps[ 'group-cover-image' ] = array ( 'name' => __( 'Cover Photo' , 'buddyboss' ), 'position' => 25 ); } // If friends component is active, add invitations. if ( bp_is_active( 'friends' ) ) { $this ->group_creation_steps[ 'group-invites' ] = array ( 'name' => __( 'Invites' , 'buddyboss' ), 'position' => 30 ); } /** * Filters the list of valid groups statuses. * * @since BuddyPress 1.1.0 * * @param array $value Array of valid group statuses. */ $this ->valid_status = apply_filters( 'groups_valid_status' , array ( 'public' , 'private' , 'hidden' ) ); // Auto Group Membership Approval when non group member performs group activity. $this ->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true; } /** * Set up canonical stack for this component. * * @since BuddyPress 2.1.0 */ public function setup_canonical_stack() { if ( ! bp_is_groups_component() ) { return ; } if ( empty ( $this ->current_group ) ) { return ; } $customizer_option = 'group_default_tab' ; $default_tab = '' ; if ( function_exists( 'bp_nouveau_get_temporary_setting' ) && function_exists( 'bp_nouveau_get_appearance_settings' ) ) { $default_tab = bp_nouveau_get_temporary_setting( $customizer_option ,bp_nouveau_get_appearance_settings( $customizer_option ) ); } $default_tab = bp_is_active( $default_tab ) ? $default_tab : 'members' ; /** * Filters the default groups extension. * * @since BuddyPress 1.6.0 * * @param string $value BP_GROUPS_DEFAULT_EXTENSION constant if defined, * else 'members'. */ $this ->default_extension = apply_filters( 'bp_groups_default_extension' , defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : ( '' === $default_tab ) ? 'members' : $default_tab ); $bp = buddypress(); $user_has_access = $this ->current_group->user_has_access; $is_visible = $this ->current_group->is_visible; if ( ! $user_has_access && $is_visible ) { $bp ->current_action = 'request-membership' ; } // members are displayed in the front nav. if ( bp_is_current_action( 'home' ) || ! bp_current_action() ) { $bp ->current_action = $this ->default_extension; } // Prepare for a redirect to the canonical URL. $bp ->canonical_stack[ 'base_url' ] = bp_get_group_permalink( $this ->current_group ); if ( bp_current_action() ) { $bp ->canonical_stack[ 'action' ] = bp_current_action(); } if ( ! empty ( $bp ->action_variables ) ) { $bp ->canonical_stack[ 'action_variables' ] = bp_action_variables(); } // When viewing the default extension, the canonical URL should not have // that extension's slug, unless more has been tacked onto the URL via // action variables. if ( bp_is_current_action( $this ->default_extension ) && empty ( $bp ->action_variables ) ) { unset( $bp ->canonical_stack[ 'action' ] ); } } /** * Set up component navigation. * * @since BuddyPress 1.5.0 * * @see BP_Component::setup_nav() for a description of arguments. * * @param array $main_nav Optional. See BP_Component::setup_nav() for description. * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. */ public function setup_nav( $main_nav = array (), $sub_nav = array () ) { $bp = buddypress(); // Determine user to use. if ( bp_displayed_user_domain() ) { $user_domain = bp_displayed_user_domain(); } elseif ( bp_loggedin_user_domain() ) { $user_domain = bp_loggedin_user_domain(); } else { $user_domain = false; } // Only grab count if we're on a user page. if ( bp_is_user() ) { $class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count' ; $nav_name = sprintf( /* translators: %s: Group count for the current user */ __( 'Groups %s' , 'buddyboss' ), sprintf( '<span class="%s">%s</span>' , esc_attr( $class ), bp_get_total_group_count_for_user() ) ); } else { $nav_name = __( 'Groups' , 'buddyboss' ); } $slug = bp_get_groups_slug(); // Add 'Groups' to the main navigation. $main_nav = array ( 'name' => $nav_name , 'slug' => $slug , 'position' => 70, 'screen_function' => 'groups_screen_my_groups' , 'default_subnav_slug' => 'my-groups' , 'item_css_id' => $this ->id ); if ( ! empty ( $user_domain ) ) { $access = bp_core_can_edit_settings(); $groups_link = trailingslashit( $user_domain . $slug ); // Add the My Groups nav item. $sub_nav [] = array ( 'name' => __( 'My Groups' , 'buddyboss' ), 'slug' => 'my-groups' , 'parent_url' => $groups_link , 'parent_slug' => $slug , 'screen_function' => 'groups_screen_my_groups' , 'position' => 10, 'item_css_id' => 'groups-my-groups' ); // Add the Group Invites nav item. $sub_nav [] = array ( 'name' => __( 'Invitations' , 'buddyboss' ), 'slug' => 'invites' , 'parent_url' => $groups_link , 'parent_slug' => $slug , 'screen_function' => 'groups_screen_group_invites' , 'user_has_access' => $access , 'position' => 30 ); parent::setup_nav( $main_nav , $sub_nav ); } if ( bp_is_groups_component() && bp_is_single_item() ) { // Reset sub nav. $sub_nav = array (); /* * The top-level Groups item is called 'Memberships' for legacy reasons. * It does not appear in the interface. */ bp_core_new_nav_item( array ( 'name' => __( 'My Groups' , 'buddyboss' ), 'slug' => $this ->current_group->slug, 'position' => -1, // Do not show in BuddyBar. 'screen_function' => 'groups_screen_group_home' , 'default_subnav_slug' => $this ->default_extension, 'item_css_id' => $this ->id ), 'groups' ); $group_link = bp_get_group_permalink( $this ->current_group ); // Add the "Members" subnav item, as this will always be present. $sub_nav [] = array ( 'name' => sprintf( apply_filters( 'group_single_members_label' , __( 'Members' , 'buddyboss' ) ). __( ' %s' , 'buddyboss' ), '<span>' . number_format( $this ->current_group->total_member_count ) . '</span>' ), 'slug' => 'members' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_members' , 'user_has_access' => $this ->current_group->user_has_access, 'position' => 10, 'item_css_id' => 'members' , ); $members_link = trailingslashit( $group_link . 'members' ); // Common params to all member sub nav items. $default_params = array ( 'parent_url' => $members_link , 'parent_slug' => $this ->current_group->slug . '_members' , 'screen_function' => 'groups_screen_group_members' , 'user_has_access' => $this ->current_group->user_has_access, 'show_in_admin_bar' => true, ); // $sub_nav[] = array_merge( array( // 'name' => __( 'All Members', 'buddyboss' ), // 'slug' => 'all-members', // 'position' => 0, // ), $default_params ); // // $sub_nav[] = array_merge( array( // 'name' => __( 'Group Leaders', 'buddyboss' ), // 'slug' => 'leaders', // 'position' => 10, // ), $default_params ); if ( bp_is_active( 'activity' ) ) { $sub_nav [] = array ( 'name' => __( 'Feed' , 'buddyboss' ), 'slug' => 'activity' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_activity' , 'position' => 11, 'user_has_access' => $this ->current_group->user_has_access, 'item_css_id' => 'activity' , 'no_access_url' => $group_link , ); } if ( bp_enable_group_hierarchies() ) { $descendant_groups = bp_get_descendent_groups( bp_get_current_group_id(), bp_loggedin_user_id() ); if ( $total_descendant = count ( $descendant_groups ) ) { $sub_nav [] = array ( 'name' => sprintf( __( 'Subgroups' , 'buddyboss' ), '<span>' . number_format( $total_descendant ) . '</span>' ), 'slug' => 'subgroups' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_subgroups' , 'position' => 20, 'user_has_access' => $this ->current_group->user_has_access, 'item_css_id' => 'subgroups' , 'no_access_url' => $group_link , ); } } // If this is a private group, and the user is not a // member and does not have an outstanding invitation, // show a "Request Membership" nav item. if ( groups_check_for_membership_request( bp_loggedin_user_id(), $this ->current_group->id ) || bp_current_user_can( 'groups_request_membership' , array ( 'group_id' => $this ->current_group->id ) ) ) { $sub_nav [] = array ( 'name' => __( 'Request Access' , 'buddyboss' ), 'slug' => 'request-membership' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_request_membership' , 'position' => 30 ); } if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) { $sub_nav [] = array ( 'name' => __( 'Send Invites' , 'buddyboss' ), 'slug' => 'send-invites' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_invite' , 'item_css_id' => 'invite' , 'position' => 70, 'user_has_access' => $this ->current_group->user_has_access, 'no_access_url' => $group_link , ); } if ( bp_is_active( 'media' ) && bp_is_group_media_support_enabled() ) { $sub_nav [] = array ( 'name' => __( 'Photos' , 'buddyboss' ), 'slug' => 'photos' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_media' , 'position' => 80, 'user_has_access' => $this ->current_group->user_has_access, 'item_css_id' => 'photos' , 'no_access_url' => $group_link , ); if ( bp_is_group_albums_support_enabled() ) { $sub_nav [] = array ( 'name' => __( 'Albums' , 'buddyboss' ), 'slug' => 'albums' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_albums' , 'position' => 85, 'user_has_access' => $this ->current_group->user_has_access, 'item_css_id' => 'albums' , 'no_access_url' => $group_link , ); } } // If the user is a group admin, then show the group admin nav item. if ( bp_is_item_admin() ) { $sub_nav [] = array ( 'name' => __( 'Manage' , 'buddyboss' ), 'slug' => 'admin' , 'parent_url' => $group_link , 'parent_slug' => $this ->current_group->slug, 'screen_function' => 'groups_screen_group_admin' , 'position' => 1000, 'user_has_access' => true, 'item_css_id' => 'admin' , 'no_access_url' => $group_link , ); $admin_link = trailingslashit( $group_link . 'admin' ); // Common params to all nav items. $default_params = array ( 'parent_url' => $admin_link , 'parent_slug' => $this ->current_group->slug . '_manage' , 'screen_function' => 'groups_screen_group_admin' , 'user_has_access' => bp_is_item_admin(), 'show_in_admin_bar' => true, ); $sub_nav [] = array_merge ( array ( 'name' => __( 'Details' , 'buddyboss' ), 'slug' => 'edit-details' , 'position' => 0, ), $default_params ); $sub_nav [] = array_merge ( array ( 'name' => __( 'Settings' , 'buddyboss' ), 'slug' => 'group-settings' , 'position' => 10, ), $default_params ); if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) { $sub_nav [] = array_merge ( array ( 'name' => __( 'Photo' , 'buddyboss' ), 'slug' => 'group-avatar' , 'position' => 20, ), $default_params ); } if ( bp_group_use_cover_image_header() ) { $sub_nav [] = array_merge ( array ( 'name' => __( 'Cover Photo' , 'buddyboss' ), 'slug' => 'group-cover-image' , 'position' => 25, ), $default_params ); } $sub_nav [] = array_merge ( array ( 'name' => __( 'Members' , 'buddyboss' ), 'slug' => 'manage-members' , 'position' => 30, ), $default_params ); if ( 'private' == $this ->current_group->status ) { $sub_nav [] = array_merge ( array ( 'name' => __( 'Requests' , 'buddyboss' ), 'slug' => 'membership-requests' , 'position' => 40, ), $default_params ); } $sub_nav [] = array_merge ( array ( 'name' => __( 'Delete' , 'buddyboss' ), 'slug' => 'delete-group' , 'position' => 1000, ), $default_params ); } foreach ( $sub_nav as $nav ) { bp_core_new_subnav_item( $nav , 'groups' ); } } if ( isset( $this ->current_group->user_has_access ) ) { /** * Fires at the end of the groups navigation setup if user has access. * * @since BuddyPress 1.0.2 * * @param bool $user_has_access Whether or not user has access. */ do_action( 'groups_setup_nav' , $this ->current_group->user_has_access ); } else { /** This action is documented in bp-groups/bp-groups-loader.php */ do_action( 'groups_setup_nav' ); } } /** * Set up the component entries in the WordPress Admin Bar. * * @since BuddyPress 1.5.0 * * @see BP_Component::setup_nav() for a description of the $wp_admin_nav * parameter array. * * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description. */ public function setup_admin_bar( $wp_admin_nav = array () ) { // Menus for logged in user. if ( is_user_logged_in() ) { // Setup the logged in user variables. $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); // Pending group invites. $count = groups_get_invite_count_for_user(); $title = __( 'Groups' , 'buddyboss' ); $pending = __( 'No Pending Invites' , 'buddyboss' ); if ( ! empty ( $count ) ) { $title = sprintf( /* translators: %s: Group invitation count for the current user */ __( 'Groups %s' , 'buddyboss' ), '<span class="count">' . bp_core_number_format( $count ) . '</span>' ); $pending = sprintf( /* translators: %s: Group invitation count for the current user */ __( 'Pending Invites %s' , 'buddyboss' ), '<span class="count">' . bp_core_number_format( $count ) . '</span>' ); } // Add the "My Account" sub menus. $wp_admin_nav [] = array ( 'parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this ->id, 'title' => $title , 'href' => $groups_link ); // My Groups. $wp_admin_nav [] = array ( 'parent' => 'my-account-' . $this ->id, 'id' => 'my-account-' . $this ->id . '-memberships' , 'title' => __( 'My Groups' , 'buddyboss' ), 'href' => $groups_link , 'position' => 10 ); // Invitations. $wp_admin_nav [] = array ( 'parent' => 'my-account-' . $this ->id, 'id' => 'my-account-' . $this ->id . '-invites' , 'title' => $pending , 'href' => trailingslashit( $groups_link . 'invites' ), 'position' => 30 ); // Create a Group. if ( bp_user_can_create_groups() ) { $wp_admin_nav [] = array ( 'parent' => 'my-account-' . $this ->id, 'id' => 'my-account-' . $this ->id . '-create' , 'title' => __( 'Create Group' , 'buddyboss' ), 'href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ), 'position' => 90 ); } } parent::setup_admin_bar( $wp_admin_nav ); } /** * Set up the title for pages and <title>. * * @since BuddyPress 1.5.0 */ public function setup_title() { if ( bp_is_groups_component() ) { $bp = buddypress(); if ( bp_is_my_profile() && !bp_is_single_item() ) { $bp ->bp_options_title = __( 'My Groups' , 'buddyboss' ); } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) { $bp ->bp_options_avatar = bp_core_fetch_avatar( array ( 'item_id' => bp_displayed_user_id(), 'type' => 'thumb' , 'alt' => sprintf( __( 'Profile photo of %s' , 'buddyboss' ), bp_get_displayed_user_fullname() ) ) ); $bp ->bp_options_title = bp_get_displayed_user_fullname(); // We are viewing a single group, so set up the // group navigation menu using the $this->current_group global. } elseif ( bp_is_single_item() ) { $bp ->bp_options_title = $this ->current_group->name; $bp ->bp_options_avatar = bp_core_fetch_avatar( array ( 'item_id' => $this ->current_group->id, 'object' => 'group' , 'type' => 'thumb' , 'avatar_dir' => 'group-avatars' , 'alt' => __( 'Group Profile Photo' , 'buddyboss' ) ) ); if ( empty ( $bp ->bp_options_avatar ) ) { $bp ->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Group Profile Photo' , 'buddyboss' ) . '" class="avatar" />' ; } } } parent::setup_title(); } /** * Setup cache groups * * @since BuddyPress 2.2.0 */ public function setup_cache_groups() { // Global groups. wp_cache_add_global_groups( array ( 'bp_groups' , 'bp_group_admins' , 'bp_group_invite_count' , 'group_meta' , 'bp_groups_memberships' , 'bp_groups_memberships_for_user' , ) ); parent::setup_cache_groups(); } /** * Set up taxonomies. * * @since BuddyPress 2.6.0 */ public function register_taxonomies() { // Group Type. register_taxonomy( 'bp_group_type' , 'bp_group' , array ( 'public' => false, ) ); } } |
Changelog
Version | Description |
---|---|
BuddyPress 1.5.0 | Introduced. |
Methods
- __construct — Start the groups component creation process.
- includes — Include Groups component files.
- late_includes — Late includes method.
- register_taxonomies — Set up taxonomies.
- rest_api_init — Init the BuddyBoss REST API.
- setup_admin_bar — Set up the component entries in the WordPress Admin Bar.
- setup_cache_groups — Setup cache groups
- setup_canonical_stack — Set up canonical stack for this component.
- setup_globals — Set up component global data.
- setup_nav — Set up component navigation.
- setup_title — Set up the title for pages and .
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.