| @@ -42,8 +42,21 @@ | ||
| 42 | 42 | }, |
| 43 | 43 | ], |
| 44 | 44 | ] |
| 45 | 45 | ); |
| 46 | + | |
| 47 | + $this->route( | |
| 48 | + '/labels/count', | |
| 49 | + [ | |
| 50 | + [ | |
| 51 | + 'methods' => WP_REST_Server::READABLE, | |
| 52 | + 'callback' => [ $this, 'label_counts' ], | |
| 53 | + 'permission_callback' => function () { | |
| 54 | + return current_user_can( 'edit_others_posts' ); | |
| 55 | + }, | |
| 56 | + ], | |
| 57 | + ] | |
| 58 | + ); | |
| 46 | 59 | } |
| 47 | 60 | |
| 48 | 61 | /** |
| 49 | 62 | * Returns all labels. |
| @@ -64,6 +77,13 @@ | ||
| 64 | 77 | $response[] = call_user_func( $this->transformer, $term ); |
| 65 | 78 | } |
| 66 | 79 | |
| 67 | 80 | return rest_ensure_response( $response ); |
| 81 | + } | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * Returns an array of counts by label ID. | |
| 85 | + */ | |
| 86 | + public function label_counts( $request ) { | |
| 87 | + return rest_ensure_response( $this->labels->count() ); | |
| 68 | 88 | } |
| 69 | 89 | } |