[wp-trac] [WordPress Trac] #42752: Rest api - can not convert array to string notice
WordPress Trac
noreply at wordpress.org
Fri Dec 1 22:08:45 UTC 2017
#42752: Rest api - can not convert array to string notice
--------------------------+------------------------------
Reporter: steffanhalv | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 4.9
Severity: normal | Resolution:
Keywords: | Focuses: rest-api
--------------------------+------------------------------
Comment (by thepanther71):
I had this same issue with a plug-in I'm developing. I was trying to get
the REST api to work with datatablesJS (datatables.net) in server mode.
Their API sends a bunch of _GET parameters, including an array for
"&search" and "&order". This caused the Wordpress API to fail on the
same error code as &search and &order are expected to be strings.
For my testing (only 2 days so far), I was able to get things working by
adding json_encode to the string cast in "wp-includes/class-wp.php" line
305
I havent done extensive testing for side effects, but this seems to be
working for everything Ive tried so far. Basically, it will json encode
parameters if they come in as an array...
<code>
{{{
$this->query_vars[ $wpvar ][ $vkey ] = (string) json_encode($v);
}}}
The current structure allows $v as an array to enter this block.... Since
you cant cast an array to a string we get that notice.
I'm not familiar enough with WP base to know where else this is used that
may have an effect... testing for a few days before I formally send it as
a bug fix, but maybe @dd32 has more of an idea if it should have unwanted
side effects.
USE AT OWN RISK... I dont know the side effects on security... $v was cast
as a string for an intentional reason... forcing a json_encoded array may
need some additional casting inside.
That said, I have not seen any bad side effects with existing API's or my
custom ones yet.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/42752#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list