DevOps · Dependency management

Composer
in WordPress

One file becomes the source of truth for everything that is not your content: WordPress core, plugins from WordPress.org and your own plugins. From the classic install to Composer and Roots, on the real project 4wp.dev.

  • WP Packages
  • Bedrock
  • Own packages
  • Roots
4wp.dev — terminal
# WordPress.org plugin from WP Packages
$ composer require wp-plugin/woocommerce
# our plugin from GitHub, by tag
$ composer add-plugin 4wp-faq
# production install
$ composer install --no-dev --optimize-autoloader

01 — Three approaches

Classic, Composer or Roots?

The same WordPress site can be run three ways. The question is not which one is better, but where each one is allowed, where it is required, and what it costs.

Classic Composer Roots (Bedrock)
Updates A click in the admin, per environment Versions pinned in composer.json / composer.lock Composer + one project structure for every environment
Shared hosting Works anywhere Works: build vendor/ locally or in CI and upload Bedrock needs the document root on web/; Trellis needs a server you control
Required when One site, one person, no own code Own plugins, more than one environment, a team Deploy on push, staging, rollback, secrets outside the code
Cost Nothing up front; paid later in broken updates Learning Composer and Git, a build step Migration, a CI pipeline, SSH access

02 — Evolution

How WordPress got to Composer

Pick an era to see how plugins get into a project.

WP Packages

The Composer repository by Roots at wp-packages.org (formerly wp-composer.com) with short names wp-plugin/* and wp-theme/*. 4wp.dev installs 11 WordPress.org plugins from it.

  • Short names: wp-plugin/*, wp-theme/*
  • Repository: repo.wp-packages.org
// 4wp.dev composer.json
{
  "repositories": [
    { "name": "wp-packages", "type": "composer",
      "url": "https://repo.wp-packages.org" }
  ],
  "require": {
    "wp-plugin/woocommerce": "^11.2.2"
  }
}

03 — Two files

What you want, and what you have

composer.json

What you want, with version constraints: "4wpdev/4wp-faq": "^2.6".

composer.lock

What is actually installed, with exact versions and commits. Always in Git.

vendor/, WordPress core and third-party plugins are never in Git: Composer installs them from the lock file.

04 — Where packages come from

One file, four sources

composer.json
WordPress coreroots/wordpress
WordPress.org pluginswp-plugin/* · repo.wp-packages.org
Own plugins4wpdev/* · GitHub, by tag
PHP librariesPackagist
web/wp
web/app/plugins
vendor/

type: wordpress-plugin with composer/installers puts a package into web/app/plugins.

Package names

Before (WPackagist)Now (WP Packages)Own plugin
wpackagist-plugin/woocommercewp-plugin/woocommerce4wpdev/4wp-faq
wpackagist-theme/twentytwentyfivewp-theme/twentytwentyfive4wpdev/lms4wp

05 — Roots

The Roots stack, in one line each

Roots builds open-source tools for WordPress development. 4wp.dev runs on Bedrock.

Bedrock on 4wp.dev

4wp.dev/
├── composer.json        # what we want
├── composer.lock        # what is installed
├── .env                 # DB, WP_ENV, WP_HOME — not in Git
├── config/              # environments
└── web/                 # document root
    ├── wp/              # WordPress core (Composer)
    └── app/
        ├── mu-plugins/  # must-use: always on, Bedrock autoloader
        ├── plugins/     # wp-plugin/* and 4wpdev/*
        ├── themes/
        └── uploads/     # content — not in Git, shared between releases

06 — Our packages

20 own packages, one release flow

Every 4wp.dev plugin is a Composer package in its own GitHub repository. The site installs it by Git tag, so a release is a tag and a lock-file update.

4wp-account4wp-advanced-code4wp-ai-assistant4wp-booking4wp-bundle4wp-drive4wp-faq4wp-icons4wp-mcp-connector4wp-mega-menu4wp-notifications4wp-planner4wp-seo-helper4wp-smart-link4wp-social4wp-style-switcher4wp-todo4wp-weatherlearn-gutenberg-developmentlms4wp

11 of them are also on WordPress.org and in WP Packages as wp-plugin/4wp-*.

The passport of an own plugin

  • name — GitHub organization and slug
  • type — wordpress-plugin
  • require — its dependencies
  • No version: the version is the Git tag
{
  "name": "4wpdev/4wp-faq",
  "type": "wordpress-plugin",
  "license": "GPL-2.0-or-later",
  "require": {
    "php": ">=7.4",
    "composer/installers": "^2.0"
  }
}

07 — Commands we use

Five commands run the project

CommandWhat it does
composer add-plugin <slug>

Connects our plugin from GitHub with the right repository entry

composer link

Local only: replaces an installed plugin with a symlink to the working clone

composer release

Releases our plugin and ships it to staging

composer checks

Quality gate: forbidden files, secrets, PHP syntax, composer validate

composer install --no-dev --optimize-autoloader

How production installs dependencies

08 — Migration

From WPackagist to WP Packages

  1. Removecomposer remove wpackagist-plugin/woocommerce
  2. Switch the repository"url": "https://repo.wp-packages.org"
  3. Require with the new namecomposer require wp-plugin/woocommerce

09 — Mistakes we made

Three real mistakes

Our plugin on WordPress.org

learn-gutenberg-development is ours: it is installed from GitHub, not from the plugin directory.

Inconsistent names

Some plugins were named 4wp-dev/… or forwp/… instead of the GitHub organization 4wpdev/….

Overwriting composer.json

Replacing a plugin’s existing file dropped its dependencies and autoload. Add to it, do not replace it.

10 — Videos

Composer in short videos

LMS4WP course · 7 modules

Migrating Classic WordPress to Roots: CI/CD for a Real Project

The full build log of 4wp.dev: Bedrock and Composer, own plugins as packages, Local → Staging → Production, atomic releases and deploy on push.

Open the course

11 — FAQ

Questions

Can I still update plugins in the admin?

You should not: an update made in one environment is lost on the next deploy. Updates go through composer.json, Git and deploy, so every environment stays the same.

Does Composer work with premium plugins?

Yes, through a private repository or credentials in COMPOSER_AUTH.

Does it work on shared hosting?

Composer itself does: build vendor/ locally or in CI and upload the result. Bedrock also needs the document root pointed at web/.