[Plugin: W3 Total Cache] Media Library Import - Subdirectory Bug (4 posts)

  1. ljg3
    Posted 5 years ago #

    I was attempting to import the media library of an existing site, and although the import was working correctly, the URLs placed back into the article were broken. It seems to be an error when your site is not at the root of your domain.

    So what should have been:

    was coming through (missing slash):

    My fix was to add this after line 690 in /lib/W3/Plugin/Cdn.php

    if (!preg_match('/\/$/', $site_url)) {
        $site_url .= '/';


  2. Frederick Townes
    Posted 5 years ago #

    Can you please submit a bug submission report from the support tab of the plugin with access to your site/server?

  3. ljg3
    Posted 5 years ago #

    Unfortunately, the server I'm playing on now is firewalled into our local IPs only. I've actually switched the fix because it looks like when you retrieve the site_url, that trailing slashes are intentionally stripped. So here's the new diff I've been using (on lib/W3/Plugin/Cdn.php):

    @@ -785,7 +785,7 @@
                                             $dst_basename = basename($dst);
                                             $dst_dirname = dirname($dst);
    -                                        $dst_url = sprintf('%s%s/%s', $site_url, $upload_url, $dst_basename);
    +                                        $dst_url = sprintf('%s/%s/%s', $site_url, $upload_url, $dst_basename);
                                             w3_mkdir($dst_dirname, 0755, ABSPATH);
    @@ -971,7 +971,7 @@
                         if (preg_match_all($regexp, $post_content, $matches, PREG_SET_ORDER)) {
                             foreach ($matches as $match) {
                                 $old_url = $match[2];
    -                            $new_url = sprintf('%s%s%s', $site_url, $upload_info['upload_url'], $match[5]);
    +                            $new_url = sprintf('%s/%s%s', $site_url, $upload_info['upload_url'], $match[5]);
                                 $post_content = str_replace($old_url, $new_url, $post_content);
                                 $results[] = array(
  4. Frederick Townes
    Posted 5 years ago #

    Thanks, I'll check it out.

Topic Closed

This topic has been closed to new replies.

About this Topic