Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#56472 closed defect (bug) (fixed)

rest_get_route_for_post missing usages in Posts Controller prepare_links method

Reported by: get_dave's profile get_dave Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 6.1 Priority: normal
Severity: minor Version: 5.5
Component: REST API Keywords: has-patch
Focuses: Cc:

Description

Whilst working on https://github.com/WordPress/gutenberg/pull/42809#issuecomment-1231875463 we discovered that the function [rest_get_route_for_post](https://developer.wordpress.org/reference/functions/rest_get_route_for_post/) isn't fully implemented within the WP_REST_Posts_Controller.

As this function is filterable this can lead to inconsistencies.

https://developer.wordpress.org/reference/hooks/rest_route_for_post/

To quote:

The rest_get_route_for_post function is filterable. So it can be modified to use the slug instead of the id. But it looks like we missed some spots when implementing rest_get_route_for_post, like in prepare_links, so that will need to be addressed in a Core ticket.

Examples include:

Change History (11)

#1 @TimothyBlynJacobs
2 years ago

  • Milestone changed from Awaiting Review to 6.1
  • Owner set to TimothyBlynJacobs
  • Status changed from new to assigned
  • Version set to 5.5

This ticket was mentioned in PR #3179 on WordPress/wordpress-develop by spacedmonkey.


2 years ago
#2

  • Keywords has-patch added

spacedmonkey commented on PR #3179:


2 years ago
#3

@getdave Can you take a look

#4 @get_dave
2 years ago

  • Resolution set to worksforme
  • Status changed from assigned to closed

I tested this by checking out https://github.com/WordPress/gutenberg/pull/42809/ which modifies the route for wp_navigation. I then made a REST for a single Navigation post by slug.

I received the following which indicates that these changes are 👍

https://user-images.githubusercontent.com/444434/188420654-bc5678c1-8cdc-458c-96a4-54565bee6cb4.png

spacedmonkey commented on PR #3179:


2 years ago
#5

@getdave Do you want this in 6.0.x?

getdave commented on PR #3179:


2 years ago
#6

@getdave Do you want this in 6.0.x?

I think it would be fine for 6.1.

spacedmonkey commented on PR #3179:


2 years ago
#7

@TimothyBJacobs Can you take a look a this please. Happy to commit.

TimothyBJacobs commented on PR #3179:


2 years ago
#8

I'm also seing usages in WP_REST_Posts_Controller::create_item for the Location header. We can also use rest_get_route_for_post_type_items in WP_REST_Posts_Controller::get_items when preparing the pagination links.

#9 @SergeyBiryukov
2 years ago

  • Resolution worksforme deleted
  • Status changed from closed to reopened

Hi there, thanks for the ticket!

Reopening, as it looks like the PR has not been committed yet, so the closing in comment:4 appears to be unintentional.

See The Bug Tracker (Trac) for ticket resolution descriptions:

worksforme: The bug reported in the ticket cannot be reproduced. Sometimes, an existing plugin, hook, or feature may render the ticket moot, so the ticket can be closed without further action.

#10 @TimothyBlynJacobs
2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 54121:

REST API: Use helper functions for building routes in more places.

Props get_dave, spacedmonkey.
Fixes #56472.

TimothyBJacobs commented on PR #3179:


2 years ago
#11

Merged in da03cf1c6b3ab71ea7e56f4a050d87c41150726e.

Note: See TracTickets for help on using tickets.