Skip to:
Content

BuddyPress.org

Changeset 11933


Ignore:
Timestamp:
04/02/2018 05:35:08 PM (7 years ago)
Author:
r-a-y
Message:

Notifications: Conditionally load action and screen functions.

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

This commit also moves over the unused bp_notifications_screen_settings()
function from bp-notifications-screens.php to
bp-notifications-functions.php. This function is a candidate for future
deprecation.

See #7218.

Location:
trunk
Files:
6 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/bp-notifications-functions.php

    r11888 r11933  
    662662}
    663663
     664/**
     665 * Catch and route the 'settings' notifications screen.
     666 *
     667 * This is currently unused.
     668 *
     669 * @since 1.9.0
     670 */
     671function bp_notifications_screen_settings() {}
     672
    664673/** Meta **********************************************************************/
    665674
  • trunk/src/bp-notifications/classes/class-bp-notifications-component.php

    r11360 r11933  
    4545    public function includes( $includes = array() ) {
    4646        $includes = array(
    47             'actions',
    48             'screens',
    4947            'adminbar',
    5048            'template',
     
    5452
    5553        parent::includes( $includes );
     54    }
     55
     56    /**
     57     * Late includes method.
     58     *
     59     * Only load up certain code when on specific pages.
     60     *
     61     * @since 3.0.0
     62     */
     63    public function late_includes() {
     64        // Bail if PHPUnit is running.
     65        if ( defined( 'BP_TESTS_DIR' ) ) {
     66            return;
     67        }
     68
     69        // Bail if not on a notifications page or logged in.
     70        if ( ! bp_is_user_notifications() || ! is_user_logged_in() ) {
     71            return;
     72        }
     73
     74        // Actions.
     75        if ( bp_is_post_request() ) {
     76            require $this->path . 'bp-notifications/actions/bulk-manage.php';
     77        } elseif ( bp_is_get_request() ) {
     78            require $this->path . 'bp-notifications/actions/delete.php';
     79        }
     80
     81        // Screens.
     82        require $this->path . 'bp-notifications/screens/unread.php';
     83        if ( bp_is_current_action( 'read' ) ) {
     84            require $this->path . 'bp-notifications/screens/read.php';
     85        }
    5686    }
    5787
  • trunk/tests/phpunit/includes/loader.php

    r11931 r11933  
    2424 * loaded at the same time to prevent weird load order issues.
    2525 */
    26 $components = array( 'activity', 'friends', 'groups', 'members', 'messages', 'settings', 'xprofile' );
     26$components = array( 'activity', 'friends', 'groups', 'members', 'messages', 'notifications', 'settings', 'xprofile' );
    2727foreach ( $components as $component ) {
    2828    add_action( "bp_{$component}_includes", function() use ( $component ) {
Note: See TracChangeset for help on using the changeset viewer.