Download the PHP package underpin/script-loader without Composer

On this page you can find all versions of the php package underpin/script-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package script-loader

Underpin Script Loader

Loader That assists with adding scripts to a WordPress website.

Installation

Using Composer

composer require underpin/script-loader

Manually

This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.

require_once(__DIR__ . '/underpin-scripts/scripts.php');

Setup

  1. Install Underpin. See Underpin Docs
  2. Register new scripts as-needed.

Example

A very basic example could look something like this.

Alternatively, you can extend Script and reference the extended class directly, like so:

Enqueuing Scripts

To enqueue a script, run the loader and reference the script ID, like so:

A common practice is to extend do_actions in the script class to add the actions necessary to enqueue the script. If you don't need to use any logic to enqueue your script, the simplest way to enqueue the script is with the enqueue script middleware.

Localizing Scripts

Underpin expands on how script localization works. A common problem with using wp_localize_script is that the data needed to localize the script has to all be placed in one single call. Underpin gets around that by using the set_param method.

For example, say you wanted to localize ajaxUrl as your site's admin AJAX URL. You could do that at any time, like so:

As long as this is done before enqueue is fired, ajaxUrl will be localized. All items are localized inside of an object named after the localized_var. If no localized_var is specified, the var will be the handle.

So, if you enqueued ajaxUrl on a script with a handle called example, you would get something like:

Script Middleware

Sometimes, it is necessary to localize the same set of paramaters, or even run the same actions across many scripts. This is where script middleware comes in handy.

For example, let's say you want to build a script that utilizes the REST API, and as a result needs a nonce and the root URL localized in the script. Doing this without a script is pretty straightforward, but verbose:

This is a very common scenario for WordPress scripts. Because of this, a middleware package exists to handle this automatically. The example below would accomplish the exact same thing:

The key part of the example above is the middlewares argument. Middlewares is an array of Script_Middleware items that run in the provided order, and are intended to automate the steps needed to set up a script.

Enqueuing With Middleware

In circumstances where you always need to enqueue the script, you can use the provided enqueue middleware.

To enqueue on admin screens:

To enqueue on the front-end:

To enqueue on the login screen:

To enqueue on both front-end and back-end:

Enqueuing Conditionally

A common scenario when enqueuing a script is to enqueue it under certain conditions. This can be handled using conditional middleware, using the array-based syntax for Underpin::make_class

For example, say you only want to enqueue a script on a specific admin page:

Another example, say you only want enqueue on the home page:

Enqueuing Blocks

An increasingly common scenario with scripts is to enqueue a block script. This can be done like so:

Create Your Own Middleware

The middlewares array uses Underpin::make_class to create the class instances. This means that you can pass either:

  1. a string that references an instance of Script_Middleware (see example above).
  2. An array of arguments to construct an instance of Script_Middleware on-the-fly.

All versions of script-loader with dependencies

PHP Build Version
Package Version
Requires underpin/underpin Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package underpin/script-loader contains the following files

Loading the files please wait ....