Why is WordPress automatically modifying image URLs? (Tracking pixel from RSS)

Regarding the HTML editor, if you want to use a different path, without all the functions/ hooks that I will list below, you should use the UPLOAD FROM URL tab, and not the UPLOAD FROM COMPUTER .. that will keep the original URL.

I am not sure about the tracking pixel, how you get it in the RSS (format) or other variables in your system, but the function that sends the images to the editor is a function called image_send_to_editor();

So using the next function, will alter the URL that is SENT TO THE EDITOR..

add_filter('image_send_to_editor', 'change_image_url', 20, 8);
$original_URL = 'your_url/not_sure_how/'; // this part you have to pass the original URL..
function change_image_url($html, $id, $caption, $title, $align, $url, $size, $alt)
{
$url = $original_URL ;
return $url;
}

For using outside the editor, the upload path can be intercepted in a LOT of ways, depending on what you really need to do (like I said, I do not know HOW you get the RSS, but start with checking and hooking these function :

update_attached_file( $attachment_id, $file ) 

What you would hook here is the $file part, which originally is:

$file = _wp_relative_upload_path($file);

As you can see, it calls yet another function with $path parameter that you can hook which is:

 _wp_relative_upload_path( $path )

This function will change the $path of the image to be relative to the upload dir.

The function update_attached_file(); will also update the post_meta hidden field _wp_attached_file with:

update_post_meta( $attachment_id, '_wp_attached_file', $file );

This is yet another way to control the path. You can manipulate that custom_field to your needs. It is actually the easiest way IMHO…