Changeset 10520 for trunk/src/bp-groups/bp-groups-loader.php
- Timestamp:
- 02/05/2016 04:55:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-groups/bp-groups-loader.php
r10454 r10520 15 15 defined( 'ABSPATH' ) || exit; 16 16 17 /** 18 * Creates our Groups component. 19 * 20 * @since 1.5.0 21 */ 22 class BP_Groups_Component extends BP_Component { 23 24 /** 25 * Auto-join group when non group member performs group activity. 26 * 27 * @since 1.5.0 28 * @var bool 29 */ 30 public $auto_join; 31 32 /** 33 * The group being currently accessed. 34 * 35 * @since 1.5.0 36 * @var BP_Groups_Group 37 */ 38 public $current_group; 39 40 /** 41 * Default group extension. 42 * 43 * @since 1.6.0 44 * @todo Is this used anywhere? Is this a duplicate of $default_extension? 45 * @var string 46 */ 47 var $default_component; 48 49 /** 50 * Default group extension. 51 * 52 * @since 1.6.0 53 * @var string 54 */ 55 public $default_extension; 56 57 /** 58 * Illegal group names/slugs. 59 * 60 * @since 1.5.0 61 * @var array 62 */ 63 public $forbidden_names; 64 65 /** 66 * Group creation/edit steps (e.g. Details, Settings, Avatar, Invites). 67 * 68 * @since 1.5.0 69 * @var array 70 */ 71 public $group_creation_steps; 72 73 /** 74 * Types of group statuses (Public, Private, Hidden). 75 * 76 * @since 1.5.0 77 * @var array 78 */ 79 public $valid_status; 80 81 /** 82 * Start the groups component creation process. 83 * 84 * @since 1.5.0 85 */ 86 public function __construct() { 87 parent::start( 88 'groups', 89 _x( 'User Groups', 'Group screen page <title>', 'buddypress' ), 90 buddypress()->plugin_dir, 91 array( 92 'adminbar_myaccount_order' => 70, 93 'search_query_arg' => 'groups_search', 94 ) 95 ); 96 } 97 98 /** 99 * Include Groups component files. 100 * 101 * @since 1.5.0 102 * 103 * @see BP_Component::includes() for a description of arguments. 104 * 105 * @param array $includes See BP_Component::includes() for a description. 106 */ 107 public function includes( $includes = array() ) { 108 $includes = array( 109 'cache', 110 'forums', 111 'actions', 112 'filters', 113 'screens', 114 'classes', 115 'widgets', 116 'activity', 117 'template', 118 'adminbar', 119 'functions', 120 'notifications' 121 ); 122 123 if ( is_admin() ) { 124 $includes[] = 'admin'; 125 } 126 127 parent::includes( $includes ); 128 } 129 130 /** 131 * Set up component global data. 132 * 133 * The BP_GROUPS_SLUG constant is deprecated, and only used here for 134 * backwards compatibility. 135 * 136 * @since 1.5.0 137 * 138 * @see BP_Component::setup_globals() for a description of arguments. 139 * 140 * @param array $args See BP_Component::setup_globals() for a description. 141 */ 142 public function setup_globals( $args = array() ) { 143 $bp = buddypress(); 144 145 // Define a slug, if necessary. 146 if ( ! defined( 'BP_GROUPS_SLUG' ) ) { 147 define( 'BP_GROUPS_SLUG', $this->id ); 148 } 149 150 // Global tables for groups component. 151 $global_tables = array( 152 'table_name' => $bp->table_prefix . 'bp_groups', 153 'table_name_members' => $bp->table_prefix . 'bp_groups_members', 154 'table_name_groupmeta' => $bp->table_prefix . 'bp_groups_groupmeta' 155 ); 156 157 // Metadata tables for groups component. 158 $meta_tables = array( 159 'group' => $bp->table_prefix . 'bp_groups_groupmeta', 160 ); 161 162 // All globals for groups component. 163 // Note that global_tables is included in this array. 164 $args = array( 165 'slug' => BP_GROUPS_SLUG, 166 'root_slug' => isset( $bp->pages->groups->slug ) ? $bp->pages->groups->slug : BP_GROUPS_SLUG, 167 'has_directory' => true, 168 'directory_title' => _x( 'Groups', 'component directory title', 'buddypress' ), 169 'notification_callback' => 'groups_format_notifications', 170 'search_string' => _x( 'Search Groups...', 'Component directory search', 'buddypress' ), 171 'global_tables' => $global_tables, 172 'meta_tables' => $meta_tables, 173 ); 174 175 parent::setup_globals( $args ); 176 177 /* Single Group Globals **********************************************/ 178 179 // Are we viewing a single group? 180 if ( bp_is_groups_component() && $group_id = BP_Groups_Group::group_exists( bp_current_action() ) ) { 181 182 $bp->is_single_item = true; 183 184 /** 185 * Filters the current PHP Class being used. 186 * 187 * @since 1.5.0 188 * 189 * @param string $value Name of the class being used. 190 */ 191 $current_group_class = apply_filters( 'bp_groups_current_group_class', 'BP_Groups_Group' ); 192 193 if ( $current_group_class == 'BP_Groups_Group' ) { 194 $this->current_group = groups_get_group( array( 195 'group_id' => $group_id, 196 'populate_extras' => true, 197 ) ); 198 199 } else { 200 201 /** 202 * Filters the current group object being instantiated from previous filter. 203 * 204 * @since 1.5.0 205 * 206 * @param object $value Newly instantiated object for the group. 207 */ 208 $this->current_group = apply_filters( 'bp_groups_current_group_object', new $current_group_class( $group_id ) ); 209 } 210 211 // When in a single group, the first action is bumped down one because of the 212 // group name, so we need to adjust this and set the group name to current_item. 213 $bp->current_item = bp_current_action(); 214 $bp->current_action = bp_action_variable( 0 ); 215 array_shift( $bp->action_variables ); 216 217 // Using "item" not "group" for generic support in other components. 218 if ( bp_current_user_can( 'bp_moderate' ) ) { 219 bp_update_is_item_admin( true, 'groups' ); 220 } else { 221 bp_update_is_item_admin( groups_is_user_admin( bp_loggedin_user_id(), $this->current_group->id ), 'groups' ); 222 } 223 224 // If the user is not an admin, check if they are a moderator. 225 if ( ! bp_is_item_admin() ) { 226 bp_update_is_item_mod ( groups_is_user_mod ( bp_loggedin_user_id(), $this->current_group->id ), 'groups' ); 227 } 228 229 // Is the logged in user a member of the group? 230 if ( ( is_user_logged_in() && groups_is_user_member( bp_loggedin_user_id(), $this->current_group->id ) ) ) { 231 $this->current_group->is_user_member = true; 232 } else { 233 $this->current_group->is_user_member = false; 234 } 235 236 // Should this group be visible to the logged in user? 237 if ( 'public' == $this->current_group->status || $this->current_group->is_user_member ) { 238 $this->current_group->is_visible = true; 239 } else { 240 $this->current_group->is_visible = false; 241 } 242 243 // If this is a private or hidden group, does the user have access? 244 if ( 'private' == $this->current_group->status || 'hidden' == $this->current_group->status ) { 245 if ( $this->current_group->is_user_member && is_user_logged_in() || bp_current_user_can( 'bp_moderate' ) ) { 246 $this->current_group->user_has_access = true; 247 } else { 248 $this->current_group->user_has_access = false; 249 } 250 } else { 251 $this->current_group->user_has_access = true; 252 } 253 254 // Check once if the current group has a custom front template. 255 $this->current_group->front_template = bp_groups_get_front_template( $this->current_group ); 256 257 // Set current_group to 0 to prevent debug errors. 258 } else { 259 $this->current_group = 0; 260 } 261 262 /** 263 * Filters the list of illegal groups names/slugs. 264 * 265 * @since 1.0.0 266 * 267 * @param array $value Array of illegal group names/slugs. 268 */ 269 $this->forbidden_names = apply_filters( 'groups_forbidden_names', array( 270 'my-groups', 271 'create', 272 'invites', 273 'send-invites', 274 'forum', 275 'delete', 276 'add', 277 'admin', 278 'request-membership', 279 'members', 280 'settings', 281 'avatar', 282 $this->slug, 283 $this->root_slug, 284 ) ); 285 286 // If the user was attempting to access a group, but no group by that name was found, 404. 287 if ( bp_is_groups_component() && empty( $this->current_group ) && bp_current_action() && !in_array( bp_current_action(), $this->forbidden_names ) ) { 288 bp_do_404(); 289 return; 290 } 291 292 /** 293 * Filters the preconfigured groups creation steps. 294 * 295 * @since 1.1.0 296 * 297 * @param array $value Array of preconfigured group creation steps. 298 */ 299 $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array( 300 'group-details' => array( 301 'name' => _x( 'Details', 'Group screen nav', 'buddypress' ), 302 'position' => 0 303 ), 304 'group-settings' => array( 305 'name' => _x( 'Settings', 'Group screen nav', 'buddypress' ), 306 'position' => 10 307 ) 308 ) ); 309 310 // If avatar uploads are not disabled, add avatar option. 311 $disabled_avatar_uploads = (int) bp_disable_group_avatar_uploads(); 312 if ( ! $disabled_avatar_uploads && $bp->avatar->show_avatars ) { 313 $this->group_creation_steps['group-avatar'] = array( 314 'name' => _x( 'Photo', 'Group screen nav', 'buddypress' ), 315 'position' => 20 316 ); 317 } 318 319 if ( bp_group_use_cover_image_header() ) { 320 $this->group_creation_steps['group-cover-image'] = array( 321 'name' => _x( 'Cover Image', 'Group screen nav', 'buddypress' ), 322 'position' => 25 323 ); 324 } 325 326 // If friends component is active, add invitations. 327 if ( bp_is_active( 'friends' ) ) { 328 $this->group_creation_steps['group-invites'] = array( 329 'name' => _x( 'Invites', 'Group screen nav', 'buddypress' ), 330 'position' => 30 331 ); 332 } 333 334 /** 335 * Filters the list of valid groups statuses. 336 * 337 * @since 1.1.0 338 * 339 * @param array $value Array of valid group statuses. 340 */ 341 $this->valid_status = apply_filters( 'groups_valid_status', array( 342 'public', 343 'private', 344 'hidden' 345 ) ); 346 347 // Auto join group when non group member performs group activity. 348 $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true; 349 } 350 351 /** 352 * Set up canonical stack for this component. 353 * 354 * @since 2.1.0 355 */ 356 public function setup_canonical_stack() { 357 if ( ! bp_is_groups_component() ) { 358 return; 359 } 360 361 if ( empty( $this->current_group ) ) { 362 return; 363 } 364 365 /** 366 * Filters the default groups extension. 367 * 368 * @since 1.6.0 369 * 370 * @param string $value BP_GROUPS_DEFAULT_EXTENSION constant if defined, 371 * else 'home'. 372 */ 373 $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' ); 374 375 $bp = buddypress(); 376 377 // If the activity component is not active and the current group has no custom front, members are displayed in the home nav. 378 if ( 'members' === $this->default_extension && ! bp_is_active( 'activity' ) && ! $this->current_group->front_template ) { 379 $this->default_extension = 'home'; 380 } 381 382 if ( ! bp_current_action() ) { 383 $bp->current_action = $this->default_extension; 384 } 385 386 // Prepare for a redirect to the canonical URL. 387 $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group ); 388 389 if ( bp_current_action() ) { 390 $bp->canonical_stack['action'] = bp_current_action(); 391 } 392 393 /** 394 * If there's no custom front.php template for the group, we need to make sure the canonical stack action 395 * is set to 'home' in these 2 cases: 396 * 397 * - the current action is 'activity' (eg: site.url/groups/single/activity) and the Activity component is active 398 * - the current action is 'members' (eg: site.url/groups/single/members) and the Activity component is *not* active. 399 */ 400 if ( ! $this->current_group->front_template && ( bp_is_current_action( 'activity' ) || ( ! bp_is_active( 'activity' ) && bp_is_current_action( 'members' ) ) ) ) { 401 $bp->canonical_stack['action'] = 'home'; 402 } 403 404 if ( ! empty( $bp->action_variables ) ) { 405 $bp->canonical_stack['action_variables'] = bp_action_variables(); 406 } 407 408 // When viewing the default extension, the canonical URL should not have 409 // that extension's slug, unless more has been tacked onto the URL via 410 // action variables. 411 if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) ) { 412 unset( $bp->canonical_stack['action'] ); 413 } 414 } 415 416 /** 417 * Set up component navigation. 418 * 419 * @since 1.5.0 420 * 421 * @see BP_Component::setup_nav() for a description of arguments. 422 * 423 * @param array $main_nav Optional. See BP_Component::setup_nav() for description. 424 * @param array $sub_nav Optional. See BP_Component::setup_nav() for description. 425 */ 426 public function setup_nav( $main_nav = array(), $sub_nav = array() ) { 427 428 // Determine user to use. 429 if ( bp_displayed_user_domain() ) { 430 $user_domain = bp_displayed_user_domain(); 431 } elseif ( bp_loggedin_user_domain() ) { 432 $user_domain = bp_loggedin_user_domain(); 433 } else { 434 $user_domain = false; 435 } 436 437 // Only grab count if we're on a user page. 438 if ( bp_is_user() ) { 439 $class = ( 0 === groups_total_groups_for_user( bp_displayed_user_id() ) ) ? 'no-count' : 'count'; 440 $nav_name = sprintf( _x( 'Groups <span class="%s">%s</span>', 'Group screen nav with counter', 'buddypress' ), esc_attr( $class ), bp_get_total_group_count_for_user() ); 441 } else { 442 $nav_name = _x( 'Groups', 'Group screen nav without counter', 'buddypress' ); 443 } 444 445 $slug = bp_get_groups_slug(); 446 447 // Add 'Groups' to the main navigation. 448 $main_nav = array( 449 'name' => $nav_name, 450 'slug' => $slug, 451 'position' => 70, 452 'screen_function' => 'groups_screen_my_groups', 453 'default_subnav_slug' => 'my-groups', 454 'item_css_id' => $this->id 455 ); 456 457 if ( ! empty( $user_domain ) ) { 458 $access = bp_core_can_edit_settings(); 459 $groups_link = trailingslashit( $user_domain . $slug ); 460 461 // Add the My Groups nav item. 462 $sub_nav[] = array( 463 'name' => __( 'Memberships', 'buddypress' ), 464 'slug' => 'my-groups', 465 'parent_url' => $groups_link, 466 'parent_slug' => $slug, 467 'screen_function' => 'groups_screen_my_groups', 468 'position' => 10, 469 'item_css_id' => 'groups-my-groups' 470 ); 471 472 // Add the Group Invites nav item. 473 $sub_nav[] = array( 474 'name' => __( 'Invitations', 'buddypress' ), 475 'slug' => 'invites', 476 'parent_url' => $groups_link, 477 'parent_slug' => $slug, 478 'screen_function' => 'groups_screen_group_invites', 479 'user_has_access' => $access, 480 'position' => 30 481 ); 482 483 parent::setup_nav( $main_nav, $sub_nav ); 484 } 485 486 if ( bp_is_groups_component() && bp_is_single_item() ) { 487 488 // Reset sub nav. 489 $sub_nav = array(); 490 491 // Add 'Groups' to the main navigation. 492 $main_nav = array( 493 'name' => __( 'Memberships', 'buddypress' ), 494 'slug' => $this->current_group->slug, 495 'position' => -1, // Do not show in BuddyBar. 496 'screen_function' => 'groups_screen_group_home', 497 'default_subnav_slug' => $this->default_extension, 498 'item_css_id' => $this->id 499 ); 500 501 $group_link = bp_get_group_permalink( $this->current_group ); 502 503 // Add the "Home" subnav item, as this will always be present. 504 $sub_nav[] = array( 505 'name' => _x( 'Home', 'Group screen navigation title', 'buddypress' ), 506 'slug' => 'home', 507 'parent_url' => $group_link, 508 'parent_slug' => $this->current_group->slug, 509 'screen_function' => 'groups_screen_group_home', 510 'position' => 10, 511 'item_css_id' => 'home' 512 ); 513 514 // If this is a private group, and the user is not a 515 // member and does not have an outstanding invitation, 516 // show a "Request Membership" nav item. 517 if ( is_user_logged_in() && 518 ! $this->current_group->is_user_member && 519 ! groups_check_for_membership_request( bp_loggedin_user_id(), $this->current_group->id ) && 520 $this->current_group->status == 'private' && 521 ! groups_check_user_has_invite( bp_loggedin_user_id(), $this->current_group->id ) 522 ) { 523 524 $sub_nav[] = array( 525 'name' => _x( 'Request Membership','Group screen nav', 'buddypress' ), 526 'slug' => 'request-membership', 527 'parent_url' => $group_link, 528 'parent_slug' => $this->current_group->slug, 529 'screen_function' => 'groups_screen_group_request_membership', 530 'position' => 30 531 ); 532 } 533 534 // Forums are enabled and turned on. 535 if ( $this->current_group->enable_forum && bp_is_active( 'forums' ) ) { 536 $sub_nav[] = array( 537 'name' => _x( 'Forum', 'My Group screen nav', 'buddypress' ), 538 'slug' => 'forum', 539 'parent_url' => $group_link, 540 'parent_slug' => $this->current_group->slug, 541 'screen_function' => 'groups_screen_group_forum', 542 'position' => 40, 543 'user_has_access' => $this->current_group->user_has_access, 544 'item_css_id' => 'forums' 545 ); 546 } 547 548 if ( $this->current_group->front_template || bp_is_active( 'activity' ) ) { 549 /** 550 * If the theme is using a custom front, create activity subnav. 551 */ 552 if ( $this->current_group->front_template && bp_is_active( 'activity' ) ) { 553 $sub_nav[] = array( 554 'name' => _x( 'Activity', 'My Group screen nav', 'buddypress' ), 555 'slug' => 'activity', 556 'parent_url' => $group_link, 557 'parent_slug' => $this->current_group->slug, 558 'screen_function' => 'groups_screen_group_activity', 559 'position' => 11, 560 'user_has_access' => $this->current_group->user_has_access, 561 'item_css_id' => 'activity', 562 'no_access_url' => $group_link, 563 ); 564 } 565 566 /** 567 * Only add the members subnav if it's not the home's nav. 568 */ 569 $sub_nav[] = array( 570 'name' => sprintf( _x( 'Members %s', 'My Group screen nav', 'buddypress' ), '<span>' . number_format( $this->current_group->total_member_count ) . '</span>' ), 571 'slug' => 'members', 572 'parent_url' => $group_link, 573 'parent_slug' => $this->current_group->slug, 574 'screen_function' => 'groups_screen_group_members', 575 'position' => 60, 576 'user_has_access' => $this->current_group->user_has_access, 577 'item_css_id' => 'members', 578 'no_access_url' => $group_link, 579 ); 580 } 581 582 if ( bp_is_active( 'friends' ) && bp_groups_user_can_send_invites() ) { 583 $sub_nav[] = array( 584 'name' => _x( 'Send Invites', 'My Group screen nav', 'buddypress' ), 585 'slug' => 'send-invites', 586 'parent_url' => $group_link, 587 'parent_slug' => $this->current_group->slug, 588 'screen_function' => 'groups_screen_group_invite', 589 'item_css_id' => 'invite', 590 'position' => 70, 591 'user_has_access' => $this->current_group->user_has_access, 592 'no_access_url' => $group_link, 593 ); 594 } 595 596 // If the user is a group admin, then show the group admin nav item. 597 if ( bp_is_item_admin() ) { 598 $sub_nav[] = array( 599 'name' => _x( 'Manage', 'My Group screen nav', 'buddypress' ), 600 'slug' => 'admin', 601 'parent_url' => $group_link, 602 'parent_slug' => $this->current_group->slug, 603 'screen_function' => 'groups_screen_group_admin', 604 'position' => 1000, 605 'user_has_access' => true, 606 'item_css_id' => 'admin', 607 'no_access_url' => $group_link, 608 ); 609 610 $admin_link = trailingslashit( $group_link . 'admin' ); 611 612 // Common params to all nav items. 613 $default_params = array( 614 'parent_url' => $admin_link, 615 'parent_slug' => $this->current_group->slug . '_manage', 616 'screen_function' => 'groups_screen_group_admin', 617 'user_has_access' => bp_is_item_admin(), 618 'show_in_admin_bar' => true, 619 ); 620 621 $sub_nav[] = array_merge( array( 622 'name' => __( 'Details', 'buddypress' ), 623 'slug' => 'edit-details', 624 'position' => 0, 625 ), $default_params ); 626 627 $sub_nav[] = array_merge( array( 628 'name' => __( 'Settings', 'buddypress' ), 629 'slug' => 'group-settings', 630 'position' => 10, 631 ), $default_params ); 632 633 if ( ! bp_disable_group_avatar_uploads() && buddypress()->avatar->show_avatars ) { 634 $sub_nav[] = array_merge( array( 635 'name' => __( 'Photo', 'buddypress' ), 636 'slug' => 'group-avatar', 637 'position' => 20, 638 ), $default_params ); 639 } 640 641 if ( bp_group_use_cover_image_header() ) { 642 $sub_nav[] = array_merge( array( 643 'name' => __( 'Cover Image', 'buddypress' ), 644 'slug' => 'group-cover-image', 645 'position' => 25, 646 ), $default_params ); 647 } 648 649 $sub_nav[] = array_merge( array( 650 'name' => __( 'Members', 'buddypress' ), 651 'slug' => 'manage-members', 652 'position' => 30, 653 ), $default_params ); 654 655 if ( 'private' == $this->current_group->status ) { 656 $sub_nav[] = array_merge( array( 657 'name' => __( 'Requests', 'buddypress' ), 658 'slug' => 'membership-requests', 659 'position' => 40, 660 ), $default_params ); 661 } 662 663 $sub_nav[] = array_merge( array( 664 'name' => __( 'Delete', 'buddypress' ), 665 'slug' => 'delete-group', 666 'position' => 1000, 667 ), $default_params ); 668 } 669 670 parent::setup_nav( $main_nav, $sub_nav ); 671 } 672 673 if ( isset( $this->current_group->user_has_access ) ) { 674 675 /** 676 * Fires at the end of the groups navigation setup if user has access. 677 * 678 * @since 1.0.2 679 * 680 * @param bool $user_has_access Whether or not user has access. 681 */ 682 do_action( 'groups_setup_nav', $this->current_group->user_has_access ); 683 } else { 684 685 /** This action is documented in bp-groups/bp-groups-loader.php */ 686 do_action( 'groups_setup_nav'); 687 } 688 } 689 690 /** 691 * Set up the component entries in the WordPress Admin Bar. 692 * 693 * @since 1.5.0 694 * 695 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav 696 * parameter array. 697 * 698 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description. 699 */ 700 public function setup_admin_bar( $wp_admin_nav = array() ) { 701 702 // Menus for logged in user. 703 if ( is_user_logged_in() ) { 704 705 // Setup the logged in user variables. 706 $groups_link = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ); 707 708 // Pending group invites. 709 $count = groups_get_invite_count_for_user(); 710 $title = _x( 'Groups', 'My Account Groups', 'buddypress' ); 711 $pending = _x( 'No Pending Invites', 'My Account Groups sub nav', 'buddypress' ); 712 713 if ( ! empty( $count['total'] ) ) { 714 $title = sprintf( _x( 'Groups <span class="count">%s</span>', 'My Account Groups nav', 'buddypress' ), bp_core_number_format( $count ) ); 715 $pending = sprintf( _x( 'Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress' ), bp_core_number_format( $count ) ); 716 } 717 718 // Add the "My Account" sub menus. 719 $wp_admin_nav[] = array( 720 'parent' => buddypress()->my_account_menu_id, 721 'id' => 'my-account-' . $this->id, 722 'title' => $title, 723 'href' => $groups_link 724 ); 725 726 // My Groups. 727 $wp_admin_nav[] = array( 728 'parent' => 'my-account-' . $this->id, 729 'id' => 'my-account-' . $this->id . '-memberships', 730 'title' => _x( 'Memberships', 'My Account Groups sub nav', 'buddypress' ), 731 'href' => $groups_link 732 ); 733 734 // Invitations. 735 $wp_admin_nav[] = array( 736 'parent' => 'my-account-' . $this->id, 737 'id' => 'my-account-' . $this->id . '-invites', 738 'title' => $pending, 739 'href' => trailingslashit( $groups_link . 'invites' ) 740 ); 741 742 // Create a Group. 743 if ( bp_user_can_create_groups() ) { 744 $wp_admin_nav[] = array( 745 'parent' => 'my-account-' . $this->id, 746 'id' => 'my-account-' . $this->id . '-create', 747 'title' => _x( 'Create a Group', 'My Account Groups sub nav', 'buddypress' ), 748 'href' => trailingslashit( bp_get_groups_directory_permalink() . 'create' ) 749 ); 750 } 751 } 752 753 parent::setup_admin_bar( $wp_admin_nav ); 754 } 755 756 /** 757 * Set up the title for pages and <title>. 758 * 759 * @since 1.5.0 760 */ 761 public function setup_title() { 762 763 if ( bp_is_groups_component() ) { 764 $bp = buddypress(); 765 766 if ( bp_is_my_profile() && !bp_is_single_item() ) { 767 $bp->bp_options_title = _x( 'Memberships', 'My Groups page <title>', 'buddypress' ); 768 769 } elseif ( !bp_is_my_profile() && !bp_is_single_item() ) { 770 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 771 'item_id' => bp_displayed_user_id(), 772 'type' => 'thumb', 773 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_get_displayed_user_fullname() ) 774 ) ); 775 $bp->bp_options_title = bp_get_displayed_user_fullname(); 776 777 // We are viewing a single group, so set up the 778 // group navigation menu using the $this->current_group global. 779 } elseif ( bp_is_single_item() ) { 780 $bp->bp_options_title = $this->current_group->name; 781 $bp->bp_options_avatar = bp_core_fetch_avatar( array( 782 'item_id' => $this->current_group->id, 783 'object' => 'group', 784 'type' => 'thumb', 785 'avatar_dir' => 'group-avatars', 786 'alt' => __( 'Group Profile Photo', 'buddypress' ) 787 ) ); 788 789 if ( empty( $bp->bp_options_avatar ) ) { 790 $bp->bp_options_avatar = '<img src="' . esc_url( bp_core_avatar_default_thumb() ) . '" alt="' . esc_attr__( 'No Group Profile Photo', 'buddypress' ) . '" class="avatar" />'; 791 } 792 } 793 } 794 795 parent::setup_title(); 796 } 797 798 /** 799 * Setup cache groups 800 * 801 * @since 2.2.0 802 */ 803 public function setup_cache_groups() { 804 805 // Global groups. 806 wp_cache_add_global_groups( array( 807 'bp_groups', 808 'bp_group_admins', 809 'bp_group_invite_count', 810 'group_meta' 811 ) ); 812 813 parent::setup_cache_groups(); 814 } 815 } 17 require dirname( __FILE__ ) . '/classes/class-bp-groups-component.php'; 816 18 817 19 /**
Note: See TracChangeset
for help on using the changeset viewer.