When that array is passed to array_map, each array item is passed to wp_kses. The first and only item is the array(13). Passing an array to wp_kses worked by accident in earlier versions of WP but not in WP 5.3.1, as reported here:
It is not enough to just replace array( wp_unslash( $_POST['ap'] ) ) with wp_unslash( $_POST['ap'] ) or (array) wp_unslash( $_POST['ap'] ), though, because passing that array to array_map will remove the keyed strings (_listing_price becomes 0 etc.).
This PR fixes the issue by:
Switching to array_walk to retain string keys.
Ensuring that each item in the $_POST['ap'] array is passed to wp_kses individually, instead of passing all items as one array.
Have the changes in this PR been added to the documentation for this project?
Not required.
How to test:
Under WP 5.3.1:
Create a new listing or edit an existing one.
Edit values in the property details meta box.
Update the listing and check that your changes persist.
If you add a price, check that the _listing_price_sortable is saved:
Summary of change: Fixes https://github.com/studiopress/agentpress-listings/issues/47, where property listing details are failing to save under WordPress 5.3.1+.
The cause was this line in
includes/class-agentpress-listings.php
:array( wp_unslash( $_POST['ap'] )
causes the$_POST['ap']
array to appear as the first value in another array:When that array is passed to
array_map
, each array item is passed towp_kses
. The first and only item is thearray(13)
. Passing an array towp_kses
worked by accident in earlier versions of WP but not in WP 5.3.1, as reported here:https://core.trac.wordpress.org/ticket/48955
wp_kses expects a string for the first argument and not an array:
https://developer.wordpress.org/reference/functions/wp_kses/#parameters
It is not enough to just replace
array( wp_unslash( $_POST['ap'] ) )
withwp_unslash( $_POST['ap'] )
or(array) wp_unslash( $_POST['ap'] )
, though, because passing that array toarray_map
will remove the keyed strings (_listing_price
becomes0
etc.).This PR fixes the issue by:
array_walk
to retain string keys.$_POST['ap']
array is passed towp_kses
individually, instead of passing all items as one array.Have the changes in this PR been added to the documentation for this project? Not required.
How to test: Under WP 5.3.1:
_listing_price_sortable
is saved:Repeat these tests with an earlier version of WordPress, such as 5.1.
Suggested Changelog Entry: Ensure edited property details save under WordPress 5.3.1+.
Notes I reviewed other usages of
wp_kses
and can't see that we pass it an array instead of the expected string anywhere else.