2017 © Pedro Peláez
 

library assets

An helper component for assets manegment

image

wbf/assets

An helper component for assets manegment

  • Thursday, May 25, 2017
  • by Waga Dev
  • Repository
  • 3 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Assets Manager

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)

Usage

  • Create an array of assets:
$libs = [
    "my-style" => [
        'uri' => "...",
        'type' => 'css',
    ],
    "my-js" => [
        'uri' => "...",
        'path' => "...",
        'type' => 'js',
        'enqueue' => false
    ]
];
  • Instance a new object and enqueue
$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
]

Localization

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
]);

The Versions

25/05 2017

dev-master

9999999-dev http://www.waga.it

An helper component for assets manegment

  Sources   Download

GPL-2.0+