Changeset 8796 for trunk/wp-includes/post.php
- Timestamp:
- 09/02/2008 10:55:39 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/post.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/post.php
r8766 r8796 28 28 function get_attached_file( $attachment_id, $unfiltered = false ) { 29 29 $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); 30 // If the file is relative, prepend upload dir 31 if ( 0 !== strpos($file, '/') ) { 32 $uploads = wp_upload_dir(); 33 $file = $uploads['basedir'] . "/$file"; 34 } 35 30 36 if ( $unfiltered ) 31 37 return $file; … … 51 57 52 58 $file = apply_filters( 'update_attached_file', $file, $attachment_id ); 59 60 // Make the file path relative to the upload dir 61 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory 62 if ( 0 === strpos($file, $uploads['basedir']) ) {// Check that the upload base exists in the file path 63 $file = str_replace($uploads['basedir'], '', $file); // Remove upload dir from the file path 64 $file = ltrim($file, '/'); 65 } 66 } 53 67 54 68 return update_post_meta( $attachment_id, '_wp_attached_file', $file ); … … 2451 2465 return false; 2452 2466 2453 $url = get_the_guid( $post->ID ); 2454 2455 if ( 'attachment' != $post->post_type || !$url ) 2467 $url = ''; 2468 if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file 2469 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory 2470 if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location 2471 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location 2472 } 2473 } 2474 2475 if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this. 2476 $url = get_the_guid( $post->ID ); 2477 2478 if ( 'attachment' != $post->post_type || empty($url) ) 2456 2479 return false; 2457 2480
Note: See TracChangeset
for help on using the changeset viewer.