[ 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    = '11.0.0-alpha';
 353          $this->db_version = 13271;
 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              require $this->plugin_dir . 'bp-core/deprecated/10.0.php';
 562          }
 563  
 564          // Load wp-cli module if PHP 5.6+.
 565          if (
 566              defined( 'WP_CLI' )
 567              && ! class_exists( 'Buddypress\CLI\Command\BuddypressCommand' )
 568              && file_exists( $this->plugin_dir . 'cli/wp-cli-bp.php' )
 569              && version_compare( phpversion(), '5.6.0', '>=' ) ) {
 570              require $this->plugin_dir . 'cli/wp-cli-bp.php';
 571          }
 572      }
 573  
 574      /**
 575       * Autoload classes.
 576       *
 577       * @since 2.5.0
 578       *
 579       * @param string $class Classes to be autoloaded.
 580       * @return string Path of a class.
 581       */
 582  	public function autoload( $class ) {
 583          $class_parts = explode( '_', strtolower( $class ) );
 584  
 585          if ( 'bp' !== $class_parts[0] ) {
 586              return;
 587          }
 588  
 589          $components = array(
 590              'activity',
 591              'blogs',
 592              'core',
 593              'friends',
 594              'groups',
 595              'members',
 596              'messages',
 597              'notifications',
 598              'settings',
 599              'xprofile',
 600          );
 601  
 602          // These classes don't have a name that matches their component.
 603          $irregular_map = array(
 604              'BP_Akismet'                                 => 'activity',
 605              'BP_REST_Activity_Endpoint'                  => 'activity',
 606  
 607              'BP_REST_Blogs_Endpoint'                     => 'blogs',
 608              'BP_REST_Attachments_Blog_Avatar_Endpoint'   => 'blogs',
 609  
 610              'BP_Admin'                                   => 'core',
 611              'BP_Attachment_Avatar'                       => 'core',
 612              'BP_Attachment_Cover_Image'                  => 'core',
 613              'BP_Attachment'                              => 'core',
 614              'BP_Button'                                  => 'core',
 615              'BP_Block'                                   => 'core',
 616              'BP_Component'                               => 'core',
 617              'BP_Customizer_Control_Range'                => 'core',
 618              'BP_Date_Query'                              => 'core',
 619              'BP_Email_Delivery'                          => 'core',
 620              'BP_Email_Address'                           => 'core',
 621              'BP_Email_Recipient'                         => 'core',
 622              'BP_Email_Sender'                            => 'core',
 623              'BP_Email_Participant'                       => 'core',
 624              'BP_Email'                                   => 'core',
 625              'BP_Embed'                                   => 'core',
 626              'BP_Media_Extractor'                         => 'core',
 627              'BP_Members_Suggestions'                     => 'core',
 628              'BP_PHPMailer'                               => 'core',
 629              'BP_Recursive_Query'                         => 'core',
 630              'BP_Suggestions'                             => 'core',
 631              'BP_Theme_Compat'                            => 'core',
 632              'BP_User_Query'                              => 'core',
 633              'BP_Walker_Category_Checklist'               => 'core',
 634              /**
 635               * BP_Walker_Nav_Menu_Checklist class.
 636               *
 637               * As this class corresponding file is deprecated, it will trigger a deprecation notice if instantiated.
 638               * In a subsequent release, we'll remove it from our Classes Autoloader.
 639               *
 640               * @todo Remove the BP_Walker_Nav_Menu_Checklist from our Classes Autoloader.
 641               */
 642              'BP_Walker_Nav_Menu_Checklist'               => 'core',
 643              'BP_Walker_Nav_Menu'                         => 'core',
 644              'BP_Invitation_Manager'                      => 'core',
 645              'BP_Invitation'                              => 'core',
 646              'BP_REST_Components_Endpoint'                => 'core',
 647              'BP_REST_Attachments'                        => 'core',
 648              'BP_Admin_Types'                             => 'core',
 649              'BP_Optout'                                  => 'core',
 650              'BP_Optouts_List_Table'                      => 'core',
 651  
 652              'BP_Core_Friends_Widget'                     => 'friends',
 653              'BP_REST_Friends_Endpoint'                   => 'friends',
 654  
 655              'BP_Group_Extension'                         => 'groups',
 656              'BP_Group_Member_Query'                      => 'groups',
 657              'BP_REST_Groups_Endpoint'                    => 'groups',
 658              'BP_REST_Group_Membership_Endpoint'          => 'groups',
 659              'BP_REST_Group_Invites_Endpoint'             => 'groups',
 660              'BP_REST_Group_Membership_Request_Endpoint'  => 'groups',
 661              'BP_REST_Attachments_Group_Avatar_Endpoint'  => 'groups',
 662              'BP_REST_Attachments_Group_Cover_Endpoint'   => 'groups',
 663  
 664              'BP_Core_Members_Template'                   => 'members',
 665              'BP_Core_Members_Widget'                     => 'members',
 666              'BP_Core_Recently_Active_Widget'             => 'members',
 667              'BP_Core_Whos_Online_Widget'                 => 'members',
 668              'BP_Registration_Theme_Compat'               => 'members',
 669              'BP_Signup'                                  => 'members',
 670              'BP_REST_Members_Endpoint'                   => 'members',
 671              'BP_REST_Attachments_Member_Avatar_Endpoint' => 'members',
 672              'BP_REST_Attachments_Member_Cover_Endpoint'  => 'members',
 673              'BP_REST_Signup_Endpoint'                    => 'members',
 674              'BP_Members_Invitation_Manager'              => 'members',
 675              'BP_Members_Invitations_Template'            => 'members',
 676  
 677              'BP_REST_Messages_Endpoint'                  => 'messages',
 678  
 679              'BP_REST_Notifications_Endpoint'             => 'notifications',
 680  
 681              'BP_REST_XProfile_Fields_Endpoint'           => 'xprofile',
 682              'BP_REST_XProfile_Field_Groups_Endpoint'     => 'xprofile',
 683              'BP_REST_XProfile_Data_Endpoint'             => 'xprofile',
 684          );
 685  
 686          $component = null;
 687  
 688          // First check to see if the class is one without a properly namespaced name.
 689          if ( isset( $irregular_map[ $class ] ) ) {
 690              $component = $irregular_map[ $class ];
 691  
 692          // Next chunk is usually the component name.
 693          } elseif ( in_array( $class_parts[1], $components, true ) ) {
 694              $component = $class_parts[1];
 695          }
 696  
 697          if ( ! $component ) {
 698              return;
 699          }
 700  
 701          // Sanitize class name.
 702          $class = strtolower( str_replace( '_', '-', $class ) );
 703  
 704          if ( 'bp-rest-attachments' === $class ) {
 705              $path = dirname( __FILE__ ) . "/bp-{$component}/classes/trait-attachments.php";
 706          } else {
 707              $path = dirname( __FILE__ ) . "/bp-{$component}/classes/class-{$class}.php";
 708          }
 709  
 710          // Sanity check.
 711          if ( ! file_exists( $path ) ) {
 712              return;
 713          }
 714  
 715          /*
 716           * Sanity check 2 - Check if component is active before loading class.
 717           * Skip if PHPUnit is running, or BuddyPress is installing for the first time.
 718           */
 719          if (
 720              ! in_array( $component, array( 'core', 'members' ), true ) &&
 721              ! bp_is_active( $component ) &&
 722              ! function_exists( 'tests_add_filter' )
 723          ) {
 724              return;
 725          }
 726  
 727          require $path;
 728      }
 729  
 730      /**
 731       * Set up the default hooks and actions.
 732       *
 733       * @since 1.6.0
 734       */
 735  	private function setup_actions() {
 736  
 737          // Add actions to plugin activation and deactivation hooks.
 738          add_action( 'activate_' . $this->basename, 'bp_activation' );
 739          add_action( 'deactivate_' . $this->basename, 'bp_deactivation' );
 740  
 741          // If BuddyPress is being deactivated, do not add any actions.
 742          if ( bp_is_deactivation( $this->basename ) ) {
 743              return;
 744          }
 745  
 746          // Array of BuddyPress core actions.
 747          $actions = array(
 748              'setup_theme',              // Setup the default theme compat.
 749              'setup_current_user',       // Setup currently logged in user.
 750              'register_post_types',      // Register post types.
 751              'register_post_statuses',   // Register post statuses.
 752              'register_taxonomies',      // Register taxonomies.
 753              'register_views',           // Register the views.
 754              'register_theme_directory', // Register the theme directory.
 755              'register_theme_packages',  // Register bundled theme packages (bp-themes).
 756              'load_textdomain',          // Load textdomain.
 757              'add_rewrite_tags',         // Add rewrite tags.
 758              'generate_rewrite_rules',    // Generate rewrite rules.
 759          );
 760  
 761          // Add the actions.
 762          foreach ( $actions as $class_action ) {
 763              if ( method_exists( $this, $class_action ) ) {
 764                  add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 );
 765              }
 766          }
 767  
 768          /**
 769           * Fires after the setup of all BuddyPress actions.
 770           *
 771           * Includes bbp-core-hooks.php.
 772           *
 773           * @since 1.7.0
 774           *
 775           * @param BuddyPress $this. Current BuddyPress instance. Passed by reference.
 776           */
 777          do_action_ref_array( 'bp_after_setup_actions', array( &$this ) );
 778      }
 779  
 780      /**
 781       * Private method to align the active and database versions.
 782       *
 783       * @since 1.7.0
 784       */
 785  	private function versions() {
 786  
 787          // Get the possible DB versions (boy is this gross).
 788          $versions               = array();
 789          $versions['1.6-single'] = get_blog_option( $this->root_blog_id, '_bp_db_version' );
 790  
 791          // 1.6-single exists, so trust it.
 792          if ( ! empty( $versions['1.6-single'] ) ) {
 793              $this->db_version_raw = (int) $versions['1.6-single'];
 794  
 795          // If no 1.6-single exists, use the max of the others.
 796          } else {
 797              $versions['1.2']        = get_site_option( 'bp-core-db-version' );
 798              $versions['1.5-multi']  = get_site_option( 'bp-db-version' );
 799              $versions['1.6-multi']  = get_site_option( '_bp_db_version' );
 800              $versions['1.5-single'] = get_blog_option( $this->root_blog_id, 'bp-db-version' );
 801  
 802              // Remove empty array items.
 803              $versions             = array_filter( $versions );
 804              $this->db_version_raw = (int) ( ! empty( $versions ) ) ? (int) max( $versions ) : 0;
 805          }
 806      }
 807  
 808      /** Public Methods ********************************************************/
 809  
 810      /**
 811       * Set up BuddyPress's legacy theme directory.
 812       *
 813       * Starting with version 1.2, and ending with version 1.8, BuddyPress
 814       * registered a custom theme directory - bp-themes - which contained
 815       * the bp-default theme. Since BuddyPress 1.9, bp-themes is no longer
 816       * registered (and bp-default no longer offered) on new installations.
 817       * Sites using bp-default (or a child theme of bp-default) will
 818       * continue to have bp-themes registered as before.
 819       *
 820       * @since 1.5.0
 821       *
 822       * @todo Move bp-default to wordpress.org/extend/themes and remove this.
 823       */
 824  	public function register_theme_directory() {
 825          if ( ! bp_do_register_theme_directory() ) {
 826              return;
 827          }
 828  
 829          register_theme_directory( $this->old_themes_dir );
 830      }
 831  
 832      /**
 833       * Register bundled theme packages.
 834       *
 835       * Note that since we currently have complete control over bp-themes and
 836       * the bp-legacy folders, it's fine to hardcode these here. If at a
 837       * later date we need to automate this, an API will need to be built.
 838       *
 839       * @since 1.7.0
 840       */
 841  	public function register_theme_packages() {
 842  
 843          // Register the default theme compatibility package.
 844          bp_register_theme_package(
 845              array(
 846                  'id'      => 'legacy',
 847                  'name'    => __( 'BuddyPress Legacy', 'buddypress' ),
 848                  'version' => bp_get_version(),
 849                  'dir'     => trailingslashit( $this->themes_dir . '/bp-legacy' ),
 850                  'url'     => trailingslashit( $this->themes_url . '/bp-legacy' ),
 851              )
 852          );
 853  
 854          bp_register_theme_package(
 855              array(
 856                  'id'      => 'nouveau',
 857                  'name'    => __( 'BuddyPress Nouveau', 'buddypress' ),
 858                  'version' => bp_get_version(),
 859                  'dir'     => trailingslashit( $this->themes_dir . '/bp-nouveau' ),
 860                  'url'     => trailingslashit( $this->themes_url . '/bp-nouveau' ),
 861              )
 862          );
 863  
 864          // Register the basic theme stack. This is really dope.
 865          bp_register_template_stack( 'get_stylesheet_directory', 10 );
 866          bp_register_template_stack( 'get_template_directory', 12 );
 867          bp_register_template_stack( 'bp_get_theme_compat_dir', 14 );
 868      }
 869  
 870      /**
 871       * Set up the default BuddyPress theme compatibility location.
 872       *
 873       * @since 1.7.0
 874       */
 875  	public function setup_theme() {
 876  
 877          // Bail if something already has this under control.
 878          if ( ! empty( $this->theme_compat->theme ) ) {
 879              return;
 880          }
 881  
 882          // Setup the theme package to use for compatibility.
 883          bp_setup_theme_compat( bp_get_theme_package_id() );
 884      }
 885  }


Generated: Fri Dec 6 01:00:58 2024 Cross-referenced by PHPXref 0.7.1