mircobabini
10/8/2014 - 9:39 AM

JSON_API_Controller_Helper for JSON Api plugin for WordPress

JSON_API_Controller_Helper for JSON Api plugin for WordPress

<?php
class JSON_API_Controller_Helper {
	/**
	 * @global json_api $json_api
	 * @return array
	 */
	protected function _get () {
		global $json_api;
		$args = func_get_args ();
		
		if (func_num_args () > 1) {
			$_params = $json_api->query->get ($args);

		} else {
			$args = array_shift ($args);
			foreach ($args as $param => $list) {
				list ($value, $default) = $list;
				
				if ($value === null) {

					$values = $json_api->query->get (array ($param));
					if (sizeof ($values) > 0) {

						$value = array_shift ($values);
						if (empty ($value)) {
							$value = $default;
						}

					} else {
						$value = $default;
					}
				}
				
				$_params[ $param ] = $value;
			}
		}
		
		return $_params;

	}
	
	protected function _error ($message) {
		global $json_api;
		$json_api->error ($message);
	}
}