Skip to:
Content

BuddyPress.org


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

Messages: Conditionally load action and screen functions.

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

See #7218.

File:
1 edited

Legend:

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

    r11910 r11925  
    5959                        'cssjs',
    6060                        'cache',
    61                         'actions',
    62                         'screens',
    6361                        'filters',
    6462                        'template',
     
    7977
    8078                parent::includes( $includes );
     79        }
     80
     81        /**
     82         * Late includes method.
     83         *
     84         * Only load up certain code when on specific pages.
     85         *
     86         * @since 3.0.0
     87         */
     88        public function late_includes() {
     89                // Bail if PHPUnit is running.
     90                if ( defined( 'BP_TESTS_DIR' ) ) {
     91                        return;
     92                }
     93
     94                if ( bp_is_messages_component() ) {
     95                        // Authenticated actions.
     96                        if ( is_user_logged_in() &&
     97                                in_array( bp_current_action(), array( 'compose', 'notices', 'view' ), true )
     98                        ) {
     99                                require $this->path . 'bp-messages/actions/' . bp_current_action() . '.php';
     100                        }
     101
     102                        // Authenticated action variables.
     103                        if ( is_user_logged_in() && bp_action_variable( 0 ) &&
     104                                in_array( bp_action_variable( 0 ), array( 'delete', 'read', 'unread', 'bulk-manage', 'bulk-delete' ), true )
     105                        ) {
     106                                require $this->path . 'bp-messages/actions/' . bp_action_variable( 0 ) . '.php';
     107                        }
     108
     109                        // Authenticated actions - Star.
     110                        if ( is_user_logged_in() && bp_is_active( $this->id, 'star' ) ) {
     111                                // Single action.
     112                                if ( in_array( bp_current_action(), array( 'star', 'unstar' ), true ) ) {
     113                                        require $this->path . 'bp-messages/actions/star.php';
     114                                }
     115
     116                                // Bulk-manage.
     117                                if ( bp_is_action_variable( 'bulk-manage' ) ) {
     118                                        require $this->path . 'bp-messages/actions/bulk-manage-star.php';
     119                                }
     120                        }
     121
     122                        // Screens - User profile integration.
     123                        if ( bp_is_user() ) {
     124                                require $this->path . 'bp-messages/screens/inbox.php';
     125
     126                                /*
     127                                 * Nav items.
     128                                 *
     129                                 * 'view' is not a registered nav item, but we add a screen handler manually.
     130                                 */
     131                                if ( bp_is_user_messages() && in_array( bp_current_action(), array( 'sentbox', 'compose', 'notices', 'view' ), true ) ) {
     132                                        require $this->path . 'bp-messages/screens/' . bp_current_action() . '.php';
     133                                }
     134
     135                                // Nav item - Starred.
     136                                if ( bp_is_active( $this->id, 'star' ) && bp_is_current_action( bp_get_messages_starred_slug() ) ) {
     137                                        require $this->path . 'bp-messages/screens/starred.php';
     138                                }
     139                        }
     140                }
     141
     142                // Groups notifications HTML table.
     143                if ( bp_is_user_settings_notifications() ) {
     144                        require $this->path . 'bp-messages/screens/settings-email.php';
     145                }
    81146        }
    82147
Note: See TracChangeset for help on using the changeset viewer.