Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/02/2018 02:58:28 AM (8 years ago)
Author:
r-a-y
Message:

Settings: Conditionally load action and screen functions.

This commit conditionally loads action and screen function code for the
Settings 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 settings page. Now, we only load this
code when needed.

See #7218.

File:
1 edited

Legend:

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

    r10555 r11926  
    4343        public function includes( $includes = array() ) {
    4444                parent::includes( array(
    45                         'actions',
    46                         'screens',
    4745                        'template',
    4846                        'functions',
    4947                ) );
     48        }
     49
     50        /**
     51         * Late includes method.
     52         *
     53         * Only load up certain code when on specific pages.
     54         *
     55         * @since 3.0.0
     56         */
     57        public function late_includes() {
     58                // Bail if PHPUnit is running.
     59                if ( defined( 'BP_TESTS_DIR' ) ) {
     60                        return;
     61                }
     62
     63                // Bail if not on Settings component.
     64                if ( ! bp_is_settings_component() ) {
     65                        return;
     66                }
     67
     68                $actions = array( 'notifications', 'capabilities', 'delete-account' );
     69
     70                // Authenticated actions.
     71                if ( is_user_logged_in() ) {
     72                        if ( bp_is_current_action( 'general' ) ) {
     73                                require $this->path . 'bp-settings/screens/general.php';
     74
     75                        // Specific to post requests.
     76                        } elseif ( bp_is_post_request() && in_array( bp_current_action(), $actions, true ) ) {
     77                                require $this->path . 'bp-settings/actions/' . bp_current_action() . '.php';
     78                        }
     79                }
     80
     81                // Screens - User profile integration.
     82                if ( bp_is_user() ) {
     83                        require $this->path . 'bp-settings/screens/general.php';
     84
     85                        // Sub-nav items.
     86                        if ( in_array( bp_current_action(), $actions, true ) ) {
     87                                require $this->path . 'bp-settings/screens/' . bp_current_action() . '.php';
     88                        }
     89                }
    5090        }
    5191
Note: See TracChangeset for help on using the changeset viewer.