Opened 15 years ago
Closed 15 years ago
#11998 closed defect (bug) (fixed)
switch_to_blog and wp_upload_dir, with wpmu 2.8.4a
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | 3.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Multisite | Keywords: | has-patch |
Focuses: | Cc: |
Description
MU Trac Ticket: http://trac.mu.wordpress.org/ticket/1154
When you use the switch_to_blog, wp_upload_dir doesn't take care of the blog_id you switch to.
Here is an example, the action is running on blog id 4, but the target is blog id 14
array(6) { ["path"]=> string(74) "/data/web/srvph1/zeclic.fr/www/htdocs/wp-content/blogs.dir/4/files/2009/11" ["url"]=> string(62) "http://fandebd.zeclic.fr/wp-content/blogs.dir/14/files/2009/11" ["subdir"]=> string(8) "/2009/11" ["basedir"]=> string(67) "/data/web/srvph1/zeclic.fr/www/htdocs/wp-content/blogs.dir/4/files" ["baseurl"]=> string(54) "http://fandebd.zeclic.fr/wp-content/blogs.dir/14/files" ["error"]=> bool(false) }
Cause is /wp-includes/functions.php Line 2057 to 2060:
if ( defined('UPLOADS')) { $dir = ABSPATH . UPLOADS; $url = trailingslashit( $siteurl ) . UPLOADS; }
Correction for 'basedir' is :
global $switched; if ( defined('UPLOADS') && $switched === false) { $dir = ABSPATH . UPLOADS; $url = trailingslashit( $siteurl ) . UPLOADS; }
But 'path' key doesn't change. It's modified by another filter /wp-includes/wpmu-functions.php :
function mu_upload_dir( $uploads ) { $dir = $uploads[ 'basedir' ]; if( defined( 'BLOGUPLOADDIR' ) ) $dir = constant( 'BLOGUPLOADDIR' ); $dir = untrailingslashit( $dir ) . $uploads[ 'subdir' ]; $uploads[ 'path' ] = $dir; return $uploads; } add_filter( 'upload_dir', 'mu_upload_dir' );
Patch is :
function mu_upload_dir( $uploads ) { global $switched; $dir = $uploads[ 'basedir' ]; if( defined( 'BLOGUPLOADDIR' ) && switched === false ) $dir = constant( 'BLOGUPLOADDIR' ); $dir = untrailingslashit( $dir ) . $uploads[ 'subdir' ]; $uploads[ 'path' ] = $dir; return $uploads; } add_filter( 'upload_dir', 'mu_upload_dir' );
perhaps we can put the two patch only on wpmu-functions.php ....
my wpmu_version = '2.8.4a';
Attachments (2)
Change History (8)
#3
@
15 years ago
I think it still is a problem or something very similar still exists.
Was using wp_upload_dir but it always pointed to current blog and not the switch to blog.
Had to use WP_CONTENT_DIR constant instead.
#4
in reply to:
↑ 2
@
15 years ago
- Keywords has-patch added
Replying to wpmuguru:
Have you verified this is still a problem?
Yes, it is. The attached patch should fix it. Tested with:
function u() { switch_to_blog( 4 ); var_dump( wp_upload_dir() ); restore_current_blog(); } add_action('admin_init', 'u');
Have you verified this is still a problem?