yard / wp-package-installer
Composer installer for WordPress packages
Package info
github.com/yardinternet/wp-package-installer
Type:composer-plugin
pkg:composer/yard/wp-package-installer
Requires
- php: >=7.4
- composer-plugin-api: ^2.9
Requires (Dev)
- composer/composer: ^2.10
- php-stubs/wordpress-stubs: ^7.0
- yard/php-cs-fixer-rules: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 09:17:48 UTC
README
A Composer plugin that installs packages of type wordpress-package into a
dedicated directory, similar to how composer/installers handles plugins and
themes.
Installation
composer require yard/wp-package-installer
Usage
Give a package the wordpress-package type in its composer.json:
{
"name": "yard/some-wordpress-package",
"type": "wordpress-package"
}
When required by a project, it will be installed into:
wp-content/packages/<vendor>/<package-name>
Custom install directory
Override the default install location by setting wordpress-packages-install-dir
in the root project's composer.json:
{
"extra": {
"wordpress-packages-install-dir": "web/app/packages"
}
}
Runtime helpers
This package also ships a small set of helper functions for resolving the
filesystem path or URL of any installed wordpress-package, by its Composer
package name. They live under the Yard\WordPressPackageInstaller namespace:
Yard\WordPressPackageInstaller\package_path( string $package, ?string $path = null ): ?string— absolute filesystem path to the installed package (optionally appending$path), ornullif the package isn't installed.Yard\WordPressPackageInstaller\package_url( string $package, ?string $path = null ): ?string— URL to the installed package (optionally appending$path), ornullif the package isn't installed, its path falls outside the webroot, or the webroot cannot be determined.Yard\WordPressPackageInstaller\package_version( string $package ): ?string— installed version of the package, ornullif it isn't installed. Fordev-*versions, the commit reference is returned instead of the branch alias.
use function Yard\WordPressPackageInstaller\package_path; use function Yard\WordPressPackageInstaller\package_url; use function Yard\WordPressPackageInstaller\package_version; $path = package_path( 'yard/some-wordpress-package' ); $url = package_url( 'yard/some-wordpress-package', '/assets/style.css' ); $version = package_version( 'yard/some-wordpress-package' );
package_url() derives the URL by stripping $_SERVER['DOCUMENT_ROOT'] from
the resolved path and appending the remainder to the webroot's own URL, so it
requires the package to be installed somewhere under the site's webroot. Where
DOCUMENT_ROOT is unset, as under WP-CLI and cron, it returns null rather
than guessing a base.
Only the scheme, host and port of home_url() are used: on a subdirectory
multisite a subsite's home URL carries the subsite's path, which is no part of
where the package sits on disk.
These functions are loaded automatically wherever this package's Composer
autoloader is included (e.g. vendor/autoload.php).