Tooling & CLI
Overview of Tooling
Efficient development and maintenance of this WordPress project rely on three primary tools: Composer for PHP dependency management, NPM for frontend asset orchestration, and WP-CLI for command-line site administration.
Using these tools ensures environmental parity across development, staging, and production.
PHP Dependency Management (Composer)
We use Composer to manage the WordPress core, plugins, and third-party PHP libraries. This ensures that all dependencies are version-controlled and easily reproducible.
Key Commands
| Command | Description |
| :--- | :--- |
| composer install | Installs all dependencies defined in composer.lock. |
| composer update | Updates dependencies to their latest versions based on composer.json. |
| composer require <package> | Adds a new plugin or library to the project. |
Usage Example
To add a new plugin from WPackagist:
composer require wpackagist-plugin/akismet
Frontend Workflow (NPM)
NPM handles the compilation of assets (SASS, JavaScript) and manages block development dependencies. Most frontend tasks are executed from the theme or root directory.
Available Scripts
The following scripts are typically defined in the package.json:
npm run dev: Starts the development server with Hot Module Replacement (HMR) or file watching.npm run build: Compiles and minifies assets for production deployment.npm run lint: Runs ESLint and Stylelint to ensure code quality.
Example: Compiling Assets
# Install node modules
npm install
# Build production assets
npm run build
Site Management (WP-CLI)
WP-CLI is the primary interface for interacting with the WordPress installation without using a web browser. It is essential for automation scripts and quick configuration changes.
Common Operations
Plugin Management
Manage the lifecycle of plugins via the terminal:
# List all plugins
wp plugin list
# Activate a specific plugin
wp plugin activate classic-editor
Database Operations
Perform safe search-and-replace operations or export the database:
# Search and replace URLs (dry run recommended first)
wp search-replace 'http://old-url.com' 'https://new-url.com' --dry-run
# Export the database to a .sql file
wp db export backup.sql
User Management
Quickly create or update administrative users:
wp user create developer dev@example.com --role=administrator --user_pass=password123
Automated Workflows
To streamline the setup of a fresh environment, we recommend combining these tools into a single sequence:
# 1. Install PHP dependencies
composer install
# 2. Install JS dependencies and build assets
npm install && npm run build
# 3. (Optional) Run WP-CLI to update the database
wp core update-db
Note: Ensure your local environment meets the requirements specified in the
composer.json(PHP version) andpackage.json(Node.js version) before running these commands.