wp easy-svg pack import
Read a pack ZIP in as a new published icon set, with every icon sanitized and hardened, and pick its slug with --as. Nothing is written to the file system.
WP-CLI command · Easy SVG Pro · Status: Stable
This command reads a pack ZIP and stores it as a new icon set in the database. Every icon goes through this site's sanitizer and hardener first, exactly like an upload in the Packs tab. Nothing is unpacked to disk. After the import the set is a normal icon set you can edit in the set editor.
Usage
wp easy-svg pack import <file> [--as=<slug>]
When to use it
- You exported a set with
wp easy-svg pack exportand want it on another site. - A provisioning script sets up new client sites with the agency's standard icon sets.
- You received a pack from a designer and want it in the database rather than as files.
Do not use it when you want to keep keywords. An icon set stores only name and label per icon. Unzip the pack into wp-content/easy-svg-icons/<slug>/ instead, which keeps the manifest as it is.
Parameters
Path to the pack ZIP. It must be readable for the user WP-CLI runs as.
The collection slug to store the set under, instead of the slug in the pack's manifest. Pass a lower case slug such as brand-icons: the command does not turn it into a slug itself.
Return value
One warning per refused icon (Warning: logo.svg was not imported.), a warning when the slug was taken (acme was taken; registering as acme-2.) and a success line: Success: 48 icons imported as acme.
0 when the set was stored, warnings included. 1 when the licence or the WP-CLI feature is off, the file cannot be read, Easy SVG Support is inactive or too old to harden icons, no icon in the file was acceptable, no free slug was found, or the set could not be stored.
Default
The slug comes from --as, else from the manifest's slug, else it is pack.
Examples
Import a pack
wp easy-svg pack import acme.zip
Provision a new client site
#!/usr/bin/env bash
set -euo pipefail
for pack in /srv/agency/packs/*.zip; do
slug="$(basename "$pack" .zip)"
wp easy-svg pack import "$pack" --as="$slug"
done
wp easy-svg icons list
Import under a fixed name and stop on a collision
The command never fails on a taken slug, it moves aside to -2. If templates depend on the exact slug, check it yourself:
out="$(wp easy-svg pack import brand.zip --as=brand 2>&1)"
echo "$out"
if grep -q 'was taken' <<<"$out"; then
echo "brand already exists. The new set got another slug, templates will not find it." >&2
exit 1
fi
Defensive: make sure the set will show up
wp plugin is-active easy-svg || { echo "Easy SVG Support inactive" >&2; exit 1; }
wp option get easy_svg_pro_features --format=json | jq -e '.editor == true' >/dev/null \
|| echo "Warning: Icon set editor is off, the set is stored but not used as a collection." >&2
wp easy-svg pack import brand.zip --as=brand
How it works
- The archive is read by the same ZIP reader the Packs upload, the preset installer and the set import use. Only
.svgentries andmanifest.jsonare read, paths with..or a leading/are skipped, and the caps fromeasy_svg_pro_import_max_entries(2000 entries),easy_svg_pro_import_max_total_bytes(16 MB) and the free plugin's per file size limit apply. - The manifest names the icons and gives labels. An SVG without an entry still imports under its file name.
- Every icon is sanitized and hardened. Icons that do not survive are listed as warnings.
- The slug is taken from
--as, the manifest orpack. If a collection of that name exists, the command tries-2,-3and so on up to-999and warns. - A published
easy_svg_setpost is created with the manifest label as title. Its origin is recorded asimport-cli, and the manifest'slicense,authorandsourceare stored with the set and shown in the Packs tab. - The icons are written through the one function every set write uses. It takes the set lock and fires
easy_svg_pro_set_icons_written, so icon history and your own listeners see the import.
Pitfalls
- Keywords are lost. A set stores only name and label per icon.
- A collision does not stop the import. The set lands under
slug-2with only a warning and exit code0. Scripts that need a fixed slug must check the output. --asis used as given.--as="My Brand"is checked for collisions asMy Brand, then WordPress turns the post slug intomy-brand, and the success line still printsMy Brand. Always pass a lower case slug.- Silent caps. Entries past the entry cap or the total byte cap, and files over the per file limit, are never read, so they are not even listed as refused. A large pack can import smaller than it is. Compare the count in the success line with the pack.
- The Icon set editor feature decides visibility. The set is stored even with that feature off, but it only registers as a collection while the feature is on.
- Each run makes a new set. Importing the same pack twice gives you
acmeandacme-2. There is no update mode.