Skip to content

Instantly share code, notes, and snippets.

@aubricus
Forked from gilzow/put-inside-functions.php
Created November 20, 2018 02:41
Show Gist options
  • Save aubricus/e9eb8a0b722dcc3d2b3c3ed3f32788ac to your computer and use it in GitHub Desktop.
Save aubricus/e9eb8a0b722dcc3d2b3c3ed3f32788ac to your computer and use it in GitHub Desktop.
Removes user endpoints from WordPress REST API
<?php
/**
* Remove API Endpoints
*
* Clobber API routes to remove them from public access.
*/
function remove_wp_json_api_endpoints($endpoints) {
$toRemove = array(
"/oembed/1.0/embed",
"/wp/v2/users",
"/wp/v2/users/(?P<id>[\d]+)",
);
foreach ($toRemove as $item) {
if(isset($endpoints[$item])){
unset($endpoints[$item]);
}
}
return $endpoints;
}
add_filter('rest_endpoints', 'remove_wp_json_api_endpoints');
@aubricus
Copy link
Author

Updated to be slightly more extensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment