[wp-trac] [WordPress Trac] #11998: switch_to_blog and wp_upload_dir, with wpmu 2.8.4a

WordPress Trac wp-trac at lists.automattic.com
Mon Jan 25 03:24:03 UTC 2010


#11998: switch_to_blog and wp_upload_dir, with wpmu 2.8.4a
--------------------------+-------------------------------------------------
 Reporter:  wpmuguru      |       Owner:            
     Type:  defect (bug)  |      Status:  new       
 Priority:  normal        |   Milestone:  Unassigned
Component:  Multisite     |     Version:            
 Severity:  normal        |    Keywords:            
--------------------------+-------------------------------------------------
 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';

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11998>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list