Search code examples
wordpressrestapihookwordpress-rest-api

Hide WordPress Rest API endpoints definition


I want to hide the definition of endpoints in a WordPress rest api... in the case of https://www.wpwhitesecurity.com/wp-json I want to return a 404 or an empty array, but not the list of endpoints of the site.

Some idea?

Thanks!


Solution

  • From version 4.4.0 exists the hook rest_index, the documentation in https://developer.wordpress.org/reference/hooks/rest_index/ describes :

    This contains the data describing the API. This includes information about supported authentication schemes, supported namespaces, routes available on the API, and a small amount of data about the site.

    The next code is working perfectly as I needed :

    function my_site_rest_index( $response ){
        return array();
    }
    add_filter('rest_index', 'my_site_rest_index');