Ensure that `attachment_url_to_postid()` matches cross-scheme when front-end and back-end schemes are different.
Adds unit test. Props welcher. Fixes #33109. Built from https://develop.svn.wordpress.org/trunk@33705 git-svn-id: http://core.svn.wordpress.org/trunk@33672 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f2a9cd365b
commit
42b6ac80e7
|
@ -3431,6 +3431,14 @@ function attachment_url_to_postid( $url ) {
|
||||||
$dir = wp_upload_dir();
|
$dir = wp_upload_dir();
|
||||||
$path = $url;
|
$path = $url;
|
||||||
|
|
||||||
|
$site_url = parse_url( $dir['url'] );
|
||||||
|
$image_path = parse_url( $path );
|
||||||
|
|
||||||
|
//force the protocols to match if needed
|
||||||
|
if ( isset( $image_path['scheme'] ) && ( $image_path['scheme'] !== $site_url['scheme'] ) ) {
|
||||||
|
$path = str_replace( $image_path['scheme'], $site_url['scheme'], $path );
|
||||||
|
}
|
||||||
|
|
||||||
if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) {
|
if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) {
|
||||||
$path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
|
$path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
|
||||||
}
|
}
|
||||||
|
@ -3449,9 +3457,7 @@ function attachment_url_to_postid( $url ) {
|
||||||
* @param int|null $post_id The post_id (if any) found by the function.
|
* @param int|null $post_id The post_id (if any) found by the function.
|
||||||
* @param string $url The URL being looked up.
|
* @param string $url The URL being looked up.
|
||||||
*/
|
*/
|
||||||
$post_id = apply_filters( 'attachment_url_to_postid', $post_id, $url );
|
return (int) apply_filters( 'attachment_url_to_postid', $post_id, $url );
|
||||||
|
|
||||||
return (int) $post_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.4-alpha-33704';
|
$wp_version = '4.4-alpha-33705';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue