Version Description
Download this release
Release Info
Developer | danielbachhuber |
Plugin | WordPress REST API (Version 2) |
Version | 2.0-beta7.1 |
Comparing to | |
See all releases |
Code changes from version 2.0-beta8.1 to 2.0-beta7.1
- CHANGELOG.md +1 -37
- lib/endpoints/class-wp-rest-attachments-controller.php +0 -19
- lib/endpoints/class-wp-rest-meta-controller.php +1 -1
- lib/endpoints/class-wp-rest-posts-controller.php +22 -26
- lib/endpoints/class-wp-rest-terms-controller.php +2 -5
- lib/endpoints/class-wp-rest-users-controller.php +0 -2
- plugin.php +1 -1
- readme.txt +2 -38
CHANGELOG.md
CHANGED
@@ -1,47 +1,11 @@
|
|
1 |
# Changelog
|
2 |
|
3 |
-
## 2.0 Beta
|
4 |
|
5 |
- Ensure media of private posts are private too.
|
6 |
|
7 |
Reported by @danielbachhuber on 2016-01-08.
|
8 |
|
9 |
-
## 2.0 Beta 8.0
|
10 |
-
|
11 |
-
- Prevent fatals when uploading attachment by including admin utilities.
|
12 |
-
|
13 |
-
(props @danielbachhuber, [#1756](https://github.com/WP-API/WP-API/pull/1756))
|
14 |
-
|
15 |
-
- Return 201 status code when creating a term.
|
16 |
-
|
17 |
-
(props @danielbachhuber, [#1753](https://github.com/WP-API/WP-API/pull/1753))
|
18 |
-
|
19 |
-
- Don't permit requesting terms cross routes.
|
20 |
-
|
21 |
-
Clients should only be able to request categories from the category route, and tags from the tag route.
|
22 |
-
|
23 |
-
(props @danielbachhuber, [#1764](https://github.com/WP-API/WP-API/pull/1764))
|
24 |
-
|
25 |
-
- Set `fields=>id` when using `WP_User_Query` to fix large memory usage
|
26 |
-
|
27 |
-
(props @joehoyle, [#1770](https://github.com/WP-API/WP-API/pull/1770))
|
28 |
-
|
29 |
-
- Fix Post `_link` to attached attachments.
|
30 |
-
|
31 |
-
(props @danielbachhuber, [#1777](https://github.com/WP-API/WP-API/pull/1777))
|
32 |
-
|
33 |
-
- Add support for getting a post with a custom public status.
|
34 |
-
|
35 |
-
(props @danielbachhuber, [#1765](https://github.com/WP-API/WP-API/pull/1765))
|
36 |
-
|
37 |
-
- Ensure post content doesn't get double-slashed on update.
|
38 |
-
|
39 |
-
(props @joehoyle, [#1772](https://github.com/WP-API/WP-API/pull/1772))
|
40 |
-
|
41 |
-
- Change 'int' to 'integer' for `WP_REST_Controller::validate_schema_property()`
|
42 |
-
|
43 |
-
(props @wpsmith, [#1759](https://github.com/WP-API/WP-API/pull/1759))
|
44 |
-
|
45 |
## 2.0 Beta 7.0
|
46 |
|
47 |
- Sync infrastructure from WordPress core as of r35691.
|
1 |
# Changelog
|
2 |
|
3 |
+
## 2.0 Beta 7.1
|
4 |
|
5 |
- Ensure media of private posts are private too.
|
6 |
|
7 |
Reported by @danielbachhuber on 2016-01-08.
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
## 2.0 Beta 7.0
|
10 |
|
11 |
- Sync infrastructure from WordPress core as of r35691.
|
lib/endpoints/class-wp-rest-attachments-controller.php
CHANGED
@@ -330,9 +330,6 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|
330 |
// Get the content-type
|
331 |
$type = array_shift( $headers['content_type'] );
|
332 |
|
333 |
-
/** Include admin functions to get access to wp_tempnam() and wp_handle_sideload() */
|
334 |
-
require_once ABSPATH . 'wp-admin/includes/admin.php';
|
335 |
-
|
336 |
// Save the file
|
337 |
$tmpfname = wp_tempnam( $filename );
|
338 |
|
@@ -367,22 +364,6 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|
367 |
return $sideloaded;
|
368 |
}
|
369 |
|
370 |
-
/**
|
371 |
-
* Get the query params for collections of attachments.
|
372 |
-
*
|
373 |
-
* @return array
|
374 |
-
*/
|
375 |
-
public function get_collection_params() {
|
376 |
-
$params = parent::get_collection_params();
|
377 |
-
$params['parent'] = array(
|
378 |
-
'description' => 'Limit results to attachments from a specified parent.',
|
379 |
-
'type' => 'integer',
|
380 |
-
'default' => null,
|
381 |
-
'sanitize_callback' => 'absint',
|
382 |
-
);
|
383 |
-
return $params;
|
384 |
-
}
|
385 |
-
|
386 |
/**
|
387 |
* Handle an upload via multipart/form-data ($_FILES)
|
388 |
*
|
330 |
// Get the content-type
|
331 |
$type = array_shift( $headers['content_type'] );
|
332 |
|
|
|
|
|
|
|
333 |
// Save the file
|
334 |
$tmpfname = wp_tempnam( $filename );
|
335 |
|
364 |
return $sideloaded;
|
365 |
}
|
366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
/**
|
368 |
* Handle an upload via multipart/form-data ($_FILES)
|
369 |
*
|
lib/endpoints/class-wp-rest-meta-controller.php
CHANGED
@@ -103,7 +103,7 @@ abstract class WP_REST_Meta_Controller extends WP_REST_Controller {
|
|
103 |
'properties' => array(
|
104 |
'id' => array(
|
105 |
'description' => 'Unique identifier for the object.',
|
106 |
-
'type' => '
|
107 |
'context' => array( 'edit' ),
|
108 |
'readonly' => true,
|
109 |
),
|
103 |
'properties' => array(
|
104 |
'id' => array(
|
105 |
'description' => 'Unique identifier for the object.',
|
106 |
+
'type' => 'int',
|
107 |
'context' => array( 'edit' ),
|
108 |
'readonly' => true,
|
109 |
),
|
lib/endpoints/class-wp-rest-posts-controller.php
CHANGED
@@ -15,7 +15,20 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
15 |
|
16 |
$base = $this->get_post_type_base( $this->post_type );
|
17 |
|
18 |
-
$posts_args =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
register_rest_route( 'wp/v2', '/' . $base, array(
|
21 |
array(
|
@@ -75,7 +88,6 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
75 |
$args = array();
|
76 |
$args['paged'] = $request['page'];
|
77 |
$args['posts_per_page'] = $request['per_page'];
|
78 |
-
$args['post_parent'] = $request['parent'];
|
79 |
|
80 |
if ( is_array( $request['filter'] ) ) {
|
81 |
$args = array_merge( $args, $request['filter'] );
|
@@ -251,8 +263,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
251 |
if ( is_wp_error( $post ) ) {
|
252 |
return $post;
|
253 |
}
|
254 |
-
|
255 |
-
$post_id = wp_update_post(
|
256 |
if ( is_wp_error( $post_id ) ) {
|
257 |
if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
|
258 |
$post_id->add_data( array( 'status' => 500 ) );
|
@@ -935,11 +947,6 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
935 |
return true;
|
936 |
}
|
937 |
|
938 |
-
$post_status_obj = get_post_status_object( $post->post_status );
|
939 |
-
if ( $post_status_obj && $post_status_obj->public ) {
|
940 |
-
return true;
|
941 |
-
}
|
942 |
-
|
943 |
// Can we read the parent if we're inheriting?
|
944 |
if ( 'inherit' === $post->post_status && $post->post_parent > 0 ) {
|
945 |
$parent = get_post( $post->post_parent );
|
@@ -1202,22 +1209,22 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
1202 |
// If we have a featured image, add that.
|
1203 |
if ( $featured_image = get_post_thumbnail_id( $post->ID ) ) {
|
1204 |
$image_url = rest_url( 'wp/v2/media/' . $featured_image );
|
1205 |
-
$links['
|
1206 |
'href' => $image_url,
|
1207 |
'embeddable' => true,
|
1208 |
);
|
1209 |
}
|
1210 |
if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) {
|
1211 |
$attachments_url = rest_url( 'wp/v2/media' );
|
1212 |
-
$attachments_url = add_query_arg( '
|
1213 |
-
$links['
|
1214 |
'href' => $attachments_url,
|
1215 |
);
|
1216 |
}
|
1217 |
|
1218 |
$taxonomies = get_object_taxonomies( $post->post_type );
|
1219 |
if ( ! empty( $taxonomies ) ) {
|
1220 |
-
$links['
|
1221 |
|
1222 |
foreach ( $taxonomies as $tax ) {
|
1223 |
$taxonomy_obj = get_taxonomy( $tax );
|
@@ -1229,7 +1236,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
1229 |
$tax_base = ! empty( $taxonomy_obj->rest_base ) ? $taxonomy_obj->rest_base : $tax;
|
1230 |
$terms_url = rest_url( trailingslashit( $base ) . $post->ID . '/terms/' . $tax_base );
|
1231 |
|
1232 |
-
$links['
|
1233 |
'href' => $terms_url,
|
1234 |
'taxonomy' => $tax,
|
1235 |
'embeddable' => true,
|
@@ -1238,7 +1245,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
1238 |
}
|
1239 |
|
1240 |
if ( post_type_supports( $post->post_type, 'custom-fields' ) ) {
|
1241 |
-
$links['
|
1242 |
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/meta' ),
|
1243 |
'embeddable' => true,
|
1244 |
);
|
@@ -1534,15 +1541,4 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|
1534 |
return $this->add_additional_fields_schema( $schema );
|
1535 |
}
|
1536 |
|
1537 |
-
/**
|
1538 |
-
* Get the query params for collections of attachments.
|
1539 |
-
*
|
1540 |
-
* @return array
|
1541 |
-
*/
|
1542 |
-
public function get_collection_params() {
|
1543 |
-
$params = parent::get_collection_params();
|
1544 |
-
$params['filter'] = array();
|
1545 |
-
return $params;
|
1546 |
-
}
|
1547 |
-
|
1548 |
}
|
15 |
|
16 |
$base = $this->get_post_type_base( $this->post_type );
|
17 |
|
18 |
+
$posts_args = array(
|
19 |
+
'context' => array(
|
20 |
+
'default' => 'view',
|
21 |
+
),
|
22 |
+
'page' => array(
|
23 |
+
'default' => 1,
|
24 |
+
'sanitize_callback' => 'absint',
|
25 |
+
),
|
26 |
+
'per_page' => array(
|
27 |
+
'default' => 10,
|
28 |
+
'sanitize_callback' => 'absint',
|
29 |
+
),
|
30 |
+
'filter' => array(),
|
31 |
+
);
|
32 |
|
33 |
register_rest_route( 'wp/v2', '/' . $base, array(
|
34 |
array(
|
88 |
$args = array();
|
89 |
$args['paged'] = $request['page'];
|
90 |
$args['posts_per_page'] = $request['per_page'];
|
|
|
91 |
|
92 |
if ( is_array( $request['filter'] ) ) {
|
93 |
$args = array_merge( $args, $request['filter'] );
|
263 |
if ( is_wp_error( $post ) ) {
|
264 |
return $post;
|
265 |
}
|
266 |
+
|
267 |
+
$post_id = wp_update_post( $post, true );
|
268 |
if ( is_wp_error( $post_id ) ) {
|
269 |
if ( in_array( $post_id->get_error_code(), array( 'db_update_error' ) ) ) {
|
270 |
$post_id->add_data( array( 'status' => 500 ) );
|
947 |
return true;
|
948 |
}
|
949 |
|
|
|
|
|
|
|
|
|
|
|
950 |
// Can we read the parent if we're inheriting?
|
951 |
if ( 'inherit' === $post->post_status && $post->post_parent > 0 ) {
|
952 |
$parent = get_post( $post->post_parent );
|
1209 |
// If we have a featured image, add that.
|
1210 |
if ( $featured_image = get_post_thumbnail_id( $post->ID ) ) {
|
1211 |
$image_url = rest_url( 'wp/v2/media/' . $featured_image );
|
1212 |
+
$links['http://api.w.org/featuredmedia'] = array(
|
1213 |
'href' => $image_url,
|
1214 |
'embeddable' => true,
|
1215 |
);
|
1216 |
}
|
1217 |
if ( ! in_array( $post->post_type, array( 'attachment', 'nav_menu_item', 'revision' ) ) ) {
|
1218 |
$attachments_url = rest_url( 'wp/v2/media' );
|
1219 |
+
$attachments_url = add_query_arg( 'post_parent', $post->ID, $attachments_url );
|
1220 |
+
$links['http://api.w.org/attachment'] = array(
|
1221 |
'href' => $attachments_url,
|
1222 |
);
|
1223 |
}
|
1224 |
|
1225 |
$taxonomies = get_object_taxonomies( $post->post_type );
|
1226 |
if ( ! empty( $taxonomies ) ) {
|
1227 |
+
$links['http://api.w.org/term'] = array();
|
1228 |
|
1229 |
foreach ( $taxonomies as $tax ) {
|
1230 |
$taxonomy_obj = get_taxonomy( $tax );
|
1236 |
$tax_base = ! empty( $taxonomy_obj->rest_base ) ? $taxonomy_obj->rest_base : $tax;
|
1237 |
$terms_url = rest_url( trailingslashit( $base ) . $post->ID . '/terms/' . $tax_base );
|
1238 |
|
1239 |
+
$links['http://api.w.org/term'][] = array(
|
1240 |
'href' => $terms_url,
|
1241 |
'taxonomy' => $tax,
|
1242 |
'embeddable' => true,
|
1245 |
}
|
1246 |
|
1247 |
if ( post_type_supports( $post->post_type, 'custom-fields' ) ) {
|
1248 |
+
$links['http://api.w.org/meta'] = array(
|
1249 |
'href' => rest_url( trailingslashit( $base ) . $post->ID . '/meta' ),
|
1250 |
'embeddable' => true,
|
1251 |
);
|
1541 |
return $this->add_additional_fields_schema( $schema );
|
1542 |
}
|
1543 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1544 |
}
|
lib/endpoints/class-wp-rest-terms-controller.php
CHANGED
@@ -138,7 +138,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|
138 |
public function get_item( $request ) {
|
139 |
|
140 |
$term = get_term_by( 'term_taxonomy_id', (int) $request['id'], $this->taxonomy );
|
141 |
-
if ( ! $term
|
142 |
return new WP_Error( 'rest_term_invalid', __( "Term doesn't exist." ), array( 'status' => 404 ) );
|
143 |
}
|
144 |
if ( is_wp_error( $term ) ) {
|
@@ -202,10 +202,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|
202 |
'id' => $term['term_taxonomy_id'],
|
203 |
) );
|
204 |
|
205 |
-
|
206 |
-
$response->set_status( 201 );
|
207 |
-
$response->header( 'Location', rest_url( '/wp/v2/terms/' . $this->get_taxonomy_base( $this->taxonomy ) . '/' . $term['term_taxonomy_id'] ) );
|
208 |
-
return $response;
|
209 |
}
|
210 |
|
211 |
/**
|
138 |
public function get_item( $request ) {
|
139 |
|
140 |
$term = get_term_by( 'term_taxonomy_id', (int) $request['id'], $this->taxonomy );
|
141 |
+
if ( ! $term ) {
|
142 |
return new WP_Error( 'rest_term_invalid', __( "Term doesn't exist." ), array( 'status' => 404 ) );
|
143 |
}
|
144 |
if ( is_wp_error( $term ) ) {
|
202 |
'id' => $term['term_taxonomy_id'],
|
203 |
) );
|
204 |
|
205 |
+
return rest_ensure_response( $response );
|
|
|
|
|
|
|
206 |
}
|
207 |
|
208 |
/**
|
lib/endpoints/class-wp-rest-users-controller.php
CHANGED
@@ -125,8 +125,6 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|
125 |
$response = rest_ensure_response( $users );
|
126 |
unset( $prepared_args['number'] );
|
127 |
unset( $prepared_args['offset'] );
|
128 |
-
$prepared_args['fields'] = 'ID';
|
129 |
-
|
130 |
$count_query = new WP_User_Query( $prepared_args );
|
131 |
$total_users = $count_query->get_total();
|
132 |
$response->header( 'X-WP-Total', (int) $total_users );
|
125 |
$response = rest_ensure_response( $users );
|
126 |
unset( $prepared_args['number'] );
|
127 |
unset( $prepared_args['offset'] );
|
|
|
|
|
128 |
$count_query = new WP_User_Query( $prepared_args );
|
129 |
$total_users = $count_query->get_total();
|
130 |
$response->header( 'X-WP-Total', (int) $total_users );
|
plugin.php
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
* Description: JSON-based REST API for WordPress, developed as part of GSoC 2013.
|
5 |
* Author: WP REST API Team
|
6 |
* Author URI: http://wp-api.org
|
7 |
-
* Version: 2.0-
|
8 |
* Plugin URI: https://github.com/WP-API/WP-API
|
9 |
* License: GPL2+
|
10 |
*/
|
4 |
* Description: JSON-based REST API for WordPress, developed as part of GSoC 2013.
|
5 |
* Author: WP REST API Team
|
6 |
* Author URI: http://wp-api.org
|
7 |
+
* Version: 2.0-beta7.1
|
8 |
* Plugin URI: https://github.com/WP-API/WP-API
|
9 |
* License: GPL2+
|
10 |
*/
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: rmccue, rachelbaker, danielbachhuber, joehoyle
|
|
3 |
Tags: json, rest, api, rest-api
|
4 |
Requires at least: 4.3
|
5 |
Tested up to: 4.4
|
6 |
-
Stable tag: 2.0-
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -36,48 +36,12 @@ For full-flavoured API support, you'll need to be using pretty permalinks to use
|
|
36 |
|
37 |
== Changelog ==
|
38 |
|
39 |
-
= 2.0 Beta
|
40 |
|
41 |
* Ensure media of private posts are private too.
|
42 |
|
43 |
Reported by @danielbachhuber on 2016-01-08.
|
44 |
|
45 |
-
= 2.0 Beta 8.0 =
|
46 |
-
|
47 |
-
* Prevent fatals when uploading attachment by including admin utilities.
|
48 |
-
|
49 |
-
(props @danielbachhuber, [#1756](https://github.com/WP-API/WP-API/pull/1756))
|
50 |
-
|
51 |
-
* Return 201 status code when creating a term.
|
52 |
-
|
53 |
-
(props @danielbachhuber, [#1753](https://github.com/WP-API/WP-API/pull/1753))
|
54 |
-
|
55 |
-
* Don't permit requesting terms cross routes.
|
56 |
-
|
57 |
-
Clients should only be able to request categories from the category route, and tags from the tag route.
|
58 |
-
|
59 |
-
(props @danielbachhuber, [#1764](https://github.com/WP-API/WP-API/pull/1764))
|
60 |
-
|
61 |
-
* Set `fields=>id` when using `WP_User_Query` to fix large memory usage
|
62 |
-
|
63 |
-
(props @joehoyle, [#1770](https://github.com/WP-API/WP-API/pull/1770))
|
64 |
-
|
65 |
-
* Fix Post `_link` to attached attachments.
|
66 |
-
|
67 |
-
(props @danielbachhuber, [#1777](https://github.com/WP-API/WP-API/pull/1777))
|
68 |
-
|
69 |
-
* Add support for getting a post with a custom public status.
|
70 |
-
|
71 |
-
(props @danielbachhuber, [#1765](https://github.com/WP-API/WP-API/pull/1765))
|
72 |
-
|
73 |
-
* Ensure post content doesn't get double-slashed on update.
|
74 |
-
|
75 |
-
(props @joehoyle, [#1772](https://github.com/WP-API/WP-API/pull/1772))
|
76 |
-
|
77 |
-
* Change 'int' to 'integer' for `WP_REST_Controller::validate_schema_property()`
|
78 |
-
|
79 |
-
(props @wpsmith, [#1759](https://github.com/WP-API/WP-API/pull/1759))
|
80 |
-
|
81 |
= 2.0 Beta 7.0 =
|
82 |
|
83 |
* Sync infrastructure from WordPress core as of r35691.
|
3 |
Tags: json, rest, api, rest-api
|
4 |
Requires at least: 4.3
|
5 |
Tested up to: 4.4
|
6 |
+
Stable tag: 2.0-beta7.1
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
36 |
|
37 |
== Changelog ==
|
38 |
|
39 |
+
= 2.0 Beta 7.1 =
|
40 |
|
41 |
* Ensure media of private posts are private too.
|
42 |
|
43 |
Reported by @danielbachhuber on 2016-01-08.
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
= 2.0 Beta 7.0 =
|
46 |
|
47 |
* Sync infrastructure from WordPress core as of r35691.
|