Version Description
(2009-11-17): = * Initial Public Release
Download this release
Release Info
Developer | dphiffer |
Plugin | JSON API |
Version | 0.5 |
Comparing to | |
See all releases |
Code changes from version 0.6 to 0.5
- readme.txt +106 -116
- singletons/introspector.php +38 -40
- singletons/query.php +1 -1
- singletons/response.php +2 -7
readme.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
=== JSON API ===
|
2 |
Contributors: dphiffer
|
3 |
-
Tags: json, api, ajax, cms, admin, integration
|
4 |
Requires at least: 2.8
|
5 |
Tested up to: 2.8
|
6 |
Stable tag: 0.6
|
@@ -9,9 +9,9 @@ A RESTful API for WordPress
|
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
-
This plugin was created for The Museum of Modern Art, whose weblog [Inside/Out](http://moma.org/explore/inside_out) appears within an existing structure built with Ruby on Rails. Instead of reimplementing the site templates as a WordPress theme, we opted for a Rails front-end that displays content served from a WordPress back-end.
|
13 |
|
14 |
-
The current release (0.
|
15 |
|
16 |
See the Other Notes section for complete API documentation.
|
17 |
|
@@ -31,21 +31,24 @@ Requests use a simple REST-style HTTP GET or POST. To invoke the API, include a
|
|
31 |
JSON API operates in two modes:
|
32 |
|
33 |
1. *Implicit mode* is triggered by setting the `json` query var to a non-empty value on any WordPress page. The content that would normally appear on that page is returned in JSON format.
|
34 |
-
1. *Explicit mode* is triggered by setting `json` to a known method string. See the *API Reference* section below for a complete method listing.
|
35 |
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
|
44 |
* `http://www.example.org/?json=get_recent_posts`
|
45 |
* `http://www.example.org/?json=get_post&post_id=47`
|
46 |
* `http://www.example.org/?json=get_tag_posts&tag_slug=banana`
|
47 |
|
48 |
-
|
49 |
|
50 |
* `http://www.example.org/api/get_recent_posts/`
|
51 |
* `http://www.example.org/api/get_post/?post_id=47`
|
@@ -53,14 +56,13 @@ JSON API operates in two modes:
|
|
53 |
|
54 |
== Responses ==
|
55 |
|
56 |
-
The standard response format for JSON API is (as you may have guessed)
|
57 |
|
58 |
Here is an example response from `http://localhost/wordpress/?json=1` called on a default WordPress installation (formatted for readability):
|
59 |
|
60 |
{
|
61 |
"status": "ok",
|
62 |
"count": 1,
|
63 |
-
"count_total": 1,
|
64 |
"pages": 1,
|
65 |
"posts": [
|
66 |
{
|
@@ -107,11 +109,11 @@ The JSON API reference is split into four sections:
|
|
107 |
|
108 |
1. Request arguments
|
109 |
1. Response objects
|
110 |
-
1. Plugin hooks
|
111 |
1. Introspection methods
|
112 |
1. Data manipulation methods
|
113 |
|
114 |
-
__About API changes__
|
|
|
115 |
All methods are currently subject to change until the plugin reaches maturity. Please read the the changelog carefully before updating to subsequent releases.
|
116 |
|
117 |
== 1. Request arguments ==
|
@@ -133,20 +135,23 @@ These arguments are available to modify all introspection methods:
|
|
133 |
* `custom_fields` - Includes values from posts' Custom Fields. Expects a comma-separated list of custom field keys.
|
134 |
* `author_meta` - Includes additional author metadata. Should be a comma-separated list of metadata fields.
|
135 |
|
136 |
-
__About `include`/`exclude` arguments__
|
137 |
-
|
|
|
|
|
|
|
138 |
|
139 |
-
|
140 |
|
141 |
-
|
142 |
|
143 |
-
|
144 |
-
|
|
|
145 |
|
146 |
-
__Naming compatibility__
|
147 |
Developers familiar with WordPress may notice that many names for properties and arguments have been changed. This was a stylistic choice that intends to provide more clarity and consistency in the interface.
|
148 |
|
149 |
-
|
150 |
|
151 |
* `id` - Integer
|
152 |
* `slug` - String
|
@@ -165,7 +170,7 @@ Developers familiar with WordPress may notice that many names for properties and
|
|
165 |
* `comment_status` - String (`"open"` or `"closed"`)
|
166 |
* `custom_fields` - Object (included by setting the `custom_fields` argument to a comma-separated list of custom field names)
|
167 |
|
168 |
-
|
169 |
|
170 |
* `id` - Integer
|
171 |
* `slug` - String
|
@@ -174,14 +179,14 @@ Developers familiar with WordPress may notice that many names for properties and
|
|
174 |
* `parent` - Integer
|
175 |
* `post_count` - Integer
|
176 |
|
177 |
-
|
178 |
|
179 |
* `id` - Integer
|
180 |
* `slug` - String
|
181 |
* `title` - String
|
182 |
* `description` - String
|
183 |
|
184 |
-
|
185 |
|
186 |
* `id` - Integer
|
187 |
* `slug` - String
|
@@ -194,7 +199,7 @@ Developers familiar with WordPress may notice that many names for properties and
|
|
194 |
|
195 |
Note: You can include additional values by setting the `author_meta` argument to a comma-separated list of metadata fields.
|
196 |
|
197 |
-
|
198 |
|
199 |
* `id` - Integer
|
200 |
* `name` - String
|
@@ -204,62 +209,33 @@ Note: You can include additional values by setting the `author_meta` argument to
|
|
204 |
* `parent` - Integer
|
205 |
* `author` - Object (only set if the comment author was registered & logged in)
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
The `redirect` response style is useful for when you need the user's browser to make a request directly rather than making proxy requests using a tool like cURL. Setting a `redirect` argument causes the user's browser to redirect back to the specified URL instead of returning a JSON object. The resulting `status` value is included as an extra query variable.
|
210 |
|
211 |
-
|
212 |
|
213 |
* `http://www.example.com/foo?status=ok`
|
214 |
* `http://www.example.com/foo?status=error`
|
215 |
|
216 |
-
You can
|
217 |
-
|
218 |
-
== 3. Plugin hooks ==
|
219 |
-
|
220 |
-
JSON API currently exposes a single [filter hook](http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters) for you to modify the output.
|
221 |
-
|
222 |
-
== Filter: json_api_encode ==
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
= Example =
|
227 |
-
|
228 |
-
add_filter('json_api_encode', 'encode_kittens_field');
|
229 |
-
|
230 |
-
encode_kittens_field($response) {
|
231 |
-
if (isset($response['posts'])) {
|
232 |
-
array_walk($response['posts'], 'add_kittens_field');
|
233 |
-
} else if (isset($response['post'])) {
|
234 |
-
add_kittens_field($response['post']);
|
235 |
-
}
|
236 |
-
return $response;
|
237 |
-
}
|
238 |
-
|
239 |
-
add_kittens_field(&$post) {
|
240 |
-
$post->kittens = 'Kittens!';
|
241 |
-
}
|
242 |
-
|
243 |
-
|
244 |
-
== 4. Introspection methods ==
|
245 |
|
246 |
Introspection methods are used to retrieve data from WordPress.
|
247 |
|
248 |
|
249 |
-
|
250 |
|
251 |
Returns an array of recent posts. You can invoke this from the WordPress home page either by setting `json` to a non-empty value (i.e., `json=1`) or from any page by setting `json=get_recent_posts`.
|
252 |
|
253 |
-
|
254 |
|
255 |
* `page` - return a specific page number from the results
|
256 |
|
257 |
-
|
258 |
|
259 |
{
|
260 |
"status": "ok",
|
261 |
"count": 10,
|
262 |
-
"count_total": 79,
|
263 |
"pages": 7,
|
264 |
"posts": [
|
265 |
{ ... },
|
@@ -268,61 +244,66 @@ Returns an array of recent posts. You can invoke this from the WordPress home pa
|
|
268 |
]
|
269 |
}
|
270 |
|
|
|
271 |
|
272 |
-
== Method: get_post ==
|
273 |
|
274 |
-
|
275 |
|
276 |
-
|
277 |
|
|
|
278 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a post URL
|
279 |
* `post_id` - set to the post's ID
|
280 |
* `post_slug` - set to the post's URL slug
|
281 |
|
282 |
-
|
283 |
|
284 |
{
|
285 |
"status": "ok",
|
286 |
"post": { ... }
|
287 |
}
|
288 |
|
|
|
289 |
|
290 |
-
|
|
|
291 |
|
292 |
Returns a single page object.
|
293 |
|
294 |
-
|
295 |
|
296 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a page URL
|
297 |
* `page_id` - set to the page's ID
|
298 |
* `page_slug` - set to the page's URL slug
|
299 |
|
300 |
-
|
301 |
|
302 |
{
|
303 |
"status": "ok",
|
304 |
"page": { ... }
|
305 |
}
|
306 |
|
307 |
-
|
|
|
|
|
|
|
308 |
|
309 |
Returns an array of posts/pages in a specific category.
|
310 |
|
311 |
-
|
312 |
|
313 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a date archive page
|
314 |
* `date` - set to a date in the format `YYYY` or `YYYYMM` or `YYYYMMDD`
|
315 |
|
316 |
-
|
317 |
|
318 |
* `page` - return a specific page number from the results
|
319 |
|
320 |
-
|
321 |
|
322 |
{
|
323 |
"status": "ok",
|
324 |
"count": 10,
|
325 |
-
"count_total": 79,
|
326 |
"pages": 7,
|
327 |
"posts": [
|
328 |
{ ... },
|
@@ -331,26 +312,28 @@ Returns an array of posts/pages in a specific category.
|
|
331 |
]
|
332 |
}
|
333 |
|
334 |
-
|
|
|
|
|
|
|
335 |
|
336 |
Returns an array of posts/pages in a specific category.
|
337 |
|
338 |
-
|
339 |
|
340 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a category archive page
|
341 |
* `category_id` - set to the category's ID
|
342 |
* `category_slug` - set to the category's URL slug
|
343 |
|
344 |
-
|
345 |
|
346 |
* `page` - return a specific page number from the results
|
347 |
|
348 |
-
|
349 |
|
350 |
{
|
351 |
"status": "ok",
|
352 |
"count": 10,
|
353 |
-
"count_total": 79,
|
354 |
"pages": 7,
|
355 |
"category": { ... }
|
356 |
"posts": [
|
@@ -360,27 +343,28 @@ Returns an array of posts/pages in a specific category.
|
|
360 |
]
|
361 |
}
|
362 |
|
|
|
363 |
|
364 |
-
|
|
|
365 |
|
366 |
Returns an array of posts/pages with a specific tag.
|
367 |
|
368 |
-
|
369 |
|
370 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a tag archive page
|
371 |
* `tag_id` - set to the tag's ID
|
372 |
* `tag_slug` - set to the tag's URL slug
|
373 |
|
374 |
-
|
375 |
|
376 |
* `page` - return a specific page number from the results
|
377 |
|
378 |
-
|
379 |
|
380 |
{
|
381 |
"status": "ok",
|
382 |
"count": 10,
|
383 |
-
"count_total": 79,
|
384 |
"pages": 7,
|
385 |
"tag": { ... }
|
386 |
"posts": [
|
@@ -390,56 +374,58 @@ Returns an array of posts/pages with a specific tag.
|
|
390 |
]
|
391 |
}
|
392 |
|
|
|
|
|
393 |
|
394 |
-
|
395 |
|
396 |
Returns an array of posts/pages written by a specific author.
|
397 |
|
398 |
-
|
399 |
|
400 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on an author archive page
|
401 |
* `author_id` - set to the author's ID
|
402 |
* `author_slug` - set to the author's URL slug
|
403 |
|
404 |
-
|
405 |
|
406 |
* `page` - return a specific page number from the results
|
407 |
|
408 |
-
|
409 |
|
410 |
{
|
411 |
"status": "ok",
|
412 |
"count": 10,
|
413 |
-
"count_total": 79,
|
414 |
"pages": 7,
|
415 |
"author": { ... }
|
416 |
"posts": [
|
417 |
{ ... },
|
418 |
{ ... },
|
419 |
-
...
|
420 |
]
|
421 |
}
|
422 |
|
|
|
423 |
|
424 |
-
|
|
|
425 |
|
426 |
Returns an array of posts/pages in response to a search query.
|
427 |
|
428 |
-
|
429 |
|
430 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a search results page
|
431 |
* `search` - set to the desired search query
|
432 |
|
433 |
-
|
434 |
|
435 |
* `page` - return a specific page number from the results
|
436 |
|
437 |
-
|
438 |
|
439 |
{
|
440 |
"status": "ok",
|
441 |
"count": 10,
|
442 |
-
"count_total": 79,
|
443 |
"pages": 7,
|
444 |
"posts": [
|
445 |
{ ... },
|
@@ -448,12 +434,14 @@ Returns an array of posts/pages in response to a search query.
|
|
448 |
]
|
449 |
}
|
450 |
|
|
|
|
|
451 |
|
452 |
-
|
453 |
|
454 |
Returns both an array of date page permalinks and a tree structure representation of the archive.
|
455 |
|
456 |
-
|
457 |
|
458 |
{
|
459 |
"status": "ok",
|
@@ -470,14 +458,16 @@ Returns both an array of date page permalinks and a tree structure representatio
|
|
470 |
}
|
471 |
}
|
472 |
|
473 |
-
Note: the tree is arranged by
|
|
|
|
|
474 |
|
475 |
|
476 |
-
|
477 |
|
478 |
Returns an array of active categories.
|
479 |
|
480 |
-
|
481 |
|
482 |
{
|
483 |
"status": "ok",
|
@@ -489,12 +479,14 @@ Returns an array of active categories.
|
|
489 |
]
|
490 |
}
|
491 |
|
|
|
|
|
492 |
|
493 |
== Method: get_tag_index ==
|
494 |
|
495 |
Returns an array of active tags.
|
496 |
|
497 |
-
|
498 |
|
499 |
{
|
500 |
"status": "ok",
|
@@ -506,12 +498,14 @@ Returns an array of active tags.
|
|
506 |
]
|
507 |
}
|
508 |
|
|
|
|
|
509 |
|
510 |
== Method: get_author_index ==
|
511 |
|
512 |
Returns an array of active blog authors.
|
513 |
|
514 |
-
|
515 |
|
516 |
{
|
517 |
"status": "ok",
|
@@ -523,44 +517,40 @@ Returns an array of active blog authors.
|
|
523 |
]
|
524 |
}
|
525 |
|
|
|
526 |
|
527 |
-
|
|
|
528 |
|
529 |
Data manipulation methods are used for saving content back to WordPress.
|
530 |
|
531 |
-
|
|
|
532 |
The data manipulation methods are still very incomplete.
|
533 |
|
534 |
|
535 |
-
|
536 |
|
537 |
Submits a comment to a WordPress post.
|
538 |
|
539 |
-
|
540 |
|
541 |
* `post_id` - which post to comment on
|
542 |
* `name` - the commenter's name
|
543 |
* `email` - the commenter's email address
|
544 |
* `content` - the comment content
|
545 |
|
546 |
-
|
547 |
|
548 |
* `redirect` - redirect instead of returning a JSON object
|
549 |
* `redirect_ok` - redirect to a specific URL when the status value is `ok`
|
550 |
* `redirect_error` - redirect to a specific URL when the status value is `error`
|
551 |
-
* `redirect_pending` - redirect to a specific URL when the status value is `pending`
|
552 |
|
553 |
-
|
554 |
-
|
555 |
-
* `pending` - assigned if the comment submission is pending moderation
|
556 |
|
557 |
|
558 |
== Changelog ==
|
559 |
|
560 |
-
= 0.6 (2009-11-30): =
|
561 |
-
* Added `count_total` response
|
562 |
-
* Added `json_api_encode` filter
|
563 |
-
* Fixed bugs in the introspector's `get_current_category` and `get_current_tag`
|
564 |
-
|
565 |
= 0.5 (2009-11-17): =
|
566 |
* Initial Public Release
|
1 |
=== JSON API ===
|
2 |
Contributors: dphiffer
|
3 |
+
Tags: json, api, ajax, cms, admin, integration
|
4 |
Requires at least: 2.8
|
5 |
Tested up to: 2.8
|
6 |
Stable tag: 0.6
|
9 |
|
10 |
== Description ==
|
11 |
|
12 |
+
This plugin was created for The Museum of Modern Art, whose weblog [Inside/Out](http://moma.org/explore/inside_out) appears within an existing website structure built with Ruby on Rails. Instead of reimplementing the site templates as a WordPress theme, we opted for a Rails front-end that displays content served from a WordPress back-end. This plugin provides the necessary interface for retrieving content and accepting comment submissions.
|
13 |
|
14 |
+
The current release (0.5) implements a mostly-complete set of introspection methods and a method for submitting comments. I plan on offering a complete set of authentication & data manipulation methods, but my current focus is on features we're actually using at MoMA.org.
|
15 |
|
16 |
See the Other Notes section for complete API documentation.
|
17 |
|
31 |
JSON API operates in two modes:
|
32 |
|
33 |
1. *Implicit mode* is triggered by setting the `json` query var to a non-empty value on any WordPress page. The content that would normally appear on that page is returned in JSON format.
|
|
|
34 |
|
35 |
+
2. *Explicit mode* is triggered by setting `json` to a known method string. See the API Reference section below for a complete method listing.
|
36 |
|
37 |
+
== Example requests ==
|
38 |
+
|
39 |
+
Implicit mode:
|
40 |
+
|
41 |
+
* `http://www.example.org/?json=1`
|
42 |
+
* `http://www.example.org/?p=47&json=1`
|
43 |
+
* `http://www.example.org/tag/banana/?json=1`
|
44 |
|
45 |
+
Explicit mode:
|
46 |
|
47 |
* `http://www.example.org/?json=get_recent_posts`
|
48 |
* `http://www.example.org/?json=get_post&post_id=47`
|
49 |
* `http://www.example.org/?json=get_tag_posts&tag_slug=banana`
|
50 |
|
51 |
+
You can also use a different URL syntax for explicit-mode requests if your weblog is configured to use `mod_rewrite` for permalinks:
|
52 |
|
53 |
* `http://www.example.org/api/get_recent_posts/`
|
54 |
* `http://www.example.org/api/get_post/?post_id=47`
|
56 |
|
57 |
== Responses ==
|
58 |
|
59 |
+
The standard response format for JSON API is (as you may have guessed) JSON. For more information about the JSON format, see http://json.org/.
|
60 |
|
61 |
Here is an example response from `http://localhost/wordpress/?json=1` called on a default WordPress installation (formatted for readability):
|
62 |
|
63 |
{
|
64 |
"status": "ok",
|
65 |
"count": 1,
|
|
|
66 |
"pages": 1,
|
67 |
"posts": [
|
68 |
{
|
109 |
|
110 |
1. Request arguments
|
111 |
1. Response objects
|
|
|
112 |
1. Introspection methods
|
113 |
1. Data manipulation methods
|
114 |
|
115 |
+
__About API changes__
|
116 |
+
|
117 |
All methods are currently subject to change until the plugin reaches maturity. Please read the the changelog carefully before updating to subsequent releases.
|
118 |
|
119 |
== 1. Request arguments ==
|
135 |
* `custom_fields` - Includes values from posts' Custom Fields. Expects a comma-separated list of custom field keys.
|
136 |
* `author_meta` - Includes additional author metadata. Should be a comma-separated list of metadata fields.
|
137 |
|
138 |
+
__About `include`/`exclude` arguments__
|
139 |
+
|
140 |
+
The default behavior includes all post values. You only need to specify one of `include` or `exclude` — the former will implicitly leave out those fields you haven't specified and the latter will implicitly include them. For example, a query of `exclude=comments` will include everything *except* the comments, so there's no need to also specify anything with the `include` argument.
|
141 |
+
|
142 |
+
== 2. Response types ==
|
143 |
|
144 |
+
This section describes data objects you can retrieve from WordPress as well as the behavior of URL redirects.
|
145 |
|
146 |
+
__Status values__
|
147 |
|
148 |
+
All API requests will result in a status value. The basic values are `ok` and `error`. For certain data manipulation methods, additional status values are available (such as `pending` in the case of a comment submission). Each API method listed below includes its possible status values.
|
149 |
+
|
150 |
+
__Naming compatibility__
|
151 |
|
|
|
152 |
Developers familiar with WordPress may notice that many names for properties and arguments have been changed. This was a stylistic choice that intends to provide more clarity and consistency in the interface.
|
153 |
|
154 |
+
__Post response object__
|
155 |
|
156 |
* `id` - Integer
|
157 |
* `slug` - String
|
170 |
* `comment_status` - String (`"open"` or `"closed"`)
|
171 |
* `custom_fields` - Object (included by setting the `custom_fields` argument to a comma-separated list of custom field names)
|
172 |
|
173 |
+
__Category response object__
|
174 |
|
175 |
* `id` - Integer
|
176 |
* `slug` - String
|
179 |
* `parent` - Integer
|
180 |
* `post_count` - Integer
|
181 |
|
182 |
+
__Tag response object__
|
183 |
|
184 |
* `id` - Integer
|
185 |
* `slug` - String
|
186 |
* `title` - String
|
187 |
* `description` - String
|
188 |
|
189 |
+
__Author response object__
|
190 |
|
191 |
* `id` - Integer
|
192 |
* `slug` - String
|
199 |
|
200 |
Note: You can include additional values by setting the `author_meta` argument to a comma-separated list of metadata fields.
|
201 |
|
202 |
+
__Comment response object__
|
203 |
|
204 |
* `id` - Integer
|
205 |
* `name` - String
|
209 |
* `parent` - Integer
|
210 |
* `author` - Object (only set if the comment author was registered & logged in)
|
211 |
|
212 |
+
__Redirects__
|
|
|
|
|
213 |
|
214 |
+
Setting the `redirect` argument to `http://www.example.com/foo` will result in one of the following URLs depending on the resulting status value:
|
215 |
|
216 |
* `http://www.example.com/foo?status=ok`
|
217 |
* `http://www.example.com/foo?status=error`
|
218 |
|
219 |
+
You can alternatively set `redirect_ok` to `http://www.example.com/handle_ok` and `redirect_error` to `http://www.example.com/handle_error` to have more control over the redirect behavior.
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
+
== 3. Introspection methods ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
|
223 |
Introspection methods are used to retrieve data from WordPress.
|
224 |
|
225 |
|
226 |
+
__Method: `get_recent_posts`__
|
227 |
|
228 |
Returns an array of recent posts. You can invoke this from the WordPress home page either by setting `json` to a non-empty value (i.e., `json=1`) or from any page by setting `json=get_recent_posts`.
|
229 |
|
230 |
+
Optional arguments:
|
231 |
|
232 |
* `page` - return a specific page number from the results
|
233 |
|
234 |
+
Response format:
|
235 |
|
236 |
{
|
237 |
"status": "ok",
|
238 |
"count": 10,
|
|
|
239 |
"pages": 7,
|
240 |
"posts": [
|
241 |
{ ... },
|
244 |
]
|
245 |
}
|
246 |
|
247 |
+
Status values: `ok`, `error`
|
248 |
|
|
|
249 |
|
250 |
+
__Method: `get_post`__
|
251 |
|
252 |
+
Returns a single post object.
|
253 |
|
254 |
+
One of the following is required:
|
255 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a post URL
|
256 |
* `post_id` - set to the post's ID
|
257 |
* `post_slug` - set to the post's URL slug
|
258 |
|
259 |
+
Response format:
|
260 |
|
261 |
{
|
262 |
"status": "ok",
|
263 |
"post": { ... }
|
264 |
}
|
265 |
|
266 |
+
Status values: `ok`, `error`
|
267 |
|
268 |
+
|
269 |
+
__Method: `get_page`__
|
270 |
|
271 |
Returns a single page object.
|
272 |
|
273 |
+
One of the following is required:
|
274 |
|
275 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a page URL
|
276 |
* `page_id` - set to the page's ID
|
277 |
* `page_slug` - set to the page's URL slug
|
278 |
|
279 |
+
Response format:
|
280 |
|
281 |
{
|
282 |
"status": "ok",
|
283 |
"page": { ... }
|
284 |
}
|
285 |
|
286 |
+
Status values: `ok`, `error`
|
287 |
+
|
288 |
+
|
289 |
+
__Method: `get_date_posts`__
|
290 |
|
291 |
Returns an array of posts/pages in a specific category.
|
292 |
|
293 |
+
One of the following is required:
|
294 |
|
295 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a date archive page
|
296 |
* `date` - set to a date in the format `YYYY` or `YYYYMM` or `YYYYMMDD`
|
297 |
|
298 |
+
Optional arguments:
|
299 |
|
300 |
* `page` - return a specific page number from the results
|
301 |
|
302 |
+
Response format:
|
303 |
|
304 |
{
|
305 |
"status": "ok",
|
306 |
"count": 10,
|
|
|
307 |
"pages": 7,
|
308 |
"posts": [
|
309 |
{ ... },
|
312 |
]
|
313 |
}
|
314 |
|
315 |
+
Status values: `ok`, `error`
|
316 |
+
|
317 |
+
|
318 |
+
__Method: `get_category_posts`__
|
319 |
|
320 |
Returns an array of posts/pages in a specific category.
|
321 |
|
322 |
+
One of the following is required:
|
323 |
|
324 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a category archive page
|
325 |
* `category_id` - set to the category's ID
|
326 |
* `category_slug` - set to the category's URL slug
|
327 |
|
328 |
+
Optional arguments:
|
329 |
|
330 |
* `page` - return a specific page number from the results
|
331 |
|
332 |
+
Response format:
|
333 |
|
334 |
{
|
335 |
"status": "ok",
|
336 |
"count": 10,
|
|
|
337 |
"pages": 7,
|
338 |
"category": { ... }
|
339 |
"posts": [
|
343 |
]
|
344 |
}
|
345 |
|
346 |
+
Status values: `ok`, `error`
|
347 |
|
348 |
+
|
349 |
+
__Method: `get_tag_posts`__
|
350 |
|
351 |
Returns an array of posts/pages with a specific tag.
|
352 |
|
353 |
+
One of the following is required:
|
354 |
|
355 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a tag archive page
|
356 |
* `tag_id` - set to the tag's ID
|
357 |
* `tag_slug` - set to the tag's URL slug
|
358 |
|
359 |
+
Optional arguments:
|
360 |
|
361 |
* `page` - return a specific page number from the results
|
362 |
|
363 |
+
Response format:
|
364 |
|
365 |
{
|
366 |
"status": "ok",
|
367 |
"count": 10,
|
|
|
368 |
"pages": 7,
|
369 |
"tag": { ... }
|
370 |
"posts": [
|
374 |
]
|
375 |
}
|
376 |
|
377 |
+
Status values: `ok`, `error`
|
378 |
+
|
379 |
|
380 |
+
__Method: `get_author_posts`__
|
381 |
|
382 |
Returns an array of posts/pages written by a specific author.
|
383 |
|
384 |
+
One of the following is required:
|
385 |
|
386 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on an author archive page
|
387 |
* `author_id` - set to the author's ID
|
388 |
* `author_slug` - set to the author's URL slug
|
389 |
|
390 |
+
Optional arguments:
|
391 |
|
392 |
* `page` - return a specific page number from the results
|
393 |
|
394 |
+
Response format:
|
395 |
|
396 |
{
|
397 |
"status": "ok",
|
398 |
"count": 10,
|
|
|
399 |
"pages": 7,
|
400 |
"author": { ... }
|
401 |
"posts": [
|
402 |
{ ... },
|
403 |
{ ... },
|
404 |
+
{ ... }
|
405 |
]
|
406 |
}
|
407 |
|
408 |
+
Status values: `ok`, `error`
|
409 |
|
410 |
+
|
411 |
+
__Method: `get_search_results`__
|
412 |
|
413 |
Returns an array of posts/pages in response to a search query.
|
414 |
|
415 |
+
One of the following is required:
|
416 |
|
417 |
* Invoking the JSON API implicitly (i.e., `?json=1`) on a search results page
|
418 |
* `search` - set to the desired search query
|
419 |
|
420 |
+
Optional arguments:
|
421 |
|
422 |
* `page` - return a specific page number from the results
|
423 |
|
424 |
+
Response format:
|
425 |
|
426 |
{
|
427 |
"status": "ok",
|
428 |
"count": 10,
|
|
|
429 |
"pages": 7,
|
430 |
"posts": [
|
431 |
{ ... },
|
434 |
]
|
435 |
}
|
436 |
|
437 |
+
Status values: `ok`, `error`
|
438 |
+
|
439 |
|
440 |
+
__Method: `get_date_index`__
|
441 |
|
442 |
Returns both an array of date page permalinks and a tree structure representation of the archive.
|
443 |
|
444 |
+
Response format:
|
445 |
|
446 |
{
|
447 |
"status": "ok",
|
458 |
}
|
459 |
}
|
460 |
|
461 |
+
Note: the tree is arranged by [year] > [month] > [number of posts].
|
462 |
+
|
463 |
+
Status values: `ok`, `error`
|
464 |
|
465 |
|
466 |
+
__Method: `get_category_index`__
|
467 |
|
468 |
Returns an array of active categories.
|
469 |
|
470 |
+
Response format:
|
471 |
|
472 |
{
|
473 |
"status": "ok",
|
479 |
]
|
480 |
}
|
481 |
|
482 |
+
Status values: `ok`, `error`
|
483 |
+
|
484 |
|
485 |
== Method: get_tag_index ==
|
486 |
|
487 |
Returns an array of active tags.
|
488 |
|
489 |
+
Response format:
|
490 |
|
491 |
{
|
492 |
"status": "ok",
|
498 |
]
|
499 |
}
|
500 |
|
501 |
+
Status values: `ok`, `error`
|
502 |
+
|
503 |
|
504 |
== Method: get_author_index ==
|
505 |
|
506 |
Returns an array of active blog authors.
|
507 |
|
508 |
+
Response format:
|
509 |
|
510 |
{
|
511 |
"status": "ok",
|
517 |
]
|
518 |
}
|
519 |
|
520 |
+
Status values: `ok`, `error`
|
521 |
|
522 |
+
|
523 |
+
== 4. Data manipulation methods ==
|
524 |
|
525 |
Data manipulation methods are used for saving content back to WordPress.
|
526 |
|
527 |
+
**Incomplete**
|
528 |
+
|
529 |
The data manipulation methods are still very incomplete.
|
530 |
|
531 |
|
532 |
+
__Method: `submit_comment`__
|
533 |
|
534 |
Submits a comment to a WordPress post.
|
535 |
|
536 |
+
Required arguments:
|
537 |
|
538 |
* `post_id` - which post to comment on
|
539 |
* `name` - the commenter's name
|
540 |
* `email` - the commenter's email address
|
541 |
* `content` - the comment content
|
542 |
|
543 |
+
Optional arguments:
|
544 |
|
545 |
* `redirect` - redirect instead of returning a JSON object
|
546 |
* `redirect_ok` - redirect to a specific URL when the status value is `ok`
|
547 |
* `redirect_error` - redirect to a specific URL when the status value is `error`
|
548 |
+
* `redirect_pending` - redirect to a specific URL when the status value is `pending` (comment pending review)
|
549 |
|
550 |
+
Status values: `ok`, `error`, `pending`
|
|
|
|
|
551 |
|
552 |
|
553 |
== Changelog ==
|
554 |
|
|
|
|
|
|
|
|
|
|
|
555 |
= 0.5 (2009-11-17): =
|
556 |
* Initial Public Release
|
singletons/introspector.php
CHANGED
@@ -69,62 +69,60 @@ class JSON_API_Introspector {
|
|
69 |
if ($wp_category->term_id == 1 && $wp_category->slug == 'uncategorized') {
|
70 |
continue;
|
71 |
}
|
72 |
-
$categories[] = $this->
|
73 |
}
|
74 |
return $categories;
|
75 |
}
|
76 |
|
77 |
-
function
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
return $this->
|
|
|
|
|
|
|
|
|
|
|
83 |
}
|
84 |
-
return null;
|
85 |
-
}
|
86 |
-
|
87 |
-
function get_category_object($wp_category) {
|
88 |
-
return new JSON_API_Category($wp_category);
|
89 |
}
|
90 |
|
91 |
-
function
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
$
|
98 |
-
return $this->get_category_object($wp_category);
|
99 |
}
|
100 |
|
101 |
function get_tags() {
|
102 |
$wp_tags = get_tags();
|
103 |
-
return array_map(array(&$this, '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
|
106 |
function get_current_tag() {
|
107 |
global $json_api;
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
return $this->get_tag_by_slug($json_api->query->tag_slug);
|
112 |
}
|
113 |
-
return
|
114 |
-
}
|
115 |
-
|
116 |
-
function get_tag_object($wp_tag) {
|
117 |
-
return new JSON_API_Tag($wp_tag);
|
118 |
-
}
|
119 |
-
|
120 |
-
function get_tag_by_id($tag_id) {
|
121 |
-
$wp_tag = get_term_by('id', $tag_id, 'post_tag');
|
122 |
-
return $this->get_tag_object($wp_tag);
|
123 |
-
}
|
124 |
-
|
125 |
-
function get_tag_by_slug($tag_slug) {
|
126 |
-
$wp_tag = get_term_by('slug', $tag_slug, 'post_tag');
|
127 |
-
return $this->get_tag_object($wp_tag);
|
128 |
}
|
129 |
|
130 |
function get_authors() {
|
69 |
if ($wp_category->term_id == 1 && $wp_category->slug == 'uncategorized') {
|
70 |
continue;
|
71 |
}
|
72 |
+
$categories[] = $this->get_category($wp_category);
|
73 |
}
|
74 |
return $categories;
|
75 |
}
|
76 |
|
77 |
+
function get_category($arg) {
|
78 |
+
if (is_object($arg)) {
|
79 |
+
return new JSON_API_Category($arg);
|
80 |
+
} else if (is_numeric($arg)) {
|
81 |
+
$wp_category = get_term_by('id', $arg, 'category');
|
82 |
+
return $this->get_category($wp_category);
|
83 |
+
} else if (is_string($arg)) {
|
84 |
+
$wp_category = get_term_by('slug', $arg, 'category');
|
85 |
+
return $this->get_category($wp_category);
|
86 |
+
} else {
|
87 |
+
return null;
|
88 |
}
|
|
|
|
|
|
|
|
|
|
|
89 |
}
|
90 |
|
91 |
+
function get_current_category() {
|
92 |
+
global $json_api;
|
93 |
+
$category = $json_api->query->category_id;
|
94 |
+
if (empty($category)) {
|
95 |
+
$category = $json_api->query->category_slug;
|
96 |
+
}
|
97 |
+
return $this->get_category($category);
|
|
|
98 |
}
|
99 |
|
100 |
function get_tags() {
|
101 |
$wp_tags = get_tags();
|
102 |
+
return array_map(array(&$this, 'get_tag'), $wp_tags);
|
103 |
+
}
|
104 |
+
|
105 |
+
function get_tag($arg) {
|
106 |
+
if (is_object($arg)) {
|
107 |
+
return new JSON_API_Tag($arg);
|
108 |
+
} else if (is_numeric($arg)) {
|
109 |
+
$wp_tag = get_term_by('id', $arg, 'post_tag');
|
110 |
+
return $this->get_tag($wp_tag);
|
111 |
+
} else if (is_string($arg)) {
|
112 |
+
$wp_tag = get_term_by('slug', $arg, 'post_tag');
|
113 |
+
return $this->get_tag($wp_tag);
|
114 |
+
} else {
|
115 |
+
return null;
|
116 |
+
}
|
117 |
}
|
118 |
|
119 |
function get_current_tag() {
|
120 |
global $json_api;
|
121 |
+
$tag = $json_api->query->tag_id;
|
122 |
+
if (empty($tag)) {
|
123 |
+
$tag = $json_api->query->tag_slug;
|
|
|
124 |
}
|
125 |
+
return $this->get_tag($tag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
}
|
127 |
|
128 |
function get_authors() {
|
singletons/query.php
CHANGED
@@ -152,5 +152,5 @@ class JSON_API_Query {
|
|
152 |
return 'error';
|
153 |
}
|
154 |
}
|
155 |
-
|
156 |
}
|
152 |
return 'error';
|
153 |
}
|
154 |
}
|
155 |
+
|
156 |
}
|
singletons/response.php
CHANGED
@@ -21,7 +21,6 @@ class JSON_API_Response {
|
|
21 |
global $wp_query;
|
22 |
return $this->get_json(array(
|
23 |
'count' => count($posts),
|
24 |
-
'count_total' => $wp_query->found_posts,
|
25 |
'pages' => $wp_query->max_num_pages,
|
26 |
'posts' => $posts
|
27 |
), $status);
|
@@ -47,8 +46,6 @@ class JSON_API_Response {
|
|
47 |
$data = array_merge(array('status' => $status), $data);
|
48 |
}
|
49 |
|
50 |
-
$data = apply_filters('json_api_encode', $data);
|
51 |
-
|
52 |
if (!empty($_REQUEST['dev'])) {
|
53 |
// Don't JSON encode the data in dev mode
|
54 |
return $data;
|
@@ -57,10 +54,8 @@ class JSON_API_Response {
|
|
57 |
return json_encode($data);
|
58 |
} else {
|
59 |
// Use PEAR's Services_JSON encoder otherwise
|
60 |
-
|
61 |
-
|
62 |
-
require_once "$json_api_dir/library/JSON.php";
|
63 |
-
}
|
64 |
$json = new Services_JSON();
|
65 |
return $json->encode($data);
|
66 |
}
|
21 |
global $wp_query;
|
22 |
return $this->get_json(array(
|
23 |
'count' => count($posts),
|
|
|
24 |
'pages' => $wp_query->max_num_pages,
|
25 |
'posts' => $posts
|
26 |
), $status);
|
46 |
$data = array_merge(array('status' => $status), $data);
|
47 |
}
|
48 |
|
|
|
|
|
49 |
if (!empty($_REQUEST['dev'])) {
|
50 |
// Don't JSON encode the data in dev mode
|
51 |
return $data;
|
54 |
return json_encode($data);
|
55 |
} else {
|
56 |
// Use PEAR's Services_JSON encoder otherwise
|
57 |
+
global $json_api_dir;
|
58 |
+
require_once "$json_api_dir/library/JSON.php";
|
|
|
|
|
59 |
$json = new Services_JSON();
|
60 |
return $json->encode($data);
|
61 |
}
|