Last active
October 12, 2022 17:50
-
-
Save kingkool68/2d013af7895268cef93d9464cffa133b to your computer and use it in GitHub Desktop.
Remove the User endpoints from the 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
<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> |
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 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