Skip to main content
Login Join
Snippet · PHP

Disable REST API User Enumeration

Shared by Yusuf mudagal · May 3, 2026 · @rest_endpoints

39 views
Back to Snippets

Removes the public WordPress REST user endpoints to reduce username discovery on sites that do not expose author archives or public user directories.

add_filter( 'rest_endpoints', 'wpfolks_disable_rest_user_endpoints' );

function wpfolks_disable_rest_user_endpoints( $endpoints ) {
    unset( $endpoints['/wp/v2/users'], $endpoints['/wp/v2/users/(?P<id>[d]+)'] );

    return $endpoints;
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments