REST API: Allow a CSV list of term IDs to be passed to /posts.

[39048] added CSV support to array types, this change explicitly parses term lists as IDs, and adds tests.

Props timmydcrawford, pento.
Fixes #38553.



git-svn-id: https://develop.svn.wordpress.org/trunk@39055 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2016-10-31 11:05:37 +00:00
parent ee84a7a31a
commit 0153b0bb9b
2 changed files with 32 additions and 2 deletions

View File

@@ -1196,8 +1196,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
continue;
}
$terms = array_map( 'absint', $request[ $base ] );
$result = wp_set_object_terms( $post_id, $terms, $taxonomy->name );
$result = wp_set_object_terms( $post_id, $request[ $base ], $taxonomy->name );
if ( is_wp_error( $result ) ) {
return $result;
@@ -1965,11 +1964,20 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
'items' => array(
'type' => 'integer',
),
'arg_options' => array(
'sanitize_callback' => 'wp_parse_id_list',
),
'context' => array( 'view', 'edit' ),
);
$schema['properties'][ $base . '_exclude' ] = array(
'description' => sprintf( __( 'The terms in the %s taxonomy that should not be assigned to the object.' ), $taxonomy->name ),
'type' => 'array',
'items' => array(
'type' => 'integer',
),
'arg_options' => array(
'sanitize_callback' => 'wp_parse_id_list',
),
'context' => array( 'view', 'edit' ),
);
}