[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Member Loader.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Members
   7   * @since 1.5.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Defines the BuddyPress Members Component.
  15   *
  16   * @since 1.5.0
  17   */
  18  class BP_Members_Component extends BP_Component {
  19  
  20      /**
  21       * Member types.
  22       *
  23       * @see bp_register_member_type()
  24       *
  25       * @since 2.2.0
  26       * @var array
  27       */
  28      public $types = array();
  29  
  30      /**
  31       * Start the members component creation process.
  32       *
  33       * @since 1.5.0
  34       */
  35  	public function __construct() {
  36          parent::start(
  37              'members',
  38              __( 'Members', 'buddypress' ),
  39              buddypress()->plugin_dir,
  40              array(
  41                  'adminbar_myaccount_order' => 20,
  42                  'search_query_arg'         => 'members_search',
  43                  'features'                 => array( 'invitations' )
  44              )
  45          );
  46      }
  47  
  48      /**
  49       * Include bp-members files.
  50       *
  51       * @since 1.5.0
  52       *
  53       * @see BP_Component::includes() for description of parameters.
  54       *
  55       * @param array $includes See {@link BP_Component::includes()}.
  56       */
  57  	public function includes( $includes = array() ) {
  58  
  59          // Always include these files.
  60          $includes = array(
  61              'cssjs',
  62              'filters',
  63              'template',
  64              'adminbar',
  65              'functions',
  66              'blocks',
  67              'widgets',
  68              'cache',
  69              'invitations',
  70              'notifications',
  71          );
  72  
  73          if ( bp_is_active( 'activity' ) ) {
  74              $includes[] = 'activity';
  75          }
  76  
  77          // Include these only if in admin.
  78          if ( is_admin() ) {
  79              $includes[] = 'admin';
  80          }
  81  
  82          parent::includes( $includes );
  83      }
  84  
  85      /**
  86       * Late includes method.
  87       *
  88       * Only load up certain code when on specific pages.
  89       *
  90       * @since 3.0.0
  91       */
  92  	public function late_includes() {
  93          // Bail if PHPUnit is running.
  94          if ( defined( 'BP_TESTS_DIR' ) ) {
  95              return;
  96          }
  97  
  98          // Members.
  99          if ( bp_is_members_component() ) {
 100              // Actions - Random member handler.
 101              if ( isset( $_GET['random-member'] ) ) {
 102                  require $this->path . 'bp-members/actions/random.php';
 103              }
 104  
 105              // Screens - Directory.
 106              if ( bp_is_members_directory() ) {
 107                  require $this->path . 'bp-members/screens/directory.php';
 108              }
 109          }
 110  
 111          // Members - User main nav screen.
 112          if ( bp_is_user() ) {
 113              require $this->path . 'bp-members/screens/profile.php';
 114  
 115              // Action - Delete avatar.
 116              if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
 117                  require $this->path . 'bp-members/actions/delete-avatar.php';
 118              }
 119  
 120              // Sub-nav items.
 121              if ( is_user_logged_in() &&
 122                  in_array( bp_current_action(), array( 'change-avatar', 'change-cover-image' ), true )
 123              ) {
 124                  require $this->path . 'bp-members/screens/' . bp_current_action() . '.php';
 125              }
 126          }
 127  
 128          // Members - Theme compatibility.
 129          if ( bp_is_members_component() || bp_is_user() ) {
 130              new BP_Members_Theme_Compat();
 131          }
 132  
 133          // Registration / Activation.
 134          if ( bp_is_register_page() || bp_is_activation_page() ) {
 135              if ( bp_is_register_page() ) {
 136                  require $this->path . 'bp-members/screens/register.php';
 137              } else {
 138                  require $this->path . 'bp-members/screens/activate.php';
 139              }
 140  
 141              // Theme compatibility.
 142              new BP_Registration_Theme_Compat();
 143          }
 144  
 145          // Invitations.
 146          if ( is_user_logged_in() && bp_is_user_members_invitations() ) {
 147              // Actions.
 148              if ( isset( $_POST['members_invitations'] ) ) {
 149                  require $this->path . 'bp-members/actions/invitations-bulk-manage.php';
 150              }
 151  
 152              // Screens.
 153              require $this->path . 'bp-members/screens/invitations.php';
 154          }
 155      }
 156  
 157      /**
 158       * Set up bp-members global settings.
 159       *
 160       * The BP_MEMBERS_SLUG constant is deprecated, and only used here for
 161       * backwards compatibility.
 162       *
 163       * @since 1.5.0
 164       *
 165       * @see BP_Component::setup_globals() for description of parameters.
 166       *
 167       * @param array $args See {@link BP_Component::setup_globals()}.
 168       */
 169  	public function setup_globals( $args = array() ) {
 170          global $wpdb;
 171  
 172          $bp = buddypress();
 173  
 174          /** Component Globals ************************************************
 175           */
 176  
 177          // Define a slug, as a fallback for backpat.
 178          if ( !defined( 'BP_MEMBERS_SLUG' ) ) {
 179              define( 'BP_MEMBERS_SLUG', $this->id );
 180          }
 181  
 182          // Fetch the default directory title.
 183          $default_directory_titles = bp_core_get_directory_page_default_titles();
 184          $default_directory_title  = $default_directory_titles[$this->id];
 185  
 186          // Override any passed args.
 187          $args = array(
 188              'slug'            => BP_MEMBERS_SLUG,
 189              'root_slug'       => isset( $bp->pages->members->slug ) ? $bp->pages->members->slug : BP_MEMBERS_SLUG,
 190              'has_directory'   => true,
 191              'directory_title' => isset( $bp->pages->members->title ) ? $bp->pages->members->title : $default_directory_title,
 192              'search_string'   => __( 'Search Members...', 'buddypress' ),
 193              'global_tables'   => array(
 194                  'table_name_invitations'   => bp_core_get_table_prefix() . 'bp_invitations',
 195                  'table_name_last_activity' => bp_core_get_table_prefix() . 'bp_activity',
 196                  'table_name_optouts'       => bp_core_get_table_prefix() . 'bp_optouts',
 197                  'table_name_signups'       => $wpdb->base_prefix . 'signups', // Signups is a global WordPress table.
 198              ),
 199              'notification_callback' => 'members_format_notifications',
 200              'block_globals'         => array(
 201                  'bp/dynamic-members' => array(
 202                      'widget_classnames' => array( 'widget_bp_core_members_widget', 'buddypress' ),
 203                  ),
 204                  'bp/online-members' => array(
 205                      'widget_classnames' => array( 'widget_bp_core_whos_online_widget', 'buddypress' ),
 206                  ),
 207                  'bp/active-members' => array(
 208                      'widget_classnames' => array( 'widget_bp_core_recently_active_widget', 'buddypress' ),
 209                  ),
 210              ),
 211          );
 212  
 213          parent::setup_globals( $args );
 214  
 215          /** Logged in user ***************************************************
 216           */
 217  
 218          // The core userdata of the user who is currently logged in.
 219          $bp->loggedin_user->userdata       = bp_core_get_core_userdata( bp_loggedin_user_id() );
 220  
 221          // Fetch the full name for the logged in user.
 222          $bp->loggedin_user->fullname       = isset( $bp->loggedin_user->userdata->display_name ) ? $bp->loggedin_user->userdata->display_name : '';
 223  
 224          // Hits the DB on single WP installs so get this separately.
 225          $bp->loggedin_user->is_super_admin = $bp->loggedin_user->is_site_admin = is_super_admin( bp_loggedin_user_id() );
 226  
 227          // The domain for the user currently logged in. eg: http://example.com/members/andy.
 228          $bp->loggedin_user->domain         = bp_core_get_user_domain( bp_loggedin_user_id() );
 229  
 230          /** Displayed user ***************************************************
 231           */
 232  
 233          // The core userdata of the user who is currently being displayed.
 234          $bp->displayed_user->userdata = bp_core_get_core_userdata( bp_displayed_user_id() );
 235  
 236          // Fetch the full name displayed user.
 237          $bp->displayed_user->fullname = isset( $bp->displayed_user->userdata->display_name ) ? $bp->displayed_user->userdata->display_name : '';
 238  
 239          // The domain for the user currently being displayed.
 240          $bp->displayed_user->domain   = bp_core_get_user_domain( bp_displayed_user_id() );
 241  
 242          // Initialize the nav for the members component.
 243          $this->nav = new BP_Core_Nav();
 244  
 245          // If A user is displayed, check if there is a front template
 246          if ( bp_get_displayed_user() ) {
 247              $bp->displayed_user->front_template = bp_displayed_user_get_front_template();
 248          }
 249  
 250          /** Signup ***********************************************************
 251           */
 252  
 253          $bp->signup = new stdClass;
 254  
 255          /** Profiles Fallback ************************************************
 256           */
 257  
 258          if ( ! bp_is_active( 'xprofile' ) ) {
 259              $bp->profile       = new stdClass;
 260              $bp->profile->slug = 'profile';
 261              $bp->profile->id   = 'profile';
 262          }
 263  
 264          /** Network Invitations **************************************************
 265           */
 266  
 267          $bp->members->invitations = new stdClass;
 268      }
 269  
 270      /**
 271       * Set up canonical stack for this component.
 272       *
 273       * @since 2.1.0
 274       */
 275  	public function setup_canonical_stack() {
 276          $bp = buddypress();
 277  
 278          /** Default Profile Component ****************************************
 279           */
 280          if ( bp_displayed_user_has_front_template() ) {
 281              $bp->default_component = 'front';
 282          } elseif ( bp_is_active( 'activity' ) && isset( $bp->pages->activity ) ) {
 283              $bp->default_component = bp_get_activity_slug();
 284          } else {
 285              $bp->default_component = ( 'xprofile' === $bp->profile->id ) ? 'profile' : $bp->profile->id;
 286          }
 287  
 288          if ( defined( 'BP_DEFAULT_COMPONENT' ) && BP_DEFAULT_COMPONENT ) {
 289              $default_component = BP_DEFAULT_COMPONENT;
 290              if ( 'profile' === $default_component ) {
 291                  $default_component = 'xprofile';
 292              }
 293  
 294              if ( bp_is_active( $default_component ) ) {
 295                  $bp->default_component = BP_DEFAULT_COMPONENT;
 296              }
 297          }
 298  
 299          /** Canonical Component Stack ****************************************
 300           */
 301  
 302          if ( bp_displayed_user_id() ) {
 303              $bp->canonical_stack['base_url'] = bp_displayed_user_domain();
 304  
 305              if ( bp_current_component() ) {
 306                  $bp->canonical_stack['component'] = bp_current_component();
 307              }
 308  
 309              if ( bp_current_action() ) {
 310                  $bp->canonical_stack['action'] = bp_current_action();
 311              }
 312  
 313              if ( !empty( $bp->action_variables ) ) {
 314                  $bp->canonical_stack['action_variables'] = bp_action_variables();
 315              }
 316  
 317              // Looking at the single member root/home, so assume the default.
 318              if ( ! bp_current_component() ) {
 319                  $bp->current_component = $bp->default_component;
 320  
 321              // The canonical URL will not contain the default component.
 322              } elseif ( bp_is_current_component( $bp->default_component ) && ! bp_current_action() ) {
 323                  unset( $bp->canonical_stack['component'] );
 324              }
 325  
 326              // If we're on a spammer's profile page, only users with the 'bp_moderate' cap
 327              // can view subpages on the spammer's profile.
 328              //
 329              // users without the cap trying to access a spammer's subnav page will get
 330              // redirected to the root of the spammer's profile page.  this occurs by
 331              // by removing the component in the canonical stack.
 332              if ( bp_is_user_spammer( bp_displayed_user_id() ) && ! bp_current_user_can( 'bp_moderate' ) ) {
 333                  unset( $bp->canonical_stack['component'] );
 334              }
 335          }
 336      }
 337  
 338      /**
 339       * Get the Avatar and Cover image subnavs.
 340       *
 341       * @since 6.0.0
 342       *
 343       * @return array The Avatar and Cover image subnavs.
 344       */
 345  	public function get_avatar_cover_image_subnavs() {
 346          $subnavs = array();
 347  
 348          $access       = bp_core_can_edit_settings();
 349          $slug         = bp_get_profile_slug();
 350          $profile_link = bp_get_members_component_link( buddypress()->profile->id );
 351  
 352          // Change Avatar.
 353          if ( buddypress()->avatar->show_avatars ) {
 354              $subnavs[] = array(
 355                  'name'            => _x( 'Change Profile Photo', 'Profile header sub menu', 'buddypress' ),
 356                  'slug'            => 'change-avatar',
 357                  'parent_url'      => $profile_link,
 358                  'parent_slug'     => $slug,
 359                  'screen_function' => 'bp_members_screen_change_avatar',
 360                  'position'        => 30,
 361                  'user_has_access' => $access
 362              );
 363          }
 364  
 365          // Change Cover image.
 366          if ( bp_displayed_user_use_cover_image_header() ) {
 367              $subnavs[] = array(
 368                  'name'            => _x( 'Change Cover Image', 'Profile header sub menu', 'buddypress' ),
 369                  'slug'            => 'change-cover-image',
 370                  'parent_url'      => $profile_link,
 371                  'parent_slug'     => $slug,
 372                  'screen_function' => 'bp_members_screen_change_cover_image',
 373                  'position'        => 40,
 374                  'user_has_access' => $access
 375              );
 376          }
 377  
 378          return $subnavs;
 379      }
 380  
 381      /**
 382       * Set up fall-back component navigation if XProfile is inactive.
 383       *
 384       * @since 1.5.0
 385       *
 386       * @see BP_Component::setup_nav() for a description of arguments.
 387       *
 388       * @param array $main_nav Optional. See BP_Component::setup_nav() for
 389       *                        description.
 390       * @param array $sub_nav  Optional. See BP_Component::setup_nav() for
 391       *                        description.
 392       */
 393  	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
 394  
 395          // Don't set up navigation if there's no member.
 396          if ( ! is_user_logged_in() && ! bp_is_user() ) {
 397              return;
 398          }
 399  
 400          $is_xprofile_active = bp_is_active( 'xprofile' );
 401  
 402          // Bail if XProfile component is active and there's no custom front page for the user.
 403          if ( ! bp_displayed_user_has_front_template() && $is_xprofile_active ) {
 404              add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
 405              return;
 406          }
 407  
 408          // Determine user to use.
 409          if ( bp_displayed_user_domain() ) {
 410              $user_domain = bp_displayed_user_domain();
 411          } elseif ( bp_loggedin_user_domain() ) {
 412              $user_domain = bp_loggedin_user_domain();
 413          } else {
 414              return;
 415          }
 416  
 417          // Set slug to profile in case the xProfile component is not active
 418          $slug = bp_get_profile_slug();
 419  
 420          // Defaults to empty navs
 421          $this->main_nav = array();
 422          $this->sub_nav  = array();
 423  
 424          if ( ! $is_xprofile_active ) {
 425              $this->main_nav = array(
 426                  'name'                => _x( 'Profile', 'Member profile main navigation', 'buddypress' ),
 427                  'slug'                => $slug,
 428                  'position'            => 20,
 429                  'screen_function'     => 'bp_members_screen_display_profile',
 430                  'default_subnav_slug' => 'public',
 431                  'item_css_id'         => buddypress()->profile->id
 432              );
 433  
 434          /**
 435           * The xProfile component is active.
 436           *
 437           * We need to make sure the Change Avatar and Change Cover Image subnavs are
 438           * added just like it was the case before.
 439           */
 440          } else {
 441              add_action( 'bp_xprofile_setup_nav', array( $this, 'setup_xprofile_nav' ) );
 442          }
 443  
 444          /**
 445           * Setup the subnav items for the member profile.
 446           *
 447           * This is required in case there's a custom front or in case the xprofile component
 448           * is not active.
 449           */
 450          $this->sub_nav = array(
 451              'name'            => _x( 'View', 'Member profile view', 'buddypress' ),
 452              'slug'            => 'public',
 453              'parent_url'      => trailingslashit( $user_domain . $slug ),
 454              'parent_slug'     => $slug,
 455              'screen_function' => 'bp_members_screen_display_profile',
 456              'position'        => 10
 457          );
 458  
 459          /**
 460           * If there's a front template the members component nav
 461           * will be there to display the user's front page.
 462           */
 463          if ( bp_displayed_user_has_front_template() ) {
 464              $main_nav = array(
 465                  'name'                => _x( 'Home', 'Member Home page', 'buddypress' ),
 466                  'slug'                => 'front',
 467                  'position'            => 5,
 468                  'screen_function'     => 'bp_members_screen_display_profile',
 469                  'default_subnav_slug' => 'public',
 470              );
 471  
 472              // We need a dummy subnav for the front page to load.
 473              $front_subnav = $this->sub_nav;
 474              $front_subnav['parent_slug'] = 'front';
 475  
 476              // In case the subnav is displayed in the front template
 477              $front_subnav['parent_url'] = trailingslashit( $user_domain . 'front' );
 478  
 479              // Set the subnav
 480              $sub_nav[] = $front_subnav;
 481  
 482              /**
 483               * If the profile component is not active, we need to create a new
 484               * nav to display the WordPress profile.
 485               */
 486              if ( ! $is_xprofile_active ) {
 487                  add_action( 'bp_members_setup_nav', array( $this, 'setup_profile_nav' ) );
 488              }
 489  
 490          /**
 491           * If there's no front template and xProfile is not active, the members
 492           * component nav will be there to display the WordPress profile
 493           */
 494          } else {
 495              $main_nav  = $this->main_nav;
 496              $sub_nav   = array( $this->sub_nav );
 497  
 498              if ( ! $is_xprofile_active ) {
 499                  $sub_nav = array_merge( $sub_nav, $this->get_avatar_cover_image_subnavs() );
 500              }
 501          }
 502  
 503          parent::setup_nav( $main_nav, $sub_nav );
 504      }
 505  
 506      /**
 507       * Set up a profile nav in case the xProfile
 508       * component is not active and a front template is
 509       * used.
 510       *
 511       * @since 2.6.0
 512       */
 513  	public function setup_profile_nav() {
 514          if ( empty( $this->main_nav ) || empty( $this->sub_nav ) ) {
 515              return;
 516          }
 517  
 518          // Add the main nav
 519          bp_core_new_nav_item( $this->main_nav, 'members' );
 520  
 521          // Add the sub nav item.
 522          bp_core_new_subnav_item( $this->sub_nav, 'members' );
 523  
 524          // Get the Avatar and cover image subnavs.
 525          $this->setup_xprofile_nav();
 526      }
 527  
 528      /**
 529       * Set up the xProfile nav.
 530       *
 531       * @since 6.0.0
 532       */
 533  	public function setup_xprofile_nav() {
 534          // Get the Avatar and cover image subnavs.
 535          $items = $this->get_avatar_cover_image_subnavs();
 536  
 537          foreach ( $items as $item ) {
 538              bp_core_new_subnav_item( $item, 'members' );
 539          }
 540      }
 541  
 542      /**
 543       * Get the Avatar and Cover image admin navs.
 544       *
 545       * @since 6.0.0
 546       *
 547       * @param  string $admin_bar_menu_id The Admin bar menu ID to attach sub items to.
 548       * @return array                     The Avatar and Cover image admin navs.
 549       */
 550  	public function get_avatar_cover_image_admin_navs( $admin_bar_menu_id = '' ) {
 551          $wp_admin_nav = array();
 552          $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
 553  
 554          if ( ! $admin_bar_menu_id ) {
 555              $admin_bar_menu_id = $this->id;
 556          }
 557  
 558          // Edit Avatar.
 559          if ( buddypress()->avatar->show_avatars ) {
 560              $wp_admin_nav[] = array(
 561                  'parent'   => 'my-account-' . $admin_bar_menu_id,
 562                  'id'       => 'my-account-' . $admin_bar_menu_id . '-change-avatar',
 563                  'title'    => _x( 'Change Profile Photo', 'My Account Profile sub nav', 'buddypress' ),
 564                  'href'     => trailingslashit( $profile_link . 'change-avatar' ),
 565                  'position' => 30
 566              );
 567          }
 568  
 569          // Edit Cover Image
 570          if ( bp_displayed_user_use_cover_image_header() ) {
 571              $wp_admin_nav[] = array(
 572                  'parent'   => 'my-account-' . $admin_bar_menu_id,
 573                  'id'       => 'my-account-' . $admin_bar_menu_id . '-change-cover-image',
 574                  'title'    => _x( 'Change Cover Image', 'My Account Profile sub nav', 'buddypress' ),
 575                  'href'     => trailingslashit( $profile_link . 'change-cover-image' ),
 576                  'position' => 40
 577              );
 578          }
 579  
 580          return $wp_admin_nav;
 581      }
 582  
 583      /**
 584       * Get the members invitations admin bar navs.
 585       *
 586       * @since 8.0.0
 587       *
 588       * @param  string $admin_bar_menu_id The Admin bar menu ID to attach sub items to.
 589       * @return array                     The members invitations admin navs.
 590       */
 591  	public function get_members_invitations_admin_navs( $admin_bar_menu_id = '' ) {
 592          $wp_admin_nav = array();
 593          $invite_link  = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
 594  
 595          if ( ! $admin_bar_menu_id ) {
 596              $admin_bar_menu_id = $this->id;
 597          }
 598  
 599          return $wp_admin_nav;
 600      }
 601  
 602      /**
 603       * Set up the Admin Bar.
 604       *
 605       * @since 6.0.0
 606       *
 607       * @param array $wp_admin_nav Admin Bar items.
 608       */
 609  	public function setup_admin_bar( $wp_admin_nav = array() ) {
 610          // Menus for logged in user.
 611          if ( is_user_logged_in() ) {
 612              $profile_link = trailingslashit( bp_loggedin_user_domain() . bp_get_profile_slug() );
 613  
 614              if ( ! bp_is_active( 'xprofile' ) ) {
 615                  // Add the "Profile" sub menu.
 616                  $wp_admin_nav[] = array(
 617                      'parent' => buddypress()->my_account_menu_id,
 618                      'id'     => 'my-account-' . $this->id,
 619                      'title'  => _x( 'Profile', 'My Account Profile', 'buddypress' ),
 620                      'href'   => $profile_link
 621                  );
 622  
 623                  // View Profile.
 624                  $wp_admin_nav[] = array(
 625                      'parent'   => 'my-account-' . $this->id,
 626                      'id'       => 'my-account-' . $this->id . '-public',
 627                      'title'    => _x( 'View', 'My Account Profile sub nav', 'buddypress' ),
 628                      'href'     => $profile_link,
 629                      'position' => 10
 630                  );
 631  
 632                  $wp_admin_nav = array_merge( $wp_admin_nav, $this->get_avatar_cover_image_admin_navs() );
 633  
 634              /**
 635               * The xProfile is active.
 636               *
 637               * Add the Change Avatar and Change Cover Image Admin Bar items
 638               * to the xProfile Admin Bar Menu.
 639               */
 640              } else {
 641                  add_filter( 'bp_xprofile_admin_nav', array( $this, 'setup_xprofile_admin_nav' ), 2 );
 642              }
 643          }
 644  
 645          parent::setup_admin_bar( $wp_admin_nav );
 646      }
 647  
 648      /**
 649       * Adds "Profile > Change Avatar" & "Profile > Change Cover Image" subnav item
 650       * under the "Profile" adminbar menu.
 651       *
 652       * @since 6.0.0
 653       *
 654       * @param array $wp_admin_nav The Profile adminbar nav array.
 655       * @return array
 656       */
 657  	public function setup_xprofile_admin_nav( $wp_admin_nav ) {
 658          $items = $this->get_avatar_cover_image_admin_navs( buddypress()->profile->id );
 659  
 660          if ( $items ) {
 661              $wp_admin_nav = array_merge( $wp_admin_nav, $items );
 662          }
 663  
 664          return $wp_admin_nav;
 665      }
 666  
 667      /**
 668       * Set up the title for pages and <title>.
 669       *
 670       * @since 1.5.0
 671       */
 672  	public function setup_title() {
 673          $bp = buddypress();
 674  
 675          if ( bp_is_my_profile() ) {
 676              $bp->bp_options_title = __( 'You', 'buddypress' );
 677          } elseif ( bp_is_user() ) {
 678              $bp->bp_options_title  = bp_get_displayed_user_fullname();
 679              $bp->bp_options_avatar = bp_core_fetch_avatar( array(
 680                  'item_id' => bp_displayed_user_id(),
 681                  'type'    => 'thumb',
 682                  'alt'     => sprintf( __( 'Profile picture of %s', 'buddypress' ), $bp->bp_options_title )
 683              ) );
 684          }
 685  
 686          parent::setup_title();
 687      }
 688  
 689      /**
 690       * Setup cache groups.
 691       *
 692       * @since 2.2.0
 693       */
 694  	public function setup_cache_groups() {
 695  
 696          // Global groups.
 697          wp_cache_add_global_groups( array(
 698              'bp_last_activity',
 699              'bp_member_type'
 700          ) );
 701  
 702          parent::setup_cache_groups();
 703      }
 704  
 705      /**
 706       * Init the BP REST API.
 707       *
 708       * @since 5.0.0
 709       * @since 6.0.0 Adds the Member Cover and Signup REST endpoints.
 710       * @since 9.0.0 Moves the `BP_REST_Components_Endpoint` controller in `BP_Core` component.
 711       *
 712       * @param array $controllers Optional. See BP_Component::rest_api_init() for
 713       *                           description.
 714       */
 715  	public function rest_api_init( $controllers = array() ) {
 716          $controllers = array(
 717              'BP_REST_Members_Endpoint',
 718              'BP_REST_Attachments_Member_Avatar_Endpoint',
 719          );
 720  
 721          if ( bp_is_active( 'members', 'cover_image' ) ) {
 722              $controllers[] = 'BP_REST_Attachments_Member_Cover_Endpoint';
 723          }
 724  
 725          if ( bp_get_signup_allowed() ) {
 726              $controllers[] = 'BP_REST_Signup_Endpoint';
 727          }
 728  
 729          parent::rest_api_init( $controllers );
 730      }
 731  
 732      /**
 733       * Register the BP Members Blocks.
 734       *
 735       * @since 6.0.0
 736       *
 737       * @param array $blocks Optional. See BP_Component::blocks_init() for
 738       *                      description.
 739       */
 740  	public function blocks_init( $blocks = array() ) {
 741          parent::blocks_init(
 742              array(
 743                  'bp/member' => array(
 744                      'name'               => 'bp/member',
 745                      'editor_script'      => 'bp-member-block',
 746                      'editor_script_url'  => plugins_url( 'js/blocks/member.js', dirname( __FILE__ ) ),
 747                      'editor_script_deps' => array(
 748                          'wp-blocks',
 749                          'wp-element',
 750                          'wp-components',
 751                          'wp-i18n',
 752                          'wp-block-editor',
 753                          'bp-block-components',
 754                          'bp-block-data',
 755                      ),
 756                      'style'              => 'bp-member-block',
 757                      'style_url'          => plugins_url( 'css/blocks/member.css', dirname( __FILE__ ) ),
 758                      'render_callback'    => 'bp_members_render_member_block',
 759                      'attributes'         => array(
 760                          'itemID'              => array(
 761                              'type'    => 'integer',
 762                              'default' => 0,
 763                          ),
 764                          'avatarSize'          => array(
 765                              'type'    => 'string',
 766                              'default' => 'full',
 767                          ),
 768                          'displayMentionSlug'  => array(
 769                              'type'    => 'boolean',
 770                              'default' => true,
 771                          ),
 772                          'displayActionButton' => array(
 773                              'type'    => 'boolean',
 774                              'default' => true,
 775                          ),
 776                          'displayCoverImage'   => array(
 777                              'type'    => 'boolean',
 778                              'default' => true,
 779                          ),
 780                      ),
 781                  ),
 782                  'bp/members' => array(
 783                      'name'               => 'bp/members',
 784                      'editor_script'      => 'bp-members-block',
 785                      'editor_script_url'  => plugins_url( 'js/blocks/members.js', dirname( __FILE__ ) ),
 786                      'editor_script_deps' => array(
 787                          'wp-blocks',
 788                          'wp-element',
 789                          'wp-components',
 790                          'wp-i18n',
 791                          'wp-api-fetch',
 792                          'wp-url',
 793                          'wp-block-editor',
 794                          'bp-block-components',
 795                          'bp-block-data',
 796                          'lodash',
 797                      ),
 798                      'style'              => 'bp-members-block',
 799                      'style_url'          => plugins_url( 'css/blocks/members.css', dirname( __FILE__ ) ),
 800                      'attributes'         => array(
 801                          'itemIDs'            => array(
 802                              'type'  => 'array',
 803                              'items' => array(
 804                                  'type' => 'integer',
 805                              ),
 806                          ),
 807                          'avatarSize'         => array(
 808                              'type'    => 'string',
 809                              'default' => 'full',
 810                          ),
 811                          'displayMentionSlug' => array(
 812                              'type'    => 'boolean',
 813                              'default' => true,
 814                          ),
 815                          'displayUserName'    => array(
 816                              'type'    => 'boolean',
 817                              'default' => true,
 818                          ),
 819                          'extraData'          => array(
 820                              'type'    => 'string',
 821                              'default' => 'none',
 822                              'enum'    => array( 'last_activity', 'latest_update', 'none' ),
 823                          ),
 824                          'layoutPreference'   => array(
 825                              'type'    => 'string',
 826                              'default' => 'list',
 827                              'enum'    => array( 'list', 'grid' ),
 828                          ),
 829                          'columns'            => array(
 830                              'type'    => 'number',
 831                              'default' => 2,
 832                          ),
 833                      ),
 834                      'render_callback'    => 'bp_members_render_members_block',
 835                  ),
 836                  'bp/dynamic-members' => array(
 837                      'name'               => 'bp/dynamic-members',
 838                      'editor_script'      => 'bp-dynamic-members-block',
 839                      'editor_script_url'  => plugins_url( 'js/blocks/dynamic-members.js', dirname( __FILE__ ) ),
 840                      'editor_script_deps' => array(
 841                          'wp-blocks',
 842                          'wp-element',
 843                          'wp-components',
 844                          'wp-i18n',
 845                          'wp-block-editor',
 846                          'bp-block-data',
 847                          'bp-block-components',
 848                      ),
 849                      'style'              => 'bp-dynamic-members-block',
 850                      'style_url'          => plugins_url( 'css/blocks/dynamic-members.css', dirname( __FILE__ ) ),
 851                      'attributes'         => array(
 852                          'title'         => array(
 853                              'type'    => 'string',
 854                              'default' => __( 'Members', 'buddypress' ),
 855                          ),
 856                          'maxMembers'    => array(
 857                              'type'    => 'number',
 858                              'default' => 5,
 859                          ),
 860                          'memberDefault' => array(
 861                              'type'    => 'string',
 862                              'default' => 'active',
 863                          ),
 864                          'linkTitle'     => array(
 865                              'type'    => 'boolean',
 866                              'default' => false,
 867                          ),
 868                      ),
 869                      'render_callback'    => 'bp_members_render_dynamic_members_block',
 870                  ),
 871                  'bp/online-members'  => array(
 872                      'name'               => 'bp/online-members',
 873                      'editor_script'      => 'bp-online-members-block',
 874                      'editor_script_url'  => plugins_url( 'js/blocks/online-members.js', dirname( __FILE__ ) ),
 875                      'editor_script_deps' => array(
 876                          'wp-blocks',
 877                          'wp-element',
 878                          'wp-components',
 879                          'wp-i18n',
 880                          'wp-block-editor',
 881                          'bp-block-components',
 882                      ),
 883                      'editor_style'       => 'bp-member-avatar-blocks',
 884                      'editor_style_url'   => plugins_url( 'css/blocks/member-avatar-blocks.css', dirname( __FILE__ ) ),
 885                      'attributes'         => array(
 886                          'title'      => array(
 887                              'type'    => 'string',
 888                              'default' => __( 'Who\'s Online', 'buddypress' ),
 889                          ),
 890                          'maxMembers' => array(
 891                              'type'    => 'number',
 892                              'default' => 15,
 893                          ),
 894                      ),
 895                      'render_callback'    => 'bp_members_render_online_members_block',
 896                  ),
 897                  'bp/active-members'  => array(
 898                      'name'               => 'bp/active-members',
 899                      'editor_script'      => 'bp-active-members-block',
 900                      'editor_script_url'  => plugins_url( 'js/blocks/active-members.js', dirname( __FILE__ ) ),
 901                      'editor_script_deps' => array(
 902                          'wp-blocks',
 903                          'wp-element',
 904                          'wp-components',
 905                          'wp-i18n',
 906                          'wp-block-editor',
 907                          'bp-block-components',
 908                      ),
 909                      'editor_style'       => 'bp-member-avatar-blocks',
 910                      'editor_style_url'   => plugins_url( 'css/blocks/member-avatar-blocks.css', dirname( __FILE__ ) ),
 911                      'attributes'         => array(
 912                          'title'      => array(
 913                              'type'    => 'string',
 914                              'default' => __( 'Recently Active Members', 'buddypress' ),
 915                          ),
 916                          'maxMembers' => array(
 917                              'type'    => 'number',
 918                              'default' => 15,
 919                          ),
 920                      ),
 921                      'render_callback'    => 'bp_members_render_active_members_block',
 922                  ),
 923              )
 924          );
 925      }
 926  }


Generated: Thu Jul 29 01:01:39 2021 Cross-referenced by PHPXref 0.7.1