REST APIeasy-svg/v1/library/off

easy-svg/v1/library/off

Switches icons off or back on: a switched-off icon stays stored and keeps rendering, but is no longer offered in the editor.

REST endpoint, Easy SVG, Status: Public, defined in includes/panel.php

Usage

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

Example

curl -X POST https://example.com/wp-json/easy-svg/v1/library/off \
	-H 'Content-Type: application/json' \
	-H 'X-WP-Nonce: <nonce>' \
	-d '{"ids":[42,43],"off":true}'

Description

Calls easy_svg_switch_icons(). For each id of an esw_icon post, off: true sets the post meta _easy_svg_off to 1 and off: false deletes it. Ids that are not an icon are skipped silently, with no error. If anything changed, the icon cache is dropped. A switched-off icon stays in the WordPress icon registry, so a page that already uses it keeps showing it. Only the list of GET /wp/v2/icons, which the editor offers from, leaves it out (easy_svg_hide_off_icons(), active while the icon library is on). A value such as the string "false" counts as false.

Permission: administrators only. Every easy-svg/v1 route checks easy_svg_panel_rest_permission(), that is current_user_can( 'manage_options' ). Without a login WordPress answers 401 rest_forbidden; logged in without manage_options (an editor, say) it answers 403 rest_forbidden. A missing required argument or a value of the wrong type is refused with 400 before that check (rest_missing_callback_param or rest_invalid_param), for guests too.

Parameters

body
idsinteger[]
Required

Icon post ids, at most 500.

body
offboolean
Required

true switches off, false back on.

body
limitinteger

How many icons the list in the answer carries, 1 to 500. Default 500.

Response

The first page of the library as GET easy-svg/v1/library gives it, from easy_svg_panel_library_payload()..

{
  "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>",
      "off": true
    }
  ],
  "total": 1,
  "offset": 0,
  "limit": 500,
  "has_more": false,
  "truncated": false
}
The handler reads the JSON body only; send Content-Type: application/json. Values in the query string are ignored by the handler.