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


Generated: Tue May 18 01:01:42 2021 Cross-referenced by PHPXref 0.7.1