The whole site stack package is end game of using Composer with WordPress.
It would depend on your project what exactly to put in a package and how to configure it.
For example it can be something like this (original gist) :
{
"name" : "rarst/install-test",
"description" : "Test project for WordPress stack via Composer",
"authors" : [
{
"name" : "Andrey Savchenko",
"homepage": "https://www.Rarst.net/"
}
],
"type" : "project",
"repositories": [
{
"type": "composer",
"url" : "https://wpackagist.org"
}
],
"config" : {
"vendor-dir": "wp-content/vendor"
},
"require" : {
"johnpbloch/wordpress" : ">=4.9",
"rarst/fragment-cache" : "^1.3",
"rarst/update-blocker" : "^1.1"
},
"require-dev" : {
"rarst/laps" : "^1.4.4",
"rarst/toolbar-theme-switcher" : "^1.5",
"wpackagist-plugin/a-fresher-cache" : "*",
"wpackagist-plugin/core-control" : "*",
"wpackagist-plugin/monster-widget" : "*",
"wpackagist-plugin/theme-check" : "*",
"wpackagist-plugin/user-switching" : "*",
"wpackagist-plugin/wcm-user-language-switcher": "*"
},
"extra" : {
"wordpress-install-dir": "wp"
}
}
rarst/*
vendor namespacetype
is set to project
(rather than default library
), it is mostly semantic hint that this is root packagerepositories
declare WordPress Packagist proxy for Composer access to official WordPress plugin repositoryvendor
directory is relocated inside wp-content
wp
subdirectory (using custom wordpress-install-dir
configuration option of core installer, required by core package)composer.json
from gist into empty directorycomposer install --prefer-dist
in that directoryRun:
composer create-project rarst/install-test wordpress dev-master --repository-url=https://www.rarst.net --prefer-dist
This will tell Composer to create project:
rarst/install-test
packagewordpress
directorydev-master
versionrarst.net/packages.json
Composer repositoryAfter install the project directory will have the following content:
wp
WordPress corewp-content
plugins
wordpress-plugin
typethemes
wordpress-theme
typevendor
library
typeautoload.php
combined class autoload file for all packagescomposer.json
project file we ran install forcomposer.lock
file with exact current state of packageswp-config.php
was not created by this example, but should be placed hereIn one command we have neat and nearly complete subdirectory install! The example package we used only lacks properly set up wp-config.php
and index.php
for complete WordPress site.
Notably we made changes to the default WordPress directory structure, which you might be used to. This enables us to update parts of it separately, without worry that core update erases content packages inside of it.
This is supported natively by WordPress configuration, see documentation in Codex:
Since our whole stack shares single Composer–driven autoload for classes — we need to include it into WordPress boot process.
There is no native WordPress convention for autoload and in practice wp-config.php
is most appropriate place to set it up.
For example it might look like this at the top of wp-config.php
(created at the root, one level above core subdirectory):
require __DIR__ . '/wp-content/vendor/autoload.php';