WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 18 months ago

#23483 new defect (bug)

Incorrect image URL for subsites when using UPLOADS constant on multisite subdirectory installation — at Version 3

Reported by: creativeinfusion Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5.1
Component: Upload Keywords:
Focuses: multisite Cc:

Description (last modified by SergeyBiryukov)

If the UPLOADS constant is used on a Wordpress Multisite installed to subdirectory, using subdirectory mode, then image URLs for subsites are incorrect.

Example:

  • WP MS installed to www.domain.com/wordpress, subdirectory not subdomain
  • UPLOADS set to 'assets'

Main site uploads images to /wordpress/assets/...
Main site image URL is www.domain.com/wordpress/assets/...

  1. Create subsite called 'subsite';
  2. Subsite uploads images to /wordpress/assets/sites/2/...
  3. Subsite image URL is www.domain.com/uk/assets/sites/2/... when it should be www.domain.com/assets/sites/2/...

This is because wp_upload_dir() uses get_option('siteurl') to derive the URL. It is probably right for subdomain multisite but wrong in this use case.

Change History (3)

comment:1 @creativeinfusion2 years ago

Tentative fix - check if multisite and not using subdomain install and use network_site_url instead

	if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) {
		$dir = ABSPATH . UPLOADS;
		if ( is_multsite() && is_subdomain_install() ) {
			$url = trailingslashit( $siteurl ) . UPLOADS;
		} else {
			$url = trailingslashit( network_site_url() ) . UPLOADS;
		}
	}

comment:2 @sabreuse2 years ago

  • Component changed from General to Multisite

comment:3 @SergeyBiryukov2 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.