[oik] plugins.com

WordPress plugins and themes

  • Home
  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bw_get_attached_file_name() – Return the ‘correct’ URL for the attached image

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:

1 to 28 of 28
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 );
}
 

 View on GitHub View on Trac

Published: March 5, 2013 | Last updated: December 18, 2017

Information

Function name: bw_get_attached_file_name
Plugin ref: oik-nivo-slider – jQuery nivo slider
Version: 1.16.0
Sourcefile: nivo.php
File ref: nivo.php
Deprecated?: No
API Letters: A,B,F,G,N

Recent plugin updates

oik-weight-zone-shipping v0.2.2 

Upgrade to oik-weight-zone-shipping v0.2.2 for internationalized strings for migration. This version may also resolve a problem where a Warning message is produced while listing Shipping classes.

 ...
oik-weight-zone-shipping v0.2.1 

oik-weight-zone-shipping v0.2.1 fixes a problem with v0.2.0 on worpress.org, where two new files weren't included in the SVN repository.

 ...
oik-weightcountry-shipping v1.4.0 

oik-weightcountry-shipping v1.4.0 has been tested with WordPress 5.6 and WooCommerce 4.8.0. It is no longer supported. We suggest you switch to the oik weight zone shipping plugin.

 ...
oik-weight-zone-shipping v0.2.0 

oik-weight-zone-shipping v0.2.0 now supports migration from oik weight/country shipping. You can create Multi Rate shipping tables and methods restricting shipping classes.

 ...
oik-css v1.1.1 

oik-css v1.1.1 contains an update for improved compatibility with Gutenberg. It has been tested with WordPress 5.6 and WordPress Multi Site.

 ...

Plugins

  • All Plugins
  • oik base plugin
  • FREE oik plugins
  • WordPress plugins
  • Premium oik plugins

Themes

  • FREE themes
  • Bespoke themes
  • Premium themes

Blocks

  • All Blocks
  • Block examples
  • About Blocks

Shortcodes

  • All Shortcodes
  • Shortcode examples
  • About Shortcodes

Reference

  • About APIs
  • All APIs
  • All Classes
  • All Files
  • All Hooks

Support

  • Contact
  • Cookies policy
  • Get API key
  • Privacy
  • Request support
  • Sitemap
  • Stay informed
  • Terms and Conditions
oik-plugins
Email: [email protected]

Weight shipping plugins

Find out which cart weight shipping plugin you need for your WooCommerce site.
Which cart weight based plugin do I need?

Site:  www.oik-plugins.com
© Copyright oik-plugins 2011-2021. All rights reserved.


Website designed and developed by Herb Miller of Bobbing Wide
Proudly powered by WordPress and oik-plugins