When switching between blogs, wp_upload_dir 'baseurl' and 'url' may be pointing to the current blog not the switched one
|Reported by:||igmoweb||Owned by:|
Only tested on subfolder multisite (I don't have a way to test on a subdomain install right now).
It seems very similar to ticket #23483 but I'm not sure if it should be treated the same:
Example with two blogs in a network:
- www.mydomain.com/my-source-blog (ID:5)
- www.mydomain.com/my-destination-blog (ID:15)
I discover this while trying to move a post with images from a blog to another. The post is copied and images inside the post are copied too.
Starting point: The current blog ID is 15 (my-destination-blog). I'm trying to get upload URLs from the current blog:
switch_to_blog( 5 ); $source_upload_dir = wp_upload_dir(); $source_upload_baseurl = $source_upload_dir['baseurl']; restore_current_blog(); $destination_upload_dir = wp_upload_dir(); $destination_upload_baseurl = $destination_upload_dir ['baseurl'];
At this point, $source_upload_baseurl is:
Where should be:
$destination_upload_baseurl is fine.
It seems that if get_option( 'upload_url_path' ) returns false, wp_upload_dir() makes use of WP_CONTENT_URL constant that is set to the current blog URL at the beggining of the execution (in default-constants.php):
define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
This value obviously does not change when switching a blog.