22
33Class SCF_Rest_Types_Endpoint
44
5- * Extends the /wp/v2/types endpoint to include SCF fields.
5+ * Extends the /wp/v2/types endpoint to include SCF fields and source filtering .
66* @since SCF 6.5.0
77
88## Methods
@@ -13,6 +13,35 @@ Initialize the class.
1313
1414* @since SCF 6.5.0
1515
16+ ### ` filter_types_request `
17+
18+ Filter post types requests, fires for both collection and individual requests.
19+ We only want to handle individual requets to ensure the post type requested matches the source.
20+
21+ * @since SCF 6.5.0
22+ * @param mixed $response The current response, either response or null.
23+ * @param array $handler The handler for the route.
24+ * @param WP_REST_Request $request The request object.
25+ * @return mixed The response or null.
26+
27+ ### ` filter_post_type `
28+
29+ Filter individual post type in the response.
30+
31+ * @since SCF 6.5.0
32+ * @param WP_REST_Response $response The response object.
33+ * @param WP_Post_Type $post_type The post type object.
34+ * @param WP_REST_Request $request The request object.
35+ * @return WP_REST_Response|null The filtered response or null to filter it out.
36+
37+ ### ` get_source_post_types `
38+
39+ Get an array of post types for each source.
40+
41+ * @since SCF 6.5.0
42+ * @param string $source The source to get post types for.
43+ * @return array An array of post type names for the specified source.
44+
1645### ` register_extra_fields `
1746
1847Register extra SCF fields for the post types endpoint.
@@ -34,3 +63,42 @@ Get the schema for the SCF fields.
3463
3564* @since SCF 6.5.0
3665* @return array The schema for the SCF fields.
66+
67+ ### ` register_parameters `
68+
69+ Register the source parameter for the post types endpoint.
70+
71+ * @since SCF 6.5.0
72+
73+ ### ` get_source_param_definition `
74+
75+ Get the source parameter definition
76+
77+ * @since SCF 6.5.0
78+ * @return array Parameter definition
79+
80+ ### ` add_parameter_to_endpoints `
81+
82+ Add source parameter directly to the endpoints for proper documentation
83+
84+ * @since SCF 6.5.0
85+ * @param array $endpoints The REST API endpoints.
86+ * @return array Modified endpoints
87+
88+ ### ` add_collection_params `
89+
90+ Add source parameter to the collection parameters for the types endpoint.
91+
92+ * @since SCF 6.5.0
93+ * @param array $query_params JSON Schema-formatted collection parameters.
94+ * @return array Modified collection parameters.
95+
96+ ### ` clean_types_response `
97+
98+ Clean up null entries from the response
99+
100+ * @since SCF 6.5.0
101+ * @param array $response The response data.
102+ * @param WP_REST_Server $server The REST server instance.
103+ * @param WP_REST_Request $request The original request.
104+ * @return array The filtered response data.
0 commit comments