-
-
Save aubricus/e9eb8a0b722dcc3d2b3c3ed3f32788ac to your computer and use it in GitHub Desktop.
Removes user endpoints from 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 | |
/** | |
* 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to be slightly more extensible.