Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/02/2018 04:32:31 AM (6 years ago)
Author:
r-a-y
Message:

XProfile: Conditionally load action and screen functions.

This commit conditionally loads action and screen function code for the
XProfile component, utilizing the 'bp_late_include' hook introduced in
r11884.

Previously, we loaded these functions at all times, which is unnecessary
when a user is not on a BuddyPress extended profile page. Now, we only load
this code when needed.

See #7218.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-component.php

    r11360 r11928  
    6868            'cssjs',
    6969            'cache',
    70             'actions',
    7170            'activity',
    72             'screens',
    7371            'caps',
    7472            'filters',
     
    8482
    8583        parent::includes( $includes );
     84    }
     85
     86    /**
     87     * Late includes method.
     88     *
     89     * Only load up certain code when on specific pages.
     90     *
     91     * @since 3.0.0
     92     */
     93    public function late_includes() {
     94        // Bail if PHPUnit is running.
     95        if ( defined( 'BP_TESTS_DIR' ) ) {
     96            return;
     97        }
     98
     99        // Bail if not on a user page.
     100        if ( ! bp_is_user() ) {
     101            return;
     102        }
     103
     104        // User nav.
     105        if ( bp_is_profile_component() ) {
     106            require $this->path . 'bp-xprofile/screens/public.php';
     107
     108            // Action - Delete avatar.
     109            if ( is_user_logged_in()&& bp_is_user_change_avatar() && bp_is_action_variable( 'delete-avatar', 0 ) ) {
     110                require $this->path . 'bp-xprofile/actions/delete-avatar.php';
     111            }
     112
     113            // Sub-nav items.
     114            if ( is_user_logged_in() &&
     115                in_array( bp_current_action(), array( 'edit', 'change-avatar', 'change-cover-image' ), true )
     116            ) {
     117                require $this->path . 'bp-xprofile/screens/' . bp_current_action() . '.php';
     118            }
     119        }
     120
     121        // Settings.
     122        if ( is_user_logged_in() && bp_is_user_settings_profile() ) {
     123            require $this->path . 'bp-xprofile/screens/settings-profile.php';
     124        }
    86125    }
    87126
Note: See TracChangeset for help on using the changeset viewer.