Skip to content

Instantly share code, notes, and snippets.

@timwhitlock
Created February 11, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timwhitlock/7bc9684c51f79c33c84783002fa00479 to your computer and use it in GitHub Desktop.
Save timwhitlock/7bc9684c51f79c33c84783002fa00479 to your computer and use it in GitHub Desktop.
Disable non-GET requests to WordPress REST API
<?php
/**
* Plugin Name: Disable POSTing to REST API
* Version: 0
*/
add_filter( 'rest_authentication_errors', function( $access = null ){
if( 'GET' !== $_SERVER['REQUEST_METHOD'] ){
return new WP_Error( 'rest_cannot_access', 'Nope', array( 'status' => 405 ) );
}
return $access;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment