1 | <?php |
||
11 | class Router { |
||
12 | |||
13 | /** |
||
14 | * Carbon Fields routes |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $routes = array( |
||
19 | 'post_meta' => array( |
||
20 | 'path' => '/posts/(?P<id>\d+)', |
||
21 | 'callback' => 'get_post_meta', |
||
22 | 'permission_callback' => 'allow_access', |
||
23 | 'methods' => 'GET', |
||
24 | ), |
||
25 | 'term_meta' => array( |
||
26 | 'path' => '/terms/(?P<id>\d+)', |
||
27 | 'callback' => 'get_term_meta', |
||
28 | 'permission_callback' => 'allow_access', |
||
29 | 'methods' => 'GET', |
||
30 | ), |
||
31 | 'user_meta' => array( |
||
32 | 'path' => '/users/(?P<id>\d+)', |
||
33 | 'callback' => 'get_user_meta', |
||
34 | 'permission_callback' => 'allow_access', |
||
35 | 'methods' => 'GET', |
||
36 | ), |
||
37 | 'comment_meta' => array( |
||
38 | 'path' => '/comments/(?P<id>\d+)', |
||
39 | 'callback' => 'get_comment_meta', |
||
40 | 'permission_callback' => 'allow_access', |
||
41 | 'methods' => 'GET', |
||
42 | ), |
||
43 | 'theme_options' => array( |
||
44 | 'path' => '/options/', |
||
45 | 'callback' => 'options_accessor', |
||
46 | 'permission_callback' => 'options_permission', |
||
47 | 'methods' => array( 'GET', 'POST' ), |
||
48 | ), |
||
49 | 'association_data' => array( |
||
50 | 'path' => '/association', |
||
51 | 'callback' => 'get_association_data', |
||
52 | 'permission_callback' => 'allow_access', |
||
53 | 'methods' => 'GET', |
||
54 | ), |
||
55 | 'attachment_data' => array( |
||
56 | 'path' => '/attachment', |
||
57 | 'callback' => 'get_attachment_data', |
||
58 | 'permission_callback' => 'allow_access', |
||
59 | 'methods' => 'GET', |
||
60 | ), |
||
61 | ); |
||
62 | |||
63 | /** |
||
64 | * Version of the API |
||
65 | * |
||
66 | * @see set_version() |
||
67 | * @see get_version() |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $version = '1'; |
||
71 | |||
72 | /** |
||
73 | * Vendor slug for the API |
||
74 | * |
||
75 | * @see set_vendor() |
||
76 | * @see get_vendor() |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $vendor = 'carbon-fields'; |
||
80 | |||
81 | /** |
||
82 | * ContainerRepository instance |
||
83 | * |
||
84 | * @var ContainerRepository |
||
85 | */ |
||
86 | protected $container_repository; |
||
87 | |||
88 | /** |
||
89 | * @param ContainerRepository $container_repository |
||
90 | */ |
||
91 | public function __construct( ContainerRepository $container_repository ) { |
||
94 | |||
95 | /** |
||
96 | * Boot up functionality |
||
97 | */ |
||
98 | public function boot() { |
||
101 | |||
102 | /** |
||
103 | * Set routes |
||
104 | */ |
||
105 | public function set_routes( $routes ) { |
||
108 | |||
109 | /** |
||
110 | * Return routes |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | public function get_routes() { |
||
117 | |||
118 | /** |
||
119 | * Set version |
||
120 | */ |
||
121 | public function set_version( $version ) { |
||
124 | |||
125 | /** |
||
126 | * Return version |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function get_version() { |
||
133 | |||
134 | /** |
||
135 | * Set vendor |
||
136 | */ |
||
137 | public function set_vendor( $vendor ) { |
||
140 | |||
141 | /** |
||
142 | * Return vendor |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | public function get_vendor() { |
||
149 | |||
150 | /** |
||
151 | * Allow access to an endpoint |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function allow_access() { |
||
158 | |||
159 | /** |
||
160 | * Register custom routes |
||
161 | * |
||
162 | * @see register_route() |
||
163 | */ |
||
164 | public function register_routes() { |
||
169 | |||
170 | /** |
||
171 | * Register a custom REST route |
||
172 | * |
||
173 | * @param array $route |
||
174 | */ |
||
175 | protected function register_route( $route ) { |
||
182 | |||
183 | /** |
||
184 | * Proxy method for handling get/set for theme options |
||
185 | * |
||
186 | * @param WP_REST_Request $request |
||
187 | * @return array|WP_REST_Response |
||
188 | */ |
||
189 | public function options_accessor( $request ) { |
||
198 | |||
199 | /** |
||
200 | * Proxy method for handling theme options permissions |
||
201 | * |
||
202 | * @param WP_REST_Request $request |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function options_permission( $request ) { |
||
208 | |||
209 | /** |
||
210 | * Wrapper method used for retrieving data from Data_Manager |
||
211 | * |
||
212 | * @param string $container_type |
||
213 | * @param string $object_id |
||
214 | * @return array |
||
215 | */ |
||
216 | protected function get_all_field_values( $container_type, $object_id = null ) { |
||
234 | |||
235 | /** |
||
236 | * Get Carbon Fields post meta values |
||
237 | * |
||
238 | * @param array $data |
||
239 | * @return array |
||
240 | */ |
||
241 | public function get_post_meta( $data ) { |
||
245 | |||
246 | /** |
||
247 | * Get Carbon Fields user meta values |
||
248 | * |
||
249 | * @param array $data |
||
250 | * @return array |
||
251 | */ |
||
252 | public function get_user_meta( $data ) { |
||
256 | |||
257 | /** |
||
258 | * Get Carbon Fields term meta values |
||
259 | * |
||
260 | * @param array $data |
||
261 | * @return array |
||
262 | */ |
||
263 | public function get_term_meta( $data ) { |
||
267 | |||
268 | /** |
||
269 | * Get Carbon Fields comment meta values |
||
270 | * |
||
271 | * @param array $data |
||
272 | * @return array |
||
273 | */ |
||
274 | public function get_comment_meta( $data ) { |
||
278 | |||
279 | /** |
||
280 | * Get Carbon Fields association options data. |
||
281 | * |
||
282 | * @return array |
||
283 | */ |
||
284 | public function get_association_data() { |
||
308 | |||
309 | /** |
||
310 | * Get attachment data by given ID or URL. |
||
311 | * |
||
312 | * @return array |
||
313 | */ |
||
314 | public function get_attachment_data() { |
||
320 | |||
321 | /** |
||
322 | * Retrieve Carbon theme options |
||
323 | * |
||
324 | * @return array |
||
325 | */ |
||
326 | protected function get_options() { |
||
330 | |||
331 | /** |
||
332 | * Set Carbon theme options |
||
333 | * |
||
334 | * @param WP_REST_Request $request Full data about the request. |
||
335 | * @return WP_Error|WP_REST_Response |
||
336 | */ |
||
337 | protected function set_options( $request ) { |
||
354 | } |
||
355 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.