[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/ -> class-buddypress.php (source)

   1  <?php
   2  /**
   3   * Main BuddyPress Class.
   4   *
   5   * @package BuddyPress
   6   * @subpackage Main
   7   * @since 1.6.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Main BuddyPress Class.
  15   *
  16   * Tap tap tap... Is this thing on?
  17   *
  18   * @since 1.6.0
  19   */
  20  class BuddyPress {
  21  
  22      /** Magic *****************************************************************/
  23  
  24      /**
  25       * BuddyPress uses many variables, most of which can be filtered to
  26       * customize the way that it works. To prevent unauthorized access,
  27       * these variables are stored in a private array that is magically
  28       * updated using PHP 5.2+ methods. This is to prevent third party
  29       * plugins from tampering with essential information indirectly, which
  30       * would cause issues later.
  31       *
  32       * @see BuddyPress::setup_globals()
  33       * @var array
  34       */
  35      private $data;
  36  
  37      /** Not Magic *************************************************************/
  38  
  39      /**
  40       * Primary BuddyPress navigation.
  41       *
  42       * @var array Primary BuddyPress navigation.
  43       */
  44      public $bp_nav = array();
  45  
  46      /**
  47       * Options for the BuddyPress navigation.
  48       *
  49       * @var array Secondary BuddyPress navigation to $bp_nav.
  50       */
  51      public $bp_options_nav = array();
  52  
  53      /**
  54       * Unfiltered URI.
  55       *
  56       * @see bp_core_set_uri_globals()
  57       * @var array The unfiltered URI broken down into chunks.
  58       */
  59      public $unfiltered_uri = array();
  60  
  61      /**
  62       * Canonical stack.
  63       *
  64       * @see bp_redirect_canonical()
  65       * @see bp_core_new_nav_item()
  66       * @var array The canonical URI stack.
  67       */
  68      public $canonical_stack = array();
  69  
  70      /**
  71       * Current action variables.
  72       *
  73       * @var array Additional navigation elements (supplemental).
  74       */
  75      public $action_variables = array();
  76  
  77      /**
  78       * Current member type.
  79       *
  80       * @var string Current member directory type.
  81       */
  82      public $current_member_type = '';
  83  
  84      /**
  85       * BuddyPress required components.
  86       *
  87       * @var array Required components (core, members).
  88       */
  89      public $required_components = array();
  90  
  91      /**
  92       * BuddyPress loaded components.
  93       *
  94       * @var array Additional active components.
  95       */
  96      public $loaded_components = array();
  97  
  98      /**
  99       * BuddyPress active components.
 100       *
 101       * @var array Active components.
 102       */
 103      public $active_components = array();
 104  
 105      /**
 106       * Whether autoload is in use.
 107       *
 108       * @since 2.5.0
 109       *
 110       * @var bool
 111       */
 112      public $do_autoload = true;
 113  
 114      /** Option Overload *******************************************************/
 115  
 116      /**
 117       * BuddyPress options.
 118       *
 119       * @var array Optional Overloads default options retrieved from get_option().
 120       */
 121      public $options = array();
 122  
 123      /** Singleton *************************************************************/
 124  
 125      /**
 126       * Main BuddyPress Instance.
 127       *
 128       * BuddyPress is great.
 129       * Please load it only one time.
 130       * For this, we thank you.
 131       *
 132       * Insures that only one instance of BuddyPress exists in memory at any
 133       * one time. Also prevents needing to define globals all over the place.
 134       *
 135       * @since 1.7.0
 136       *
 137       * @static object $instance
 138       * @see buddypress()
 139       *
 140       * @return BuddyPress|null The one true BuddyPress.
 141       */
 142  	public static function instance() {
 143  
 144          // Store the instance locally to avoid private static replication.
 145          static $instance = null;
 146  
 147          // Only run these methods if they haven't been run previously.
 148          if ( null === $instance ) {
 149              $instance = new BuddyPress();
 150              $instance->constants();
 151              $instance->setup_globals();
 152              $instance->legacy_constants();
 153              $instance->includes();
 154              $instance->setup_actions();
 155          }
 156  
 157          // Always return the instance.
 158          return $instance;
 159  
 160          // The last metroid is in captivity. The galaxy is at peace.
 161      }
 162  
 163      /** Magic Methods *********************************************************/
 164  
 165      /**
 166       * A dummy constructor to prevent BuddyPress from being loaded more than once.
 167       *
 168       * @since 1.7.0
 169       *
 170       * @see BuddyPress::instance()
 171       * @see buddypress()
 172       */
 173  	private function __construct() {
 174          /* Do nothing here */
 175      }
 176  
 177      /**
 178       * A dummy magic method to prevent BuddyPress from being cloned.
 179       *
 180       * @since 1.7.0
 181       */
 182  	public function __clone() {
 183          _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'buddypress' ), '1.7' );
 184      }
 185  
 186      /**
 187       * A dummy magic method to prevent BuddyPress from being unserialized.
 188       *
 189       * @since 1.7.0
 190       */
 191  	public function __wakeup() {
 192          _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'buddypress' ), '1.7' );
 193      }
 194  
 195      /**
 196       * Magic method for checking the existence of a certain custom field.
 197       *
 198       * @since 1.7.0
 199       *
 200       * @param string $key Key to check the set status for.
 201       *
 202       * @return bool
 203       */
 204  	public function __isset( $key ) {
 205          return isset( $this->data[ $key ] );
 206      }
 207  
 208      /**
 209       * Magic method for getting BuddyPress variables.
 210       *
 211       * @since 1.7.0
 212       *
 213       * @param string $key Key to return the value for.
 214       *
 215       * @return mixed
 216       */
 217  	public function __get( $key ) {
 218          return isset( $this->data[ $key ] ) ? $this->data[ $key ] : null;
 219      }
 220  
 221      /**
 222       * Magic method for setting BuddyPress variables.
 223       *
 224       * @since 1.7.0
 225       *
 226       * @param string $key   Key to set a value for.
 227       * @param mixed  $value Value to set.
 228       */
 229  	public function __set( $key, $value ) {
 230          $this->data[ $key ] = $value;
 231      }
 232  
 233      /**
 234       * Magic method for unsetting BuddyPress variables.
 235       *
 236       * @since 1.7.0
 237       *
 238       * @param string $key Key to unset a value for.
 239       */
 240  	public function __unset( $key ) {
 241          if ( isset( $this->data[ $key ] ) ) {
 242              unset( $this->data[ $key ] );
 243          }
 244      }
 245  
 246      /**
 247       * Magic method to prevent notices and errors from invalid method calls.
 248       *
 249       * @since 1.7.0
 250       *
 251       * @param string $name
 252       * @param array  $args
 253       *
 254       * @return null
 255       */
 256  	public function __call( $name = '', $args = array() ) {
 257          unset( $name, $args );
 258  
 259          return null;
 260      }
 261  
 262      /** Private Methods *******************************************************/
 263  
 264      /**
 265       * Bootstrap constants.
 266       *
 267       * @since 1.6.0
 268       */
 269  	private function constants() {
 270  
 271          // Place your custom code (actions/filters) in a file called
 272          // '/plugins/bp-custom.php' and it will be loaded before anything else.
 273          if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) ) {
 274              require WP_PLUGIN_DIR . '/bp-custom.php';
 275          }
 276  
 277          // Path and URL.
 278          if ( ! defined( 'BP_PLUGIN_DIR' ) ) {
 279              define( 'BP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
 280          }
 281  
 282          if ( ! defined( 'BP_PLUGIN_URL' ) ) {
 283              define( 'BP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
 284          }
 285  
 286          // Legacy forum constant - supported for compatibility with bbPress 2.
 287          if ( ! defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) {
 288              define( 'BP_FORUMS_PARENT_FORUM_ID', 1 );
 289          }
 290  
 291          // Legacy forum constant - supported for compatibility with bbPress 2.
 292          if ( ! defined( 'BP_FORUMS_SLUG' ) ) {
 293              define( 'BP_FORUMS_SLUG', 'forums' );
 294          }
 295  
 296          // Only applicable to those running trunk.
 297          if ( ! defined( 'BP_SOURCE_SUBDIRECTORY' ) ) {
 298              define( 'BP_SOURCE_SUBDIRECTORY', '' );
 299          }
 300  
 301          // Define on which blog ID BuddyPress should run.
 302          if ( ! defined( 'BP_ROOT_BLOG' ) ) {
 303  
 304              // Default to use current blog ID.
 305              // Fulfills non-network installs and BP_ENABLE_MULTIBLOG installs.
 306              $root_blog_id = get_current_blog_id();
 307  
 308              // Multisite check.
 309              if ( is_multisite() ) {
 310  
 311                  // Multiblog isn't enabled.
 312                  if ( ! defined( 'BP_ENABLE_MULTIBLOG' ) || ( defined( 'BP_ENABLE_MULTIBLOG' ) && (int) constant( 'BP_ENABLE_MULTIBLOG' ) === 0 ) ) {
 313                      // Check to see if BP is network-activated
 314                      // We're not using is_plugin_active_for_network() b/c you need to include the
 315                      // /wp-admin/includes/plugin.php file in order to use that function.
 316  
 317                      // Get network-activated plugins.
 318                      $plugins = get_site_option( 'active_sitewide_plugins' );
 319  
 320                      // Basename.
 321                      $basename = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
 322  
 323                      // Plugin is network-activated; use main site ID instead.
 324                      if ( isset( $plugins[ $basename ] ) ) {
 325                          $current_site = get_current_site();
 326                          $root_blog_id = $current_site->blog_id;
 327                      }
 328                  }
 329              }
 330  
 331              define( 'BP_ROOT_BLOG', $root_blog_id );
 332          }
 333  
 334          // The search slug has to be defined nice and early because of the way
 335          // search requests are loaded.
 336          //
 337          // @todo Make this better.
 338          if ( ! defined( 'BP_SEARCH_SLUG' ) ) {
 339              define( 'BP_SEARCH_SLUG', 'search' );
 340          }
 341      }
 342  
 343      /**
 344       * Component global variables.
 345       *
 346       * @since 1.6.0
 347       */
 348  	private function setup_globals() {
 349  
 350          /** Versions */
 351  
 352          $this->version    = '10.0.0-alpha';
 353          $this->db_version = 12850;
 354  
 355          /** Loading */
 356  
 357          /**
 358           * Should deprecated code be loaded?
 359           *
 360           * @since 2.0.0 Defaults to false always
 361           * @since 2.8.0 Defaults to true on upgrades, false for new installs.
 362           */
 363          $this->load_deprecated = false;
 364  
 365          /** Toolbar */
 366  
 367          /**
 368           * @var string The primary toolbar ID.
 369           */
 370          $this->my_account_menu_id = '';
 371  
 372          /** URIs */
 373  
 374          /**
 375           * @var int The current offset of the URI.
 376           * @see bp_core_set_uri_globals()
 377           */
 378          $this->unfiltered_uri_offset = 0;
 379  
 380          /**
 381           * @var bool Are status headers already sent?
 382           */
 383          $this->no_status_set = false;
 384  
 385          /** Components */
 386  
 387          /**
 388           * @var string Name of the current BuddyPress component (primary).
 389           */
 390          $this->current_component = '';
 391  
 392          /**
 393           * @var string Name of the current BuddyPress item (secondary).
 394           */
 395          $this->current_item = '';
 396  
 397          /**
 398           * @var string Name of the current BuddyPress action (tertiary).
 399           */
 400          $this->current_action = '';
 401  
 402          /**
 403           * @var bool Displaying custom 2nd level navigation menu (I.E a group).
 404           */
 405          $this->is_single_item = false;
 406  
 407          /** Root */
 408  
 409          /**
 410           * Filters the BuddyPress Root blog ID.
 411           *
 412           * @since 1.5.0
 413           *
 414           * @const constant BP_ROOT_BLOG BuddyPress Root blog ID.
 415           */
 416          $this->root_blog_id = (int) apply_filters( 'bp_get_root_blog_id', BP_ROOT_BLOG );
 417  
 418          /** Paths */
 419  
 420          // BuddyPress root directory.
 421          $this->file       = constant( 'BP_PLUGIN_DIR' ) . 'bp-loader.php';
 422          $this->basename   = basename( constant( 'BP_PLUGIN_DIR' ) ) . '/bp-loader.php';
 423          $this->plugin_dir = trailingslashit( constant( 'BP_PLUGIN_DIR' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) );
 424          $this->plugin_url = trailingslashit( constant( 'BP_PLUGIN_URL' ) . constant( 'BP_SOURCE_SUBDIRECTORY' ) );
 425  
 426          // Languages.
 427          $this->lang_dir = $this->plugin_dir . 'bp-languages';
 428  
 429          // Templates (theme compatibility).
 430          $this->themes_dir = $this->plugin_dir . 'bp-templates';
 431          $this->themes_url = $this->plugin_url . 'bp-templates';
 432  
 433          // Themes (for bp-default).
 434          $this->old_themes_dir = $this->plugin_dir . 'bp-themes';
 435          $this->old_themes_url = $this->plugin_url . 'bp-themes';
 436  
 437          /** Theme Compat */
 438  
 439          $this->theme_compat = new stdClass(); // Base theme compatibility class.
 440          $this->filters      = new stdClass(); // Used when adding/removing filters.
 441  
 442          /** Users */
 443  
 444          $this->current_user   = new stdClass();
 445          $this->displayed_user = new stdClass();
 446  
 447          /** Post types and taxonomies */
 448  
 449          /**
 450           * Filters the post type slug for the email component.
 451           *
 452           * @since 2.5.0
 453           *
 454           * @param string $value Email post type slug.
 455           */
 456          $this->email_post_type = apply_filters( 'bp_email_post_type', 'bp-email' );
 457  
 458          /**
 459           * Filters the taxonomy slug for the email type component.
 460           *
 461           * @since 2.5.0
 462           *
 463           * @param string $value Email type taxonomy slug.
 464           */
 465          $this->email_taxonomy_type = apply_filters( 'bp_email_tax_type', 'bp-email-type' );
 466      }
 467  
 468      /**
 469       * Legacy BuddyPress constants.
 470       *
 471       * Try to avoid using these. Their values have been moved into variables
 472       * in the instance, and have matching functions to get/set their values.
 473       *
 474       * @since 1.7.0
 475       */
 476  	private function legacy_constants() {
 477  
 478          // Define the BuddyPress version.
 479          if ( ! defined( 'BP_VERSION' ) ) {
 480              define( 'BP_VERSION', $this->version );
 481          }
 482  
 483          // Define the database version.
 484          if ( ! defined( 'BP_DB_VERSION' ) ) {
 485              define( 'BP_DB_VERSION', $this->db_version );
 486          }
 487  
 488          // Define if deprecated functions should be ignored.
 489          if ( ! defined( 'BP_IGNORE_DEPRECATED' ) ) {
 490              define( 'BP_IGNORE_DEPRECATED', true );
 491          }
 492      }
 493  
 494      /**
 495       * Include required files.
 496       *
 497       * @since 1.6.0
 498       */
 499  	private function includes() {
 500          spl_autoload_register( array( $this, 'autoload' ) );
 501  
 502          // Load the WP abstraction file so BuddyPress can run on all WordPress setups.
 503          require $this->plugin_dir . 'bp-core/bp-core-wpabstraction.php';
 504  
 505          // Setup the versions (after we include multisite abstraction above).
 506          $this->versions();
 507  
 508          /** Update/Install */
 509  
 510          // Theme compatibility.
 511          require $this->plugin_dir . 'bp-core/bp-core-template-loader.php';
 512          require $this->plugin_dir . 'bp-core/bp-core-theme-compatibility.php';
 513  
 514          // Require all of the BuddyPress core libraries.
 515          require $this->plugin_dir . 'bp-core/bp-core-dependency.php';
 516          require $this->plugin_dir . 'bp-core/bp-core-actions.php';
 517          require $this->plugin_dir . 'bp-core/bp-core-caps.php';
 518          require $this->plugin_dir . 'bp-core/bp-core-cache.php';
 519          require $this->plugin_dir . 'bp-core/bp-core-cssjs.php';
 520          require $this->plugin_dir . 'bp-core/bp-core-update.php';
 521          require $this->plugin_dir . 'bp-core/bp-core-options.php';
 522          require $this->plugin_dir . 'bp-core/bp-core-taxonomy.php';
 523          require $this->plugin_dir . 'bp-core/bp-core-filters.php';
 524          require $this->plugin_dir . 'bp-core/bp-core-attachments.php';
 525          require $this->plugin_dir . 'bp-core/bp-core-avatars.php';
 526          require $this->plugin_dir . 'bp-core/bp-core-widgets.php';
 527          require $this->plugin_dir . 'bp-core/bp-core-template.php';
 528          require $this->plugin_dir . 'bp-core/bp-core-adminbar.php';
 529          require $this->plugin_dir . 'bp-core/bp-core-buddybar.php';
 530          require $this->plugin_dir . 'bp-core/bp-core-catchuri.php';
 531          require $this->plugin_dir . 'bp-core/bp-core-functions.php';
 532          require $this->plugin_dir . 'bp-core/bp-core-moderation.php';
 533          require $this->plugin_dir . 'bp-core/bp-core-loader.php';
 534          require $this->plugin_dir . 'bp-core/bp-core-customizer-email.php';
 535          require $this->plugin_dir . 'bp-core/bp-core-rest-api.php';
 536          require $this->plugin_dir . 'bp-core/bp-core-blocks.php';
 537  
 538          // Maybe load deprecated functionality (this double negative is proof positive!).
 539          if ( ! bp_get_option( '_bp_ignore_deprecated_code', ! $this->load_deprecated ) ) {
 540              require $this->plugin_dir . 'bp-core/deprecated/1.2.php';
 541              require $this->plugin_dir . 'bp-core/deprecated/1.5.php';
 542              require $this->plugin_dir . 'bp-core/deprecated/1.6.php';
 543              require $this->plugin_dir . 'bp-core/deprecated/1.7.php';
 544              require $this->plugin_dir . 'bp-core/deprecated/1.9.php';
 545              require $this->plugin_dir . 'bp-core/deprecated/2.0.php';
 546              require $this->plugin_dir . 'bp-core/deprecated/2.1.php';
 547              require $this->plugin_dir . 'bp-core/deprecated/2.2.php';
 548              require $this->plugin_dir . 'bp-core/deprecated/2.3.php';
 549              require $this->plugin_dir . 'bp-core/deprecated/2.4.php';
 550              require $this->plugin_dir . 'bp-core/deprecated/2.5.php';
 551              require $this->plugin_dir . 'bp-core/deprecated/2.6.php';
 552              require $this->plugin_dir . 'bp-core/deprecated/2.7.php';
 553              require $this->plugin_dir . 'bp-core/deprecated/2.8.php';
 554              require $this->plugin_dir . 'bp-core/deprecated/2.9.php';
 555              require $this->plugin_dir . 'bp-core/deprecated/3.0.php';
 556              require $this->plugin_dir . 'bp-core/deprecated/4.0.php';
 557              require $this->plugin_dir . 'bp-core/deprecated/6.0.php';
 558              require $this->plugin_dir . 'bp-core/deprecated/7.0.php';
 559              require $this->plugin_dir . 'bp-core/deprecated/8.0.php';
 560              require $this->plugin_dir . 'bp-core/deprecated/9.0.php';
 561          }
 562  
 563          // Load wp-cli module if PHP 5.6+.
 564          if (
 565              defined( 'WP_CLI' )
 566              && ! class_exists( 'Buddypress\CLI\Command\BuddypressCommand' )
 567              && file_exists( $this->plugin_dir . 'cli/wp-cli-bp.php' )
 568              && version_compare( phpversion(), '5.6.0', '>=' ) ) {
 569              require $this->plugin_dir . 'cli/wp-cli-bp.php';
 570          }
 571      }
 572  
 573      /**
 574       * Autoload classes.
 575       *
 576       * @since 2.5.0
 577       *
 578       * @param string $class Classes to be autoloaded.
 579       * @return string Path of a class.
 580       */
 581  	public function autoload( $class ) {
 582          $class_parts = explode( '_', strtolower( $class ) );
 583  
 584          if ( 'bp' !== $class_parts[0] ) {
 585              return;
 586          }
 587  
 588          $components = array(
 589              'activity',
 590              'blogs',
 591              'core',
 592              'friends',
 593              'groups',
 594              'members',
 595              'messages',
 596              'notifications',
 597              'settings',
 598              'xprofile',
 599          );
 600  
 601          // These classes don't have a name that matches their component.
 602          $irregular_map = array(
 603              'BP_Akismet'                                 => 'activity',
 604              'BP_REST_Activity_Endpoint'                  => 'activity',
 605  
 606              'BP_REST_Blogs_Endpoint'                     => 'blogs',
 607              'BP_REST_Attachments_Blog_Avatar_Endpoint'   => 'blogs',
 608  
 609              'BP_Admin'                                   => 'core',
 610              'BP_Attachment_Avatar'                       => 'core',
 611              'BP_Attachment_Cover_Image'                  => 'core',
 612              'BP_Attachment'                              => 'core',
 613              'BP_Button'                                  => 'core',
 614              'BP_Block'                                   => 'core',
 615              'BP_Component'                               => 'core',
 616              'BP_Customizer_Control_Range'                => 'core',
 617              'BP_Date_Query'                              => 'core',
 618              'BP_Email_Delivery'                          => 'core',
 619              'BP_Email_Address'                           => 'core',
 620              'BP_Email_Recipient'                         => 'core',
 621              'BP_Email_Sender'                            => 'core',
 622              'BP_Email_Participant'                       => 'core',
 623              'BP_Email'                                   => 'core',
 624              'BP_Embed'                                   => 'core',
 625              'BP_Media_Extractor'                         => 'core',
 626              'BP_Members_Suggestions'                     => 'core',
 627              'BP_PHPMailer'                               => 'core',
 628              'BP_Recursive_Query'                         => 'core',
 629              'BP_Suggestions'                             => 'core',
 630              'BP_Theme_Compat'                            => 'core',
 631              'BP_User_Query'                              => 'core',
 632              'BP_Walker_Category_Checklist'               => 'core',
 633              /**
 634               * BP_Walker_Nav_Menu_Checklist class.
 635               *
 636               * As this class corresponding file is deprecated, it will trigger a deprecation notice if instantiated.
 637               * In a subsequent release, we'll remove it from our Classes Autoloader.
 638               *
 639               * @todo Remove the BP_Walker_Nav_Menu_Checklist from our Classes Autoloader.
 640               */
 641              'BP_Walker_Nav_Menu_Checklist'               => 'core',
 642              'BP_Walker_Nav_Menu'                         => 'core',
 643              'BP_Invitation_Manager'                      => 'core',
 644              'BP_Invitation'                              => 'core',
 645              'BP_REST_Components_Endpoint'                => 'core',
 646              'BP_REST_Attachments'                        => 'core',
 647              'BP_Admin_Types'                             => 'core',
 648              'BP_Optout'                                  => 'core',
 649              'BP_Optouts_List_Table'                      => 'core',
 650  
 651              'BP_Core_Friends_Widget'                     => 'friends',
 652              'BP_REST_Friends_Endpoint'                   => 'friends',
 653  
 654              'BP_Group_Extension'                         => 'groups',
 655              'BP_Group_Member_Query'                      => 'groups',
 656              'BP_REST_Groups_Endpoint'                    => 'groups',
 657              'BP_REST_Group_Membership_Endpoint'          => 'groups',
 658              'BP_REST_Group_Invites_Endpoint'             => 'groups',
 659              'BP_REST_Group_Membership_Request_Endpoint'  => 'groups',
 660              'BP_REST_Attachments_Group_Avatar_Endpoint'  => 'groups',
 661              'BP_REST_Attachments_Group_Cover_Endpoint'   => 'groups',
 662  
 663              'BP_Core_Members_Template'                   => 'members',
 664              'BP_Core_Members_Widget'                     => 'members',
 665              'BP_Core_Recently_Active_Widget'             => 'members',
 666              'BP_Core_Whos_Online_Widget'                 => 'members',
 667              'BP_Registration_Theme_Compat'               => 'members',
 668              'BP_Signup'                                  => 'members',
 669              'BP_REST_Members_Endpoint'                   => 'members',
 670              'BP_REST_Attachments_Member_Avatar_Endpoint' => 'members',
 671              'BP_REST_Attachments_Member_Cover_Endpoint'  => 'members',
 672              'BP_REST_Signup_Endpoint'                    => 'members',
 673              'BP_Members_Invitation_Manager'              => 'members',
 674              'BP_Members_Invitations_Template'            => 'members',
 675  
 676              'BP_REST_Messages_Endpoint'                  => 'messages',
 677  
 678              'BP_REST_Notifications_Endpoint'             => 'notifications',
 679  
 680              'BP_REST_XProfile_Fields_Endpoint'           => 'xprofile',
 681              'BP_REST_XProfile_Field_Groups_Endpoint'     => 'xprofile',
 682              'BP_REST_XProfile_Data_Endpoint'             => 'xprofile',
 683          );
 684  
 685          $component = null;
 686  
 687          // First check to see if the class is one without a properly namespaced name.
 688          if ( isset( $irregular_map[ $class ] ) ) {
 689              $component = $irregular_map[ $class ];
 690  
 691          // Next chunk is usually the component name.
 692          } elseif ( in_array( $class_parts[1], $components, true ) ) {
 693              $component = $class_parts[1];
 694          }
 695  
 696          if ( ! $component ) {
 697              return;
 698          }
 699  
 700          // Sanitize class name.
 701          $class = strtolower( str_replace( '_', '-', $class ) );
 702  
 703          if ( 'bp-rest-attachments' === $class ) {
 704              $path = dirname( __FILE__ ) . "/bp-{$component}/classes/trait-attachments.php";
 705          } else {
 706              $path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php";
 707          }
 708  
 709          // Sanity check.
 710          if ( ! file_exists( $path ) ) {
 711              return;
 712          }
 713  
 714          /*
 715           * Sanity check 2 - Check if component is active before loading class.
 716           * Skip if PHPUnit is running, or BuddyPress is installing for the first time.
 717           */
 718          if (
 719              ! in_array( $component, array( 'core', 'members' ), true ) &&
 720              ! bp_is_active( $component ) &&
 721              ! function_exists( 'tests_add_filter' )
 722          ) {
 723              return;
 724          }
 725  
 726          require $path;
 727      }
 728  
 729      /**
 730       * Set up the default hooks and actions.
 731       *
 732       * @since 1.6.0
 733       */
 734  	private function setup_actions() {
 735  
 736          // Add actions to plugin activation and deactivation hooks.
 737          add_action( 'activate_' . $this->basename, 'bp_activation' );
 738          add_action( 'deactivate_' . $this->basename, 'bp_deactivation' );
 739  
 740          // If BuddyPress is being deactivated, do not add any actions.
 741          if ( bp_is_deactivation( $this->basename ) ) {
 742              return;
 743          }
 744  
 745          // Array of BuddyPress core actions.
 746          $actions = array(
 747              'setup_theme',              // Setup the default theme compat.
 748              'setup_current_user',       // Setup currently logged in user.
 749              'register_post_types',      // Register post types.
 750              'register_post_statuses',   // Register post statuses.
 751              'register_taxonomies',      // Register taxonomies.
 752              'register_views',           // Register the views.
 753              'register_theme_directory', // Register the theme directory.
 754              'register_theme_packages',  // Register bundled theme packages (bp-themes).
 755              'load_textdomain',          // Load textdomain.
 756              'add_rewrite_tags',         // Add rewrite tags.
 757              'generate_rewrite_rules',    // Generate rewrite rules.
 758          );
 759  
 760          // Add the actions.
 761          foreach ( $actions as $class_action ) {
 762              if ( method_exists( $this, $class_action ) ) {
 763                  add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 );
 764              }
 765          }
 766  
 767          /**
 768           * Fires after the setup of all BuddyPress actions.
 769           *
 770           * Includes bbp-core-hooks.php.
 771           *
 772           * @since 1.7.0
 773           *
 774           * @param BuddyPress $this. Current BuddyPress instance. Passed by reference.
 775           */
 776          do_action_ref_array( 'bp_after_setup_actions', array( &$this ) );
 777      }
 778  
 779      /**
 780       * Private method to align the active and database versions.
 781       *
 782       * @since 1.7.0
 783       */
 784  	private function versions() {
 785  
 786          // Get the possible DB versions (boy is this gross).
 787          $versions               = array();
 788          $versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' );
 789  
 790          // 1.6-single exists, so trust it.
 791          if ( ! empty( $versions['1.6-single'] ) ) {
 792              $this->db_version_raw = (int) $versions['1.6-single'];
 793  
 794          // If no 1.6-single exists, use the max of the others.
 795          } else {
 796              $versions['1.2']        = get_site_option( 'bp-core-db-version' );
 797              $versions['1.5-multi']  = get_site_option( 'bp-db-version' );
 798              $versions['1.6-multi']  = get_site_option( '_bp_db_version' );
 799              $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' );
 800  
 801              // Remove empty array items.
 802              $versions             = array_filter( $versions );
 803              $this->db_version_raw = (int) ( ! empty( $versions ) ) ? (int) max( $versions ) : 0;
 804          }
 805      }
 806  
 807      /** Public Methods ********************************************************/
 808  
 809      /**
 810       * Set up BuddyPress's legacy theme directory.
 811       *
 812       * Starting with version 1.2, and ending with version 1.8, BuddyPress
 813       * registered a custom theme directory - bp-themes - which contained
 814       * the bp-default theme. Since BuddyPress 1.9, bp-themes is no longer
 815       * registered (and bp-default no longer offered) on new installations.
 816       * Sites using bp-default (or a child theme of bp-default) will
 817       * continue to have bp-themes registered as before.
 818       *
 819       * @since 1.5.0
 820       *
 821       * @todo Move bp-default to wordpress.org/extend/themes and remove this.
 822       */
 823  	public function register_theme_directory() {
 824          if ( ! bp_do_register_theme_directory() ) {
 825              return;
 826          }
 827  
 828          register_theme_directory( $this->old_themes_dir );
 829      }
 830  
 831      /**
 832       * Register bundled theme packages.
 833       *
 834       * Note that since we currently have complete control over bp-themes and
 835       * the bp-legacy folders, it's fine to hardcode these here. If at a
 836       * later date we need to automate this, an API will need to be built.
 837       *
 838       * @since 1.7.0
 839       */
 840  	public function register_theme_packages() {
 841  
 842          // Register the default theme compatibility package.
 843          bp_register_theme_package(
 844              array(
 845                  'id'      => 'legacy',
 846                  'name'    => __( 'BuddyPress Legacy', 'buddypress' ),
 847                  'version' => bp_get_version(),
 848                  'dir'     => trailingslashit( $this->themes_dir . '/bp-legacy' ),
 849                  'url'     => trailingslashit( $this->themes_url . '/bp-legacy' ),
 850              )
 851          );
 852  
 853          bp_register_theme_package(
 854              array(
 855                  'id'      => 'nouveau',
 856                  'name'    => __( 'BuddyPress Nouveau', 'buddypress' ),
 857                  'version' => bp_get_version(),
 858                  'dir'     => trailingslashit( $this->themes_dir . '/bp-nouveau' ),
 859                  'url'     => trailingslashit( $this->themes_url . '/bp-nouveau' ),
 860              )
 861          );
 862  
 863          // Register the basic theme stack. This is really dope.
 864          bp_register_template_stack( 'get_stylesheet_directory', 10 );
 865          bp_register_template_stack( 'get_template_directory', 12 );
 866          bp_register_template_stack( 'bp_get_theme_compat_dir', 14 );
 867      }
 868  
 869      /**
 870       * Set up the default BuddyPress theme compatibility location.
 871       *
 872       * @since 1.7.0
 873       */
 874  	public function setup_theme() {
 875  
 876          // Bail if something already has this under control.
 877          if ( ! empty( $this->theme_compat->theme ) ) {
 878              return;
 879          }
 880  
 881          // Setup the theme package to use for compatibility.
 882          bp_setup_theme_compat( bp_get_theme_package_id() );
 883      }
 884  }


Generated: Tue Oct 26 01:00:55 2021 Cross-referenced by PHPXref 0.7.1