• Resolved diegootgs

    (@diegootgs)


    Hi there, this is Diego from the WPML compatibility team.

    We got several reports where SVG images are not working if the WPML Media Translator plugin is activated. E.g. here https://wpml.org/forums/topic/svg-broken-in-widgets/

    We created the following errata for this issue: https://wpml.org/errata/svg-support-activating-wpml-media-strips-uploads-folders-from-svg-image-url/

    After some debugging, we found that it happens because the SVG Support plugin is changing the image filepath in the?_wp_attachment_metadata?field.

    E.g. without SVG support plugin, we would have something like this when using wp_get_attachment_metadata:

    	
    {
        "width": 570,
        "height": 723,
        "file": "2023\/08\/image.svg",
        "sizes": {

    But with SVG support, we have this:

    {
        "width": 570,
        "height": 723,
        "file": "image.svg",
        "sizes": {

    As WPML Media uses the info from “file” to replace the URL, this breaks the image.

    This happens on the bodhi_svgs_generate_svg_attachment_metadata() function of your plugin, at the following snippet:

    $metadata = array(
    	'width'		=> intval($dimensions->width),
    	'height'	=> intval($dimensions->height),
    	'file'      => $filename
    );

    Fix

    It works correctly after the following steps:

    • Replace the snippet above with:
    $metadata = array(
    	'width'     => intval($dimensions->width),
    	'height'    => intval($dimensions->height),
    	'file'      => date("Y") . '/' . date("m") . '/' . $filename
    );
    • Increase the hook priority to 1:
    add_filter( 'wp_generate_attachment_metadata', 'bodhi_svgs_generate_svg_attachment_metadata', 1, 3 );
    

    Could you please check if it’s possible to implement this fix?

    The page I need help with: [log in to see the link]

  • The topic ‘Issue with WPML Media Translator’ is closed to new replies.