Skip to:
Content

BuddyPress.org

Changeset 11885


Ignore:
Timestamp:
03/05/2018 12:00:25 AM (21 months ago)
Author:
r-a-y
Message:

Activity: Conditionally load action and screen functions.

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

A special case is required for PHPUnit as PHPUnit doesn't like conditional-
included files when running multiple unit tests. So for PHPUnit, we
include all action and screen code at once, just like before.

See #7218.

Location:
trunk
Files:
17 added
2 deleted
2 edited

Legend:

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

    r11360 r11885  
    5252        $includes = array(
    5353            'cssjs',
    54             'actions',
    55             'screens',
    5654            'filters',
    5755            'adminbar',
     
    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        /*
     100         * Load activity action and screen code if PHPUnit isn't running.
     101         *
     102         * For PHPUnit, we load these files in tests/phpunit/includes/install.php.
     103         */
     104        if ( bp_is_current_component( 'activity' ) ) {
     105            // Authenticated actions - Only fires when JS is disabled.
     106            if ( is_user_logged_in() &&
     107                in_array( bp_current_action(), array( 'delete', 'spam', 'post', 'reply', 'favorite', 'unfavorite' ), true )
     108            ) {
     109                require $this->path . 'bp-activity/actions/' . bp_current_action() . '.php';
     110            }
     111
     112            // RSS feeds.
     113            if ( bp_is_current_action( 'feed' ) || bp_is_action_variable( 'feed', 0 ) ) {
     114                require $this->path . 'bp-activity/actions/feeds.php';
     115            }
     116
     117            // Screens - Directory.
     118            if ( bp_is_activity_directory() ) {
     119                require $this->path . 'bp-activity/screens/directory.php';
     120            }
     121
     122            // Screens - User main nav.
     123            if ( bp_is_user() ) {
     124                require $this->path . 'bp-activity/screens/just-me.php';
     125            }
     126
     127            // Screens - User secondary nav.
     128            if ( bp_is_user() && in_array( bp_current_action(), array( 'friends', 'groups', 'favorites', 'mentions' ), true ) ) {
     129                require $this->path . 'bp-activity/screens/' . bp_current_action() . '.php';
     130            }
     131
     132            // Screens - Single permalink.
     133            if ( bp_is_current_action( 'p' ) || is_numeric( bp_current_action() ) ) {
     134                require $this->path . 'bp-activity/screens/permalink.php';
     135            }
     136
     137            // Theme compatibility.
     138            new BP_Activity_Theme_Compat();
     139        }
     140
     141        // Activity notifications HTML table.
     142        if ( bp_is_user_settings_notifications() ) {
     143            require $this->path . 'bp-activity/screens/settings-email.php';
     144        }
    86145    }
    87146
  • trunk/tests/phpunit/includes/loader.php

    r11882 r11885  
    1717}
    1818tests_add_filter( 'bp_send_email_delivery_class', '_bp_mock_mailer' );
     19
     20/**
     21 * Load up activity action and screen code.
     22 *
     23 * In BuddyPress, this is loaded conditionally, but PHPUnit needs all files
     24 * loaded at the same time to prevent weird load order issues.
     25 */
     26add_action( 'bp_activity_includes', function() {
     27    $dirs = array(
     28        buddypress()->plugin_dir . 'bp-activity/actions/',
     29        buddypress()->plugin_dir . 'bp-activity/screens/',
     30    );
     31
     32    foreach ( $dirs as $dir ) {
     33        foreach ( glob( $dir . "*.php" ) as $file ) {
     34            require $file;
     35        }
     36    }
     37} );
Note: See TracChangeset for help on using the changeset viewer.