Skip to:
Content

BuddyPress.org

Changeset 11389


Ignore:
Timestamp:
01/19/2017 07:25:11 PM (8 years ago)
Author:
boonebgorges
Message:

Prevent BuddyPress from loading when the minimum PHP version is not met.

When the server is running a version of PHP lower than 5.3.0, an
admin notice is thrown, and the rest of BuddyPress is not loaded.

The bp-loader.php file must remain compatible with WP's minimum PHP
version, to prevent fatal errors when activating BuddyPress. In order
to reduce the cognitive overhead involved in maintaining PHP compat
for this file, the BuddyPress class has been moved into its own
class-buddypress.php file.

Props r-a-y.
See #7277.

Location:
trunk/src
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-loader.php

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

    r11388 r11389  
    11<?php
    2 /**
    3  * The BuddyPress Plugin.
    4  *
    5  * BuddyPress is social networking software with a twist from the creators of WordPress.
    6  *
    7  * @package BuddyPress
    8  * @subpackage Main
    9  * @since 1.0.0
    10  */
    11 
    12 /**
    13  * Plugin Name: BuddyPress
    14  * Plugin URI:  https://buddypress.org/
    15  * Description: BuddyPress helps site builders and WordPress developers add community features to their websites, with user profile fields, activity streams, messaging, and notifications.
    16  * Author:      The BuddyPress Community
    17  * Author URI:  https://buddypress.org/
    18  * Version:     2.8.0-alpha
    19  * Text Domain: buddypress
    20  * Domain Path: /bp-languages/
    21  * License:     GPLv2 or later (license.txt)
    22  */
    23 
    24 // Exit if accessed directly
     2
     3// Exit if accessed directly.
    254defined( 'ABSPATH' ) || exit;
    265
    27 /** Constants *****************************************************************/
    28 
    29 if ( !class_exists( 'BuddyPress' ) ) :
    306/**
    317 * Main BuddyPress Class.
     
    757733    }
    758734}
    759 
    760 /**
    761  * The main function responsible for returning the one true BuddyPress Instance to functions everywhere.
    762  *
    763  * Use this function like you would a global variable, except without needing
    764  * to declare the global.
    765  *
    766  * Example: <?php $bp = buddypress(); ?>
    767  *
    768  * @return BuddyPress The one true BuddyPress Instance.
    769  */
    770 function buddypress() {
    771     return BuddyPress::instance();
    772 }
    773 
    774 /**
    775  * Hook BuddyPress early onto the 'plugins_loaded' action.
    776  *
    777  * This gives all other plugins the chance to load before BuddyPress, to get
    778  * their actions, filters, and overrides setup without BuddyPress being in the
    779  * way.
    780  */
    781 if ( defined( 'BUDDYPRESS_LATE_LOAD' ) ) {
    782     add_action( 'plugins_loaded', 'buddypress', (int) BUDDYPRESS_LATE_LOAD );
    783 
    784 // "And now here's something we hope you'll really like!"
    785 } else {
    786     $GLOBALS['bp'] = buddypress();
    787 }
    788 
    789 endif;
Note: See TracChangeset for help on using the changeset viewer.