-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rest API: add /revisions endpoint for global styles (#49974)
* Initial commit: - adding /revisions endpoint to global styles API - tests * Updating tests to account for author and is_latest response properties * There's an existing protected method called `prepare_links` in Gutenberg_REST_Global_Styles_Controller that we can overwrite in the subclass. It makes for less code and a neater abstraction. * Refactored to extract revisions endpoint registration and associated classes into Gutenberg_REST_Global_Styles_Revisions_Controller Returning revisions URL in prepare_links * Update tests * Removing unused comment and method.
- Loading branch information
Showing
6 changed files
with
624 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lib/compat/wordpress-6.3/class-gutenberg-rest-global-styles-controller-6-3.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* REST API: Gutenberg_REST_Global_Styles_Controller class | ||
* | ||
* @package Gutenberg | ||
* @subpackage REST_API | ||
*/ | ||
|
||
/** | ||
* Base Global Styles REST API Controller. | ||
*/ | ||
class Gutenberg_REST_Global_Styles_Controller_6_3 extends Gutenberg_REST_Global_Styles_Controller_6_2 { | ||
/** | ||
* Revision controller. | ||
* | ||
* @since 6.3.0 | ||
* @var WP_REST_Revisions_Controller | ||
*/ | ||
private $revisions_controller; | ||
|
||
/** | ||
* Prepares links for the request. | ||
* | ||
* @since 5.9.0 | ||
* @since 6.3 Adds revisions to version-history. | ||
* | ||
* @param integer $id ID. | ||
* @return array Links for the given post. | ||
*/ | ||
protected function prepare_links( $id ) { | ||
$base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); | ||
|
||
$links = array( | ||
'self' => array( | ||
'href' => rest_url( trailingslashit( $base ) . $id ), | ||
), | ||
); | ||
|
||
if ( post_type_supports( $this->post_type, 'revisions' ) ) { | ||
$revisions = wp_get_latest_revision_id_and_total_count( $id ); | ||
$revisions_count = ! is_wp_error( $revisions ) ? $revisions['count'] : 0; | ||
$revisions_base = sprintf( '/%s/%s/%d/revisions', $this->namespace, $this->rest_base, $id ); | ||
$links['version-history'] = array( | ||
'href' => rest_url( $revisions_base ), | ||
'count' => $revisions_count, | ||
); | ||
} | ||
|
||
return $links; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.