Reputation: 1124
I'd like to try to use wordpress as backend only solution. I'd like to use wordpress json api. So I looked at what it offers. It's quite complete, but I want to remove some functionality. For example There's this route :
"\/wp\/v2\/posts\/(?P<id>[\\d]+)"
I'd like to limit it to GET. I'd like to completely remove some endpoints (like users/* or settings) and remove some methods inside endpoints.
I stumbled upon this https://github.com/WP-API/WP-API/issues/2338. I understand how it works, but I don't get where I can use this code, do I have to make a plugin of my own for that ? Also they don't talk about limiting methods, only endpoints, everything or just the post api.
well, I want it to become more of a public json api. How can I do that ?
Upvotes: 1
Views: 2336
Reputation: 1124
I didnt think about using .htaccess, it was then trivial.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^wp-json/wp/v2/users.*$ - [R=404]
RewriteRule ^wp-json/wp/v2/settings.*$ - [R=404]
RewriteRule ^wp-json/wp/v2/statuses.*$ - [R=404]
RewriteRule ^wp-json/wp/v2/comments.*$ - [R=404]
RewriteCond %{REQUEST_METHOD} !GET
RewriteRule ^wp-json/.*$ - [R=404]
</IfModule>
Allows me to prevent from getting users, settings, statuses and comments at all, the two last lines prevents from using anything but GET.
Upvotes: 2