Skip to:
Content

BuddyPress.org


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.