WP-CLIwp easy-svg pack import

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 export and 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

query
filepositional
Required

Path to the pack ZIP. It must be readable for the user WP-CLI runs as.

query
--asoption

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

stdouttext

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.

exit codeint

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

  1. The archive is read by the same ZIP reader the Packs upload, the preset installer and the set import use. Only .svg entries and manifest.json are read, paths with .. or a leading / are skipped, and the caps from easy_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.
  2. The manifest names the icons and gives labels. An SVG without an entry still imports under its file name.
  3. Every icon is sanitized and hardened. Icons that do not survive are listed as warnings.
  4. The slug is taken from --as, the manifest or pack. If a collection of that name exists, the command tries -2, -3 and so on up to -999 and warns.
  5. A published easy_svg_set post is created with the manifest label as title. Its origin is recorded as import-cli, and the manifest's license, author and source are stored with the set and shown in the Packs tab.
  6. 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-2 with only a warning and exit code 0. Scripts that need a fixed slug must check the output.
  • --as is used as given. --as="My Brand" is checked for collisions as My Brand, then WordPress turns the post slug into my-brand, and the success line still prints My 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 acme and acme-2. There is no update mode.