REST APIeasy-svg/v1/library/add

easy-svg/v1/library/add

Adds one icon from SVG markup, sanitized and hardened on the way in.

REST endpoint · Easy SVG · Status: Internal · Defined in includes/panel.php

Internal: not part of the promised public surface. It may change without notice.

Usage

POST /wp-json/easy-svg/v1/library/add

Example

curl -X POST https://example.com/wp-json/easy-svg/v1/library/add \
	-H 'Content-Type: application/json' \
	-H 'X-WP-Nonce: <nonce>' \
	-d '{"label":"Heart","markup":"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>"}'

Description

The label is sanitized as text and becomes the slug; a taken slug gets a number appended and added.wanted shows what was asked for. The markup meets the same sanitizer, size and complexity bounds as an upload. Refusals answer 422 easy_svg_add_failed with a sentence from easy_svg_panel_add_message().

Permission: manage_options (easy_svg_panel_rest_permission)

Parameters

body
labelstring

The visible name; the slug is derived from it and never moves. Without one the add fails with bad_name.

Response

The library payload plus added (id, slug, wanted).

{
  "items": [
    {
      "id": 42,
      "slug": "heart",
      "label": "Heart",
      "content": "<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 21l-8-8a5 5 0 0 1 8-6 5 5 0 0 1 8 6z"/></svg>"
    }
  ],
  "total": 1,
  "truncated": false,
  "added": {
    "id": 42,
    "slug": "heart",
    "wanted": "heart"
  }
}
The handler reads the JSON body only; send Content-Type: application/json. Values in the query string are ignored by the handler.