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-xprofile/bp-xprofile-loader.php

    r8568 r8610  
    219219        }
    220220
    221         // Privacy Settings
    222         if ( bp_is_active( 'settings' ) ) {
    223 
    224             // Get the settings slug
    225             $settings_slug = bp_get_settings_slug();
    226 
    227             // Add the sub-navigation
    228             $sub_nav[] = array(
    229                 'name'            => __( 'Profile', 'buddypress' ),
    230                 'slug'            => 'profile',
    231                 'parent_url'      => trailingslashit( $user_domain . $settings_slug ),
    232                 'parent_slug'     => $settings_slug,
    233                 'screen_function' => 'bp_xprofile_screen_settings',
    234                 'position'        => 30,
    235                 'user_has_access' => bp_core_can_edit_settings()
    236             );
    237         }
     221        // The Settings > Profile nav item can only be set up after
     222        // the Settings component has run its own nav routine
     223        add_action( 'bp_settings_setup_nav', array( $this, 'setup_settings_nav' ) );
    238224
    239225        parent::setup_nav( $main_nav, $sub_nav );
     226    }
     227
     228    /**
     229     * Set up the Settings > Profile nav item.
     230     *
     231     * Loaded in a separate method because the Settings component may not
     232     * be loaded in time for BP_XProfile_Component::setup_nav().
     233     *
     234     * @since BuddyPress (2.1.0)
     235     */
     236    public function setup_settings_nav() {
     237        if ( ! bp_is_active( 'settings' ) ) {
     238            return;
     239        }
     240
     241        // Determine user to use
     242        if ( bp_displayed_user_domain() ) {
     243            $user_domain = bp_displayed_user_domain();
     244        } elseif ( bp_loggedin_user_domain() ) {
     245            $user_domain = bp_loggedin_user_domain();
     246        } else {
     247            return;
     248        }
     249
     250        // Get the settings slug
     251        $settings_slug = bp_get_settings_slug();
     252
     253        bp_core_new_subnav_item( array(
     254            'name'            => __( 'Profile', 'buddypress' ),
     255            'slug'            => 'profile',
     256            'parent_url'      => trailingslashit( $user_domain . $settings_slug ),
     257            'parent_slug'     => $settings_slug,
     258            'screen_function' => 'bp_xprofile_screen_settings',
     259            'position'        => 30,
     260            'user_has_access' => bp_core_can_edit_settings()
     261        ) );
    240262    }
    241263
     
    355377        $bp->profile = new BP_XProfile_Component();
    356378}
    357 add_action( 'bp_setup_components', 'bp_setup_xprofile', 6 );
     379add_action( 'bp_setup_components', 'bp_setup_xprofile', 2 );
Note: See TracChangeset for help on using the changeset viewer.