PluginProbe
Parse.ly / 3.23.4
Parse.ly v3.23.4
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / rest-api / utils / class-endpoint-post.php

class-endpoint-post.php in Parse.ly 3.23.4, at src/rest-api/utils/class-endpoint-post.php

73 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Utils API Endpoint: Post
4 *
5 * @package Parsely
6 * @since 3.20.5
7 */
8
9 declare(strict_types=1);
10
11 namespace Parsely\REST_API\Utils;
12
13 use Parsely\REST_API\Base_Endpoint;
14 use Parsely\REST_API\Use_Post_ID_Parameter_Trait;
15 use WP_REST_Request;
16 use WP_REST_Response;
17
18 /**
19 * The Utils API Post endpoint.
20 *
21 * Provides an endpoint for utility functions related to Posts.
22 *
23 * @since 3.20.5
24 */
25 class Endpoint_Post extends Base_Endpoint {
26 use Use_Post_ID_Parameter_Trait;
27
28 /**
29 * Returns the endpoint's name.
30 *
31 * @since 3.20.5
32 *
33 * @return string The endpoint's name.
34 */
35 public static function get_endpoint_name(): string {
36 return 'post';
37 }
38
39 /**
40 * Registers the routes for the endpoint.
41 *
42 * @since 3.20.5
43 */
44 public function register_routes(): void {
45 /**
46 * GET /utils/post/{post_id}/rest-route
47 * Returns the REST route of a Post.
48 */
49 $this->register_rest_route_with_post_id(
50 '/rest-route',
51 array( 'GET' ),
52 array( $this, 'get_rest_route' )
53 );
54 }
55
56 /**
57 * API Endpoint: GET /utils/post/{post_id}/rest-route
58 *
59 * Returns the REST route of a post.
60 *
61 * @since 3.20.5
62 *
63 * @param WP_REST_Request $request The request object.
64 * @return WP_REST_Response The response object.
65 */
66 public function get_rest_route( WP_REST_Request $request ) {
67 $post_id = $request->get_param( 'post_id' );
68 $post_rest_route = rest_get_route_for_post( $post_id );
69
70 return new WP_REST_Response( array( 'data' => $post_rest_route ), 200 );
71 }
72 }
73