=== JSON REST API === Contributors: rmccue Tags: json, rest, api, rest-api Requires at least: 3.5 Tested up to: 3.7 Stable tag: 0.7 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html JSON-based REST API for WordPress, developed as part of GSoC 2013. == Description == This is a project to create a JSON-based REST API for WordPress. This project is run by Ryan McCue and is part of the WordPress 2013 GSoC projects. WordPress is moving towards becoming a fully-fledged application framework, and we need new APIs. This project was born to create an easy-to-use, easy-to-understand and well-tested framework for creating these APIs, plus creating APIs for core. This plugin is currently in Summer of Code mode, but is planned for core integration in the future. Please do not rely on any part of the plugin in production environments until the project has become part of core, as it is liable to change significantly. All tickets for the project are being tracked on the [GSoC Trac][]. Make sure you use the JSON REST API component. You can also take a look at the [recent updates][] for the project. [GSoC Trac]: https://gsoc.trac.wordpress.org/query?component=JSON+REST+API [recent updates]: http://make.wordpress.org/core/tag/json-api/ == Installation == ### As a Plugin Drop this directory in and activate it. You need to be using pretty permalinks to use the plugin, as it uses custom rewrite rules to power the API. ### As Part of Core Drop `wp-json.php` into your WordPress directory, and drop `class-wp-json-server.php` into your `wp-includes/` directory. You'll need working `PATH_INFO` on your server, but you don't need pretty permalinks enabled. == Changelog == = 0.7 = * The response handler object is now passed into the endpoint objects via the constructor, allowing you to avoid excess global state where possible. It's recommended to use this where possible rather than the global object. (props @rmccue, [#2][gh-2]) * Fix undefined variables and indices (props @pippinsplugins, [#5][gh-5]) * Correct call to deactivation hook (props @ericpedia, [#9][gh-9]) * Check metadata access correctly rather than always hiding for users without the `edit_post_meta` capability (props @kokarn, [#10][gh-10]) * Return all term metadata, rather than just the last one (props @afurculita, [#13][gh-13]) * Access post metadata from cache where possible - Note, this is a backwards compatibility break, as the format of the metadata has changed. This may change again in the near future, so don't rely on it until 1.0. (props @afurculita, [#14][gh-14]) * Add term_link to prepare_term (props @afurculita, [#15][gh-15]) * Fix hardcoded `/pages` references in `WP_JSON_CustomPostType` (props @thenbrent, [#26][gh-26]) * Sanitize headers for newlines (props @kokarn, [#7][gh-7]) * Register rewrite rules during plugin activation (props @pippinsplugins, [#17][gh-17]) [View all changes](https://github.com/rmccue/WP-API/compare/0.6...0.7) [gh-2]: https://github.com/WP-API/WP-API/issues/2 [gh-5]: https://github.com/WP-API/WP-API/issues/5 [gh-7]: https://github.com/WP-API/WP-API/issues/7 [gh-9]: https://github.com/WP-API/WP-API/issues/9 [gh-10]: https://github.com/WP-API/WP-API/issues/10 [gh-13]: https://github.com/WP-API/WP-API/issues/13 [gh-14]: https://github.com/WP-API/WP-API/issues/14 [gh-15]: https://github.com/WP-API/WP-API/issues/15 [gh-17]: https://github.com/WP-API/WP-API/issues/17 [gh-26]: https://github.com/WP-API/WP-API/issues/26 = 0.6 = * Huge documentation update - Guides on getting started and extending the API are [now available for your perusal][docs] * Add generic CPT class - Plugins are now encouraged to extend `WP_JSON_CustomPostType` and get free hooking for common actions. This removes most of the boilerplate that you needed to write for new CPT-based routes and endpoints ([#380][]) * Use defined filter priorities for endpoint registration - It's now easier to inject your own endpoints at a defined point * Update the schema - Now includes documentation on the Media entity, plus more ([#264][]) * Add better taxonomy support - You can now query for taxonomies and terms directly. The routes here might seem strange (`/posts/types/post/taxonomies/category` for example), but the intention is to [future-proof them](http://make.wordpress.org/core/2013/07/28/potential-roadmap-for-taxonomy-meta-and-post-relationships/) as much as possible([#275][]) * Ensure the JSON URL is relative to the home URL ([#375][]) * Check all date formats for If-Unmodified-Since ([#378][]) * Register the correct URL for the JS library ([#376][]) * Correct the usage of meta links ([#379][]) * Add filters for post type and post status data ([#380][]) * Separate parent post and parent comment relation ([#330][]() [View all changes](https://github.com/rmccue/WP-API/compare/0.5...0.6) [docs]: https://github.com/rmccue/WP-API/tree/master/docs [#264]: https://gsoc.trac.wordpress.org/ticket/264 [#275]: https://gsoc.trac.wordpress.org/ticket/275 [#330]: https://gsoc.trac.wordpress.org/ticket/330 [#375]: https://gsoc.trac.wordpress.org/ticket/375 [#376]: https://gsoc.trac.wordpress.org/ticket/376 [#378]: https://gsoc.trac.wordpress.org/ticket/378 [#379]: https://gsoc.trac.wordpress.org/ticket/379 [#380]: https://gsoc.trac.wordpress.org/ticket/380 = 0.5 = * Add support for media - This has been a long time coming, and it's finally at a point where I'm happy to push it out. Good luck. ([#272][]) * Separate the post-related endpoints - Post-related endpoints are now located in the `WP_JSON_Posts` class. When implementing custom post type support, it's recommended to subclass this. The various types are now also only registered via hooks, rather than directly in the server class, which should make it easier to override them as well ([#348][]) * Add page support - This is a good base if you're looking to create your own custom post type support ([#271][]) * Switch from fields to context - Rather than passing in a list of fields that you want, you can now pass in a context (usually `view` or `edit`) ([#328][]). * Always send headers via the server handler - Endpoints are now completely separate from the request, so the server class can now be used for non-HTTP/JSON handlers if needed ([#293][]) * Use better error codes for disabled features ([#338][]) * Send `X-WP-Total` and `X-WP-TotalPages` headers for information on post/pagination counts ([#266][]) [View all changes](https://github.com/rmccue/WP-API/compare/0.4...0.5) [#266]: https://gsoc.trac.wordpress.org/ticket/266 [#271]: https://gsoc.trac.wordpress.org/ticket/271 [#272]: https://gsoc.trac.wordpress.org/ticket/272 [#293]: https://gsoc.trac.wordpress.org/ticket/293 [#328]: https://gsoc.trac.wordpress.org/ticket/328 [#338]: https://gsoc.trac.wordpress.org/ticket/338 [#348]: https://gsoc.trac.wordpress.org/ticket/348 = 0.4 = * Add Backbone-based models and collections - These are available to your code by declaring a dependency on `wp-api` ([#270][]) * Check `json_route` before using it ([#336][]) * Conditionally load classes ([#337][]) * Add additional test helper plugin - Provides code coverage as needed to the API client tests. Currently unused. ([#269][]) * Move `json_url()` and `get_json_url()` to `plugin.php` - This allows using both outside of the API itself ([#343][]) * `getPost(0)` now returns an error rather than the latest post ([#344][]) * [View all changes](https://github.com/rmccue/WP-API/compare/0.3...0.4) [#269]: https://gsoc.trac.wordpress.org/ticket/269 [#270]: https://gsoc.trac.wordpress.org/ticket/270 [#336]: https://gsoc.trac.wordpress.org/ticket/336 [#337]: https://gsoc.trac.wordpress.org/ticket/337 [#343]: https://gsoc.trac.wordpress.org/ticket/343 [#344]: https://gsoc.trac.wordpress.org/ticket/344 = 0.3 = * Add initial comment endpoints to get comments for a post, and get a single comment ([#320][]) * Return a Post entity when updating a post, rather than wrapping it with useless text ([#329][]) * Allow filtering the output as well as input. You can now use the `json_dispatch_args` filter for input as well as the `json_serve_request` filter for output to serve up alternative formats (e.g. MsgPack, XML (if you're insane)) * Include a `profile` link in the index, to indicate the JSON Schema that the API conforms to. In the future, this will be versioned. [#320]: https://gsoc.trac.wordpress.org/ticket/320 [#329]: https://gsoc.trac.wordpress.org/ticket/329 = 0.2 = * Allow all public query vars to be passed to WP Query - Some private query vars can also be passed in, and all can if the user has `edit_posts` permissions ([#311][]) * Pagination can now be handled by using the `page` argument without messing with WP Query syntax ([#266][]) * The index now generates links for non-variable routes ([#268][]) * Editing a post now supports the `If-Unmodified-Since` header. Pass this in to avoid conflicting edits ([#294][]) * Post types and post statuses now have endpoints to access their data ([#268][]) * [View all changes](https://github.com/rmccue/WP-API/compare/0.1.2...0.2) [#268]: https://gsoc.trac.wordpress.org/ticket/268 [#294]: https://gsoc.trac.wordpress.org/ticket/294 [#266]: https://gsoc.trac.wordpress.org/ticket/266 [#311]: https://gsoc.trac.wordpress.org/ticket/311 = 0.1.2 = * Disable media handling to avoid fatal error ([#298][]) [#298]: http://gsoc.trac.wordpress.org/ticket/298 = 0.1.1 = * No changes, process error = 0.1 = * Enable the code to be used via the plugin architecture (now uses rewrite rules if running in this mode) * Design documents are now functionally complete for the current codebase ([#264][]) * Add basic writing support ([#265][]) * Filter fields by default - Unfiltered results are available via their corresponding `*_raw` key, which is only available to users with `edit_posts` ([#290][]) * Use correct timezones for manual offsets (GMT+10, e.g.) ([#279][]) * Allow permanently deleting posts ([#292]) * [View all changes](https://github.com/rmccue/WP-API/compare/b3a8d7656ffc58c734aad95e0839609011b26781...0.1.1) [#264]: https://gsoc.trac.wordpress.org/ticket/264 [#265]: https://gsoc.trac.wordpress.org/ticket/265 [#279]: https://gsoc.trac.wordpress.org/ticket/279 [#290]: https://gsoc.trac.wordpress.org/ticket/290 [#292]: https://gsoc.trac.wordpress.org/ticket/292 = 0.0.4 = * Hyperlinks now available in most constructs under the 'meta' key. At the moment, the only thing under this key is 'links', but more will come eventually. (Try browsing with a browser tool like JSONView; you should be able to view all content just by clicking the links.) * Accessing / now gives an index which briefly describes the API and gives links to more (also added the HIDDEN_ENDPOINT constant to hide from this). * Post collections now contain a summary of the post, with the full post available via the single post call. (prepare_post() has fields split into post and post-extended) * Post entities have dropped post_ prefixes, and custom_fields has changed to post_meta. * Now supports JSONP callback via the _jsonp argument. This can be disabled separately to the API itself, as it's only needed for cross-origin requests. * Internal: No longer extends the XMLRPC class. All relevant pieces have been copied over. Further work still needs to be done on this, but it's a start. = 0.0.3 = - Now accepts JSON bodies if an endpoint is marked with ACCEPT_JSON