Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multisite issue with main site #111

Closed
JonasBrand opened this issue Jan 31, 2018 · 4 comments
Closed

Multisite issue with main site #111

JonasBrand opened this issue Jan 31, 2018 · 4 comments

Comments

@JonasBrand
Copy link
Contributor

When using WP Document Revisions in a multisite installation, there are issues with the uploads folder setting when using the plugin both on the main site (usually site with ID = 1) and on other sub-sites.

This is how the uploads folder is set by default for multisite installations:
Your first site on a fresh install will put uploaded files in the traditional location of /wp-content/uploads/, however all subsequent sites on your network will be in the /wp-content/uploads/sites/ folder, in their own subfolder based on the site number, designated by the database. These files will be accessible via that URL.
Source: https://codex.wordpress.org/Multisite_Network_Administration#Uploaded_File_Path

When I set the uploads path in the WP Document Revisions network-wide setting to
"[PATH]/wp-content/uploads", it will work on the main site but not on other subsites.

When I set it to "[PATH]/wp-content/uploads/sites/%site_id%/", it won't work on the main site but on the other subsites.

@JonasBrand
Copy link
Contributor Author

JonasBrand commented Jan 31, 2018

I can provide a pull request, but would appreciate your input on which directory should be used for the main site.

Options I see:

  • Always use the default directory for the main site.
    → Quick fix, but there would be no way to use a custom directory for the main site.
  • Have two separate settings for the main site and subsites in the Network Settings.
    → More development effort but most flexible solution.
  • Run a str_replace to remove "/sites/%site_id%" from the site option.
    → Quick solution to cover the default case, but also allow a custom directory for the main site.

Suggestion for Option 3:

// make site specific on multisite
if ( is_multisite() && ! is_network_admin() ) {
    if(is_main_site()) {
        $dir = str_replace( '/sites/%site_id%', '', $dir );
    }

    $dir = str_replace( '%site_id%', $wpdb->blogid, $dir );
}

(in https://github.com/benbalter/wp-document-revisions/blob/master/includes/class-wp-document-revisions.php#L1031)

Possible cases to be covered:

  • /uploads/sites/%site_id% (default)
    → Main site: /uploads
    → Sub-site 2: /uploads/sites/1
  • /documents/%site_id%
    → Main site: /documents/1
    → Sub-site 2: /documents/2
  • /uploads/sites/%site_id%/documents
    → Main site: /documents
    → Sub-site 2: /sites/2/documents

@benbalter
Copy link
Collaborator

I believe is_network_admin in https://github.com/benbalter/wp-document-revisions/blob/master/includes/class-wp-document-revisions.php#L1032 should be is_main_site. Does that solve the problem?

@JonasBrand
Copy link
Contributor Author

No, that won't solve the problem. As far as I understand, the ´!is_network_admin´ is required to avoid that the %site_id% is replaced when you're on the Network Admin screen.

See my suggestion above. I would think that covers everything.

@benbalter
Copy link
Collaborator

@JonasBrand that last option works for me! If you're willing/able to submit a pull request, I'd be glad to review and merge.

benbalter added a commit that referenced this issue Jan 31, 2018
Fixes #111: Multisite issue with main site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants