This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
51 lines (43 loc) · 1.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Plugin Name: WP Laravel Elixir
* Plugin URI: https://github.com/sourceboat/wp-laravel-elixir/
* Description: Get versioned Laravel Elixir file paths in WordPress.
* Version: 1.0.1
* Author: Sourceboat
* Author URI: https://sourceboat.com/
* License: MIT License
*/
if (! function_exists('elixir')) {
/**
* Get the path to a versioned Elixir file.
*
* @param string $file
* @param string $buildDirectory
* @return string
*
* @throws \InvalidArgumentException
*/
function elixir($file, $buildDirectory = 'build')
{
static $manifest = [];
static $manifestPath;
$public_path = get_stylesheet_directory() . '/dist/';
$public_uri = get_stylesheet_directory_uri() . '/dist/';
if (empty($manifest) || $manifestPath !== $buildDirectory) {
$path = $public_path . $buildDirectory . '/rev-manifest.json';
if (file_exists($path)) {
$manifest = json_decode(file_get_contents($path), true);
$manifestPath = $buildDirectory;
}
}
if (isset($manifest[$file])) {
return $public_uri . trim($buildDirectory . '/' . $manifest[$file], '/');
}
$unversioned = $public_path . $file;
if (file_exists($unversioned)) {
return $public_uri . trim($file, '/');
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}