Skip to:
Content

BuddyPress.org

Changeset 14013


Ignore:
Timestamp:
08/31/2024 01:26:36 AM (6 weeks ago)
Author:
imath
Message:

Introduce a function to inform about whether BP was loaded from src

bp_is_running_from_src_subdirectory() informs whether BuddyPress was loaded from the src subdirectory (trunk version). This function exposes the 'bp_is_running_from_src_subdirectory' to let developers tests code that is only available when BuddyPress is built.

Props emaralive, espellcaste.

See #9210
Fixes #9224
Closes https://github.com/buddypress/buddypress/pull/358

Location:
trunk/src
Files:
4 edited

Legend:

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

    r13998 r14013  
    138138function bp_is_running_wp( $version, $compare = '>=' ) {
    139139    return version_compare( $GLOBALS['wp_version'], $version, $compare );
     140}
     141
     142/**
     143 * Informs whether BuddyPress was loaded from the `src` subdirectory (trunk version).
     144 *
     145 * @since 15.0.0
     146 *
     147 * @return boolean True if BuddyPress was loaded from the `src` subdirectory, false otherwise.
     148 */
     149function bp_is_running_from_src_subdirectory() {
     150    $is_src = defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src';
     151
     152    /**
     153     * Filter here to edit the way BuddyPress was loaded.
     154     *
     155     * @since 15.0.0
     156     *
     157     * @param boolean $is_src True if BuddyPress was loaded from the `src` subdirectory, false otherwise.
     158     */
     159    return apply_filters( 'bp_is_running_from_src_subdirectory', $is_src );
    140160}
    141161
     
    27672787
    27682788    // Ensure the assets can be located when running from /src/.
    2769     if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
     2789    if ( bp_is_running_from_src_subdirectory() ) {
    27702790        $ext = str_replace( '.min', '', $ext );
    27712791    }
     
    49815001     * version of BuddyPress do not load deprecated functions.
    49825002     */
    4983     if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
     5003    if ( bp_is_running_from_src_subdirectory() ) {
    49845004        return array();
    49855005    }
  • trunk/src/bp-core/bp-core-rest-api.php

    r13968 r14013  
    3434 */
    3535function bp_rest_in_buddypress() {
    36     $is_src = defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src';
    37 
    38     return ! $is_src && ! bp_rest_is_plugin_active();
     36    return ! bp_is_running_from_src_subdirectory() && ! bp_rest_is_plugin_active();
    3937}
    4038
  • trunk/src/bp-core/bp-core-template-loader.php

    r13968 r14013  
    242242function bp_locate_template_asset( $filename ) {
    243243    // Ensure assets can be located when running from /src/.
    244     if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && 'src' === BP_SOURCE_SUBDIRECTORY ) {
     244    if ( bp_is_running_from_src_subdirectory() ) {
    245245        $filename = str_replace( '.min', '', $filename );
    246246    }
  • trunk/src/bp-templates/bp-legacy/buddypress-functions.php

    r13882 r14013  
    407407
    408408        // Ensure the assets can be located when running from /src/.
    409         if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
     409        if ( bp_is_running_from_src_subdirectory() ) {
    410410            $file = str_replace( '.min', '', $file );
    411411        }
Note: See TracChangeset for help on using the changeset viewer.