Amazon_S3_And_CloudFront::get_attachment_local_url PHP Method

get_attachment_local_url() public method

This is a direct copy of wp_get_attachment_url() from /wp-includes/post.php as we filter the URL in AS3CF and can't remove this filter using the current implementation of globals for class instances.
public get_attachment_local_url ( integer $post_id ) : string | false
$post_id integer
return string | false Attachment URL, otherwise false.
    public function get_attachment_local_url($post_id)
    {
        $url = '';
        // Get attached file.
        if ($file = get_post_meta($post_id, '_wp_attached_file', true)) {
            // Get upload directory.
            if (($uploads = wp_upload_dir()) && false === $uploads['error']) {
                // Check that the upload base exists in the file location.
                if (0 === strpos($file, $uploads['basedir'])) {
                    // Replace file location with url location.
                    $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file);
                } elseif (false !== strpos($file, 'wp-content/uploads')) {
                    $url = $uploads['baseurl'] . substr($file, strpos($file, 'wp-content/uploads') + 18);
                } else {
                    // It's a newly-uploaded file, therefore $file is relative to the basedir.
                    $url = $uploads['baseurl'] . "/{$file}";
                }
            }
        }
        if (empty($url)) {
            return false;
        }
        // Set correct domain on multisite subdomain installs
        if (is_multisite()) {
            $siteurl = trailingslashit(get_option('siteurl'));
            $network_siteurl = trailingslashit(network_site_url());
            if (0 !== strpos($url, $siteurl)) {
                // URL already using site URL, no replacement needed
                $url = str_replace($network_siteurl, $siteurl, $url);
            }
        }
        return $url;
    }
Amazon_S3_And_CloudFront