WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 months ago

#47911 reviewing enhancement

redirect_guess_404_permalink does not consider public custom posts status

Reported by: goaroundagain Owned by: SergeyBiryukov
Milestone: 6.0 Priority: normal
Severity: normal Version: 5.2.2
Component: Canonical Keywords: has-patch has-unit-tests early
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 (4)

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 11 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 11 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
47911_htdat_3.diff (1.6 KB) - added by costdev 2 months ago.
Unit test updated with @covers tag and minor comment change for consistency.

Download all attachments as: .zip

Change History (20)

#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
11 months ago

  • Milestone changed from Future Release to 5.8

@htdat
11 months ago

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

@htdat
11 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
8 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
8 months ago

  • Keywords needs-unit-tests removed

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

#12 @hellofromTonya
8 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.

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


3 months ago

#14 @audrasjb
3 months ago

  • Keywords has-unit-tests added

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


2 months ago

#16 @audrasjb
2 months ago

  • Keywords early added
  • Milestone changed from 5.9 to 6.0
  • Type changed from defect (bug) to enhancement

As per today's bug scrub, this enhancement should be considered earlier in the release cycle. Moving to milestone 6.0 with the early workflow keyword.

@costdev
2 months ago

Unit test updated with @covers tag and minor comment change for consistency.

Note: See TracTickets for help on using tickets.