Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 98 | All time: 9,830 This week: 488 |
Version | License | PHP version | Categories | |||
wp_register 1.0.0 | Custom (specified... | 5 | HTML, PHP 5, Content management |
Description | Author | |
This package can minify and unify CSS and JavaScript for WordPress. Innovation Award
|
Register, minify and unify CSS and JavaScript resources in WordPress.
The preferred way to install this extension is through composer.
To install PHP Wordpress Register library, simply:
$ composer require Josantonius/WP_Register
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:
$ composer require Josantonius/WP_Register --prefer-source
Or you can also clone the complete repository with Git:
$ git clone https://github.com/Josantonius/WP_Register.git
This 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".
To use this class, simply:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\WP_Register\WP_Register;
Available methods in this library:
Add scripts or styles.
WP_Register::add($type, $data);
| 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
Sets whether to merge the content of files into a single file.
WP_Register::unify($id, $params, $minify);
| 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
Check if a particular style or script has been added to be enqueued.
WP_Register::isAdded($type, $name);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Script or style ID | string | Yes | |
@return ? boolean
Remove before script or style have been registered.
WP_Register::isAdded($type, $name);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Script or style ID | string | Yes | |
@return ? boolean true
Example of use for this library:
<?php
require __DIR__ . '/vendor/autoload.php';
use Josantonius\WP_Register\WP_Register;
WP_Register::add('script', [
'name' => 'HTML_script',
'url' => 'http://josantonius.com/js/html5.js'
]);
WP_Register::add('script', [
'name' => 'NavigationScript',
'url' => 'http://josantonius.com/js/navigation.js',
'place' => 'admin',
'deps' => ['jquery'],
'version' => '1.1.3',
'footer' => true,
'params' => ['date' => date('now')],
]);
Additionally, a nonce is created for each script using its name. In this example, it will be accessible from JavaScript using NavigationScript.nonce
.
wp_verify_nonce($nonce, 'NavigationScript');
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 NavigationScript.pluginUrl
.
WP_Register::add('style', [
'name' => 'EditorStyle',
'url' => 'http://josantonius.com/js/editor-style.css'
]);
WP_Register::add('style', [
'name' => 'DefaultStyle',
'url' => 'http://josantonius.com/js/style.css',
'place' => 'admin',
'deps' => [],
'version' => '1.1.3',
'media' => 'all'
])
WP_Register::unify('UniqueID', 'http://josantonius.com/min/');
WP_Register::unify('UniqueID', 'http://josantonius.com/min/', true);
WP_Register::unify('UniqueID', [
'styles' => 'http://josantonius.com/min/css/',
'scripts' => 'http://josantonius.com/min/js/'
]);
WP_Register::unify('UniqueID', [
'styles' => 'http://josantonius.com/min/css/',
'scripts' => 'http://josantonius.com/min/js/'
]);
WP_Register::isAdded('script', 'HTML_script');
WP_Register::isAdded('script', 'NavigationScript');
WP_Register::isAdded('style', 'EditorStyle');
WP_Register::isAdded('style', 'DefaultStyle');
WP_Register::remove('script', 'HTML_script');
WP_Register::remove('script', 'NavigationScript');
WP_Register::remove('style', 'EditorStyle');
WP_Register::remove('style', 'DefaultStyle');
To run tests simply:
$ git clone https://github.com/Josantonius/WP_Register.git
$ cd WP_Register
$ bash bin/install-wp-tests.sh wordpress_test root '' localhost latest
$ phpunit
This is intended for large and long-lived objects.
All files in this repository were created and uploaded automatically with Reposgit Creator.
This project is licensed under MIT license. See the LICENSE file for more info.
2017 Josantonius, josantonius.com
If you find it useful, let me know :wink:
Files (38) |
File | Role | Description | ||
---|---|---|---|---|
bin (1 file) | ||||
src (1 file, 1 directory) | ||||
tests (2 files, 1 directory) | ||||
vendor (1 file, 2 directories) | ||||
.editorconfig | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONDUCT.md | Data | Auxiliary data | ||
contributors.txt | Doc. | Documentation | ||
LICENSE | Lic. | License text | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README-ES.md | Doc. | Documentation | ||
README.md | Doc. | Documentation | ||
_config.yml | Data | Auxiliary data |
Files (38) | / | tests |
File | Role | Description | ||
---|---|---|---|---|
WP_Register (1 directory) | ||||
bootstrap.php | Example | Example script | ||
sample-plugin.php | Aux. | Auxiliary script |
Files (38) | / | tests | / | WP_Register | / | Test |
File | Role | Description |
---|---|---|
RegisterAdminScriptsTest.php | Class | Class source |
RegisterAdminStylesTest.php | Class | Class source |
RegisterScriptsTest.php | Class | Class source |
RegisterStylesTest.php | Class | Class source |
UnifyAdminFilesTest.php | Class | Class source |
UnifyFilesTest.php | Class | Class source |
Files (38) | / | vendor |
File | Role | Description | ||
---|---|---|---|---|
composer (8 files) | ||||
josantonius (2 directories) | ||||
autoload.php | Aux. | Auxiliary script |
Files (38) | / | vendor | / | composer |
File | Role | Description |
---|---|---|
autoload_classmap.php | Aux. | Auxiliary script |
autoload_namespaces.php | Aux. | Auxiliary script |
autoload_psr4.php | Aux. | Auxiliary script |
autoload_real.php | Class | Class source |
autoload_static.php | Class | Class source |
ClassLoader.php | Class | Class source |
installed.json | Data | Auxiliary data |
LICENSE | Lic. | License text |
Files (38) | / | vendor | / | josantonius |
Files (38) | / | vendor | / | josantonius | / | file |
File | Role | Description | ||
---|---|---|---|---|
src (1 directory) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text |
Files (38) | / | vendor | / | josantonius | / | file | / | src | / | File |
File | Role | Description |
---|---|---|
File.php | Class | Class source |
Files (38) | / | vendor | / | josantonius | / | json |
File | Role | Description | ||
---|---|---|---|---|
src (1 directory) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text |
Files (38) | / | vendor | / | josantonius | / | json | / | src | / | Json |
Files (38) | / | vendor | / | josantonius | / | json | / | src | / | Json | / | Exception |
File | Role | Description |
---|---|---|
JsonException.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
User Comments (2) | ||||||||
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.