2017 © Pedro Peláez
 

library wp-enqueue-manager

A WordPress library to bulk register assets.

image

hametuha/wp-enqueue-manager

A WordPress library to bulk register assets.

  • Sunday, January 28, 2018
  • by fumikito
  • Repository
  • 0 Watchers
  • 0 Stars
  • 110 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

wp-enqueue-manager

Bulk register WordPress assets with specified folder structure. Good shortcut for your theme development., (*1)

Travis CI master branch, (*2)

Installation

Use composer., (*3)

composer require hametuha/wp-enqueue-manager

Usage

Write dependnecies in your assets(js and css) header as comment. format is like wpdeps=dependencies. CSV ready., (*4)

This notation will be used for the deps argument of wp_register_script(doc) and wp_register_style(doc)., (*5)

Operations should be done in init hook or before. Write codes in your functions.php., (*6)

Javascript

Header file should be like below:, (*7)

/*!
 * wpdeps=jquery,thicbox
 */
jQuery(document).ready(function($){
  // Do something.
});

NOTICE: If you use autoprefixer or minify tools, be careful about cleaning up comments., (*8)

Then, register them all from your theme or plugin., (*9)

// Register all js in folder.
// e.g. /assets/js/sample.js will be regsitered as 'my-sample'.
Hametuha\WpEnqueueManager::register_js( __DIR__ . '/assets/, 'my-', '1.0.0' );

Stylesheet

Same as javascript, regsier, (*10)

/*!
 * wpdeps=bootstrap
 */
body{
   background-color: red;
}

And, run register_styles., (*11)

// Register all css in folder.
// e.g. /assets/css/sample.css will be regsitered as 'my-sample'.
Hametuha\WpEnqueueManager::register_styles( __DIR__ . '/assets/, 'my-', '1.0.0' );

Versionning

If you are a theme or plugin author, it's proper to pass the version of your theme/plugin. Lazy authors may just pass null or skip the argument. Then the file modified time will be used as version string., (*12)

Localization

For Javascript localization, you can bulk register localization vars., (*13)

Hametuha\WpEnqueueManager::register_js_var_files( __DIR__ . '/l10n );

File name equals js handle name. Camelized handle name should be var name. PHP files should return var array., (*14)

For example, if you put my-sample.php below in l10n directory., (*15)

<?php
// Avoide direct load.
defined( 'ABSPATH' ) || die();
// Return JS vars.
return [
    'label' => 'This is my var!',
];

Registered infromation are below:, (*16)

  • Handle: my-sample
  • Var name: MySample
  • Var: returned array of file.

So, you can refer PHP variables from JS like this:, (*17)

$('.button').on('click', function(){
    alert(MySample.label);
    // => This is my var!
};

License

MIT., (*18)

The Versions

28/01 2018

dev-master

9999999-dev

A WordPress library to bulk register assets.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar fumikito

28/01 2018

1.0.2

1.0.2.0

A WordPress library to bulk register assets.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar fumikito

20/12 2017

1.0.1

1.0.1.0

A PHP library for bulk register.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar fumikito

20/12 2017

1.0.0

1.0.0.0

A PHP library for bulk register.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar fumikito