Make WordPress Core

Changes between Initial Version and Version 2 of Ticket #53181


Ignore:
Timestamp:
05/11/2021 06:13:00 PM (5 years ago)
Author:
SergeyBiryukov
Comment:

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Just noting that I could not reproduce the issue on a clean install, attachment_url_to_postid() seems to work as expected for me.

On wp-include/media.php line 4809 it does something strange:

if ( 0 === strpos( $path, $dir['baseurl'] . '/' ) ) {
  $path = substr( $path, strlen( $dir['baseurl'] . '/' ) );
}

It removes the baseurl, leaving a partial path that will never be found in the database.

This particular code was added in [30501] / #30346 to replace incorrect ltrim() usage introduced with the function in [29029] / #27891.

This matches how the _wp_attached_file post meta field is stored in the database, it is supposed to be a path relative to the uploads directory and not a full URL nor a full path from the root directory. See [8796] / #7622 and [36120] / #35106 for more context.

However, if the site was upgraded from an older install (before WordPress 2.7), it is possible that some _wp_attached_file values contain a full URL, which indeed might be something that attachment_url_to_postid() does not account for.

Could you share the _wp_attached_file meta value for the file in question?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #53181

    • Property Keywords reporter-feedback added
    • Property Component changed from General to Media
  • Ticket #53181 – Description

    initial v2  
    1111
    1212It removes the baseurl, leaving a partial path that will never be found in the database.
    13 However if instead it replaced $dir['baseurl'] with $dir["basedir"], it would create a valid $path.
     13However if instead it replaced `$dir['baseurl']` with `$dir["basedir"]`, it would create a valid `$path`.