Skip to content
Create a gist now

Instantly share code, notes, and snippets.

A hack that let's the Wordpress JSON-API plug-in play nicely with Co-authors Plus
diff --git a/wp-content/plugins/json-api/models/post.php b/wp-content/plugins/json-api/models/post.php
index 4a8c492..c5b28cb 100644
--- a/wp-content/plugins/json-api/models/post.php
+++ b/wp-content/plugins/json-api/models/post.php
@@ -18,7 +18,6 @@ class JSON_API_Post {
var $modified; // String (modified by date_format query var)
var $categories; // Array of objects
var $tags; // Array of objects
- var $author; // Object
var $comments; // Array of objects
var $attachments; // Array of objects
var $comment_count; // Integer
@@ -206,10 +205,21 @@ class JSON_API_Post {
function set_author_value($author_id) {
global $json_api;
- if ($json_api->include_value('author')) {
- $this->author = new JSON_API_Author($author_id);
+ if ($json_api->include_value('author') || $json_api->include_value('authors')) {
+ // Check for the Coauthors Plus plugin's function
+ if ( function_exists('get_coauthors') ) {
+ $this->authors = array();
+ if ( $wp_authors = get_coauthors() ) {
+ foreach ($wp_authors as $wp_author) {
+ $this->authors[] = new JSON_API_Author( $wp_author->ID );
+ }
+ }
+ }
+ else {
+ $this->author = new JSON_API_Author($author_id);
+ }
} else {
- unset($this->author);
+ unset($this->author, $this->authors);
}
}
@BrekiTomasson

Been trying to get this to work with v2 of the WP API that's being worked on now while moving this to a separate plugin (or function) of its own, but realizing the task is above my skill. Any chance you could help out with something like that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.