wp-cli/core-command
WP-CLI package providing the wp core command set to download, install, update, and manage WordPress core. Includes update checking via the Version Check API with flags for major/minor comparisons, forced checks, and flexible output formats.
Installation:
composer require wp-cli/core-command
Ensure wp-cli/wp-cli is also installed as a dependency.
Basic Usage: Check if WordPress is installed in the current directory:
wp core is-installed
Exit code 0 means WordPress is installed; non-zero means it is not.
First Use Case: Install WordPress in a new directory:
wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com
wp core commands. Run wp core --help to see all available subcommands.src/Command/CoreCommand.php and related classes in the src/ directory.Automated WordPress Setup:
Use wp core download followed by wp core install in deployment scripts:
wp core download --locale=en_US --path=/var/www/html
wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com
Update Workflows: Check for updates and apply them in a single command:
wp core check-update --minor
wp core update --minor --force
Multisite Management: Convert an existing single-site to multisite:
wp core multisite-convert --title="My Network" --subdomains
CI/CD Integration:
Use wp core is-installed to conditionally run WordPress-specific tasks:
if wp core is-installed; then
wp plugin install my-plugin
else
echo "WordPress not installed. Skipping plugin installation."
fi
Local Development:
wp core download --locale=fr_FR to set up a French WordPress instance.--dry-run before applying them:
wp core update-db --dry-run
Server Maintenance:
wp core update in a cron job for automated updates.wp core check-update-db --network to verify all sites in a multisite network are up-to-date.Custom Installations:
wp core download --skip-content
wp core install --url=https://example.com/blog --title="Blog"
wp option update siteurl https://example.com/blog
Laravel Artisan Integration:
Create a custom Artisan command to wrap wp core commands:
// app/Console/Commands/InstallWordPress.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
class InstallWordPress extends Command
{
protected $signature = 'wp:install {url} {title} {email}';
protected $description = 'Install WordPress using wp-cli';
public function handle()
{
$process = new Process(['wp', 'core', 'install',
'--url=' . $this->argument('url'),
'--title=' . $this->argument('title'),
'--admin_user=admin',
'--admin_email=' . $this->argument('email')
]);
$process->run();
$this->output->writeln($process->getOutput());
}
}
Register the command in app/Console/Kernel.php:
protected $commands = [
Commands\InstallWordPress::class,
];
Run with:
php artisan wp:install https://example.com "My Site" admin@example.com
Environment-Specific Configurations:
Use Laravel's .env to store sensitive data (e.g., admin passwords) and pass them securely:
wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com --prompt=admin_password < <(echo -n "securepassword123")
Logging and Error Handling: Redirect output to Laravel logs for debugging:
$process = new Process(['wp', 'core', 'update']);
$process->run(function ($type, $buffer) {
\Log::info($buffer);
});
Permission Issues:
www-data, nginx) has write permissions to the WordPress directory and wp-content.--force cautiously; it may overwrite critical files if misused.Multisite Rewrite Rules:
After converting to multisite, manually update .htaccess or nginx.conf to avoid 404 errors. The package does not automate this.
Locale Limitations:
Downloading a locale for an older WordPress version may fail. Use --skip-locale-check to bypass this:
wp core download --locale=fr_FR --version=5.0 --skip-locale-check
Update Locks:
If you see Error: Another update is currently in progress, clear the lock manually:
wp option delete core_updater.lock
Network vs. Single-Site:
Commands like wp core check-update-db --network require a multisite installation. Misuse may lead to unexpected behavior.
Verbose Output:
Use --debug with WP-CLI for detailed logs (requires WP-CLI >= 2.0):
WP_CLI_DEBUG=1 wp core update
Dry Runs:
Always test database updates with --dry-run first:
wp core update-db --dry-run
Checksum Failures:
If checksums fail during updates, use --insecure temporarily (not recommended for production):
wp core update --insecure
Custom Paths: Specify a custom path for downloads/installations to avoid cluttering the current directory:
wp core download --path=/tmp/wordpress
Version Pinning: Update to a specific version (e.g., for testing):
wp core update --version=5.8.2
Output Formatting:
Use --format=json for machine-readable output in scripts:
wp core check-update --format=json
Skip Emails: Avoid sending emails during automated installs:
wp core install --skip-email
Composer Integration:
Use wp-cli/wp-cli and wp-cli/core-command together in composer.json:
{
"require": {
"wp-cli/wp-cli": "^2.7",
"wp-cli/core-command": "^2.5"
}
}
Testing: Leverage Behat steps for automated testing. Example:
Given a WP install
When I run `wp core version`
Then STDOUT should be a version string == "5.8.2"
Caching: Downloaded WordPress files are cached locally. Clear the cache with:
wp cache flush
Subdirectory Installs:
For subdirectory installs (e.g., /blog), update siteurl and home options post-install:
wp option update siteurl https://example.com/blog
wp option update home https://example.com/blog
Custom User Tables:
If using custom user tables (e.g., CUSTOM_USER_TABLE), ensure the tables exist before running wp core install. The package ignores admin_email and admin_password if the user already exists.
HTTPS/SSL:
For secure downloads, ensure your server trusts the WordPress SSL certificate. Use --insecure only as a last resort.
How can I help you explore Laravel packages today?