Skip to content

Instantly share code, notes, and snippets.

@kingkool68
Last active October 12, 2022 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingkool68/2d013af7895268cef93d9464cffa133b to your computer and use it in GitHub Desktop.
Save kingkool68/2d013af7895268cef93d9464cffa133b to your computer and use it in GitHub Desktop.
Remove the User endpoints from the WordPress Rest API
<IfModule mod_rewrite.c>
RewriteEngine On
# Block _method=GET query string used for compatibility in the REST API
# See https://developer.wordpress.org/rest-api/using-the-rest-api/global-parameters/#_method-or-x-http-method-override-header
RewriteCond %{QUERY_STRING} \b_method=GET\b [NC]
RewriteRule ^ - [F]
</IfModule>
<?php
/**
* Remove default WP JSON API routes dealing with lisitng users
*
* @param array $endpoints The endpoints to modify
*/
public function filter_rest_endpoints( $endpoints = array() ) {
$keys_to_remove = array(
'/wp/v2/users',
'/wp/v2/users/(?P<id>[\\d]+)',
);
foreach ( $keys_to_remove as $key ) {
unset( $endpoints[ $key ] );
}
return $endpoints;
}
add_filter( 'rest_endpoints', 'filter_rest_endpoints' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment