Does something like is_rest() exist

It’s a good point by @Milo, the REST_REQUEST constant is defined as true, within rest_api_loaded() if $GLOBALS[‘wp’]->query_vars[‘rest_route’] is non-empty. It’s hooked into parse_request via: add_action( ‘parse_request’, ‘rest_api_loaded’ ); but parse_request fires later than init – See for example the Codex here. There was a suggestion (by Daniel Bachhuber) in ticket #34373 regarding WP_Query::is_rest(), but it … Read more

WordPress 4.7.1 REST API still exposing users

This code snippet will hide the users, posts, and comments endpoint results and give 404 as the result, while the rest of the API calls keep running as they were. ::UPDATE:: add_filter(‘rest_endpoints’, function(){ $toRemove = [‘users’, ‘posts’, ‘comments’]; foreach($toRemove as $val) { if (isset($endpoints[‘/wp/v2/’.$val])) { unset($endpoints[‘/wp/v2/’.$val]); } if(isset($endpoints[‘/wp/v2/’.$val.’/(?P<id>[\d]+)’])) { unset($endpoints[‘/wp/v2/’.$val.’/(?P<id>[\d]+)’]); } } return $endpoints; }); … Read more