Wordpress has an awesome REST API interface. https://developer.wordpress.org/rest-api/reference/
But the content in wp_options table seems to be missing REST support. Is there a way to access the content in wp_otions table as REST endpoint via plugins?. Thanks.
There is the
settings
endpoint, but it only contains a surprisingly limited amount of them it seems.This is something you could very easily do yourself though. I'm not sure if any plugins do it, but I also wouldn't recommend a plugin for something that can be done with less than 20 lines of code.
You just need to register a route using
register_rest_route()
on therest_api_init
hook, and pass it a callback function. You can drop code like this in yourfunctions.php
file or create a Must Use Plugin and drop the code in there, either way.The above will give you access to whatever option you want by accessing:
I went ahead and dropped an example on a site of mine:
https://xhynk.com/content-mask/wp-json/my-custom-route/v1/opt/?option_name=blogname https://xhynk.com/content-mask/wp-json/my-custom-route/v1/opt/?option_name=siteurl
However, this will potentially expose anything in your options table. I went ahead and commented out the
permission_callback
so that any person, signed in or not, can access it. However, I also added a check like this:You can see that
home
will fail: https://xhynk.com/content-mask/wp-json/my-custom-route/v1/opt/?option_name=homeI would recommend adding in a valid array of options, or using the
permission_callback
in order to lock it down a bit. You could even have an access key instead, and keep that key secret. Either way, be aware of the security implications of exposing your entirewp_options
table, and take some sort of preventative measure!