Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#35531 closed defect (bug) (fixed)

`url_to_postid` can fail in some contexts due to `set_url_scheme`

Reported by: batmoo's profile batmoo Owned by: johnbillion's profile johnbillion
Milestone: 4.5 Priority: normal
Severity: normal Version: 4.4
Component: Rewrite Rules Keywords: has-patch has-unit-tests https
Focuses: multisite Cc:


This is a follow-up to #34144.

The set_url_scheme addition breaks the use of url_to_postid when there is a mismatch between the current scheme and the scheme of the home_url.

Example: In a multisite environment, I have two blogs: and Only has https enabled and we force home_url for to always return an http URL.

The following will fail if called from

switch_to_blog( 2 ); //
$post_id = url_to_postid( '' );

This is because set_url_scheme forces the permalink to have an https scheme but the bit of code in url_to_postid that strips the home_url() form the URL will fail because of the scheme mismatch.

I think the better fix would be to make sure that the set_url_scheme call matches the scheme of home_url.

Attachments (1)

35531.diff (2.6 KB) - added by johnbillion 8 years ago.

Download all attachments as: .zip

Change History (8)

#1 @batmoo
8 years ago

  • Summary changed from `set_url_scheme` in `url_to_postid` can fail in some contexts to `url_to_postid` can fail in some contexts due to `set_url_scheme`

#2 @ocean90
8 years ago

  • Keywords needs-unit-tests needs-patch added
  • Version changed from trunk to 4.4

@swissspidy Can you take a look at this?

8 years ago

#3 @johnbillion
8 years ago

  • Keywords has-patch has-unit-tests added; needs-unit-tests needs-patch removed
  • Milestone changed from Awaiting Review to 4.5

#4 @johnbillion
8 years ago

  • Focuses multisite added

#5 @johnbillion
8 years ago

  • Owner set to johnbillion
  • Status changed from new to accepted

#6 @johnbillion
8 years ago

  • Keywords https added

#7 @johnbillion
8 years ago

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

In 36750:

Rewrite Rules: Ensure url_to_postid() operates as expected when it's used in the context of another site within a Multisite network that uses mixed URL schemes.

Fixes #35531

Note: See TracTickets for help on using tickets.