Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/26/2022 02:59:36 PM (3 years ago)
Author:
imath
Message:

First step towards only loading Template Packs assets in BP pages

Avoid loading these assets everywhere inside the blog is a frequent request made by BuddyPress users. In 11.0.0 we are doing a first step into this direction by making available a new filter to restrict Template Packs assets loading to BuddyPress pages.

We encourage these users to simply add the add_filter( 'bp_enqueue_assets_in_bp_pages_only', '__return_true' ); code into a BP Custom file for instance to contribute to testing whether it has an unwanted side effect on the BuddyPress plugins that they might have activated.

This will help us feel more secure about completely restricting these assets to BP pages in a second step.

Props dcavins

Fixes #8679

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-dependency.php

    r12728 r13306  
    500500
    501501/**
    502  * Fires the 'bp_enqueue_embed_scripts' action in the <head> for BP oEmbeds.
    503  *
    504  * @since 2.6.0
    505  */
    506 function bp_enqueue_embed_scripts() {
    507     if ( ! is_buddypress() ) {
     502 * Fires an action hook to enqueue scripts and styles for specific BuddyPress contexts.
     503 *
     504 * @since 11.0.0
     505 *
     506 * @param string $context The specific BuddyPress context. Supported values are `embed` and `community`.
     507 *                        Default: `embed`.
     508 */
     509function bp_enqueue_context_scripts( $context = 'embed' ) {
     510    $bp_pages_only_assets = false;
     511
     512    /**
     513     * Filter here & return `true` to restrict BP Assets loading to BP Pages.
     514     *
     515     * @since 11.0.0
     516     *
     517     * @param bool $value False to carry on loading BP Assets "everywhere". True otherwise.
     518     */
     519    $bp_pages_only = apply_filters( 'bp_enqueue_assets_in_bp_pages_only', false );
     520
     521    if ( 'embed' === $context || $bp_pages_only ) {
     522        $bp_pages_only_assets = true;
     523    }
     524
     525    if ( $bp_pages_only_assets && ! is_buddypress() ) {
    508526        return;
    509527    }
    510528
    511529    /**
    512      * Enqueue CSS and JS files for BuddyPress embeds.
    513      *
    514      * @since 2.6.0
    515      */
    516     do_action( 'bp_enqueue_embed_scripts' );
     530     * Enqueue CSS and JS files for a specific BuddyPress context.
     531     *
     532     * @since 11.0.0
     533     */
     534    do_action( "bp_enqueue_{$context}_scripts" );
     535}
     536
     537/**
     538 * Fires the 'bp_enqueue_embed_scripts' action in the <head> for BP oEmbeds.
     539 *
     540 * @since 2.6.0
     541 */
     542function bp_enqueue_embed_scripts() {
     543    return bp_enqueue_context_scripts( 'embed' );
     544}
     545
     546/**
     547 * Fires the  `bp_enqueue_community_scripts` action for Template packs scripts and styles.
     548 *
     549 * @since 11.0.0
     550 */
     551function bp_enqueue_community_scripts() {
     552    return bp_enqueue_context_scripts( 'community' );
    517553}
    518554
Note: See TracChangeset for help on using the changeset viewer.