WOOF :: json_get( String $url, Boolean $assoc = false, String $cache = false, Object $req = null )

Returns:

  • Object The JSON object if the request is successful and the assoc argument is false.
  • Array An associative array representing the JSON output if the request is successful and assoc is true.
  • Array An array of objects or associative arrays, if the json output has an array at the root level.
  • Boolean false if the JSON could not be retrieved.

Retrieves a json object or associative array by requesting a JSON string from a remote URL and decoding it. This method can also cache the result of the request using the WordPress transients API, accepting the same duration string accepted by the WOOF::cache.

Example:

Parameters:

  • String $url

    The URL to retrieve JSON from.

  • Boolean $assoc = false

    Whether to convert the JSON string to an assocative array (true) or an object (false).

  • String $cache = false

    For setting a value only. Either an:
    * integer number of seconds to store the transient
    * a string describing the time period, as parsed by the WOOF::seconds function (see related methods).
    * OR false if you do not wish to cache the request. This may be appropriate if the JSON API already caches its output.

  • Object $req = null

    An output parameter, allowing you to capture the request object created by the wp_remote_get method (which is used to request the JSON string). This will only be populated if a request is required, and may be useful for debugging purposes to discover errors.

Latest From the Blog

MasterPress 1.1.4 now available

MasterPress 1.1.4 is now available. This release contains an important compatibility fix for WordPress 4.5 to allow correct detection of the taxonomy term editing screen. Without this fix, any custom fields you have attached to custom taxonomies will not be shown at all in the editing form. Note also that MasterPress will still detect the edit screen correctly in… 

Plugin Requirements

MasterPress requires a minimum of WordPress version 3.4, MySQL 5, and PHP version 5.2.4.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the WordPress.com hosted service.

Traversal