Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the parent menu item field in REST API responses #34835

Merged
merged 1 commit into from
Sep 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/class-wp-rest-menu-items-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public function prepare_item_for_response( $post, $request ) {

if ( rest_is_field_included( 'parent', $fields ) ) {
// Same as post_parent, expose as integer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this inline comment as well? To avoid the same mistake in the future.

Based on this property definition, menu_item_parent is what we need in this case.

https://github.com/WordPress/wordpress-develop/blob/f44a99529758e9a5ada443347c5febb5b8a67b6f/src/wp-includes/nav-menu.php#L797-L800

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's saying to treat the type of menu_item_parent as an int, the same as post_parent, so seems correct, but maybe a bit ambiguous.

$data['parent'] = (int) $menu_item->post_parent;
$data['parent'] = (int) $menu_item->menu_item_parent;
}

if ( rest_is_field_included( 'menu_order', $fields ) ) {
Expand Down