[wp-trac] [WordPress Trac] #35531: `set_url_scheme` in `url_to_postid` can fail in some contexts

WordPress Trac noreply at wordpress.org
Tue Jan 19 20:17:44 UTC 2016


#35531: `set_url_scheme` in `url_to_postid` can fail in some contexts
---------------------------+-----------------------------
 Reporter:  batmoo         |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Rewrite Rules  |    Version:  trunk
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 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:
 insecure.example.com and secure.example.com. Only secure.example.com has
 {{{https}}} enabled and we force {{{home_url}}} for insecure.example.com
 to always return an {{{http}}} URL.

 The following will fail if called from https://secure.example.com:

 {{{
 switch_to_blog( 2 ); // insecure.example.com
 $post_id = url_to_postid( 'http://insecure.example.com/2016/01/01/hello/'
 );
 restore_current_blog();
 }}}

 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}}}.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35531>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list