Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@aubricus aubricus commented Nov 20, 2018

Updated to be slightly more extensible.

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