Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petenelson/extending-wp-rest-api
Sample code for extending the WordPress REST API
https://github.com/petenelson/extending-wp-rest-api
Last synced: 3 months ago
JSON representation
Sample code for extending the WordPress REST API
- Host: GitHub
- URL: https://github.com/petenelson/extending-wp-rest-api
- Owner: petenelson
- Created: 2015-07-09T18:27:26.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-03T00:47:15.000Z (almost 7 years ago)
- Last Synced: 2024-01-19T15:05:49.499Z (6 months ago)
- Language: PHP
- Size: 199 KB
- Stars: 30
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Lists
- awesome-wordpress-developer-tips - Pete Nelson
README
# Extending the WP REST API
Sample code for extending the [WordPress REST API](https://wordpress.org/plugins/rest-api/). [Slides are also available](https://docs.google.com/presentation/d/1o4gJnEcq1vbDUsjZu_zRfh8D7crxzU45gTCquZOFODw/pub?start=false&loop=false&delayms=3000)## Examples in this Code
* Add revision counts to posts: ```register_api_field()```
* Add featured image URL and dimensions to posts: ```rest_prepare_post``` filter and ```add_link()```
* Custom routes: ```register_rest_route```
* Custom authentication: ```determine_current_user``` filter
* Forcing API Link in headers to SSL: ```rest_url``` filter
* Disallowing non-SSL requests: ```rest_pre_dispatch``` filter
* Non-JSON responses: ```rest_pre_serve_request``` filter
* Change base API URL prefix: ```‘rest_url_prefix’``` filter
* Hide media endpoing from non-authenticated users: ```global $wp_post_types; $wp_post_types['attachment']->show_in_rest = is_user_logged_in();```
* Disabled media endpoint: ```rest_dispatch_request``` filter