From 0cac69f505d08f89c9a991ca798ffcaf0e742b96 Mon Sep 17 00:00:00 2001 From: nacin Date: Fri, 27 Apr 2012 16:08:58 +0000 Subject: [PATCH] Return false in get_attached_file() when the file does not exist, rather than a path to the base uploads directory. props mikeschinkel. fixes #18855. git-svn-id: http://svn.automattic.com/wordpress/trunk@20613 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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;