Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function create_item_permissions_check( $request ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
$prepared_post = $this->prepare_item_for_database( $request );
$prepared_post = $this->prepare_item_for_database( $request );

if ( is_wp_error( $prepared_post ) ) {
return $prepared_post;
Expand Down Expand Up @@ -651,7 +651,7 @@ public function prepare_item_for_response( $item, $request ) { // phpcs:ignore V
// Wrap the data in a response object.
$response = rest_ensure_response( $data );

$links = $this->prepare_links( $template->id );
$links = $this->prepare_links( $template );
$response->add_links( $links );
if ( ! empty( $links['self']['href'] ) ) {
$actions = $this->get_available_actions();
Expand All @@ -664,7 +664,6 @@ public function prepare_item_for_response( $item, $request ) { // phpcs:ignore V
return $response;
}


/**
* Prepares links for the request.
*
Expand All @@ -673,12 +672,12 @@ public function prepare_item_for_response( $item, $request ) { // phpcs:ignore V
* @param integer $id ID.
* @return array Links for the given post.
*/
protected function prepare_links( $id ) {
protected function prepare_links( $template ) {
$base = sprintf( '%s/%s', $this->namespace, $this->rest_base );

$links = array(
'self' => array(
'href' => rest_url( trailingslashit( $base ) . $id ),
'href' => rest_url( trailingslashit( $base ) . $template->id ),
),
'collection' => array(
'href' => rest_url( $base ),
Expand All @@ -688,6 +687,20 @@ protected function prepare_links( $id ) {
),
);

if ( post_type_supports( $this->post_type, 'author' ) && ! empty( $template->author ) ) {
$links['author'] = array(
'href' => rest_url( 'wp/v2/users/' . $template->author ),
'embeddable' => true,
);
}

if ( 'theme' === $template->source || 'theme' === $template->origin ) {
$links['theme'] = array(
'href' => rest_url( 'wp/v2/themes/' . $template->theme ),
'embeddable' => true,
);
}

return $links;
}

Expand Down Expand Up @@ -857,7 +870,7 @@ public function get_item_schema() {
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'author' => array(
'author' => array(
'description' => __( 'The ID for the author of the template.' ),
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
Expand Down