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.
wp core install), which are not natively consumable by Laravel’s dependency-injection or service-container patterns. A Laravel wrapper would need to abstract these commands into a service layer.wp core update) interact with filesystems, databases, and HTTP APIs, requiring careful handling of environment variables, permissions, and error recovery in a Laravel context.composer.json extra.laravel metadata, no Facade/ServiceProvider patterns).\Symfony\Component\Process\Process) to shell out to wp-cli.wp-cli under the hood.wp_options, wp_posts), which may conflict with Laravel’s migrations or Eloquent models. A Laravel integration would need to isolate WordPress DB operations (e.g., via a separate connection or schema).wp core install create admin users with arbitrary passwords and write to disk. Laravel’s security layer (e.g., CSRF, auth) would need to validate inputs before delegating to wp-cli.exec() or shell_exec() without proper escaping.Why integrate wp-cli/core-command into Laravel?
spatie/laravel-wordpress) achieve the same result with lower risk?Environment Assumptions:
wp-cli support)?Performance:
Maintenance:
wp-cli when WordPress releases a new version? Will Laravel apps vendor-lock to a specific wp-cli version?Alternatives:
laravel-wordpress, wp-vip/goose) that avoid wp-cli entirely?Laravel + WP-CLI:
symfony/process) for shell delegation.wp-cli commands as custom commands.Compatibility:
wp-cli/core-command supports PHP 7.4+ (check for 8.1+ compatibility).wp-cli/wp-cli version)./var/www/wordpress). Laravel’s storage paths must be separate.Phase 1: Proof of Concept
wp-cli globally or via Composer (wp-cli/wp-cli).wp core version) using Symfony Process:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
$process = new Process(['wp', 'core', 'version']);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
Phase 2: Laravel Wrapper
wp-cli commands as Laravel services:
// app/Providers/WpCliServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Process\Process;
class WpCliServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('wp-cli', function ($app) {
return new class {
public function version(string $wpPath): string
{
$process = new Process(['wp', 'core', 'version'], $wpPath);
$process->run();
return $process->getOutput();
}
};
});
}
}
wp-cli functionality:
// 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} {admin_user} {admin_email}';
public function handle()
{
$process = new Process([
'wp', 'core', 'install',
'--url=' . $this->argument('url'),
'--title=' . $this->argument('title'),
'--admin_user=' . $this->argument('admin_user'),
'--admin_email=' . $this->argument('admin_email'),
]);
$process->run();
$this->output->write($process->getOutput());
}
}
Phase 3: Environment Abstraction
// config/wp_sites.php
return [
'site1' => [
'path' => '/var/www/site1',
'db' => [
'host' => 'localhost',
'name' => 'site1_db',
],
],
];
env() for dynamic paths/credentials.Phase 4: Async Operations
wp core update), use Laravel Queues:
// app/Jobs/UpdateWordPress.php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Symfony\Component\Process\Process;
class UpdateWordPress implements ShouldQueue
{
use Queueable;
public function handle()
{
$process = new Process(['wp', 'core', 'update']);
$process->run();
// Log output or dispatch a notification.
}
}
| Step | Task | Dependencies | Risk | |------|------|------------
How can I help you explore Laravel packages today?