diff --git a/wp-includes/post.php b/wp-includes/post.php index ad79941b4..6ce110ebf 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -168,12 +168,12 @@ add_action( 'init', 'create_initial_post_types', 0 ); // highest priority * * @param int $attachment_id Attachment ID. * @param bool $unfiltered Whether to apply filters. - * @return string The file path to the attached file. + * @return string|bool The file path to the attached file, or false if the attachment does not exist. */ function get_attached_file( $attachment_id, $unfiltered = false ) { $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); // If the file is relative, prepend upload dir - if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) + if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) $file = $uploads['basedir'] . "/$file"; if ( $unfiltered ) return $file;