Created
February 11, 2017 15:00
-
-
Save timwhitlock/7bc9684c51f79c33c84783002fa00479 to your computer and use it in GitHub Desktop.
Disable non-GET requests to WordPress REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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