Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

BP_Legacy::locate_asset_in_stack( string $file, string $type = 'css', string $script_handle = '' )

Get the URL and handle of a web-accessible CSS or JS asset


Description Description

We provide two levels of customizability with respect to where CSS and JS files can be stored: (1) the child theme/parent theme/theme compat hierarchy, and (2) the "template stack" of /buddypress/css/, /community/css/, and /css/. In this way, CSS and JS assets can be overloaded, and default versions provided, in exactly the same way as corresponding PHP templates.

We are duplicating some of the logic that is currently found in bp_locate_template() and the _template_stack() functions. Those functions were built with PHP templates in mind, and will require refactoring in order to provide "stack" functionality for assets that must be accessible both using file_exists() (the file path) and at a public URI.

This method is marked private, with the understanding that the implementation is subject to change or removal in an upcoming release, in favor of a unified _template_stack() system. Plugin and theme authors should not attempt to use what follows.


Parameters Parameters

$file

(Required) A filename like buddypress.css.

$type

(Optional) Either "js" or "css" (the default).

Default value: 'css'

$script_handle

(Optional) If set, used as the script name in wp_enqueue_script.

Default value: ''


Top ↑

Return Return

(array) An array of data for the wp*enqueue** function: 'handle' (eg 'bp-child-css') and a 'location' (the URI of the asset)


Top ↑

Source Source

File: bp-templates/bp-legacy/buddypress-functions.php

	private function locate_asset_in_stack( $file, $type = 'css', $script_handle = '' ) {
		$locations = array();

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

		// No need to check child if template == stylesheet.
		if ( is_child_theme() ) {
			$locations[] = array(
				'type' => 'bp-child',
				'dir'  => get_stylesheet_directory(),
				'uri'  => get_stylesheet_directory_uri(),
				'file' => $file,
			);

			$locations[] = array(
				'type' => 'bp-child',
				'dir'  => get_stylesheet_directory(),
				'uri'  => get_stylesheet_directory_uri(),
				'file' => str_replace( '.min', '', $file ),
			);
		}

		$locations[] = array(
			'type' => 'bp-parent',
			'dir'  => get_template_directory(),
			'uri'  => get_template_directory_uri(),
			'file' => str_replace( '.min', '', $file ),
		);

		$locations[] = array(
			'type' => 'bp-legacy',
			'dir'  => bp_get_theme_compat_dir(),
			'uri'  => bp_get_theme_compat_url(),
			'file' => $file,
		);

		// Subdirectories within the top-level $locations directories.
		$subdirs = array(
			'buddypress/' . $type,
			'community/' . $type,
			$type,
		);

		$retval = array();

		foreach ( $locations as $location ) {
			foreach ( $subdirs as $subdir ) {
				if ( file_exists( trailingslashit( $location['dir'] ) . trailingslashit( $subdir ) . $location['file'] ) ) {
					$retval['location'] = trailingslashit( $location['uri'] ) . trailingslashit( $subdir ) . $location['file'];
					$retval['handle']   = ( $script_handle ) ? $script_handle : "{$location['type']}-{$type}";

					break 2;
				}
			}
		}

		return $retval;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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