Added a custom controller for querying WordPress options (4 posts)

  1. hermanvandermaas
    Posted 4 years ago #

    Hello dphiffer, thank you for writing this great plugin!
    I added a new controller that I needed for a project, for querying the WordPress options, for example the blogtitle. It can be downloaded at http://waywayway.nl/easyapp/wp-content/uploads/2012/05/json-api.1.0.7-plus-WPoptions-controller.zip

    This controller must be activated in the WordPress dashboard: Settings > JSON API.

    Example usage:

    This URL: http://example.org/?json=options.get_options&options=blogname,show_on_front

    For a blog with blogname 'My blog name' that has a page as the front page, not the usual list of posts, this outputs:

      "status": "ok",
      "blogname": "My blog name",
      "show_on_front": "page"

    - Added a file 'options.php' in folder 'controllers'.
    - Changed the plugin name in 'json-api.php' to 'Plugin Name: JSON API - with WordPress options by http://waywayway.nl', to make clear in the WordPress dashboard that the plugin is extended with a custom controller.

    Content of 'options.php':

    class JSON_API_options_Controller {
    	// Get WordPress option settings from the options table, e.g. the blog name, see http://codex.wordpress.org/Option_Reference
        public function get_options() {
            global $json_api;
            $optionstring = $json_api->query->options;
    	$optionarrayindexed = explode(',', $optionstring);
    	foreach ($optionarrayindexed as $option) {
    		$optionarrayassociative["$option"] = get_option($option);
    	if ($optionstring) {
    	        return $optionarrayassociative;
    	} else {
    		$json_api->error("Include 'options' var in your request, options comma separated. See for a list of options: http://codex.wordpress.org/Option_Reference");
    		return null;


  2. hermanvandermaas
    Posted 4 years ago #

    And here is a download link to a file "json-api.zip", for direct installation of the plugin version 1.7 with WP options controller in the WordPress dashboard. Download the .zip file to your computer, log into the WP dashboard, go to Plugins > Add new > upload .zip file and choose the downloaded file. Then click activate plugin and in the dashboard go to Settings > JSON API, for additional settings.

    Download link for direct plugin installation:

  3. hermanvandermaas
    Posted 4 years ago #

    A list of the WordPress options table is here: http://codex.wordpress.org/Option_Reference

  4. pimschaaf
    Posted 3 years ago #

    Thanks Herman,

    A nice addition to this great plugin. I'm planning to use it in combination with the Options Framework plugin (http://wptheming.com/options-framework-plugin)


    works straight out of the box.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic