Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/12/2014 03:01:27 AM (11 years ago)
Author:
boonebgorges
Message:

Untangle some load order and mutual dependency issues between component loaders

BuddyPress's components are dependent upon each other in numerous ways. All
components depend in one way or another on bp-core. Many components reference
bp-members functions and globals. References to bp-xprofile can be found in
a number of components. And so on. We have managed to make these dependencies
work on a case-by-case basis, though the system becomes less stable as it
becomes more complex. The fact that all components are loaded at
bp_setup_components introduces the possibliity of numerous race conditions that
may not cause problems on vanilla installations of BuddyPress, but can cause
fatal errors when trying to customize in various ways.

As part of an ongoing project to disentangle and regularize these dependencies
(see eg #5750), this changeset introduces a few enhancements that make the
dependencies between components more predictable, more serialized, and more
stable.

  • In bp-members and bp-groups, move canonical_stack determination out of the main setup_globals() method and into its own setup_canonical_stack() method. This new method runs after all components have had a chance to run setup_globals(). As a result, the components are able to reference each other safely when determining default and fallback components for redirects (for example, the members component has access to the activity component's slug and other global data when determining whether example.com/members/boone/activity/ should resolve to example.com/members/boone/)
  • In bp-members, use only WP core data to set up the loggedin_user and displayed_user global objects. Previously, these objects were configured by referenced to xprofile, which required that xprofile be loaded before members. Now, users' display names are first loaded from wp_users, and are overridden by the xprofile component via filter, only after xprofile has fully initialized.
  • In bp-xprofile, move the Settings > Profile navigation setup routine out of the main setup_nav() task. bp-xprofile loads early, before bp-settings has had a chance to set up its top-level navigation. As a result, bp-xprofile must wait until the bp_settings_setup_nav action to add its Profile subnav item.
  • Fine-tune the component load order. bp-core, which acts more like a library of common functionality than like a traditional component, is moved from bp_setup_components:10 to bp_loaded:0. This ensures that it is available to all other components. bp-xprofile, which must load after bp-members but at the same time is closely coupled to it, is moved to bp_setup_components:2, just after bp-members.

These changes are enough to make it possible to move forward on dependent
tickets; see, for example, #5407. It's likely that significant entanglement
and load-order issues remain. We'll continue to fix them as they arise, by
making load order more explicit, and by breaking the component bootstrap
process into increasingly discrete chunks.

Fixes #5436

Props boonebgorges, r-a-y

File:
1 edited

Legend:

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

    r8605 r8610  
    241241        }
    242242
    243         if ( bp_is_groups_component() && !empty( $this->current_group ) ) {
    244 
    245             $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' );
    246 
    247             if ( !bp_current_action() ) {
    248                 $bp->current_action = $this->default_extension;
    249             }
    250 
    251             // Prepare for a redirect to the canonical URL
    252             $bp->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
    253 
    254             if ( bp_current_action() ) {
    255                 $bp->canonical_stack['action'] = bp_current_action();
    256             }
    257 
    258             if ( !empty( $bp->action_variables ) ) {
    259                 $bp->canonical_stack['action_variables'] = bp_action_variables();
    260             }
    261 
    262             // When viewing the default extension, the canonical URL should not have
    263             // that extension's slug, unless more has been tacked onto the URL via
    264             // action variables
    265             if ( bp_is_current_action( $this->default_extension ) && empty( $bp->action_variables ) )  {
    266                 unset( $bp->canonical_stack['action'] );
    267             }
    268 
    269         }
    270 
    271243        // Preconfigured group creation steps
    272244        $this->group_creation_steps = apply_filters( 'groups_create_group_steps', array(
     
    306278        // Auto join group when non group member performs group activity
    307279        $this->auto_join = defined( 'BP_DISABLE_AUTO_GROUP_JOIN' ) && BP_DISABLE_AUTO_GROUP_JOIN ? false : true;
     280    }
     281
     282    /**
     283     * Set up canonical stack for this component.
     284     *
     285     * @since BuddyPress (2.1.0)
     286     */
     287    public function setup_canonical_stack() {
     288        if ( ! bp_is_groups_component() ) {
     289            return;
     290        }
     291
     292        if ( empty( $this->current_group ) ) {
     293            return;
     294        }
     295
     296
     297        $this->default_extension = apply_filters( 'bp_groups_default_extension', defined( 'BP_GROUPS_DEFAULT_EXTENSION' ) ? BP_GROUPS_DEFAULT_EXTENSION : 'home' );
     298
     299        if ( !bp_current_action() ) {
     300            buddypress()->current_action = $this->default_extension;
     301        }
     302
     303        // Prepare for a redirect to the canonical URL
     304        buddypress()->canonical_stack['base_url'] = bp_get_group_permalink( $this->current_group );
     305
     306        if ( bp_current_action() ) {
     307            buddypress()->canonical_stack['action'] = bp_current_action();
     308        }
     309
     310        if ( !empty( buddypress()->action_variables ) ) {
     311            buddypress()->canonical_stack['action_variables'] = bp_action_variables();
     312        }
     313
     314        // When viewing the default extension, the canonical URL should not have
     315        // that extension's slug, unless more has been tacked onto the URL via
     316        // action variables
     317        if ( bp_is_current_action( $this->default_extension ) && empty( buddypress()->action_variables ) )  {
     318            unset( buddypress()->canonical_stack['action'] );
     319        }
    308320    }
    309321
Note: See TracChangeset for help on using the changeset viewer.