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


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1