unprefix/unprefix-scripts

This package is abandoned and no longer maintained. No replacement package was suggested.

A little library to register and enqueue scripts in WordPress.

Installs: 543

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 1

Type:wordpress-plugin

3.0.0 2017-07-31 22:24 UTC

This package is not auto-updated.

Last update: 2020-02-27 17:57:23 UTC


README

Build Status codecov License Mit

Unprefix Scripts

A little library to register and enqueue scripts in WordPress.

It's possible to deregister scripts and styles as well and localize variable to be able to access them from within every js file.

Example

$lists = [
    'scripts => [
        // Modernizr.
        'modernizr' => [
            'modernizr',
            Plugin::getPluginDirUrl('/assets/js/vendor/modernizr.min.js'),
            array(),
            '3.3.1',
            true,
            function () {
                return true;
            },
            function () {
                return true;
            },
        ],
    ],
    'styles' => [
        // Select2.
        'select2' => [
            'select2',
            Plugin::getPluginDirUrl('/assets/css/vendor/select2.min.css'),
            array(),
            '',
            'screen',
            function () {
                return true;
            },
            function () {
                return true;
            },
        ],
    ],
];

$unRegisterScriptsList = [
    'styles'  => [
        [
            'handle'  => 'script-handle',
            'condition' => function() {
                // ... condition
            }
        ],
    ],
    'scripts => [
        [
            'handle'  => 'script-handle',
            'condition' => function() {
                // ... condition
            }
        ],
    ]
];

$localizedList = [
    'localized' => [
        [
            'handle' => is_admin() ? 'admin' : 'front',
            'name'   => 'handlename',
            [
                'lang'        => get_bloginfo('language'),
                'date_format' => get_option('date_format'),
                'time_format' => get_option('time_format'),
            ],
        ],  
    ]
];

// Create the Instances.
$scripts           = new ScriptsFacade($lists);
$unRegister        = new UnRegister($unRegisterScriptsList);
$localizedScripts  = new LocalizeScripts($localizedList);

// Register the scripts.
add_action('enqueue_scripts', [$unRegister, 'unRegister'], 10);
add_action('enqueue_scripts', [$scripts, 'register'], 20);
add_action('enqueue_scripts', [$scripts, 'enqueuer'], 30);
add_action('enqueue_scripts', [$localizedScripts, 'localizeScripts'], 40);