File: /var/www/linde-ai/wp-content/themes/linde/functions/manifest.php
<?php
/**
* Gets the current version of a file from the manifest.json file.
*
* @param String $filename The non-hashed filename (e.g. "style.css", "assets/images/my-image.png").
* @param String $manifestPath Full path to the manifest file. If not set,
* assumes the file is located in
* /wp-content/themes/linde/frontend/.
*
* @return String|\WP_Error The path to the current corresponding file
* (e.g. /wp-content/themes/linde/frontend/style.12345.css).
* In the event of a failure, an instance of \WP_Error
* will be returned with more details.
*/
function get_frontend_static_asset($filename, $manifestPath = null) {
// Set the default path if one isn't provided.
if (is_null($manifestPath)) {
$manifestPath = __DIR__ . '/../frontend/manifest.json';
}
// Check the file exists before we try to load it.
if (!file_exists($manifestPath)) {
throw new Exception("Frontend manifest (manifest.json) file cannot be found. Project development or build script needs to be ran at least once for this file to appear.", 1);
}
$manifest = json_decode(file_get_contents($manifestPath), true);
// Attempt to match the requested file.
if (!array_key_exists($filename, $manifest)) {
throw new Exception("The requested file could not be matched. Looks like '" . $filename . "' property doesn't exist in manifest.json", 1);
}
$resource_path = $manifest[$filename];
// If file path already contains full URL, we don't need to prefix it with anything
if (strpos($resource_path, 'http') !== false) {
return $resource_path;
}
// Prefix file path URL with URL to root of WordPress site
return get_home_url() . $resource_path;
}
// DON'T DELETE STUFF ABOVE THIS LINE IF YOU AREN'T 100% SURE YOU KNOW WHAT YOU ARE DOING