Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
@@ -633,7 +633,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
* @param WP_REST_Request $request Request object.
|
||||
* @return WP_REST_Response Response object.
|
||||
*/
|
||||
public function prepare_item_for_response( $item, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
|
||||
public function prepare_item_for_response( $item, $request ) {
|
||||
// Restores the more descriptive, specific name for use within this method.
|
||||
$template = $item;
|
||||
|
||||
@@ -760,7 +760,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
protected function prepare_links( $id ) {
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( rest_get_route_for_post( $id ) ),
|
||||
'href' => rest_url( sprintf( '/%s/%s/%s', $this->namespace, $this->rest_base, $id ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
'href' => rest_url( rest_get_route_for_post_type_items( $this->post_type ) ),
|
||||
@@ -770,6 +770,27 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
|
||||
),
|
||||
);
|
||||
|
||||
if ( post_type_supports( $this->post_type, 'revisions' ) ) {
|
||||
$template = get_block_template( $id, $this->post_type );
|
||||
if ( $template instanceof WP_Block_Template && ! empty( $template->wp_id ) ) {
|
||||
$revisions = wp_get_latest_revision_id_and_total_count( $template->wp_id );
|
||||
$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0;
|
||||
$revisions_base = sprintf( '/%s/%s/%s/revisions', $this->namespace, $this->rest_base, $id );
|
||||
|
||||
$links['version-history'] = array(
|
||||
'href' => rest_url( $revisions_base ),
|
||||
'count' => $revisions_count,
|
||||
);
|
||||
|
||||
if ( $revisions_count > 0 ) {
|
||||
$links['predecessor-version'] = array(
|
||||
'href' => rest_url( $revisions_base . '/' . $revisions['latest_id'] ),
|
||||
'id' => $revisions['latest_id'],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user