[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

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


Generated: Tue Sep 29 01:01:36 2020 Cross-referenced by PHPXref 0.7.1