element-source REST endpoint
List the posts a custom element's item can fill from, or one post's values for its fields.
Endpoint#
List the posts a custom element's item can fill from, or one post's values for its fields. Available from Kindly Edit 0.11.0.
/wp-json/cantata-edit/v1/element-source
GET#
This operation uses a server permission callback. Browser clients need an authenticated WordPress session and REST nonce.
Permission expression in this release:
'permission_callback' => static fn() => current_user_can( 'edit_posts' ),
The callback also reads only the post types the element's definition names, and only posts the caller may read (read_post).
Registered argument schema#
{
"element": { "type": "string", "required": true },
"id": { "type": "integer", "minimum": 0 },
"search": { "type": "string" }
}
element: the definition's slug, the file name without its number (11-featured-events.jsonisfeatured-events).- Without
id: up to 30 posts,[ { "id", "title", "when" } ], sorted as the definition'ssource.sortsays, and only upcoming ones when it setsupcoming.searchnarrows them. - With
id:{ "id", "title", "values" }, wherevaluesmaps each field key in the definition'sfillto its value: words,{ "start": "Y-m-d", "end": "Y-m-d" }for a date field, or{ "id", "src", "srcset", "width", "height", "alt" }for an image field. Addresses are relative to the site.
Errors#
| Status | Code | When |
|---|---|---|
| 401 | rest_forbidden |
Not signed in. |
| 403 | rest_forbidden |
Signed in without edit_posts. |
| 404 | cantata_edit_no_source |
No such element, or it has nothing to fill from. |
| 404 | cantata_edit_source_missing |
The post is gone, is another type, or the caller can't read it. |
Implementation#
cantata_edit_custom_elements, cantata_edit_custom_candidates and cantata_edit_custom_fill in includes/custom-elements.php.
Client handling#
The editor calls it from an item's Fill from control. Filling copies the values into the page once; nothing updates by itself.