[wp-trac] [WordPress Trac] #25650: When switching between blogs, wp_upload_dir 'baseurl' and 'url' may be pointing to the current blog not the switched one

WordPress Trac noreply at wordpress.org
Thu Jun 2 22:27:17 UTC 2022


#25650: When switching between blogs, wp_upload_dir 'baseurl' and 'url' may be
pointing to the current blog not the switched one
--------------------------+------------------------------
 Reporter:  igmoweb       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Upload        |     Version:  3.6.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  multisite
--------------------------+------------------------------

Comment (by ideag):

 I had another idea to identify if {{{WP_CONTENT_URL}}} was explicitly set
 in {{{wp-config.php}}}. It goes along these lines (at the top of
 {{{content_url()}}} method):
 {{{
 $url = WP_CONTENT_URL;
 if ( ms_is_switched() ) {
     $original_blog_id = $GLOBALS['_wp_switched_stack'][0];
     $dynamic_content_url = get_blog_option( $original_blog_id, 'siteurl' )
 . '/wp-content';
     if ( WP_CONTENT_URL === $dynamic_content_url ) {
         $url = get_option( 'siteurl' ) . '/wp-content';
     }
 }
 }}}
 The upside for this it allows to avoids creating a new constant in the
 step 3 of the above patch.
 The downside is this adds an additional loop of {{{switch_to_blog()}}}
 inside the {{{get_blog_option()}}} method and an additional call to
 get_option(), so it should have a bigger performance fingerprint, it uses
 a global variable and is in general harder to read and understand and I'm
 not sure I can write a test that would not rely on the same code we are
 testing.
 Also, most significantly, this would fail if someone explicitly set their
 {{{WP_CONTENT_URL}}} to the upload url of the main site. Can't find a way
 around that yet.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/25650#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list