bp_locate_template_asset( string $filename )

Get file data of the highest priority asset that exists.


Description Description

Similar to bp_locate_template(), but for files like CSS and JS.


Parameters Parameters

$filename

(Required) Relative filename to search for.


Top ↑

Return Return

(false|array) Array of asset data if one is located (includes absolute filepath and URI). Boolean false on failure.


Top ↑

Source Source

File: bp-core/bp-core-template-loader.php

function bp_locate_template_asset( $filename ) {
	// Ensure assets can be located when running from /src/.
	if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && 'src' === BP_SOURCE_SUBDIRECTORY ) {
		$filename = str_replace( '.min', '', $filename );
	}

	// Use bp_locate_template() to find our asset.
	$located = bp_locate_template( $filename, false );
	if ( false === $located ) {
		return false;
	}

	// Set up data array.
	$data = array();
	$data['file'] = $data['uri'] = $located;

	$find = array(
		get_theme_root(),
		bp_get_theme_compat_dir()
	);

	$replace = array(
		get_theme_root_uri(),
		bp_get_theme_compat_url()
	);

	// Make sure URI path is relative to site URL.
	$data['uri'] = str_replace( $find, $replace, $data['uri'] );

	return $data;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.