unprefix / unprefix-scripts
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
Requires
- php: >=5.6.0
Requires (Dev)
- brain/monkey: ^1.4
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2020-02-27 17:57:23 UTC
README
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);