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


Generated: Thu Apr 2 01:01:33 2020 Cross-referenced by PHPXref 0.7.1