Open aubreypwd opened 4 years ago
Have you checked WP Core Trac to see if this is a known issue, or reported it?
@richaber Did not find on Trac: https://core.trac.wordpress.org/search?q=wp_get_attachment_image_url going to confirm this and report if I can verify on fresh install.
So in my example, I have a sub-dir site with three sites:
1) The root site (ID: 1
)
2) site-2 (ID: 2
)
3) site-3 (ID: 3
)
Then I load up site 2
wp-admin/ and let the following code run in an mu-plugin/
:
add_action( 'plugins_loaded', function() {
switch_to_blog( 3 );
error_log( print_r( (object) [ __FILE__ => __LINE__,
wp_get_attachment_image_url( 4, 'full' ),
get_site( get_current_blog_id() ),
], true ) );
restore_current_blog();
} );
This switches to site 3
and gets an attachment URL using wp_get_attachment_image_url
and outputs the WP_Site of site 3
, but in the output:
(
[/app/public/wp-content/mu-plugins/debug.php] => 9
[0] => http://wordpress-subdir.test/site-2/wp-content/uploads/sites/3/2020/01/Database.png
[1] => WP_Site Object
(
[blog_id] => 3
[domain] => wordpress-subdir.test
[path] => /site-3/
[site_id] => 1
[registered] => 2020-01-31 20:43:10
[last_updated] => 2020-01-31 20:43:10
[public] => 1
[archived] => 0
[mature] => 0
[spam] => 0
[deleted] => 0
[lang_id] => 0
)
)
Notice that the URL [0] => http://wordpress-subdir.test/site-2/wp-content/uploads/sites/3/2020/01/Database.png
contains the site slug site-2
of site 2
even though we are actively on site 3
via switch_to_blog()
.
Oddly, on sub-domain I get:
(
[/app/public/wp-content/mu-plugins/debug.php] => 9
[0] => http://site2.wordpress-subdomain.test/wp-content/uploads/sites/3/2020/01/terminal-gnome.ong_.png
[1] => WP_Site Object
(
[blog_id] => 3
[domain] => site3.wordpress-subdomain.test
[path] => /
[site_id] => 1
[registered] => 2020-01-31 21:28:57
[last_updated] => 2020-01-31 21:28:57
[public] => 1
[archived] => 0
[mature] => 0
[spam] => 0
[deleted] => 0
[lang_id] => 0
)
)
Which does NOT contain the site slug of the admin dashboard.
Thought I would back this up with a little video explaining my findings: http://aubrey.pw/d/2019/1580507121.mp4
...even though
switch_to_blog()
is on another.Example
In the above example
$source_urls
all have paths appended instead of the path of switch_to_blog().