WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. hermanvandermaas
    Member
    Posted 2 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"
    }

    Changes:
    - 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':

    <?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;
    	}
    
        }
    
    }
    
    ?>

    http://wordpress.org/extend/plugins/json-api/

  2. hermanvandermaas
    Member
    Posted 2 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:
    http://www.waywayway.nl/bin/wp-content/upLoads/json-api.zip

  3. hermanvandermaas
    Member
    Posted 2 years ago #

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

  4. pimschaaf
    Member
    Posted 2 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)

    http://example.org/?json=options.get_options&options=optionsframework,name

    works straight out of the box.

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic