Docs / API & Plugin Development / Smush API Docs

4. Smush API Docs

Written by Luke Britt & Patrick | Last updated: October 12, 2020

WPMU DEV is dedicated to supporting advanced users in every possible way. Our Smush API Documentation is an ongoing project. Information about new commands will be added here as it becomes available.

4.1 WP-CLI

Link to chapter 1

WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installations and much more, without using a web browser. Smush has an integration module with WP CLI, which will allow you to simplify a few common tasks.

Image optimization

Allows optimizing single images, batch optimization, as well as bulk optimization of the whole media library.

Command
wp smush compress [–type=] [–image=]

Parameters

type
String
Optimize single image, batch or all images. Accepts: all, single, batch. Default: all.
image
Integer
Attachment ID to compress. Default: 0 (all).

Examples
Smush all images.
wp smush compress

Smush single image with ID = 10.
wp smush compress --type=single --image=10

Smush first 5 images.
wp smush compress --type=batch --image=5

Note that the wp smush compress command will respect all current settings in the Smush plugin on the site where the command is run. In other words, if the Super-Smush option is enabled on the site, running this command will super-smush the images.

List unoptimized images

Command
wp smush list []

Parameters

count
Integer
Limit number of images to get.

Examples
Get all unoptimized images.
wp smush list

Get the first 100 images that are not optimized.
wp smush list 100

Restore images

Allows restoring images that have backups (backups need to be enabled via the “Store a copy of my full size images” option in Smush).

Command
wp smush restore [–id=]

Parameters

id
Integer
Attachment ID to restore. Optional parameter.

Examples
Restore all images that have backups.
wp smush restore

Restore single image with ID = 10.
wp smush restore --id=10

Restore all images on a site with slug blog on a WordPress multisite instance using subdomains.
wp smush restore --url=blog.example.com