Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#31667 closed defect (bug) (invalid)

URL from wp_get_attachment_image_src includes "sites/1" after using switch_to_blog(1)

Reported by: leedo's profile leedo Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1.1
Component: Upload Keywords: reporter-feedback
Focuses: multisite Cc:

Description

We're trying to do galleries that work across blogs in a network, and I ran into what seems like a minor bug.

Normally, our uploads directory for blog #1 is the base uploads directory. However, if we're in the admin for blog #2 and switch_to_blog(1), the uploads directory for blog #1 now has sites/1 included in it.

I was able to work around this by symlinking sites/1 to ../, but thought this might be something worth fixing.

Change History (4)

#1 follow-up: @jeremyfelt
9 years ago

  • Component changed from Networks and Sites to Upload
  • Keywords reporter-feedback added

In mu-plugins, I added:

add_action( 'admin_init', 'jf_do_this' );
function jf_do_this() {
	switch_to_blog(1);
	die( wp_upload_dir()['path'] );
}

At first, my uploads directory was as expected, /srv/www/wordpress-develop/src/wp-content/uploads/2015/04.

If I set BLOG_ID_CURRENT_SITE to 2 so that is_main_site() returns false on blog_id 1, then I get an uploads directory of /srv/www/wordpress-develop/src/wp-content/uploads/sites/1/2015/04.

Looking at wp_upload_dir(), the only way to trigger this should be if one of is_main_network(), is_main_site(), or defined( 'MULTISITE' ) is false. Can you confirm this on your setup?

#2 in reply to: ↑ 1 @leedo
9 years ago

Actually, looking closer at this, I'm seeing the cause. In our sunrise.php we're always setting $current_site->blog_id to the ID of the currently selected blog. Sorry for the confusion, probably safe to close this ticket.

Last edited 9 years ago by leedo (previous) (diff)

#3 @leedo
9 years ago

  • Resolution set to invalid
  • Status changed from new to closed

#4 @DrewAPicture
9 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.