Skip to content

SVG uploads in the WP Customizer not working #289

@patrickwc

Description

@patrickwc

Describe the bug

For some reason, when using Safe SVG uploading SVGs used to work within the customizer. Now they do not.

After some time testing, I managed to use a filter on Plupload which enabled uploading (plupload_default_settings)

I think this might be because Customizer uses Plupload, whose default config is missing svg from the allowed file extensions. But it worked before, so I am not sure really. In case it helps, this is what fixed it for me:

if (
			isset( $settings['filters']['mime_types'] )
			&& \is_array( $settings['filters']['mime_types'] )
		) {
			foreach ( $settings['filters']['mime_types'] as &$mime_type ) {
				if (
					isset( $mime_type['extensions'] )
					&& \is_string( $mime_type['extensions'] )
					&& \strpos( $mime_type['extensions'], 'svg' ) === false
				) {
					$mime_type['extensions'] .= ',svg,svgz';
				}
			}
		}

Steps to Reproduce

  • Add a custom customizer image via the theme customizer API http://codex.wordpress.org/Theme_Customization_API
  • via WP_Customize_Image_Control or WP_Customize_Media_Control
  • try and add an SVG.
  • The same SVG upload works in the media library, but not via the customizer.

Screenshots, screen recording, code snippet

See #279 (comment)

Environment information

all browsers etc

WordPress information

Latest WP. Tried with all plugins disabled apart from Safe SVG too.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions