network-media-library
network-media-library copied to clipboard
Support `wp_get_attachment_url()`
wp_get_attachment_url()
should work transparently in the same way that wp_get_attachment_image_src()
does.
This needs some filters adding to WordPress core in order for it to be able to work.
There is a wp_get_attachment_url
filter which could be used for this.
/**
* Filters the attachment URL.
*
* @since 2.1.0
*
* @param string $url URL for the given attachment.
* @param int $attachment_id Attachment post ID.
*/
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
Probably this would fix:
add_filter( 'wp_get_attachment_url', function( $image, $attachment_id ) {
static $switched = false;
if ( $switched ) {
return $image;
}
if ( is_media_site() ) {
return $image;
}
switch_to_media_site();
$switched = true;
$image = wp_get_attachment_url( $attachment_id );
$switched = false;
restore_current_blog();
return $image;
}, 999, 2 );