[wp-trac] [WordPress Trac] #51058: attachment_url_to_postid does not retrieve post ID of really large images

WordPress Trac noreply at wordpress.org
Sun Sep 6 21:34:46 UTC 2020


#51058: attachment_url_to_postid does not retrieve post ID of really large images
-----------------------------+------------------------------
 Reporter:  littler.chicken  |       Owner:  (none)
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Media            |     Version:  trunk
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:
-----------------------------+------------------------------

Comment (by littler.chicken):

 To reproduce, upload a very large image to your site (wider than 2560px).
 Get the URL of the original uploaded image.

 Add code to dump out some information similar to this:


 {{{
 add_filter(
         'the_content',
         function( $content ) {
                 // Enter the URL of the original image
                 var_dump( attachment_url_to_postid( 'https://nightly.local
 /wp-content/uploads/2020/03/roman-kraft-197672.jpg' ) );
                 // Now add -scaled to the original image name
                 var_dump( attachment_url_to_postid( 'https://nightly.local
 /wp-content/uploads/2020/03/roman-kraft-197672-scaled.jpg' ) );
                 return $content;
         }
 );
 }}}

 For the first, WordPress will output `0` as no image exists with that
 filename. The second will return the image ID, because that's the filename
 assigned to the `_wp_attached_file` meta key (ref:
 [https://core.trac.wordpress.org/browser/tags/5.5/src/wp-
 includes/media.php#L4634]).

 When I use this function, it's in the context of parsing the RSS feed, at
 which point the original ID is not available, but I'm retrieving it from
 the database so that the image can be replaced with a smaller copy.
 Currently, without a secondary check for the `-scaled` image, the
 replacement fails for very large images.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51058#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list