|
| 1 | +# REST API |
| 2 | + |
| 3 | +<Badge type="tip" vertical="top" text="Elementor Core" /> <Badge type="warning" vertical="top" text="Intermediate" /> |
| 4 | + |
| 5 | +All endpoints live under the `elementor/v1` namespace. All read endpoints accept an optional `context` argument: `frontend` (default) or `preview`. Read permission is `is_user_logged_in()`. |
| 6 | + |
| 7 | +## `GET /elementor/v1/global-classes` |
| 8 | + |
| 9 | +Lightweight index — labels only, in display order. |
| 10 | + |
| 11 | +| Argument | Type | Required | Default | |
| 12 | +| -------- | ---- | -------- | ------- | |
| 13 | +| `context` | string | no | `frontend` | |
| 14 | + |
| 15 | +```json |
| 16 | +{ |
| 17 | + "data": [ |
| 18 | + { "id": "g-abc", "label": "Card" }, |
| 19 | + { "id": "g-def", "label": "Button" } |
| 20 | + ] |
| 21 | +} |
| 22 | +``` |
| 23 | + |
| 24 | +## `GET /elementor/v1/global-classes/post` |
| 25 | + |
| 26 | +Full class definitions referenced by a specific document. |
| 27 | + |
| 28 | +| Argument | Type | Required | Default | |
| 29 | +| -------- | ---- | -------- | ------- | |
| 30 | +| `post_id` | integer | yes | — | |
| 31 | +| `context` | string | no | `frontend` | |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "data": { |
| 36 | + "g-abc": { "id": "g-abc", "label": "Card", "type": "class", "variants": [ ] } |
| 37 | + }, |
| 38 | + "meta": { "order": [ "g-abc" ] } |
| 39 | +} |
| 40 | +``` |
| 41 | + |
| 42 | +`meta.order` is the intersection of the global order with the IDs used by the document. |
| 43 | + |
| 44 | +## `GET /elementor/v1/global-classes/styles` |
| 45 | + |
| 46 | +Bulk fetch by ID list. |
| 47 | + |
| 48 | +| Argument | Type | Required | Default | |
| 49 | +| -------- | ---- | -------- | ------- | |
| 50 | +| `ids` | string | yes | — | |
| 51 | +| `context` | string | no | `frontend` | |
| 52 | + |
| 53 | +`ids` is comma-separated. Missing IDs resolve to `null` in `data` and are omitted from `meta.order`. |
| 54 | + |
| 55 | +```json |
| 56 | +{ |
| 57 | + "data": { |
| 58 | + "g-abc": { "id": "g-abc", "label": "Card", "type": "class", "variants": [ ] }, |
| 59 | + "g-missing": null |
| 60 | + }, |
| 61 | + "meta": { "order": [ "g-abc" ] } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +## `PUT /elementor/v1/global-classes` |
| 66 | + |
| 67 | +Create, update, delete, and reorder. |
| 68 | + |
| 69 | +| Argument | Type | Required | Default | Notes | |
| 70 | +| -------- | ---- | -------- | ------- | ----- | |
| 71 | +| `context` | string | no | `frontend` | | |
| 72 | +| `changes` | object | yes | — | `{ added, deleted, modified, order? }`. `additionalProperties: false`. | |
| 73 | +| `items` | object | yes | — | Map of `class_id → { id, label, type, variants }` for **touched** items only. | |
| 74 | +| `order` | string[] | yes | — | Full ordered list of class IDs after the operation. | |
| 75 | + |
| 76 | +**Permission:** `current_user_can( Add_Capabilities::UPDATE_CLASS )`. |
| 77 | + |
| 78 | +**Responses:** |
| 79 | + |
| 80 | +- `204 No Content` on success. |
| 81 | +- `200 OK` with `{ "code": "DUPLICATED_LABEL", "modifiedLabels": { … } }` when duplicates were auto-renamed. |
| 82 | +- `400 Bad Request` with `code: "invalid_items" | "invalid_order" | "global_classes_limit_exceeded"`. The limit error carries `meta.current_count` and `meta.max_allowed`. |
| 83 | + |
| 84 | +Hard limit: **1000** classes. Set `changes.order = true` when reordering, or per-document style caches won't be invalidated. |
| 85 | + |
| 86 | +```js |
| 87 | +PUT /elementor/v1/global-classes |
| 88 | +{ |
| 89 | + "context": "frontend", |
| 90 | + "changes": { |
| 91 | + "added": ["g-new"], |
| 92 | + "deleted": [], |
| 93 | + "modified": ["g-abc"], |
| 94 | + "order": true |
| 95 | + }, |
| 96 | + "items": { |
| 97 | + "g-abc": { /* full item */ }, |
| 98 | + "g-new": { /* full item */ } |
| 99 | + }, |
| 100 | + "order": [ "g-new", "g-abc", "g-def" ] |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## `GET /elementor/v1/global-classes/usage` |
| 105 | + |
| 106 | +Detailed usage report across the site. |
| 107 | + |
| 108 | +| Argument | Type | Required | Default | |
| 109 | +| -------- | ---- | -------- | ------- | |
| 110 | +| `context` | string | no | `frontend` | |
| 111 | + |
| 112 | +**Permission:** `current_user_can( 'manage_options' )`. |
0 commit comments