Ticket #18855: get_attached_file-returns-false.diff
| File get_attached_file-returns-false.diff, 1.1 KB (added by , 15 years ago) |
|---|
-
post.php
168 168 * 169 169 * @param int $attachment_id Attachment ID. 170 170 * @param bool $unfiltered Whether to apply filters. 171 * @return string The file path to the attached file.171 * @return string|bool The file path to the attached file, or false if the attachment does not exist. 172 172 */ 173 173 function get_attached_file( $attachment_id, $unfiltered = false ) { 174 174 $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); 175 // If the file is relative, prepend upload dir 176 if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) 177 $file = $uploads['basedir'] . "/$file"; 175 if ( ! empty ( $file ) ) { 176 // If the file is relative, prepend upload dir 177 if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) ) 178 $file = $uploads['basedir'] . "/$file"; 179 } 178 180 if ( $unfiltered ) 179 181 return $file; 180 182 return apply_filters( 'get_attached_file', $file, $attachment_id );