Skip to content

Commit 66a87a6

Browse files
committed
Add full support for the [gallery] shortcode.
1 parent 2a53ae9 commit 66a87a6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

network-media-library.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,27 @@ function admin_post_thumbnail_html( string $content, $post_id, $thumbnail_id ) :
237237
return $image;
238238
}, 999, 4 );
239239

240+
/**
241+
* Filters the default gallery shortcode output so it shows media from the network media library site.
242+
*
243+
* @param string $output The gallery output.
244+
* @param array $attr Attributes of the gallery shortcode.
245+
* @param int $instance Unique numeric ID of this gallery shortcode instance.
246+
* @return string The gallery output.
247+
*/
248+
function filter_post_gallery( string $output, array $attr, int $instance ) : string {
249+
remove_filter( 'post_gallery', __NAMESPACE__ . '\filter_post_gallery', 0 );
250+
251+
switch_to_media_site();
252+
$output = gallery_shortcode( $attr );
253+
restore_current_blog();
254+
255+
add_filter( 'post_gallery', __NAMESPACE__ . '\filter_post_gallery', 0, 3 );
256+
257+
return $output;
258+
}
259+
add_filter( 'post_gallery', __NAMESPACE__ . '\filter_post_gallery', 0, 3 );
260+
240261
// Allow users to upload attachments.
241262
add_action( 'load-async-upload.php', __NAMESPACE__ . '\switch_to_media_site', 0 );
242263
add_action( 'wp_ajax_upload-attachment', __NAMESPACE__ . '\switch_to_media_site', 0 );

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A future version of this plugin will hopefully remove the need for users to be a
3939

4040
## Compatibility
4141

42-
Network Media Library works transparently and seamlessly with all built-in WordPress media functionality, including uploading files, cropping images, inserting into posts, and viewing attachments. Its functionality works with the site icon, site logo, background and header images, featured images, and regular media.
42+
Network Media Library works transparently and seamlessly with all built-in WordPress media functionality, including uploading files, cropping images, inserting into posts, and viewing attachments. Its functionality works with the site icon, site logo, background and header images, featured images, galleries, the audio and image widgets, and regular media management.
4343

4444
Some functionality, such as editing or deleting attachments, can only be performed from the admin area of the central media library. Links to media from other sites mostly work, although there are a couple of edge case bugs in WordPress core that need to be fixed (I'll get to these soon).
4545

0 commit comments

Comments
 (0)