[Plugin: JSON API] exclude doesn't work while include does
-
The exclude option doesn’t seem to work, while include does.
For example, /api/get_recent_posts/?page=1&count=1&dev=1&include=date works fine and returns just the date for each object, but /api/get_recent_posts/?page=1&count=1&dev=1&exclude=date still returns date along with the rest of the fields.
The problem lies in this code:
function setup() { global $json_api; $this->include_values = array(); if ($json_api->query->include) { $this->include_values = explode(',', $json_api->query->include); } if ($json_api->query->exclude) { $exclude = explode(',', $json_api->query->exclude); $this->include_values = array_diff($this->include_values, $exclude); } }
For includes, it works fine, but for excludes, it tries to subtract from an empty array, getting nada, and then this code:
function is_value_included($key) { if (empty($this->include_values)) { return true; } else { return in_array($key, $this->include_values); } }
forces everything to be included.
I’ve thought about the possible solutions and the only ones that come to mind are: either maintain a comprehensive list of includes and then remove whatever is in excludes (not so elegant), or maintain a separate exclude option and have the is_value_included() function check this list in addition to the inclusion list.
- The topic ‘[Plugin: JSON API] exclude doesn't work while include does’ is closed to new replies.