REST API: Make sure the class_list property is a list#10515
REST API: Make sure the class_list property is a list#10515dlh01 wants to merge 8 commits intoWordPress:trunkfrom
class_list property is a list#10515Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
The fix makes sense. The unit tests are failing with following error: |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
Fixed! |
|
|
||
| if ( rest_is_field_included( 'class_list', $fields ) ) { | ||
| $data['class_list'] = get_post_class( array(), $post->ID ); | ||
| $data['class_list'] = array_values( get_post_class( array(), $post->ID ) ); |
There was a problem hiding this comment.
Would it make sense to rather put this in get_post_class()? So the function can return with this change:
- return array_unique( $classes );
+ return array_values( array_unique( $classes ) );There was a problem hiding this comment.
That would work too. My reason for putting it here is that it's the API's responsibility to ensure that the value is, at this instant, a list, whether it comes from get_post_class() or somewhere else. But I don't feel too strongly about it.
There was a problem hiding this comment.
I think get_post_class() makes more sense because it will just avoid this being a problem for some other caller.
There was a problem hiding this comment.
My reason for putting it here is that it's the API's responsibility to ensure that the value is, at this instant, a list
That was my thinking as well, but I don't have a strong opinion. Patching the get_post_class works as well.
This avoids the REST API erroneously returning an object in the `class_list` property returned by `WP_REST_Posts_Controller::prepare_item_for_response()`. Developed in #10515 Props dlh, mamaduka, westonruter. Fixes #64247. git-svn-id: https://develop.svn.wordpress.org/trunk@61269 602fd350-edb4-49c9-b593-d223f7449a82
This avoids the REST API erroneously returning an object in the `class_list` property returned by `WP_REST_Posts_Controller::prepare_item_for_response()`. Developed in WordPress/wordpress-develop#10515 Props dlh, mamaduka, westonruter. Fixes #64247. Built from https://develop.svn.wordpress.org/trunk@61269 git-svn-id: http://core.svn.wordpress.org/trunk@60581 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This avoids the REST API erroneously returning an object in the `class_list` property returned by `WP_REST_Posts_Controller::prepare_item_for_response()`. Developed in WordPress/wordpress-develop#10515 Props dlh, mamaduka, westonruter. Fixes #64247. Built from https://develop.svn.wordpress.org/trunk@61269 git-svn-id: https://core.svn.wordpress.org/trunk@60581 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/64247