Composerize WordPress is a Composer plugin that converts a non-Composer-managed WordPress application (e.g., one created via tarball) to a Composer-managed WordPress application. It is based on Composerize Drupal by Grasmash.
It is not for creating new WordPress applications.
The composerize-wordpress
command will perform the following operations:
- Remove all
composer.json
andcomposer.lock
files, should they exist - Generate a new
composer.json
in the[composer-root]
directory based on template.composer.json.- Populate
require
with an entry forpantheon-systems/wordpress-composer
- Populate
require
with an entry for each project in:[core-root]/wp-content/plugins
[core-root]/wp-content/themes
- Populate
- Create or modify
[composer-root]/.gitignore
with entries for Composer-managed contributed projects as per best practices. You can modify.gitignore
after composerization if you'd prefer not to follow this practice. - Execute
composer update
to generatecomposer.lock
, autoload files, and install all dependencies in the correct locations.
It will NOT add any contributed projects in docroot/libraries
to composer.json
. You must add those to your composer.json
file manually. In addition to packagist and Wpackagist.org packages, you may also use any package from asset packagist, which makes NPM packages available to Composer.
composer global require rvtraveller/composerize-wordpress
cd path/to/wordpress/project/repo
composer composerize-wordpress --composer-root=[repo-root] --core-root=[core-root]
The [composer-root]
should be the root directory of your project, where .git
is located.
The [core-root]
should be the WordPress root, where wp-load.php
is located.
Examples:
# WordPress is located in a `docroot` subdirectory.
composer composerize-wordpress --composer-root=. --core-root=./docroot
# WordPress is located in a `web` subdirectory.
composer composerize-wordpress --composer-root=. --core-root=./web
# WordPress is located in a `public_html` subdirectory (cPanel compatible).
composer composerize-wordpress --composer-root=. --core-root=./public_html
# WordPress is located in the repository root, not in a subdirectory.
composer composerize-wordpress --composer-root=. --core-root=.
--composer-root
: Specifies the root directory of your project wherecomposer.json
will be generated. This should be the root of your Git repository, where.git
is located.--core-root
: Specifies the WordPress root directory wherewp-load.php
is located.--no-update
: Preventscomposer update
from being automatically run aftercomposer.json
is generated.--no-gitignore
: Prevents modification of the root .gitignore file.--exact-versions
: Will cause WordPress core and contributed projects (plugins, themes) to be be required with exact verions constraints incomposer.json
, rather than using the default caret operator. E.g., awordpress/core
would be required as5.0
rather than^5.0
. This prevents projects from being updated. It is not recommended as a long-term solution, but may help you convert to using Composer more easily by reducing the size of the change to your project.