Home / Disable / Remove users from WP-JSON
Duplicate Snippet

Embed Snippet on Your Site

Remove users from WP-JSON

Increase your site's security by hiding usernames from WP-JSON, that are otherwise exposed to the public.

Code Preview
php
<?php
add_filter('rest_endpoints', function( $endpoints ) {
    if ( isset( $endpoints['/wp/v2/users'] ) ) {
        unset( $endpoints['/wp/v2/users'] );
    }
    if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
        unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
    }
    return $endpoints;
});

Comments

Add a Comment