[wp-trac] [WordPress Trac] #38553: Posts Controller handle_terms throws warning
WordPress Trac
noreply at wordpress.org
Fri Oct 28 19:55:11 UTC 2016
#38553: Posts Controller handle_terms throws warning
----------------------------+-----------------------------
Reporter: timmydcrawford | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: trunk
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
If a malformatted value is passed as a term field ( categories, tags ) to
the WP_REST_Posts_Controller, the handle_terms method is currently
throwing a warning:
{{{
PHP Warning: array_map(): Argument #2 should be an array in /srv/www
/wordpress-develop/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-
controller.php on line 1053
}}}
To reproduce this warning, you can issue a curl request like:
{{{
curl -X POST -H "Authorization: Basic redacted" -H "Content-Type:
multipart/form-data;" -F "title=rad post3" -F "content=blah blah blah" -F
"categories=2,1" "http://src.wordpress-develop.dev/wp-json/wp/v2/posts"
}}}
I have attached a simple fix, but should we possibly consider either
parsing comma-separated strings into arrays, or returning an error on
malformed inputs like this? In the wpcom API, it is possible to send in a
comma-separated string - so it seems like some sort of standard needs to
emerge here.
I haven't tested other array inputs to see if similar warnings might be
thrown elsewhere.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38553>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list