From 33b7bb01bd2c33e64f1c4d939970f01c84badedf Mon Sep 17 00:00:00 2001 From: Todd Coleman Date: Wed, 14 Jan 2026 12:36:43 -0500 Subject: [PATCH 1/2] Fix SVG MIME type recognition for third-party plugins Adds global upload_mimes filter registration on init to ensure SVG MIME type is recognized in all contexts, fixing compatibility with WP Offload Media and similar plugins. Fixes #286 --- safe-svg.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/safe-svg.php b/safe-svg.php index 3bf5367..25d6f49 100644 --- a/safe-svg.php +++ b/safe-svg.php @@ -149,6 +149,10 @@ function ( $tabs ) { // Init all the things. add_action( 'init', array( $this, 'setup_blocks' ) ); + + // Register SVG MIME type globally for third-party plugin compatibility (e.g., WP Offload Media). + // This ensures wp_check_filetype() can identify SVG files in all contexts. + add_action( 'init', array( $this, 'register_svg_mime_type' ) ); add_filter( 'wp_handle_sideload_prefilter', array( $this, 'check_for_svg' ) ); add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) ); add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 ); @@ -173,6 +177,22 @@ public function allow_svg_from_upload() { add_filter( 'wp_check_filetype_and_ext', array( $this, 'fix_mime_type_svg' ), 75, 4 ); } + /** + * Register SVG MIME type globally for proper detection by third-party plugins. + * + * This ensures wp_check_filetype() can identify SVG files in all contexts, + * not just during specific admin page loads. This fixes compatibility with + * plugins like WP Offload Media that process files outside of the standard + * WordPress upload flow. + * + * @since 2.4.1 + * + * @return void + */ + public function register_svg_mime_type() { + add_filter( 'upload_mimes', array( $this, 'allow_svg' ) ); + } + /** * Custom function to check if user can upload svg. * From 5acd4555ea328673e1b4c8da651ec0c37d3eb074 Mon Sep 17 00:00:00 2001 From: Todd Coleman Date: Wed, 14 Jan 2026 13:23:47 -0500 Subject: [PATCH 2/2] Register SVG MIME type globally for improved compatibility with third-party plugins --- safe-svg.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/safe-svg.php b/safe-svg.php index 25d6f49..53fb744 100644 --- a/safe-svg.php +++ b/safe-svg.php @@ -149,10 +149,8 @@ function ( $tabs ) { // Init all the things. add_action( 'init', array( $this, 'setup_blocks' ) ); - - // Register SVG MIME type globally for third-party plugin compatibility (e.g., WP Offload Media). - // This ensures wp_check_filetype() can identify SVG files in all contexts. add_action( 'init', array( $this, 'register_svg_mime_type' ) ); + add_filter( 'wp_check_filetype_and_ext', array( $this, 'fix_mime_type_svg' ), 100, 4 ); add_filter( 'wp_handle_sideload_prefilter', array( $this, 'check_for_svg' ) ); add_filter( 'wp_handle_upload_prefilter', array( $this, 'check_for_svg' ) ); add_filter( 'wp_prepare_attachment_for_js', array( $this, 'fix_admin_preview' ), 10, 3 );