Skip to content

Commit

Permalink
Separate and document REST API routes
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas-johnson committed Sep 22, 2023
1 parent 585354a commit 75ed658
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions php/api/endpoints/class-coauthors-blocks-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public function __construct( CoAuthors_Plus $coauthors_plus ) {
* @since 3.6.0
*/
public function register_routes(): void {
$this->register_coauthors_route();
$this->register_coauthor_route();
}

/**
* Register Co-Authors Route
*
* Provide a post ID as an integer to retrieve an array of associated co-authors.
*
* Example: `/wp-json/coauthors-blocks/v1/coauthors/11111`
*
* @since 3.6.0
*/
public function register_coauthors_route(): void {
register_rest_route(
'coauthors-blocks/v1',
'/coauthors/(?P<post_id>[\d]+)',
Expand All @@ -71,7 +85,18 @@ public function register_routes(): void {
),
)
);
}

/**
* Register Co-Author Route
*
* Provide a user nicename as a hyphen-separated string to retrieve a single co-author.
*
* Example: `/wp-json/coauthors-blocks/v1/coauthor/user-nicename`
*
* @since 3.6.0
*/
public function register_coauthor_route(): void {
register_rest_route(
'coauthors-blocks/v1',
'/coauthor/(?P<user_nicename>[\w-]+)',
Expand Down

0 comments on commit 75ed658

Please sign in to comment.