function format_taxonomy($taxonomy, $taxonomy_type, $context)
{
// Permissions
switch ($context) {
case 'edit':
$tax = get_taxonomy($taxonomy_type);
if (!current_user_can($tax->cap->edit_terms)) {
return new WP_Error('unauthorized', 'User cannot edit taxonomy', 403);
}
break;
case 'display':
if (-1 == get_option('blog_public') && !current_user_can('read')) {
return new WP_Error('unauthorized', 'User cannot view taxonomy', 403);
}
break;
default:
return new WP_Error('invalid_context', 'Invalid API CONTEXT', 400);
}
$response = array();
$response['ID'] = (int) $taxonomy->term_id;
$response['name'] = (string) $taxonomy->name;
$response['slug'] = (string) $taxonomy->slug;
$response['description'] = (string) $taxonomy->description;
$response['post_count'] = (int) $taxonomy->count;
if (is_taxonomy_hierarchical($taxonomy_type)) {
$response['parent'] = (int) $taxonomy->parent;
}
$response['meta'] = (object) array('links' => (object) array('self' => (string) $this->links->get_taxonomy_link($this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type), 'help' => (string) $this->links->get_taxonomy_link($this->api->get_blog_id_for_output(), $taxonomy->slug, $taxonomy_type, 'help'), 'site' => (string) $this->links->get_site_link($this->api->get_blog_id_for_output())));
return (object) $response;
}