1 | <?php |
||
9 | class Routes { |
||
10 | |||
11 | /** |
||
12 | * Carbon Fields routes |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $routes = array( |
||
17 | 'post_meta' => array( |
||
18 | 'path' => '/posts/(?P<id>\d+)', |
||
19 | 'callback' => 'get_post_meta', |
||
20 | 'permission_callback' => 'allow_access', |
||
21 | 'methods' => 'GET', |
||
22 | ), |
||
23 | 'term_meta' => array( |
||
24 | 'path' => '/terms/(?P<id>\d+)', |
||
25 | 'callback' => 'get_term_meta', |
||
26 | 'permission_callback' => 'allow_access', |
||
27 | 'methods' => 'GET', |
||
28 | ), |
||
29 | 'user_meta' => array( |
||
30 | 'path' => '/users/(?P<id>\d+)', |
||
31 | 'callback' => 'get_user_meta', |
||
32 | 'permission_callback' => 'allow_access', |
||
33 | 'methods' => 'GET', |
||
34 | ), |
||
35 | 'comment_meta' => array( |
||
36 | 'path' => '/comments/(?P<id>\d+)', |
||
37 | 'callback' => 'get_comment_meta', |
||
38 | 'permission_callback' => 'allow_access', |
||
39 | 'methods' => 'GET', |
||
40 | ), |
||
41 | 'theme_options' => array( |
||
42 | 'path' => '/options/', |
||
43 | 'callback' => 'options_accessor', |
||
44 | 'permission_callback' => 'options_permission', |
||
45 | 'methods' => array( 'GET', 'POST' ), |
||
46 | ), |
||
47 | ); |
||
48 | |||
49 | /** |
||
50 | * Version of the API |
||
51 | * |
||
52 | * @see set_version() |
||
53 | * @see get_version() |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $version = '1'; |
||
57 | |||
58 | /** |
||
59 | * Plugin slug |
||
60 | * |
||
61 | * @see set_vendor() |
||
62 | * @see get_vendor() |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $vendor = 'carbon-fields'; |
||
66 | |||
67 | /** |
||
68 | * Instance of the Data_Manager class |
||
69 | * |
||
70 | * @var object |
||
71 | */ |
||
72 | public $data_manager; |
||
73 | |||
74 | public function __construct( $data_manager ) { |
||
79 | |||
80 | /** |
||
81 | * Creates the custom routes |
||
82 | * |
||
83 | * @see create() |
||
84 | */ |
||
85 | public function register_routes() { |
||
90 | |||
91 | /** |
||
92 | * Registers a custom REST route |
||
93 | * |
||
94 | * @param array $route |
||
95 | */ |
||
96 | public function create( $route ) { |
||
103 | |||
104 | /** |
||
105 | * Retrieves Carbon post meta |
||
106 | * |
||
107 | * @param array $data |
||
108 | * @return array |
||
109 | */ |
||
110 | public function get_post_meta( $data ) { |
||
114 | |||
115 | /** |
||
116 | * Retrieves Carbon user meta |
||
117 | * |
||
118 | * @param array $data |
||
119 | * @return array |
||
120 | */ |
||
121 | public function get_user_meta( $data ) { |
||
125 | |||
126 | /** |
||
127 | * Retrieves Carbon term meta |
||
128 | * |
||
129 | * @param array $data |
||
130 | * @return array |
||
131 | */ |
||
132 | public function get_term_meta( $data ) { |
||
136 | |||
137 | /** |
||
138 | * Retrieves Carbon comment meta |
||
139 | * |
||
140 | * @param array $data |
||
141 | * @return array |
||
142 | */ |
||
143 | public function get_comment_meta( $data ) { |
||
147 | |||
148 | /** |
||
149 | * Retrieves Carbon theme options |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | public function get_options() { |
||
157 | |||
158 | /** |
||
159 | * Set Carbon theme options |
||
160 | * |
||
161 | * @param WP_REST_Request $request Full data about the request. |
||
162 | * @return WP_Error|WP_REST_Response |
||
163 | */ |
||
164 | public function set_options( $request ) { |
||
183 | |||
184 | /** |
||
185 | * Wrapper method used for retrieving data from the $data_manager |
||
186 | * |
||
187 | * @param string $container_type |
||
188 | * @param string $id |
||
189 | * @return array |
||
190 | */ |
||
191 | public function get_data( $container_type, $id = '' ) { |
||
194 | |||
195 | /** |
||
196 | * Sets routes |
||
197 | */ |
||
198 | public function set_routes( $routes ) { |
||
201 | |||
202 | /** |
||
203 | * Returns routes |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | public function get_routes() { |
||
210 | |||
211 | /** |
||
212 | * Sets version |
||
213 | */ |
||
214 | public function set_version( $version ) { |
||
217 | |||
218 | /** |
||
219 | * Returns version |
||
220 | * |
||
221 | * @return string |
||
222 | */ |
||
223 | public function get_version() { |
||
226 | |||
227 | /** |
||
228 | * Sets vendor |
||
229 | */ |
||
230 | public function set_vendor( $vendor ) { |
||
233 | |||
234 | /** |
||
235 | * Returns vendor |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | public function get_vendor() { |
||
242 | |||
243 | /** |
||
244 | * Proxy method for handling get/set for theme options |
||
245 | * |
||
246 | * @param WP_REST_Request $request |
||
247 | * @return array|WP_REST_Response |
||
248 | */ |
||
249 | public function options_accessor( $request ) { |
||
260 | |||
261 | /** |
||
262 | * Allow access to an endpoint |
||
263 | * |
||
264 | * @return bool true |
||
265 | */ |
||
266 | public function allow_access() { |
||
269 | |||
270 | /** |
||
271 | * Proxy method for handling theme options permissions |
||
272 | * |
||
273 | * @param WP_REST_Request $request |
||
274 | * @return bool |
||
275 | */ |
||
276 | public function options_permission( $request ) { |
||
287 | } |