Created
February 8, 2021 20:24
-
-
Save techjewel/27a6c03e2f0509ac9b6372fd7ef3769d to your computer and use it in GitHub Desktop.
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 | |
/* | |
* Disable users REST endpoint for public or not author users users | |
* To access the endpoint the user must need to be contributor | |
* aka need to have edit_posts permission | |
*/ | |
add_filter( 'rest_endpoints', function ($endpoints) { | |
$endpoints_to_remove = array( | |
'/wp/v2/users' | |
); | |
if ( !current_user_can('edit_posts') ) { | |
foreach ( $endpoints_to_remove as $rem_endpoint ) { | |
foreach ( $endpoints as $maybe_endpoint => $object ) { | |
if ( stripos( $maybe_endpoint, $rem_endpoint ) !== false ) { | |
unset( $endpoints[ $maybe_endpoint ] ); | |
} | |
} | |
} | |
} | |
return $endpoints; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment