WordPress 4.4.1
[autoinstalls/wordpress.git] / wp-includes / post.php
index d0bc1a3d863f29af075d626f27498d3891cfe07f..9cf0c161faa11f3922be63c5990847f21805a307 100644 (file)
@@ -4290,7 +4290,7 @@ function get_page_uri( $page ) {
 
        foreach ( $page->ancestors as $parent ) {
                $parent = get_post( $parent );
-               if ( 'publish' === $parent->post_status ) {
+               if ( $parent ) {
                        $uri = $parent->post_name . '/' . $uri;
                }
        }
@@ -4869,7 +4869,8 @@ function wp_get_attachment_url( $post_id = 0 ) {
                                // Replace file location with url location.
                                $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
                        } elseif ( false !== strpos($file, 'wp-content/uploads') ) {
-                               $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
+                               // Get the directory name relative to the basedir (back compat for pre-2.7 uploads)
+                               $url = trailingslashit( $uploads['baseurl'] . '/' . _wp_get_attachment_relative_path( $file ) ) . basename( $file );
                        } else {
                                // It's a newly-uploaded file, therefore $file is relative to the basedir.
                                $url = $uploads['baseurl'] . "/$file";