Download the PHP package wecodemore/wp-package-assets-publisher without Composer

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

WP Package Assets Publisher

PHP Quality Assurance


What is this

A Composer plugin that "publishes" assets for packages where WordPress can find them.

Tell me more...

When building Composer-based "whole-websites" we might require via Composer packages containing WordPress code without them being WP plugins or themes.

Such packages would be placed in the vendor folder which is oftentimes outside webroot.

And that means that if such packages have assets such as images, scripts, or styles, the browser will not be able to reach them.

That forces us to either write regular WP plugins or move the vendor folder inside the webroot.

Neither of the above solutions is ideal, even if both might work depending on the use case.

This package provides an alternative: it symlinks (or copies) such assets files under wp-content/plugins folder, that is reachable by the browser.

Moreover, being that a WP standard path, we can use functions like plugin_url() to get the URL.

How it works

This is a Composer plugin that provides a custom installer for packages having "wordpress-package" as type. Additional types can be supported via configuration.

The installer does not change how the default Composer installer installs the package, but after the default installer has successfully installed the package, it looks into an extra.package-assets-paths property in the package's composer.json and symlinks all the paths found there into the /wp-content/plugins/.published-package-assets/{vendor}/{name} folder.

The wp-content base folder is determined based on configuration on root package.

When using WP Starter, its wordpress-content-dir setting suffices as configuration.

Of course, the extra.wordpress-content-dir property can be used even if WP Starter is not in use.

Usage example

Let's assume a package with a composer.json like the following:

Let's now assume the files structure of the package is the following:

Now, suppose the above package is required in a WP Starter project with the following composer.json:

After Composer install, we will find a folder structure like this (showing only the relevant bits):

So the package is regularly installed in vendor/, but its public/ folder, that was listed in the package's extra.package-assets-paths property, have been symlinked in public/wp-content/.published-package-assets/acme/awesome-package/public/.

Thanks to that, the package assets are now under webroot, and so reachable by the browser.

Helper function

Getting the full URL of that package's assets can be hard, though. This is why this package ships a helper function WeCodeMore\packageAssetUrl() which can be used anywhere like so:

The function takes two arguments, the first is the name of the package as defined in its composer.json, and the second is the relative path of the asset to retrieve. Of course, it works only if the requested path was configured in the package's extra.package-assets-paths property, and so "published" in place by this package.

Root config

Target folder

In projects not using WP Starter, the extra.wordpress-content-dir property can still be used to tell the assets published where to place th published assets.

Alternatively, the root-only extra.package-assets-publisher.publish-dir config can be used instead.

Here's an example of using the package with the Bedrock's folder structure:

Symlink or copy

The package by default tries to symlink assets paths and only resorts to copy them if symlink fails, similarly to how Composer does.

To force the package to copy the files, it is possible to use a different format for the extra.package-assets-publisher.symlink property, like the following:

To force the package to symlink the files and not attempt a copy, set extra.package-assets-publisher.symlink set to true.

Setting extra.package-assets-publisher.symlink to any non-boolean value, or not setting it at all results in the default behavior that symlink are attempted with copy fallback.

Fail hard

By default, when a failure happens, the package prints an error message, but does not break the Composer installation/update process.

To fail "hard", set extra.package-assets-publisher.strict to true.

Custom types

The installer by default only attempts to publish assets for packages with type: "wordpress-package". It is possible to support additional types, via configuration, like this:

Note: This package is an installer for custom types. By declaring support for a type we will override the default installer for that type, which means that if a package type needs to use a custom installer, it should not be added to the supported types for this package.

Package config override

Both the extra.package-assets-publisher.symlink and the extra.package-assets-publisher.strict root options, can be overridden at the package level.

That is done via the package-level extra.package-assets property, using it as an object like this:

System Requirements

License

MIT. See LICENSE file.


All versions of wp-package-assets-publisher with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
composer-plugin-api Version ^2.3
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 wecodemore/wp-package-assets-publisher contains the following files

Loading the files please wait ....