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


Generated: Tue Dec 1 01:01:37 2020 Cross-referenced by PHPXref 0.7.1