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


Generated: Tue Oct 19 01:00:57 2021 Cross-referenced by PHPXref 0.7.1