Skip to:
Content

BuddyPress.org

Changeset 7346 for trunk/bp-loader.php


Ignore:
Timestamp:
08/12/2013 09:56:33 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Switch main BuddyPress singleton pointer from a private static to a local static inside the instance() method, preventing recursive $instance references. See ​#BB2370.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-loader.php

    r7288 r7346  
    107107
    108108        /**
    109          * @var BuddyPress The one true BuddyPress
    110          */
    111         private static $instance;
    112 
    113         /**
    114109         * Main BuddyPress Instance
    115110         *
    … …  
    123118         * @since BuddyPress (1.7)
    124119         *
    125          * @staticvar array $instance
     120         * @staticvar object $instance
    126121         * @uses BuddyPress::constants() Setup the constants (mostly deprecated)
    127122         * @uses BuddyPress::setup_globals() Setup the globals needed
     123         * @uses BuddyPress::legacy_constants() Setup the legacy constants (deprecated)
    128124         * @uses BuddyPress::includes() Include the required files
    129125         * @uses BuddyPress::setup_actions() Setup the hooks and actions
    … …  
    133129         */
    134130        public static function instance() {
    135                 if ( ! isset( self::$instance ) ) {
    136                         self::$instance = new BuddyPress;
    137                         self::$instance->constants();
    138                         self::$instance->setup_globals();
    139                         self::$instance->legacy_constants();
    140                         self::$instance->includes();
    141                         self::$instance->setup_actions();
     131
     132                // Store the instance locally to avoid private static replication
     133                static $instance = null;
     134
     135                // Only run these methods if they haven't been ran previously
     136                if ( null === $instance ) {
     137                        $instance = new BuddyPress;
     138                        $instance->constants();
     139                        $instance->setup_globals();
     140                        $instance->legacy_constants();
     141                        $instance->includes();
     142                        $instance->setup_actions();
    142143                }
    143                 return self::$instance;
     144
     145                // Always return the instance
     146                return $instance;
    144147        }
    145148
Note: See TracChangeset for help on using the changeset viewer.