Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 20, 2022. It is now read-only.

Register, minify and unify CSS and JavaScript resources.

License

NotificationsYou must be signed in to change notification settings

josantonius/wp-register

Repository files navigation

Latest Stable VersionLicense

Versión en español

Register, minify and unify CSS and JavaScript resources in WordPress.



Requirements

This library is supported byPHP versions 5.6 or higher and is compatible withHHVM versions 3.0 or higher.

Installation

The preferred way to install this extension is throughComposer.

To installWP_Register library, simply:

composer require josantonius/wp-register

The previous command will only install the necessary files, if you prefer todownload the entire source code you can use:

composer require josantonius/wp-register --prefer-source

You can alsoclone the complete repository with Git:

git clone https://github.com/josantonius/wp-register.git

Orinstall it manually:

Download WP_Register.php:

wget https://raw.githubusercontent.com/josantonius/wp-register/master/src/class-wp-register.php

Available Methods

Available methods in this library:

- Add scripts or styles

WP_Register::add($type,$data);
AttributeDescriptionTypeRequiredDefault
$type'script' or 'style'stringYes
AttributekeyDescriptionTypeRequiredDefault
$dataSettingsarrayYes
nameUnique IDstringYes
urlUrl to filestringYes
place'admin' or 'front'stringNo'front'
depsDependencesarrayNo[]
versionVersionstringNofalse
footerOnly for scripts - Attach in footerbooleanNotrue
paramsOnly for scripts - Params available in JSarrayYes[]
mediaOnly for styles - MediastringNo''

@return (boolean)

- Sets whether to merge the content of files into a single file

WP_Register::unify($id,$params,$minify);
AttributeDescriptionTypeRequiredDefault
$idAction hook namestringYes
$paramsPath urlsmixedYes
$minifyMinimize file contentbooleanNofalse

@return (boolean true)

- Check if a particular style or script has been added to be enqueued

WP_Register::is_added($type,$name);
AttributeDescriptionTypeRequiredDefault
$type'script' or 'style'stringYes
$nameScript or style IDstringYes

@return (boolean)

- Remove before script or style have been registered

WP_Register::remove($type,$name);
AttributeDescriptionTypeRequiredDefault
$type'script' or 'style'stringYes
$nameScript or style IDstringYes

@return (boolean true)

Quick Start

To use this library withComposer:

require__DIR__ .'/vendor/autoload.php';useJosantonius\WP_Register;

Or If you installed itmanually, use it:

require_once__DIR__ .'/class-wp-register.php';useJosantonius\WP_Register\WP_Register;

Usage

Example of use for this library:

- Add script

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 usingNavigationScript.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 usingNavigationScript.pluginUrl.

- Add style

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'])

- Unify

WP_Register::unify('UniqueID','http://josantonius.com/min/');

- Unify and minify

WP_Register::unify('UniqueID','http://josantonius.com/min/',true);

- Unify specifying different url paths for styles and scripts

WP_Register::unify('UniqueID', ['styles'  =>'http://josantonius.com/min/css/','scripts' =>'http://josantonius.com/min/js/']);

- Unify and minify specifying different url paths for styles and scripts

WP_Register::unify('UniqueID', ['styles'  =>'http://josantonius.com/min/css/','scripts' =>'http://josantonius.com/min/js/'    ],true);

- Check if a particular style or script has been added to be registered

WP_Register::is_added('script','HTML_script');WP_Register::is_added('script','NavigationScript');WP_Register::is_added('style','EditorStyle');WP_Register::is_added('style','DefaultStyle');

- Remove before script or style have been enqueued

WP_Register::remove('script','HTML_script');WP_Register::remove('script','NavigationScript');WP_Register::remove('style','EditorStyle');WP_Register::remove('style','DefaultStyle');

Tests

To runtests you just needcomposer and to execute the following:

git clone https://github.com/josantonius/wp-register.gitcd WP_Registerbash bin/install-wp-tests.sh wordpress_test root '' localhost latestcomposer install

Run unit tests withPHPUnit:

composer phpunit

RunWordPress code standard tests withPHPCS:

composer phpcs

RunPHP Mess Detector tests to detect inconsistencies in code style:

composer phpmd

Run all previous tests:

composer tests

Sponsor

If this project helps you to reduce your development time,you can sponsor me to support my open source work 😊

License

This repository is licensed under theMIT License.

Copyright © 2017-2022,Josantonius

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp