Skip to content

Instantly share code, notes, and snippets.

@bcole808
Created June 13, 2014 18:57
Show Gist options
  • Select an option

  • Save bcole808/15902f41aef91087c006 to your computer and use it in GitHub Desktop.

Select an option

Save bcole808/15902f41aef91087c006 to your computer and use it in GitHub Desktop.

Revisions

  1. bcole808 created this gist Jun 13, 2014.
    25 changes: 25 additions & 0 deletions wpms_fix_upload_paths.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    <?php
    /***************************************************
    * Filter the results of wp_upload_dir()
    *
    * In WordPress Multisite systems that were installed prior to 3.5 the system uses the folder structure /wp-content/blogs.dir/XX to store uploaded files for each blog.
    *
    * The URL used to access these files follows the format /SITENAME/files/ but the function wp_upload_dir() does not match this format
    ***************************************************/
    function wpms_fix_upload_paths($data) {

    // Check if the base URL matches the format 'wp-content/blogs.dir/00/files'
    $needs_fixing = preg_match("/wp-content\/blogs\.dir\/(\d+)\/files/", $data['baseurl'], $uri_part);

    if ($needs_fixing) {

    $data['url'] = str_replace($uri_part[0], 'files', $data['url']);
    $data['baseurl'] = str_replace($uri_part[0], 'files', $data['baseurl']);

    }

    return $data;
    }

    // Fix upload paths
    add_filter('upload_dir', 'wpms_fix_upload_paths');