Skip to:
Content

BuddyPress.org

Changeset 11934


Ignore:
Timestamp:
04/02/2018 06:15:37 PM (7 years ago)
Author:
r-a-y
Message:

Blogs: Conditionally load action and screen functions.

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

See #7218.

Location:
trunk
Files:
5 added
1 deleted
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/actions/random.php

    r11933 r11934  
    11<?php
    22/**
    3  * BuddyPress Blogs Actions.
     3 * Blogs: Random blog action handler
    44 *
    55 * @package BuddyPress
    66 * @subpackage BlogsActions
    7  * @since 1.5.0
     7 * @since 3.0.0
    88 */
    9 
    10 // Exit if accessed directly.
    11 defined( 'ABSPATH' ) || exit;
    129
    1310/**
  • trunk/src/bp-blogs/classes/class-bp-blogs-component.php

    r11799 r11934  
    126126        $includes = array(
    127127            'cache',
    128             'actions',
    129             'screens',
    130128            'template',
    131129            'filters',
     
    143141        // Include the files.
    144142        parent::includes( $includes );
     143    }
     144
     145    /**
     146     * Late includes method.
     147     *
     148     * Only load up certain code when on specific pages.
     149     *
     150     * @since 3.0.0
     151     */
     152    public function late_includes() {
     153        // Bail if PHPUnit is running.
     154        if ( defined( 'BP_TESTS_DIR' ) ) {
     155            return;
     156        }
     157
     158        // Bail if not on a blogs page or not multisite.
     159        if ( ! bp_is_blogs_component() || ! is_multisite() ) {
     160            return;
     161        }
     162
     163        // Actions.
     164        if ( isset( $_GET['random-blog'] ) ) {
     165            require $this->path . 'bp-blogs/actions/random.php';
     166        }
     167
     168        // Screens.
     169        if ( bp_is_user() ) {
     170            require $this->path . 'bp-blogs/screens/my-blogs.php';
     171        } else {
     172            if ( bp_is_blogs_directory() ) {
     173                require $this->path . 'bp-blogs/screens/directory.php';
     174            }
     175
     176            if ( is_user_logged_in() && bp_is_current_action( 'create' ) ) {
     177                require $this->path . 'bp-blogs/screens/create.php';
     178            }
     179
     180            // Theme compatibility.
     181            new BP_Blogs_Theme_Compat();
     182        }
    145183    }
    146184
  • trunk/tests/phpunit/includes/loader.php

    r11933 r11934  
    2424 * loaded at the same time to prevent weird load order issues.
    2525 */
    26 $components = array( 'activity', 'friends', 'groups', 'members', 'messages', 'notifications', 'settings', 'xprofile' );
     26$components = array( 'activity', 'blogs', '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.