Make WordPress Core

Opened 9 hours ago

Last modified 8 hours ago

#64247 new defect (bug)

REST API: `class_list` sometimes returned as an object

Reported by: dlh's profile dlh Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 6.6
Component: REST API Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The class_list property in the REST API posts endpoint returns the array of classes generated by get_post_class(). The final step in get_post_class() is to run array_unique() over the array, which removes duplicate classes but doesn't reset the array keys, usually causing the keys to become non-sequential, and in turn causing the array to be converted to a JSON object in the REST response. See the attached screenshot showing an API response from a site affected by this issue.

(A similar problem was fixed just the other day in [61210].)

The linked PR would address the issue within the controller, since the array needs to be indexed at that point no matter how the list of classes is generated.

Attachments (1)

Screenshot 2025-11-12 at 11.58.36 AM.png (422.5 KB) - added by dlh 9 hours ago.

Download all attachments as: .zip

Change History (4)

This ticket was mentioned in PR #10515 on WordPress/wordpress-develop by @dlh.


9 hours ago
#1

  • Keywords has-patch has-unit-tests added

@Mamaduka commented on PR #10515:


9 hours ago
#2

The fix makes sense.

The unit tests are failing with following error:

Parse error: syntax error, unexpected ')' in /var/www/tests/phpunit/tests/rest-api/rest-posts-controller.php on line 2795

@dlh commented on PR #10515:


8 hours ago
#3

Fixed!

Note: See TracTickets for help on using tickets.