WordPress.org

Make WordPress Core

Changeset 20613


Ignore:
Timestamp:
04/27/2012 04:08:58 PM (6 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post.php

    r20569 r20613  
    169169 * @param int $attachment_id Attachment ID.
    170170 * @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.
    172172 */
    173173function get_attached_file( $attachment_id, $unfiltered = false ) {
    174174    $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
    175175    // If the file is relative, prepend upload dir
    176     if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
     176    if ( $file && 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
    177177        $file = $uploads['basedir'] . "/$file";
    178178    if ( $unfiltered )
Note: See TracChangeset for help on using the changeset viewer.