29 * @var string |
29 * @var string |
30 */ |
30 */ |
31 protected $rest_base; |
31 protected $rest_base; |
32 |
32 |
33 /** |
33 /** |
|
34 * Cached results of get_item_schema. |
|
35 * |
|
36 * @since 5.3.0 |
|
37 * @var array |
|
38 */ |
|
39 protected $schema; |
|
40 |
|
41 /** |
34 * Registers the routes for the objects of the controller. |
42 * Registers the routes for the objects of the controller. |
35 * |
43 * |
36 * @since 4.7.0 |
44 * @since 4.7.0 |
|
45 * |
|
46 * @see register_rest_route() |
37 */ |
47 */ |
38 public function register_routes() { |
48 public function register_routes() { |
39 /* translators: %s: register_routes() */ |
49 _doing_it_wrong( |
40 _doing_it_wrong( 'WP_REST_Controller::register_routes', sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), '4.7' ); |
50 'WP_REST_Controller::register_routes', |
|
51 /* translators: %s: register_routes() */ |
|
52 sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), |
|
53 '4.7' |
|
54 ); |
41 } |
55 } |
42 |
56 |
43 /** |
57 /** |
44 * Checks if a given request has access to get items. |
58 * Checks if a given request has access to get items. |
45 * |
59 * |
46 * @since 4.7.0 |
60 * @since 4.7.0 |
47 * |
61 * |
48 * @param WP_REST_Request $request Full data about the request. |
62 * @param WP_REST_Request $request Full details about the request. |
49 * @return WP_Error|bool True if the request has read access, WP_Error object otherwise. |
63 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
50 */ |
64 */ |
51 public function get_items_permissions_check( $request ) { |
65 public function get_items_permissions_check( $request ) { |
52 /* translators: %s: method name */ |
66 return new WP_Error( |
53 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
67 'invalid-method', |
|
68 /* translators: %s: Method name. */ |
|
69 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
70 array( 'status' => 405 ) |
|
71 ); |
54 } |
72 } |
55 |
73 |
56 /** |
74 /** |
57 * Retrieves a collection of items. |
75 * Retrieves a collection of items. |
58 * |
76 * |
59 * @since 4.7.0 |
77 * @since 4.7.0 |
60 * |
78 * |
61 * @param WP_REST_Request $request Full data about the request. |
79 * @param WP_REST_Request $request Full details about the request. |
62 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
80 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
63 */ |
81 */ |
64 public function get_items( $request ) { |
82 public function get_items( $request ) { |
65 /* translators: %s: method name */ |
83 return new WP_Error( |
66 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
84 'invalid-method', |
|
85 /* translators: %s: Method name. */ |
|
86 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
87 array( 'status' => 405 ) |
|
88 ); |
67 } |
89 } |
68 |
90 |
69 /** |
91 /** |
70 * Checks if a given request has access to get a specific item. |
92 * Checks if a given request has access to get a specific item. |
71 * |
93 * |
72 * @since 4.7.0 |
94 * @since 4.7.0 |
73 * |
95 * |
74 * @param WP_REST_Request $request Full data about the request. |
96 * @param WP_REST_Request $request Full details about the request. |
75 * @return WP_Error|bool True if the request has read access for the item, WP_Error object otherwise. |
97 * @return true|WP_Error True if the request has read access for the item, WP_Error object otherwise. |
76 */ |
98 */ |
77 public function get_item_permissions_check( $request ) { |
99 public function get_item_permissions_check( $request ) { |
78 /* translators: %s: method name */ |
100 return new WP_Error( |
79 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
101 'invalid-method', |
|
102 /* translators: %s: Method name. */ |
|
103 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
104 array( 'status' => 405 ) |
|
105 ); |
80 } |
106 } |
81 |
107 |
82 /** |
108 /** |
83 * Retrieves one item from the collection. |
109 * Retrieves one item from the collection. |
84 * |
110 * |
85 * @since 4.7.0 |
111 * @since 4.7.0 |
86 * |
112 * |
87 * @param WP_REST_Request $request Full data about the request. |
113 * @param WP_REST_Request $request Full details about the request. |
88 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
114 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
89 */ |
115 */ |
90 public function get_item( $request ) { |
116 public function get_item( $request ) { |
91 /* translators: %s: method name */ |
117 return new WP_Error( |
92 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
118 'invalid-method', |
|
119 /* translators: %s: Method name. */ |
|
120 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
121 array( 'status' => 405 ) |
|
122 ); |
93 } |
123 } |
94 |
124 |
95 /** |
125 /** |
96 * Checks if a given request has access to create items. |
126 * Checks if a given request has access to create items. |
97 * |
127 * |
98 * @since 4.7.0 |
128 * @since 4.7.0 |
99 * |
129 * |
100 * @param WP_REST_Request $request Full data about the request. |
130 * @param WP_REST_Request $request Full details about the request. |
101 * @return WP_Error|bool True if the request has access to create items, WP_Error object otherwise. |
131 * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
102 */ |
132 */ |
103 public function create_item_permissions_check( $request ) { |
133 public function create_item_permissions_check( $request ) { |
104 /* translators: %s: method name */ |
134 return new WP_Error( |
105 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
135 'invalid-method', |
|
136 /* translators: %s: Method name. */ |
|
137 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
138 array( 'status' => 405 ) |
|
139 ); |
106 } |
140 } |
107 |
141 |
108 /** |
142 /** |
109 * Creates one item from the collection. |
143 * Creates one item from the collection. |
110 * |
144 * |
111 * @since 4.7.0 |
145 * @since 4.7.0 |
112 * |
146 * |
113 * @param WP_REST_Request $request Full data about the request. |
147 * @param WP_REST_Request $request Full details about the request. |
114 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
148 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
115 */ |
149 */ |
116 public function create_item( $request ) { |
150 public function create_item( $request ) { |
117 /* translators: %s: method name */ |
151 return new WP_Error( |
118 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
152 'invalid-method', |
|
153 /* translators: %s: Method name. */ |
|
154 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
155 array( 'status' => 405 ) |
|
156 ); |
119 } |
157 } |
120 |
158 |
121 /** |
159 /** |
122 * Checks if a given request has access to update a specific item. |
160 * Checks if a given request has access to update a specific item. |
123 * |
161 * |
124 * @since 4.7.0 |
162 * @since 4.7.0 |
125 * |
163 * |
126 * @param WP_REST_Request $request Full data about the request. |
164 * @param WP_REST_Request $request Full details about the request. |
127 * @return WP_Error|bool True if the request has access to update the item, WP_Error object otherwise. |
165 * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
128 */ |
166 */ |
129 public function update_item_permissions_check( $request ) { |
167 public function update_item_permissions_check( $request ) { |
130 /* translators: %s: method name */ |
168 return new WP_Error( |
131 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
169 'invalid-method', |
|
170 /* translators: %s: Method name. */ |
|
171 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
172 array( 'status' => 405 ) |
|
173 ); |
132 } |
174 } |
133 |
175 |
134 /** |
176 /** |
135 * Updates one item from the collection. |
177 * Updates one item from the collection. |
136 * |
178 * |
137 * @since 4.7.0 |
179 * @since 4.7.0 |
138 * |
180 * |
139 * @param WP_REST_Request $request Full data about the request. |
181 * @param WP_REST_Request $request Full details about the request. |
140 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
182 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
141 */ |
183 */ |
142 public function update_item( $request ) { |
184 public function update_item( $request ) { |
143 /* translators: %s: method name */ |
185 return new WP_Error( |
144 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
186 'invalid-method', |
|
187 /* translators: %s: Method name. */ |
|
188 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
189 array( 'status' => 405 ) |
|
190 ); |
145 } |
191 } |
146 |
192 |
147 /** |
193 /** |
148 * Checks if a given request has access to delete a specific item. |
194 * Checks if a given request has access to delete a specific item. |
149 * |
195 * |
150 * @since 4.7.0 |
196 * @since 4.7.0 |
151 * |
197 * |
152 * @param WP_REST_Request $request Full data about the request. |
198 * @param WP_REST_Request $request Full details about the request. |
153 * @return WP_Error|bool True if the request has access to delete the item, WP_Error object otherwise. |
199 * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise. |
154 */ |
200 */ |
155 public function delete_item_permissions_check( $request ) { |
201 public function delete_item_permissions_check( $request ) { |
156 /* translators: %s: method name */ |
202 return new WP_Error( |
157 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
203 'invalid-method', |
|
204 /* translators: %s: Method name. */ |
|
205 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
206 array( 'status' => 405 ) |
|
207 ); |
158 } |
208 } |
159 |
209 |
160 /** |
210 /** |
161 * Deletes one item from the collection. |
211 * Deletes one item from the collection. |
162 * |
212 * |
163 * @since 4.7.0 |
213 * @since 4.7.0 |
164 * |
214 * |
165 * @param WP_REST_Request $request Full data about the request. |
215 * @param WP_REST_Request $request Full details about the request. |
166 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
216 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
167 */ |
217 */ |
168 public function delete_item( $request ) { |
218 public function delete_item( $request ) { |
169 /* translators: %s: method name */ |
219 return new WP_Error( |
170 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
220 'invalid-method', |
|
221 /* translators: %s: Method name. */ |
|
222 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
223 array( 'status' => 405 ) |
|
224 ); |
171 } |
225 } |
172 |
226 |
173 /** |
227 /** |
174 * Prepares one item for create or update operation. |
228 * Prepares one item for create or update operation. |
175 * |
229 * |
176 * @since 4.7.0 |
230 * @since 4.7.0 |
177 * |
231 * |
178 * @param WP_REST_Request $request Request object. |
232 * @param WP_REST_Request $request Request object. |
179 * @return WP_Error|object The prepared item, or WP_Error object on failure. |
233 * @return object|WP_Error The prepared item, or WP_Error object on failure. |
180 */ |
234 */ |
181 protected function prepare_item_for_database( $request ) { |
235 protected function prepare_item_for_database( $request ) { |
182 /* translators: %s: method name */ |
236 return new WP_Error( |
183 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
237 'invalid-method', |
|
238 /* translators: %s: Method name. */ |
|
239 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
240 array( 'status' => 405 ) |
|
241 ); |
184 } |
242 } |
185 |
243 |
186 /** |
244 /** |
187 * Prepares the item for the REST response. |
245 * Prepares the item for the REST response. |
188 * |
246 * |
189 * @since 4.7.0 |
247 * @since 4.7.0 |
190 * |
248 * |
191 * @param mixed $item WordPress representation of the item. |
249 * @param mixed $item WordPress representation of the item. |
192 * @param WP_REST_Request $request Request object. |
250 * @param WP_REST_Request $request Request object. |
193 * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. |
251 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
194 */ |
252 */ |
195 public function prepare_item_for_response( $item, $request ) { |
253 public function prepare_item_for_response( $item, $request ) { |
196 /* translators: %s: method name */ |
254 return new WP_Error( |
197 return new WP_Error( 'invalid-method', sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), array( 'status' => 405 ) ); |
255 'invalid-method', |
|
256 /* translators: %s: Method name. */ |
|
257 sprintf( __( "Method '%s' not implemented. Must be overridden in subclass." ), __METHOD__ ), |
|
258 array( 'status' => 405 ) |
|
259 ); |
198 } |
260 } |
199 |
261 |
200 /** |
262 /** |
201 * Prepares a response for insertion into a collection. |
263 * Prepares a response for insertion into a collection. |
202 * |
264 * |