-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REST API Support #334
REST API Support #334
Changes from 63 commits
17d8d6b
9d3a7ed
1b0c34f
abe47ce
0cc0334
55caf4f
5ed568f
bf08818
efb528f
271bce4
2fb2aee
58e513a
fbd7f59
f1a5ce9
ccf4abb
aa2a019
bc5efce
df8a93f
a4e64d1
184498c
34b23ff
d570076
41b13b5
b6903ed
84af809
2f9f388
cd2a9c0
2d9c93e
f291d0b
28ef797
da5f9e4
8e3b5a8
4b72026
f5973e3
cb616e4
326f1f0
af7397b
b4d93b0
c88fff7
1b16fae
9d75b23
ed08ddd
62a2186
f1d462d
eacccc2
d35879f
d691693
048f6e6
fafa22b
a4689d5
a3b08d7
92d202f
ab0c76b
42c1409
deeed3f
67a3ccc
248176c
d1123e4
8d2dd44
b0fef6e
65ae179
311e344
0c4599a
cd1a741
aefface
a0c360a
b78ced2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
This is the documentation support for the REST API feature. | ||
|
||
Route | Method | Description | ||
-------- | --------------- | ---------- | ||
/**authors** | GET | Search for available authors. | ||
/**posts**/`:post_id`/**authors** | GET | Get all authors from a post | ||
/**posts**/`:post_id`/**authors** | PUT | Appends a new author to a post | ||
/**posts**/`:post_id`/**authors**/`:author_id` | DELETE | Removes an author from a post | ||
/**guests** | GET | Lists of filters all the currently available guests | ||
/**guests** | POST | Creates a new guest | ||
/**guests**/`:guest_id` | PUT | Updates a new guest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably updates an existing guest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I'm going to correct this too. |
||
/**guests**/`:guest_id` | DELETE | Deletes a guest | ||
|
||
## Authors | ||
This routes allows searching for authors. | ||
|
||
### `GET` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/authors` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`q` | String | :white_check_mark: | Query parameter | ||
|
||
#### Response | ||
``` | ||
{ | ||
"authors": [ | ||
{ | ||
"id": 3, | ||
"display_name": "Dummy", | ||
"user_email": "dummy@gmail.com", | ||
"user_nicename": "dummy1" | ||
}, | ||
{ | ||
"id": 4, | ||
"display_name": "dummy2", | ||
"user_email": "dummy2@gmail.com", | ||
"user_nicename": "dummy2" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
|
||
## Posts | ||
|
||
Add, appends or remove a group of authors to an existing post. | ||
|
||
### `GET` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/posts/<post_id>/authors` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`post_id` | Int | | The post unique id. | ||
|
||
#### Response | ||
``` | ||
{ | ||
"authors": [ | ||
{ | ||
"id": 3, | ||
"display_name": "Dummy", | ||
"user_nicename": "dummy1" | ||
}, | ||
{ | ||
"id": 4, | ||
"display_name": "dummy2", | ||
"user_nicename": "dummy2" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### `PUT` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/posts/<post_id>/authors` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`coauthors` | Array | :white_check_mark: | An array of authors usernames. | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": 3, | ||
"display_name": "Dummy", | ||
"user_nicename": "dummy1" | ||
} | ||
] | ||
``` | ||
|
||
### `DELETE` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/posts/<post_id>/authors/<coauthor_id>` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`post_id` | Int | :white_check_mark: | Post id | ||
`author_id` | Int | :white_check_mark: | Author id to delete from post | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": 3, | ||
"display_name": "Dummy", | ||
"user_nicename": "dummy1" | ||
} | ||
] | ||
``` | ||
|
||
## Guests | ||
|
||
Creates, updates or removes a guest author. | ||
|
||
### `GET` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/guests` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`q` | String | :white_check_mark: | If filled, narrows the search by the `user_nicename` | ||
|
||
### `POST` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/guests` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`display_name` | String | :white_check_mark: | Display name | ||
`user_login` | String | :white_check_mark: | User login, must be unique to guests. | ||
`user_email` | String | :white_check_mark: | User email | ||
`first_name` | String | | First name | ||
`last_name` | String | | Last name | ||
`linked_account` | String | | Links the guest account to an existing account | ||
`website` | String | | User website | ||
`aim` | String | | AIM | ||
`yahooim` | String | | Yahoo IM | ||
`jabber` | String | | Jabber | ||
`Description` | String | | A text Description | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": "172", | ||
"display_name": "foo", | ||
"first_name": "Foo", | ||
"last_name": "Bar", | ||
"user_email": "foobar@gmail.com", | ||
"linked_account": "", | ||
"website": "http://www.foobar.org/", | ||
"aim": "testaim", | ||
"yahooim": "testyaho2", | ||
"jabber": "testjabber", | ||
"description": "Some simple description.", | ||
"user_nicename": "foobar", | ||
} | ||
] | ||
``` | ||
### `GET` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/guests/<guest_id>` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`ID` | Integer | :white_check_mark: | Guest Id | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": "172", | ||
"display_name": "foo", | ||
"first_name": "Foo", | ||
"last_name": "Bar", | ||
"user_email": "foobar@gmail.com", | ||
"linked_account": "", | ||
"website": "http://www.foobar.org/", | ||
"aim": "testaim", | ||
"yahooim": "testyaho2", | ||
"jabber": "testjabber", | ||
"description": "Some simple description.", | ||
"user_nicename": "foobar", | ||
} | ||
] | ||
``` | ||
|
||
### `PUT` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/guests/<guest_id>` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`display_name` | String | | Display name | ||
`user_email` | String | | User email | ||
`first_name` | String | | First name | ||
`last_name` | String | | Last name | ||
`linked_account` | String | | Links the guest account to an existing account | ||
`website` | String | | User website | ||
`aim` | String | | AIM | ||
`yahooim` | String | | Yahoo IM | ||
`jabber` | String | | Jabber | ||
`Description` | String | | A text Description | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": "172", | ||
"display_name": "foo", | ||
"first_name": "John", | ||
"last_name": "Bar", | ||
"user_email": "foobar@gmail.com", | ||
"linked_account": "", | ||
"website": "http://www.foobar.org/", | ||
"aim": "testaim", | ||
"yahooim": "testyaho2", | ||
"jabber": "testjabber", | ||
"description": "New description.", | ||
"user_nicename": "foobar", | ||
} | ||
] | ||
``` | ||
|
||
### `DELETE` | ||
|
||
**URL** : `http://<domain>/wp-json/coauthors/v1/guests/<guest_id>` | ||
|
||
**Requires Authentication**: :lock: | ||
|
||
#### Parameters | ||
|
||
Name | Type | Required | Description | ||
------------ | ------------- | ------------- | ------------- | ||
`ID` | Integer | :white_check_mark: | Guest Id | ||
|
||
#### Response | ||
``` | ||
[ | ||
{ | ||
"id": "172", | ||
"display_name": "foo", | ||
"first_name": "John", | ||
"last_name": "Bar", | ||
"user_email": "foobar@gmail.com", | ||
"linked_account": "", | ||
"website": "http://www.foobar.org/", | ||
"aim": "testaim", | ||
"yahooim": "testyaho2", | ||
"jabber": "testjabber", | ||
"description": "New description.", | ||
"user_nicename": "foobar", | ||
} | ||
] | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
|
||
require_once( dirname( __FILE__ ) . '/php/class-coauthors-template-filters.php' ); | ||
|
||
require_once( dirname( __FILE__ ) . '/php/api/boot.php' ); | ||
|
||
if ( defined( 'WP_CLI' ) && WP_CLI ) { | ||
require_once( dirname( __FILE__ ) . '/php/class-wp-cli.php' ); | ||
} | ||
|
@@ -114,7 +116,6 @@ function __construct() { | |
|
||
// Support infinite scroll for Guest Authors on author pages | ||
add_filter( 'infinite_scroll_js_settings', array( $this, 'filter_infinite_scroll_js_settings' ), 10, 2 ); | ||
|
||
} | ||
|
||
function coauthors_plus() { | ||
|
@@ -126,7 +127,6 @@ function coauthors_plus() { | |
* and the custom post type to store our author data | ||
*/ | ||
public function action_init() { | ||
|
||
// Allow Co-Authors Plus to be easily translated | ||
load_plugin_textdomain( 'co-authors-plus', null, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); | ||
|
||
|
@@ -802,7 +802,6 @@ public function add_coauthors( $post_id, $coauthors, $append = false ) { | |
global $current_user, $wpdb; | ||
|
||
$post_id = (int) $post_id; | ||
$insert = false; | ||
|
||
// Best way to persist order | ||
if ( $append ) { | ||
|
@@ -822,6 +821,9 @@ public function add_coauthors( $post_id, $coauthors, $append = false ) { | |
foreach ( $coauthors as &$author_name ) { | ||
|
||
$author = $this->get_coauthor_by( 'user_nicename', $author_name ); | ||
if ( !$author ) { | ||
continue; | ||
} | ||
$coauthor_objects[] = $author; | ||
$term = $this->update_author_term( $author ); | ||
$author_name = $term->slug; | ||
|
@@ -947,24 +949,27 @@ function filter_count_user_posts( $count, $user_id ) { | |
/** | ||
* Checks to see if the current user can set authors or not | ||
*/ | ||
function current_user_can_set_authors( $post = null ) { | ||
function current_user_can_set_authors( $post = null, $is_api_request = false ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In 271bce4, you mentioned that you added this |
||
global $typenow; | ||
|
||
if ( ! $post ) { | ||
$post = get_post(); | ||
if ( ! $post ) { | ||
if ( ! $post && ! $is_api_request) { | ||
return false; | ||
} | ||
} | ||
|
||
$post_type = $post->post_type; | ||
if ( $post ) { | ||
$post_type = $post->post_type; | ||
|
||
// TODO: need to fix this; shouldn't just say no if don't have post_type | ||
if ( ! $post_type ) { | ||
return false; | ||
// TODO: need to fix this; shouldn't just say no if don't have post_type | ||
if ( ! $post_type ) { | ||
return false; | ||
} | ||
|
||
$post_type_object = get_post_type_object( $post_type ); | ||
} | ||
|
||
$post_type_object = get_post_type_object( $post_type ); | ||
$current_user = wp_get_current_user(); | ||
if ( ! $current_user ) { | ||
return false; | ||
|
@@ -1463,6 +1468,7 @@ public function filter_jetpack_open_graph_tags( $og_tags, $image_dimensions ) { | |
// Send back the updated Open Graph Tags | ||
return apply_filters( 'coauthors_open_graph_tags', $og_tags ); | ||
} | ||
|
||
} | ||
|
||
global $coauthors_plus; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you clarify this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "Lists OR filters current available guests". It's a typo. Going to update it the docs.