dev-master
9999999-dev http://www.waga.itAn helper component for assets manegment
GPL-2.0+
by Waga Team
An helper component for assets manegment
A simple Assets Manager tailored for Wordpress., (*1)
It as some interesting features:
- If a path is provided, the asset (js or css) will be enqueued only if the file exists, so you get no 404.
- If a path is provided, the Assets Manager will use filemtime()
as asset version. This will prevent browser to serve a cached version of the asset if the file was modified.
- You can provide a callback for each asset to do additional checks before deciding whether enqueue the asset or not., (*2)
$libs = [ "my-style" => [ 'uri' => "...", 'type' => 'css', ], "my-js" => [ 'uri' => "...", 'path' => "...", 'type' => 'js', 'enqueue' => false ] ];
$a = new AssetsManager($libs); $a->enqueue();
You can pass a number of arguments to AssetsManager constructor:, (*3)
[ 'uri' => '', //A valid uri 'path' => '', //A valid path 'version' => false, //If FALSE, the filemtime will be used (if path is set) 'deps' => [], //Dependencies 'i10n' => [], //the Localication array for wp_localize_script 'type' => '', //js or css 'enqueue_callback' => false, //A valid callable that must be return true or false 'in_footer' => false, //Used for scripts 'enqueue' => true //If FALSE the script\css will only be registered ]
You can use i10n
key to pass an array for wp_localize_script()
.
See wp_localize_script() for further informations., (*4)
$libs = [ 'my-js' => [ 'i10n' => [ 'name' => myValue 'params' => [ 'foo' => 'bar', 'baz' => true ] ] ] ]
Is equivalent to, (*5)
wp_localize_script( 'my-js', 'myValue', [ 'foo' => 'bar', 'baz' => true ]);
An helper component for assets manegment
GPL-2.0+