Skip to content

Instantly share code, notes, and snippets.

@petenelson
Last active August 29, 2015 14:25
Show Gist options
  • Save petenelson/d0cd422910835f779d44 to your computer and use it in GitHub Desktop.
Save petenelson/d0cd422910835f779d44 to your computer and use it in GitHub Desktop.
WordPress REST API: Disallow non-SSL
<?php
add_filter( 'rest_pre_dispatch', 'rest_api_disallow_non_ssl', 10, 3 );
function rest_api_disallow_non_ssl( $response, $server, $request ) {
if ( ! is_ssl() ) {
$response = new WP_Error( 'rest_forbidden', __( "SSL is required to access the REST API" ), array( 'status' => 403 ) );
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment