Sample code for extending the WordPress REST API
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
admin added restrict_media_endpoint() sample Jul 25, 2017
includes fixed disable_media_endpoint filter hook Aug 3, 2017
README.md
plugin.php cleaned up whoami demo Jul 25, 2017

README.md

Extending the WP REST API

Sample code for extending the WordPress REST API. Slides are also available

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