[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/classes/ -> class-bp-groups-component.php (source)

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


Generated: Thu Sep 19 01:01:39 2019 Cross-referenced by PHPXref 0.7.1