wp-cli/media-command
WP-CLI media commands for WordPress: import files as attachments, regenerate thumbnails, replace attachment files, list registered image sizes, and fix image orientation. Useful for bulk media maintenance and automation from the command line.
wp_insert_attachment, wp_generate_attachment_metadata, etc.). Laravel does not integrate with WordPress by default, so direct adoption is not feasible without a middleware layer.Imagick, Intervention Image, or Laravel Media Library), but this would require rewriting core WP-CLI dependencies.WP_Image_Editor, wp_handle_upload) are WordPress-specific.wp-cli/http or a custom API wrapper). Laravel would invoke commands via exec() or HTTP requests.
Example:
// Laravel service to proxy WP-CLI commands
public function regenerateThumbnails(int $attachmentId) {
$output = shell_exec("wp media regenerate {$attachmentId} --yes");
return json_decode($output, true);
}
spatie/laravel-medialibrary for storage.intervention/image for image processing.php-imagick for advanced operations (e.g., EXIF orientation).| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| WordPress Dependency | High | Isolate WP-CLI calls to a dedicated service. |
| Performance Overhead | Medium | Cache results (e.g., regenerated thumbnails). |
| Maintenance Burden | High | Prefer Laravel-native libraries if possible. |
| Security | Medium | Sanitize inputs (e.g., file paths, URLs). |
| Testing Complexity | High | Mock WP-CLI service calls in Laravel tests. |
| Component | Laravel Compatibility | Notes |
|---|---|---|
| WP-CLI Commands | ❌ No | Requires external service or custom wrapper. |
| WordPress Core | ❌ No | Laravel cannot natively use wp_insert_attachment. |
| Media Libraries | ✅ Yes | spatie/laravel-medialibrary, intervention/image are viable. |
| Image Processing | ✅ Yes | Imagick, GD, or Laravel Media Library can replicate core logic. |
| Queues | ✅ Yes | Laravel Queues can dispatch WP-CLI jobs to a worker. |
| API Layer | ✅ Yes | Expose WP-CLI as a REST/gRPC service if needed. |
wp media commands are critical (e.g., regenerate, import).spatie/laravel-medialibrary).wp-cli/wp-cli:latest).exec() or HTTP.// app/Services/WpCliService.php
class WpCliService {
public function regenerateThumbnails(array $attachmentIds) {
$command = "wp media regenerate " . implode(' ', $attachmentIds) . " --yes";
return shell_exec($command);
}
}
spatie/laravel-medialibrary + intervention/image.use Intervention\Image\Facades\Image;
use Spatie\MediaLibrary\HasMedia;
class Post implements HasMedia {
public function registerMediaConversions(): void {
$this->addMediaConversion('thumbnail')
->width(200)
->height(200);
}
}
| Feature | WP-CLI Package | Laravel Alternative | Notes |
|---|---|---|---|
| Bulk Imports | ✅ wp media import |
✅ spatie/laravel-medialibrary bulk uploads |
Laravel may need custom chunking. |
| Thumbnail Regen | ✅ wp media regenerate |
✅ intervention/image + queue jobs |
Laravel lacks WP’s add_image_size. |
| Orientation Fix | ✅ wp media fix-orientation |
✅ Imagick or GD EXIF rotation |
Requires PHP extensions. |
| Pruning Thumbnails | ✅ wp media prune |
❌ No direct equivalent | Custom filesystem cleanup needed. |
| Featured Images | ✅ --featured_image |
✅ spatie/laravel-medialibrary attachments |
Laravel uses media() relationship. |
wp media image-size) → Replace with DB query or cached metadata.wp media import) → Migrate to spatie/laravel-medialibrary.wp media regenerate) → Queue jobs with intervention/image.wp media prune) → Custom Laravel filesystem cleanup.How can I help you explore Laravel packages today?