Skip to:
Content

BuddyPress.org

Changeset 5309 for trunk/bp-loader.php


Ignore:
Timestamp:
11/08/2011 08:39:23 PM (15 years ago)
Author:
johnjamesjacoby
Message:

bp-loader.php is a real boy! Introduce BuddyPress class to handle the loading of BuddyPress core and provide declarations to the $bp global variables. Ports several functions and methods from bbPress 2.0 into bp-core-update.php to manage the hand-off into the update routine. See #3739.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-loader.php

    r5298 r5309  
    11<?php
     2
     3/**
     4 * The BuddyPress Plugin
     5 *
     6 * BuddyPress is social networking software with a twist from the creators of WordPress.
     7 *
     8 * @package BuddyPress
     9 * @subpackage Main
     10 */
     11
    212/**
    313 * Plugin Name: BuddyPress
     
    515 * Description: Social networking in a box. Build a social network for your company, school, sports team or niche community all based on the power and flexibility of WordPress.
    616 * Author:      The BuddyPress Community
     17 * Author URI:  http://buddypress.org/community/members/
    718 * Version:     1.6-bleeding
    8  * Author URI:  http://buddypress.org/community/members/
     19 * Text Domain: buddypress
     20 * Domain Path: /bp-languages/
    921 * Network:     true
    1022 */
     
    1426
    1527/** Constants *****************************************************************/
    16 global $wpdb;
    17 
    18 // Define the BuddyPress version
    19 if ( !defined( 'BP_VERSION' ) )
    20         define( 'BP_VERSION', '1.6-bleeding' );
    21 
    22 // Define the database version
    23 if ( !defined( 'BP_DB_VERSION' ) )
    24         define( 'BP_DB_VERSION', 5249 );
    25 
    26 // Place your custom code (actions/filters) in a file called
    27 // '/plugins/bp-custom.php' and it will be loaded before anything else.
    28 if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
    29         require( WP_PLUGIN_DIR . '/bp-custom.php' );
    30 
    31 // Define on which blog ID BuddyPress should run
    32 if ( !defined( 'BP_ROOT_BLOG' ) ) {
    33 
    34         // Root blog is the main site on this network
    35         if ( is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    36                 $current_site = get_current_site();
    37                 $root_blog_id = $current_site->blog_id;
    38 
    39         // Root blog is every site on this network
    40         } elseif ( is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) ) {
    41                 $root_blog_id = get_current_blog_id();
    42 
    43         // Root blog is the only blog on this network
    44         } elseif( !is_multisite() ) {
    45                 $root_blog_id = 1;
     28
     29if ( !class_exists( 'BuddyPress' ) ) :
     30/**
     31 * Main BuddyPress Class
     32 *
     33 * Tap tap tap... Is this thing on?
     34 *
     35 * @since BuddyPress (1.6)
     36 */
     37class BuddyPress {
     38
     39        /**
     40         * Note to Plugin and Theme authors:
     41         *
     42         * Do not directly reference the variables below in your code. Their names
     43         * and locations in the BuddyPress class are subject to change at any time.
     44         *
     45         * Most of them have reference functions located in bp-core-functions.php.
     46         * The ones that don't can be accessed via their respective WordPress API's.
     47         *
     48         * Components are encouraged to store their data in the $bp global rather
     49         * than new globals to keep all BuddyPress data in one place.
     50         */
     51
     52        /** Version ***************************************************************/
     53
     54        /**
     55         * @var string BuddyPress version
     56         */
     57        public $version = '1.6-bleeding';
     58
     59        /**
     60         * @var int Database version of current BuddyPress files
     61         */
     62        public $db_version = 5249;
     63       
     64        /**
     65         * @var int Database version raw from database connection
     66         */
     67        public $db_version_raw = 0;
     68       
     69        /**
     70         * @var string State of BuddyPress installation
     71         */
     72        public $maintenance_mode = '';
     73
     74        /** Paths *****************************************************************/
     75
     76        /**
     77         * @var string Basename of the BuddyPress plugin directory
     78         */
     79        public $basename = '';
     80
     81        /**
     82         * @var string Absolute path to the BuddyPress plugin directory
     83         */
     84        public $plugin_dir = '';
     85
     86        /**
     87         * @var string Absolute path to the BuddyPress themes directory
     88         */
     89        public $themes_dir = '';
     90
     91        /**
     92         * @var string Absolute path to the BuddyPress language directory
     93         */
     94        public $lang_dir = '';
     95
     96        /** URLs ******************************************************************/
     97
     98        /**
     99         * @var string URL to the BuddyPress plugin directory
     100         */
     101        public $plugin_url = '';
     102
     103        /**
     104         * @var string URL to the BuddyPress themes directory
     105         */
     106        public $themes_url = '';
     107
     108        /** Users *****************************************************************/
     109
     110        /**
     111         * @var object Current user
     112         */
     113        public $current_user = array();
     114
     115        /**
     116         * @var object Displayed user
     117         */
     118        public $displayed_user = array();
     119
     120        /** Errors ****************************************************************/
     121
     122        /**
     123         * @var WP_Error Used to log and display errors
     124         */
     125        public $errors = array();
     126
     127        /** Forms *****************************************************************/
     128
     129        /**
     130         * @var int The current tab index for form building
     131         */
     132        public $tab_index = 0;
     133
     134        /** Theme Compat **********************************************************/
     135
     136        /**
     137         * @var string Theme to use for theme compatibility
     138         */
     139        public $theme_compat = '';
     140
     141        /** Extensions ************************************************************/
     142
     143        /**
     144         * @var mixed BuddyPress add-ons should append globals to this
     145         */
     146        public $extend = false;
     147
     148        /** Option Overload *******************************************************/
     149
     150        /**
     151         * @var array Optional Overloads default options retrieved from get_option()
     152         */
     153        public $options = array();
     154
     155        /** Permastructs **********************************************************/
     156
     157        /**
     158         * @var string User struct
     159         */
     160        public $user_id = '';
     161
     162        /**
     163         * @var string Edit struct
     164         */
     165        public $edit_id = '';
     166
     167        /** Statuses **************************************************************/
     168
     169        /**
     170         * @var string Public post status id. Used by forums, topics, and replies.
     171         */
     172        public $public_status_id = '';
     173
     174        /**
     175         * @var string Pending post status id. Used by topics and replies
     176         */
     177        public $pending_status_id = '';
     178
     179        /**
     180         * @var string Private post status id. Used by forums and topics.
     181         */
     182        public $private_status_id = '';
     183
     184        /**
     185         * @var string Closed post status id. Used by topics.
     186         */
     187        public $closed_status_id = '';
     188
     189        /**
     190         * @var string Spam post status id. Used by topics and replies.
     191         */
     192        public $spam_status_id = '';
     193
     194        /**
     195         * @var string Trash post status id. Used by topics and replies.
     196         */
     197        public $trash_status_id = '';
     198
     199        /**
     200         * @var string Orphan post status id. Used by topics and replies.
     201         */
     202        public $orphan_status_id = '';
     203
     204        /**
     205         * @var string Hidden post status id. Used by forums.
     206         */
     207        public $hidden_status_id = '';
     208
     209        /** Functions *************************************************************/
     210
     211        /**
     212         * The main BuddyPress loader
     213         *
     214         * @since BuddyPress (1.6)
     215         *
     216         * @uses BuddyPress::constants() Setup legacy constants
     217         * @uses BuddyPress::setup_globals() Setup globals needed
     218         * @uses BuddyPress::includes() Includ required files
     219         * @uses BuddyPress::setup_actions() Setup hooks and actions
     220         */
     221        public function __construct() {
     222                $this->constants();
     223                $this->setup_globals();
     224                $this->includes();
     225                $this->setup_actions();
    46226        }
    47227
    48         define( 'BP_ROOT_BLOG', $root_blog_id );
    49 }
    50 
    51 // Path and URL
    52 if ( !defined( 'BP_PLUGIN_DIR' ) )
    53         define( 'BP_PLUGIN_DIR', WP_PLUGIN_DIR . '/buddypress' );
    54 
    55 if ( !defined( 'BP_PLUGIN_URL' ) )
    56         define( 'BP_PLUGIN_URL', plugins_url( 'buddypress' ) );
    57 
    58 // The search slug has to be defined nice and early because of the way search requests are loaded
    59 if ( !defined( 'BP_SEARCH_SLUG' ) )
    60         define( 'BP_SEARCH_SLUG', 'search' );
    61 
    62 /** Loader ********************************************************************/
    63 
    64 // Load the WP abstraction file so BuddyPress can run on all WordPress setups.
    65 require( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
    66 
    67 // Test to see whether this is a new installation or an upgraded version of BuddyPress
    68 if ( !$bp->database_version = get_site_option( 'bp-db-version' ) ) {
    69         if ( $bp->database_version = get_option( 'bp-db-version' ) ) {
    70                 $bp->is_network_activate = 1;
    71         } else {
    72                 $bp->database_version = get_site_option( 'bp-core-db-version' );  // BP 1.2 option
     228        /**
     229         * Legacy BuddyPress constants
     230         *
     231         * Try to avoid using these. Their values have been moved into variables
     232         * in the $bp global, and have matching functions to get/set their value.
     233         *
     234         * @since BuddyPress (1.6)
     235         *
     236         * @uses is_multisite()
     237         * @uses get_current_site()
     238         * @uses get_current_blog_id()
     239         * @uses plugin_dir_path()
     240         * @uses plugin_dir_url()
     241         */
     242        public function constants() {
     243
     244                // Define the BuddyPress version
     245                if ( !defined( 'BP_VERSION' ) )
     246                        define( 'BP_VERSION', $this->version );
     247
     248                // Define the database version
     249                if ( !defined( 'BP_DB_VERSION' ) )
     250                        define( 'BP_DB_VERSION', $this->db_version );
     251
     252                // Place your custom code (actions/filters) in a file called
     253                // '/plugins/bp-custom.php' and it will be loaded before anything else.
     254                if ( file_exists( WP_PLUGIN_DIR . '/bp-custom.php' ) )
     255                        require( WP_PLUGIN_DIR . '/bp-custom.php' );
     256
     257                // Define on which blog ID BuddyPress should run
     258                if ( !defined( 'BP_ROOT_BLOG' ) ) {
     259
     260                        // Default to 1
     261                        $root_blog_id = 1;
     262                       
     263                        // Root blog is the main site on this network
     264                        if ( is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ) {
     265                                $current_site = get_current_site();
     266                                $root_blog_id = $current_site->blog_id;
     267
     268                        // Root blog is every site on this network
     269                        } elseif ( is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) ) {
     270                                $root_blog_id = get_current_blog_id();
     271                        }
     272
     273                        define( 'BP_ROOT_BLOG', $root_blog_id );
     274                }
     275
     276                // Path and URL
     277                if ( !defined( 'BP_PLUGIN_DIR' ) )
     278                        define( 'BP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     279
     280                if ( !defined( 'BP_PLUGIN_URL' ) )
     281                        define( 'BP_PLUGIN_URL', plugin_dir_url ( __FILE__ ) );
     282
     283                // The search slug has to be defined nice and early because of the way
     284                // search requests are loaded
     285                //
     286                // @todo Maxe this better
     287                if ( !defined( 'BP_SEARCH_SLUG' ) )
     288                        define( 'BP_SEARCH_SLUG', 'search' );   
     289        }
     290
     291        /**
     292         * Component global variables
     293         *
     294         * @since BuddyPress (1.6)
     295         * @access private
     296         *
     297         * @uses plugin_dir_path() To generate BuddyPress plugin path
     298         * @uses plugin_dir_url() To generate BuddyPress plugin url
     299         * @uses apply_filters() Calls various filters
     300         */
     301        private function setup_globals() {
     302
     303                /** Paths *************************************************************/
     304
     305                // BuddyPress root directory
     306                $this->file       = __FILE__;
     307                $this->basename   = plugin_basename( $this->file );
     308                $this->plugin_dir = plugin_dir_path( $this->file );
     309                $this->plugin_url = plugin_dir_url ( $this->file );
     310
     311                // Themes
     312                $this->themes_dir = $this->plugin_dir . 'bp-themes';
     313                $this->themes_url = $this->plugin_url . 'bp-themes';
     314
     315                // Languages
     316                $this->lang_dir   = $this->plugin_dir . 'bp-languages';
     317
     318                /** Identifiers *******************************************************/
     319
     320                // Status identifiers
     321                $this->spam_status_id     = apply_filters( 'bp_spam_post_status',    'spam'    );
     322                $this->closed_status_id   = apply_filters( 'bp_closed_post_status',  'closed'  );
     323                $this->orphan_status_id   = apply_filters( 'bp_orphan_post_status',  'orphan'  );
     324                $this->public_status_id   = apply_filters( 'bp_public_post_status',  'publish' );
     325                $this->pending_status_id  = apply_filters( 'bp_pending_post_status', 'pending' );
     326                $this->private_status_id  = apply_filters( 'bp_private_post_status', 'private' );
     327                $this->hidden_status_id   = apply_filters( 'bp_hidden_post_status',  'hidden'  );
     328                $this->trash_status_id    = apply_filters( 'bp_trash_post_status',   'trash'   );
     329
     330                // Other identifiers
     331                $this->user_id            = apply_filters( 'bp_user_id', 'bp_user' );
     332                $this->edit_id            = apply_filters( 'bp_edit_id', 'edit'     );
     333
     334                /** Misc **************************************************************/
     335
     336                // Errors
     337                $this->errors             = new WP_Error();
     338
     339                // Tab Index
     340                $this->tab_index          = apply_filters( 'bp_default_tab_index', 100 );
     341        }
     342
     343        /**
     344         * Include required files
     345         *
     346         * @since BuddyPress (1.6)
     347         * @access private
     348         *
     349         * @uses is_admin() If in WordPress admin, load additional file
     350         */
     351        private function includes() {
     352
     353                // Load the WP abstraction file so BuddyPress can run on all WordPress setups.
     354                require( BP_PLUGIN_DIR . '/bp-core/bp-core-wpabstraction.php' );
     355
     356                // Get the possible DB versions
     357                $versions               = array();
     358                $versions['1.2']        = get_site_option( 'bp-core-db-version' );
     359                $versions['1.5-single'] = get_site_option( 'bp-db-version'      );
     360                $versions['1.5-multi']  = get_option     ( 'bp-db-version'      );
     361                $versions['1.6']        = get_option     ( '_bp_db_version'     );
     362
     363                // Remove empty array items
     364                $versions = array_filter( $versions );
     365
     366                // Get the largest version
     367                $this->db_version_raw      = (int) max( $versions );
     368
     369                // Are we network activated?
     370                $this->is_network_activate = !empty( $versions['1.5-multi'] );
     371                       
     372                // This is a new installation
     373                if ( empty( $this->db_version_raw ) ) {
     374                        $this->maintenance_mode = 'install';
     375                        require( $this->plugin_dir . '/bp-core/admin/bp-core-update.php' );
     376
     377                // There is a previous installation
     378                } else {
     379
     380                        // Setup the BuddyPress theme directory
     381                        register_theme_directory( $this->themes_dir );
     382
     383                        // Load core
     384                        require( $this->plugin_dir . '/bp-core/bp-core-loader.php' );
     385
     386                        // Check if an update is required
     387                        if ( (int) $this->db_version_raw < (int) $this->db_version || ( !empty( $this->is_network_activate ) ) ) {
     388                                $this->maintenance_mode = 'update';
     389                                require( $this->plugin_dir . '/bp-core/admin/bp-core-update.php' );
     390                        }
     391                }               
     392        }
     393
     394        /**
     395         * Setup the default hooks and actions
     396         *
     397         * @since BuddyPress (1.6)
     398         * @access private
     399         *
     400         * @uses register_activation_hook() To register the activation hook
     401         * @uses register_deactivation_hook() To register the deactivation hook
     402         * @uses add_action() To add various actions
     403         */
     404        private function setup_actions() {
     405
     406                // Add actions to plugin activation and deactivation hooks
     407                add_action( 'activate_'   . $this->basename, 'bp_activation'   );
     408                add_action( 'deactivate_' . $this->basename, 'bp_deactivation' );
     409
     410                // If BuddyPress is being deactivated, do not add any actions
     411                if ( bp_is_deactivation( $this->basename ) )
     412                        return;
     413
     414                // Array of BuddyPress core actions
     415                $actions = array(
     416                        'setup_current_user',       // Setup currently logged in user
     417                        'register_post_types',      // Register post types
     418                        'register_post_statuses',   // Register post statuses
     419                        'register_taxonomies',      // Register taxonomies
     420                        'register_views',           // Register the views
     421                        'register_theme_directory', // Register the theme directory
     422                        'load_textdomain',          // Load textdomain
     423                        'add_rewrite_tags',         // Add rewrite tags
     424                        'generate_rewrite_rules'    // Generate rewrite rules
     425                );
     426
     427                // Add the actions
     428                foreach( $actions as $class_action )
     429                        add_action( 'bp_' . $class_action, array( $this, $class_action ), 5 );
    73430        }
    74431}
    75432
    76 // This is a new installation.
    77 if ( empty( $bp->database_version ) ) {
    78         $bp->maintenance_mode = 'install';
    79         require( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-update.php' );
    80 
    81 // There is a previous installation
    82 } else {
    83 
    84         // Setup the BuddyPress theme directory
    85         register_theme_directory( BP_PLUGIN_DIR . '/bp-themes' );
    86 
    87         // Load core
    88         require( BP_PLUGIN_DIR . '/bp-core/bp-core-loader.php' );
    89 
    90         // Check if an update is required
    91         if ( (int)$bp->database_version < (int)constant( 'BP_DB_VERSION' ) || isset( $bp->is_network_activate ) ) {
    92                 $bp->maintenance_mode = 'update';
    93                 require( BP_PLUGIN_DIR . '/bp-core/admin/bp-core-update.php' );
    94         }
    95 }
     433// "And now for something completely different"
     434$_GLOBALS['bp'] = new BuddyPress;
     435
     436endif;
    96437
    97438/** Activation ****************************************************************/
     439
     440// @todo Move this code into bp-core-update.php
    98441
    99442if ( !function_exists( 'bp_loader_activate' ) ) :
Note: See TracChangeset for help on using the changeset viewer.