Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion includes/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public function register_routes() {
'callback' => [ $this, 'search_docs' ],
'permission_callback' => '__return_true',
'args' => [
'context' => [
'description' => __( 'Scope under which the request is made; determines fields present in response.', 'wedocs' ),
'type' => 'string',
'enum' => [ 'view', 'embed', 'edit' ],
'default' => 'view',
'sanitize_callback' => 'sanitize_key',
'validate_callback' => 'rest_validate_request_arg',
],
'query' => [
'required' => true,
'type' => 'string',
Expand Down Expand Up @@ -1197,7 +1205,9 @@ public function prepare_item_for_response( $doc, $request ) {
'order' => $doc->menu_order,
];

if ( 'edit' == $request['context'] ) {
// Raw fields are edit-only data, so the caller must be able to edit the doc.
// Otherwise `context=edit` on public routes would leak password-protected content.
if ( 'edit' === $request['context'] && current_user_can( 'edit_post', $doc->ID ) ) {
$data['title']['raw'] = $doc->post_title;
$data['content']['raw'] = $doc->post_content;
}
Expand Down
Loading