Avoids incorrect results when `url_to_postid()` checking is not strict enough. Adds a bunch of Unit Tests for `url_to_postid()', which is currently only tested lightly in some XML-RPC tests.
Props gcorne, gradyetc. Fixes #20560. Built from https://develop.svn.wordpress.org/trunk@25258 git-svn-id: http://core.svn.wordpress.org/trunk@25226 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d041c830bc
commit
d03b6f9df5
|
@ -324,14 +324,14 @@ function url_to_postid($url) {
|
|||
if ( !$wp_rewrite->using_index_permalinks() )
|
||||
$url = str_replace( $wp_rewrite->index . '/', '', $url );
|
||||
|
||||
if ( false !== strpos($url, home_url()) ) {
|
||||
// Chop off http://domain.com
|
||||
if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) {
|
||||
// Chop off http://domain.com/[path]
|
||||
$url = str_replace(home_url(), '', $url);
|
||||
} else {
|
||||
// Chop off /path/to/blog
|
||||
$home_path = parse_url(home_url());
|
||||
$home_path = parse_url( home_url( '/' ) );
|
||||
$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
|
||||
$url = str_replace($home_path, '', $url);
|
||||
$url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) );
|
||||
}
|
||||
|
||||
// Trim leading and lagging slashes
|
||||
|
|
Loading…
Reference in New Issue