WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. ljg3
    Member
    Posted 4 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:
    [SITE]/[SUBDIR]/wp-content/uploads/2010/03/image.jpg

    was coming through (missing slash):
    [SITE]/[SUBDIR]wp-content/uploads/2010/03/image.jpg

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

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

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Posted 4 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
    Member
    Posted 4 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
    Member
    Posted 4 years ago #

    Thanks, I'll check it out.

Topic Closed

This topic has been closed to new replies.

About this Topic