Recommend this page to a friend! |
Classes of Josantonius | WP_Register | README.md | Download |
|
![]() PHP WordPress RegisterRegister, minify and unify CSS and JavaScript resources in WordPress.
InstallationThe preferred way to install this extension is through composer. To install PHP Wordpress Register library, simply:
The previous command will only install the necessary files, if you prefer to download the entire source code (including tests, vendor folder, exceptions not used, docs...) you can use:
Or you can also clone the complete repository with Git:
RequirementsThis library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher. To use this library in HHVM (HipHop Virtual Machine) you will have to activate the scalar types. Add the following line "hhvm.php7.scalar_types = true" in your "/etc/hhvm/php.ini". Quick Start and ExamplesTo use this class, simply:
Available MethodsAvailable methods in this library: add()Add scripts or styles.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | Attribute | key | Description | Type | Required | Default | --- | --- | --- | --- | --- | --- | | $data | | Settings | array | Yes | | | | name | Unique ID | string | Yes | | | | url | Url to file | string | Yes | | | | place | 'admin' or 'front' | string | No | 'front' | | | deps | Dependences | array | No | [] | | | version | Version | string | No | false | | | footer | Only for scripts - Attach in footer | boolean | No | true | | | params | Only for scripts - Params available in JS | array | Yes | [] | | | media | Only for styles - Media | string | No | '' | @return ? void unify()Sets whether to merge the content of files into a single file.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $id | Action hook name | string | Yes | | | $params | Path urls | mixed | Yes | | | $minify | Minimize file content | boolean | No | false | @return ? boolean true isAdded()Check if a particular style or script has been added to be enqueued.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Script or style ID | string | Yes | | @return ? boolean remove()Remove before script or style have been registered.
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Script or style ID | string | Yes | | @return ? boolean true UsageExample of use for this library:
Add script:
Additionally, a nonce is created for each script using its name. In this example, it will be accessible from JavaScript using
In the case of scripts created from plugins, the path of the plugin directory is saved as a parameter. In this example, it will be accessible from JavaScript using Add style:
Unify:
Unify and minify:
Unify specifying different url paths for styles and scripts:
Unify and minify specifying different url paths for styles and scripts:
Check if a particular style or script has been added to be registered:
Remove before script or style have been enqueued:
TestsTo run tests simply:
? TODO
Contribute
This is intended for large and long-lived objects. RepositoryAll files in this repository were created and uploaded automatically with Reposgit Creator. LicenseThis project is licensed under MIT license. See the LICENSE file for more info. Copyright2017 Josantonius, josantonius.com If you find it useful, let me know :wink: You can contact me on Twitter or through my email. |