WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 4 months ago

#47911 reviewing defect (bug)

redirect_guess_404_permalink does not consider public custom posts status

Reported by: goaroundagain Owned by: SergeyBiryukov
Milestone: 5.9 Priority: normal
Severity: normal Version: 5.2.2
Component: Canonical Keywords: has-patch
Focuses: Cc:

Description

At the moment the redirect_guess_404_permalink function does only consider the default "publish" post status and there is no way around because "publish" ist hard coded:

$post_id = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE $where AND post_status = 'publish'" );

From register_post_status: https://codex.wordpress.org/Function_Reference/register_post_status
public: (bool) (optional) Whether posts of this status should be shown in the front end of the site.

For this reason, all post with a custom post status set to public will not be found and return an 404.

I think custom post status with public set to true should also be considered.

Attachments (3)

47911.diff (663 bytes) - added by goaroundagain 2 years ago.
Easy fix, just query all public post stati and change the query to IN linke already done with post types in https://core.trac.wordpress.org/browser/tags/5.2.2/src/wp-includes/canonical.php#L673
47911_htdat.diff (1.6 KB) - added by htdat 7 months ago.
Updated the code provided by @goaroundagain and added a unit test for this ticket
47911_htdat_2.diff (1.6 KB) - added by htdat 7 months ago.
The previous diff accidentally removed unnecessary blank link so I updated it again. Basically, this diff is still to update the code provided by @goaroundagain and add a unit test for this ticket

Download all attachments as: .zip

Change History (15)

#2 @goaroundagain
2 years ago

  • Keywords close added

Never mind, just saw that this is fixed with 5.2.2 Great!

#3 @goaroundagain
2 years ago

  • Keywords close removed

Sorry for the confusion, its not fixed. Correct link to the linke in 5.2.2: https://core.trac.wordpress.org/browser/tags/5.2.2/src/wp-includes/canonical.php#L686

@goaroundagain
2 years ago

Easy fix, just query all public post stati and change the query to IN linke already done with post types in https://core.trac.wordpress.org/browser/tags/5.2.2/src/wp-includes/canonical.php#L673

#4 @goaroundagain
2 years ago

  • Keywords has-patch added

#5 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 5.3
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

Related: #47574

#6 @davidbaumwald
2 years ago

@SergeyBiryukov Is this one still on your radar for 5.3? If not, can me move it to a future milestone?

This ticket was mentioned in Slack in #core by marybaum. View the logs.


2 years ago

#8 @garrett-eclipse
2 years ago

  • Keywords needs-testing needs-unit-tests added
  • Milestone changed from 5.3 to Future Release

Moving this to a Future Release as we're now in beta3 for 5.3 and this change will need testing and possible unit tests.

#9 @SergeyBiryukov
8 months ago

  • Milestone changed from Future Release to 5.8

@htdat
7 months ago

Updated the code provided by @goaroundagain and added a unit test for this ticket

@htdat
7 months ago

The previous diff accidentally removed unnecessary blank link so I updated it again. Basically, this diff is still to update the code provided by @goaroundagain and add a unit test for this ticket

#10 @audrasjb
5 months ago

  • Keywords needs-testing removed

I tested the patch and it still applies cleanly against trunk. It looks good on my side: custom post statuses are took into account.

#11 @audrasjb
4 months ago

  • Keywords needs-unit-tests removed

Some unit tests were proposed, so let's remove this keyword.

#12 @hellofromTonya
4 months ago

  • Milestone changed from 5.8 to 5.9

Today is 5.8 Beta 1. As work continues on this ticket, punting to 5.9.

Note: See TracTickets for help on using tickets.