You appear to be a bot. Output may be restricted
Description
Return the 'correct' URL for the attached image
We cannot rely on $post->guid since the uploaded file may have been edited in the media dialog and given a new name. We need to obtain the file name from the metadata and then fully qualify it for the browser
[0] => Array ( [width] => 350 [height] => 178 [hwstring_small] => height='65' width='128' [file] => 2012/03/nggallery-example1.jpg [sizes] => Array ( [thumbnail] => Array ( [file] => nggallery-example1-150x150.jpg [width] => 150 [height] => 150 ) [medium] => Array ( [file] => nggallery-example1-256x130.jpg [width] => 256 [height] => 130 ) ) [image_meta] => Array ( [aperture] => 0 [credit] => [camera] => [caption] => [created_timestamp] => 0 [copyright] => [focal_length] => 0 [iso] => 0 [shutter_speed] => 0 [title] => ) )
When the file is "thumbnail", "medium" or "large" – or any other combination then we need to add the directory information from the "file" to the selected file. When the thumbnail parameter is a numeric [size] array we need to search the [sizes] array to try to find the best match for the specified size.
Usage
$string = bw_get_attached_file_name( $post_id, $atts );
Parameters
- $post_id
- ( integer ) required – the ID of the attachment post
- $atts
- ( array ) required – attributes containing the specified thumbnail size.
Returns
string $image – the URL for the attached image
Source
File name: oik-nivo-slider/nivo.php
Lines:
function bw_get_attached_file_name( $post_id, $atts ) { $size = bw_array_get( $atts, "thumbnail", "full" ); bw_trace2( $size, "size" ); $image = null; switch ( $size ) { case 'full': $images = get_post_custom_values( "_wp_attached_file", $post_id ); //bw_trace2( $images ); if ( $images ) { $image = $images[0]; } else { $image = null; } break; default: $size = bw_get_thumbnail_size( $atts ); $image = bw_get_best_fit( $post_id, $size ); bw_trace2( $image, "got_image", false ); break; } if ( $image ) { $upload_dir = wp_upload_dir(); $image = $upload_dir['baseurl'] . '/' . $image; } // bw_trace2( $image, "attached_image", false ); return( $image ); }