Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 737
Estuardo Estrada Avatar asked Oct 19 '25 12:10

Estuardo Estrada


1 Answers

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');
like image 198
Estuardo Estrada Avatar answered Oct 22 '25 05:10

Estuardo Estrada



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!