_wp_get_attachment_relative_path

The timeline below displays how wordpress function _wp_get_attachment_relative_path has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Gets the attachment path relative to the upload directory.
 *
 * @since 4.4.1
 * @access private
 *
 * @param string $file Attachment file name.
 * @return string Attachment path relative to the upload directory.
 */
function _wp_get_attachment_relative_path($file)
{
    $dirname = dirname($file);
    if ('.' === $dirname) {
        return '';
    }
    if (str_contains($dirname, 'wp-content/uploads')) {
        // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
        $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18);
        $dirname = ltrim($dirname, '/');
    }
    return $dirname;
}

WordPress Version: 6.1

/**
 * Gets the attachment path relative to the upload directory.
 *
 * @since 4.4.1
 * @access private
 *
 * @param string $file Attachment file name.
 * @return string Attachment path relative to the upload directory.
 */
function _wp_get_attachment_relative_path($file)
{
    $dirname = dirname($file);
    if ('.' === $dirname) {
        return '';
    }
    if (false !== strpos($dirname, 'wp-content/uploads')) {
        // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
        $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18);
        $dirname = ltrim($dirname, '/');
    }
    return $dirname;
}

WordPress Version: 5.4

/**
 * Get the attachment path relative to the upload directory.
 *
 * @since 4.4.1
 * @access private
 *
 * @param string $file Attachment file name.
 * @return string Attachment path relative to the upload directory.
 */
function _wp_get_attachment_relative_path($file)
{
    $dirname = dirname($file);
    if ('.' === $dirname) {
        return '';
    }
    if (false !== strpos($dirname, 'wp-content/uploads')) {
        // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
        $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18);
        $dirname = ltrim($dirname, '/');
    }
    return $dirname;
}

WordPress Version: 4.1

/**
 * Get the attachment path relative to the upload directory.
 *
 * @since 4.4.1
 * @access private
 *
 * @param string $file Attachment file name.
 * @return string Attachment path relative to the upload directory.
 */
function _wp_get_attachment_relative_path($file)
{
    $dirname = dirname($file);
    if ('.' === $dirname) {
        return '';
    }
    if (false !== strpos($dirname, 'wp-content/uploads')) {
        // Get the directory name relative to the upload directory (back compat for pre-2.7 uploads)
        $dirname = substr($dirname, strpos($dirname, 'wp-content/uploads') + 18);
        $dirname = ltrim($dirname, '/');
    }
    return $dirname;
}