Thanks for the ideas, folks. I went ahead and wrote a plugin. It’s not as hard coded as I feared it would have to be, thanks to wp_upload_dir()
. That function reveals the Unix path to the directory, which can be incorporated into a URL for the videos.
The plugin solution was far less work than it would have been to get rid of ms-files (I assume). And it probably would have created more problems than it solved. Especially since it really only affected video files and everything else still worked fine on all devices.
I have been toying with the idea of writing my own HTML5 video plugin for a while, and your suggestion, sontru, was the tipping point. I was actually going to write a shortcode, but I am glad you advised that a plugin would be better. Forced me to build it in a much less error prone way. I figured I’d just incorporate the solution to the URL thing in with it.
The plugin I wrote sees a regular link to a video, attempts to find all videos with the same name, but different extensions, ranks them (if they even exist) in order for HTML5 video with fallbacks, and writes out the real (un-rewritten) URLs inside proper <video>
tags.
So the plugin is uses two ways to get the better URL. One, as I said was less hard coded:
$basedir = wp_upload_dir();
$basedir = $basedir['basedir'];
$date_folder = NULL;
preg_match('#/[0-9]{4}/[0-1]{1}[0-9]{1}#', $url_to_original_file, $date_folder);
$path_to_file = $basedir . $date_folder[0] . '/' . basename($url_to_original_file);
You basically get the path to “uploads” in lines 1 and 2, get the year and month folders in lines 3 and 4, then put it together along with the filename in 5. From there, you could do a find and replace on the original URL versus the Unix path to get the un-rewritten URL.
The other way that I also used is slightly less work, but would be a bit more likely to break with future releases… I assume.
$site_number = $current_blog->blog_id;
$new_path_insert = "/wp-content/blogs.dir/$site_number/files/";
$new_url = str_replace('/files/', $new_path_insert, $original_url_to_file);
In that one, $current_blog
is a global set by WordPress. I’ll probably ditch the second version and duplicate the first version, ultimately. But I thought since you both took the time to help, you might like to see both ways I got it working.
Thanks again for the suggestions.