WP-CLIwp easy-svg pack import-link

wp easy-svg pack import-link

Fetch a share link made on another site and import the collection behind it as a new icon set, with the same address checks and sanitizing as the Templates screen.

WP-CLI command, Easy SVG Pro, Status: Stable

Site 1 makes a share link for one collection, site 2 runs this command with that link. The command fetches the pack behind the link and stores it as a new icon set, every icon sanitized and hardened. It is the same fetch and import as Paste URL on the Templates screen, so it refuses the same addresses.

Usage

wp easy-svg pack import-link <url> [--as=<slug>]

When to use it

  • A colleague made a share link with wp easy-svg share create or on the Templates screen, and you want the collection on your site without handling a ZIP file.
  • A provisioning script pulls the agency's house icons from the agency site into a new client site.

Do not use it for a pack file you already have. Use wp easy-svg pack import for that.

Parameters

query
urlpositional
Required

The share link from the other site, as it was printed or copied: https://other.example/wp-json/easy-svg-pro/v1/share/<token> or the plain permalink form https://other.example/?rest_route=/easy-svg-pro/v1/share/<token>.

query
--asoption

The collection slug to store the set under, instead of the slug in the pack's manifest. It is turned into a slug first.

Return value

stdouttext

A warning when the slug from the manifest is taken (acme was taken; registering as acme-2.), one warning per refused icon (Warning: logo.svg was not imported.) and the success line Success: 48 icons imported as acme. On a German site: 48 Icons als acme importiert.

exit codeint

0 when the set was stored, warnings included. 1 when the license, the free plugin's icon library, the WP-CLI feature, the Share links feature or the Collections feature is off, Easy SVG is inactive or too old to harden icons, the URL is not a share link, the fetch was refused or failed, the pack held no acceptable icon, 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

wp easy-svg pack import-link 'https://agency.example/wp-json/easy-svg-pro/v1/share/a1b2c3d4e5f6.Qm9yZWQgeWV0PyBUaGlzIGlzIG5vdCBhIHJlYWwgc2VjcmV0Lg' --as=house-icons
url="$(wp @agency easy-svg share create house-icons --hours=1 | head -n 1)"
wp @client easy-svg pack import-link "$url"

The link is the first line of share create's output, alone on its line.

How it works

  1. Guard: license, WP-CLI feature, Share links feature, Collections feature.
  2. The same checks as any pack import: Easy SVG must be active and able to harden icons.
  3. The address: only another site's share route is fetched. https, port 443 if a port is given, no user name, password or fragment, a host name (never an IP address, never a single label such as localhost), and the path of the share route with a token. Anything else stops with That is not a share link. It starts with https:// and ends in /easy-svg-pro/v1/share/ and a long code.
  4. The fetch: every address the host resolves to must be public. The connection is pinned to the checked address with cURL, so PHP needs cURL. Redirects are not followed, the timeout is 15 seconds, and the answer may be at most 16 MB and must be a ZIP.
  5. The ZIP is imported like an upload: every icon is sanitized and hardened, the pack becomes a new set and never merges into an existing one. The set's origin is recorded as imported from a pack, the same as an import on the Templates screen.
  6. Without --as, a taken slug is reported as a warning and the command imports again under the free variation it was offered.

Pitfalls

  • The link is short-lived. It works for the hours chosen when it was made (1, 24 or 168) and can be revoked at any time. An expired, revoked or wrong link, or Share links switched off on the other site, all end with The link has expired, was revoked, or sharing is switched off on the other site.
  • Local and private hosts are refused. A staging site on localhost, an IP address or a private network cannot be imported from: That address points into a private or local network, or could not be found. Only public websites can be imported from.
  • --as that is taken moves aside without a warning. The set lands under a free variation such as brand-2. Read the slug from the success line.
  • Each run makes a new set. Importing the same link twice gives you two sets.