Skip to content

Instantly share code, notes, and snippets.

@phillipadsmith
Created November 21, 2012 17:47
Show Gist options
  • Save phillipadsmith/4126431 to your computer and use it in GitHub Desktop.
Save phillipadsmith/4126431 to your computer and use it in GitHub Desktop.
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
Copy link

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?

@xiffy
Copy link

xiffy commented Feb 9, 2017

while researching a unauthorized post alteration via the json-api i stumbled on your code snippet and realised i was using co-authors as well, but alas, the ancient json api that was available via a plugin https://wordpress.org/plugins/json-api/ but i'll make a note to llook at your code. My first thought was, why not either a filter or action which is adhered by co-authors plus?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment