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
This commit is contained in:
nacin 2012-04-27 16:08:58 +00:00
parent c68f8c46f0
commit 0cac69f505
1 changed files with 2 additions and 2 deletions

View File

@ -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;