_load_image_to_edit_path

Retrieve the path or url of an attachment's attached file.

Description

(string|false) _load_image_to_edit_path( (string) $attachment_id, (string) $size = 'full' ); 

If the attached file is not present on the local filesystem (usually due to replication plugins), then the url of the file is returned if url fopen is supported.

Returns (string|false)

File path or url on success, false on failure.

Parameters (2)

0. $attachment_id (string)
The attachment id.
1. $size — Optional. (string) => 'full'
Image size, defaults to full..

Usage

  1. if ( !function_exists( '_load_image_to_edit_path' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image.php'; 
  3.  
  4. // The attachment id. 
  5. $attachment_id = ''; 
  6.  
  7. // Optional. Image size, defaults to 'full'. 
  8. $size = 'full'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _load_image_to_edit_path($attachment_id, $size); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/image.php  
  1. function _load_image_to_edit_path( $attachment_id, $size = 'full' ) { 
  2. $filepath = get_attached_file( $attachment_id ); 
  3.  
  4. if ( $filepath && file_exists( $filepath ) ) { 
  5. if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) { 
  6. /** 
  7. * Filters the path to the current image. 
  8. * The filter is evaluated for all image sizes except 'full'. 
  9. * @since 3.1.0 
  10. * @param string $path Path to the current image. 
  11. * @param string $attachment_id Attachment ID. 
  12. * @param string $size Size of the image. 
  13. */ 
  14. $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size ); 
  15. } elseif ( function_exists( 'fopen' ) && true == ini_get( 'allow_url_fopen' ) ) { 
  16. /** 
  17. * Filters the image URL if not in the local filesystem. 
  18. * The filter is only evaluated if fopen is enabled on the server. 
  19. * @since 3.1.0 
  20. * @param string $image_url Current image URL. 
  21. * @param string $attachment_id Attachment ID. 
  22. * @param string $size Size of the image. 
  23. */ 
  24. $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size ); 
  25.  
  26. /** 
  27. * Filters the returned path or URL of the current image. 
  28. * @since 2.9.0 
  29. * @param string|bool $filepath File path or URL to current image, or false. 
  30. * @param string $attachment_id Attachment ID. 
  31. * @param string $size Size of the image. 
  32. */ 
  33. return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );