Skip to content

Instantly share code, notes, and snippets.

@karlazz
Created January 20, 2023 00:37
Show Gist options
  • Save karlazz/31ae51d34277a27077437e9155c830dd to your computer and use it in GitHub Desktop.
Save karlazz/31ae51d34277a27077437e9155c830dd to your computer and use it in GitHub Desktop.
unset API endpoints example: user
// Unset user API endpoints to prevent user enumeration
add_filter('rest_endpoints', function($endpoints) {
unset( $endpoints['/wp/v2/users'] );
unset( $endpoints ['/wp/v2/users/(?P<id>[\d]+)']);
unset( $endpoints ['[/wp/v2/users/me]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/introspect]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/(?P<uuid>[\w\-]+)']);
return $endpoints;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment