Download the PHP package nyco/wp-assets without Composer

On this page you can find all versions of the php package nyco/wp-assets. 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 wp-assets

NYCO WordPress Assets

A developer plugin with helpers for managing assets in WordPress. It can be used to register and enqueue stylesheets with general defaults and hashed names as well as configure inline integrations such as Google Analytics, Rollbar, etc by using WordPress' native wp_enqueue/register_style/script() and wp_add_inline_script() methods. This properly loads them into the site, avoids conflicts, and exposes them to asset hooks for deeper configuration.

Installation using Composer

$1 This package uses Composer Installers to install the package in the Must Use plugins directory (/wp-content/mu-plugins):

Not using Composer? Download an archive of the code and drop it into the mu-plugins directory.

$2 Create a proxy PHP loader file inside the mu-plugins directory, or use the one included with the plugin:

Usage

Quickstart. Declare namespace in functions.php (or any php file) and instantiate.

Migrating a block such as this...

... can be done with...

Assuming main.831f1593.js is a compiled script file and 831f1593 is a hash based on the contents of the script, the filename will change if the contents of the file change. This is useful for cache busting without forcing a browser to load the script on every load using a query variable ?ver=831f1593. However, WordPress won't be able to locate scripts without a hard-coded source. ->addScript('main') will register and enqueue the first script file it finds with any hash contents between main. and .js.

Note. The autoloader sample sets an instance of WpAssets to the global scope which can be used as well;

Documentation

The core of the plugin is a single class with several methods that are available upon instantiation. For a full description of methods refer to the source.

Class (including namespace)

Methods

Add Script

Register and/or enqueue a hashed script based on it's name. File name should match the pattern script.{{ hash }}.js by default. The separator between the filename and the hash can be configured.

...args

Returns Key/value pair including wp_register_script response, wp_enqueue_script response, and the source uri of the file.

Examples

This will scan the default scripts assets directory assets/scripts/ of the current theme using the default pattern script.{{ hash }}.js, register the script with the handle script and enqueue it. To pick a different script named main.{{ hash }}.js do the following;

This script will be loaded into the footer of the document and be available to the script_loader_tag filter;

Back to top


Add Style

Register and/or enqueue a hashed style based on it's name. File name should match the pattern styles.{{ hash }}.css. The separator between the filename and the hash can be configured.

...args

Returns Key/value pair including wp_register_style response, wp_enqueue_style response, and the source uri of the file.

Examples

This will scan the default style assets directory assets/styles/ of the current theme using the default pattern style.{{ hash }}.css, register the style with the handle style and enqueue it. To pick a different style named site.{{ hash }}.css do the following;

Back to top


Add Attr

Uses the script_loader_tag filter to add an attribute and a value to a specific script. For example; crossorigin="anonymous". Attribute values may be strings. To add a boolean attribute such as async or defer pass true."

...args

Examples

Back to top


Load Integrations

This retrieves an integration configuration file from the MU Plugins directory. By default it will look for a YAML file at config/integrations.yml that contains an array of individual configuration objects then it converts the YAML file to a PHP Array and returns it. This is meant to be used with the ->enqueueInline( ...args ) method.

...args

Returns an array of individual configuration objects.

A configuration file may include multiple objects with the following parameters.

Back to top


Add Inline

Register and enqueue inline scripts and their source using wp_register/enqueue_script() and wp_add_inline_script()

Useful for cloud service integrations that are configured on the client-side (Google Analytics, Webtrends, Rollbar.js, etc.) what require loading a remote source but are configured with an inline script code block.

Also enqueues inline styles if required by the configuration. This is not possible by default and uses a technique described in this article.

...args

Returns the same array with additional inline script contents.

Examples

This will load the 'google-analytics' integration. Below is the Google Analytics configuration in config/integrations.yml...

The config/integrations/scripts/google-analytics.js script should contain something like the following;

The constant GOOGLE_ANALYTICS should be defined somewhere in another part of your configuration (wp-config.php, functions.php, or this plugin works nicely with the nyco-wp-config plugin);

The following will be printed in the head of the document;

Back to top


Register Rest Routes

Uses an array of configuration objects to register WP Rest Routes that act as JavaScript files instead of inline scripts.

...args

Returns the Array of integrations objects with all rest route details.

Back to top

Enqueue Inline Helper Function

Use the included enqueue_inline( ...handle... ) helper function to quickly add integrations. It wraps around the example described above to make it easier to call integrations based on their handle in the config/integrations.yml file. The sample autoloader includes the helper function automatically.

Integration ACF Options Page Add-on

This plugin ships with an Integrations Options page add-on to allow WordPress admins to toggle integrations on or off. It requires Advanced Custom Fields to display the options page. Create a copy of the add-on in your mu-plugins directory.

The page will then appear under the Integrations menu item.

Query Monitor Add-on

This plugin ships with an add-on for Query Monitor that displays the available integrations to the Load Integrations method and compares them to integrations that are registered. It uses the same method to display the details of the config/integrations.yml file. The sample autoloader includes the add-on automatically.


The Mayor's Office for Economic Opportunity (NYC Opportunity) is committed to sharing open source software that we use in our products. Feel free to ask questions and share feedback. Interested in contributing? See our open positions on buildwithnyc.github.io. Follow our team on Github (if you are part of the @cityofnewyork organization) or browse our work on Github.


All versions of wp-assets with dependencies

PHP Build Version
Package Version
Requires composer/installers Version ~1.0
mustangostang/spyc Version ~0.6
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 nyco/wp-assets contains the following files

Loading the files please wait ....