• Resolved Klemart3D

    (@klemart3d)


    There is a major bug in this plugin.
    The ‘file’ metadata of uploaded SVG files is incorrect in the database (‘wp_postmeta’ table filtered by meta_key = “_wp_attachment_metadata”), there is a slash at the beginning of the file name when there is none for other image formats (like jpg or png).
    This poses a problem on the front of a website because the path defined in the “srcset” of SVG images is wrong and the SVG image may not display correctly on some servers which filter resource paths with two slashes.

    To resolve this problem, in the ‘svg-support/functions/attachment.php’ file, line 73, you need to replace:
    $relative_path = str_replace($upload_dir['basedir'], '', $svg_path);
    through :
    $relative_path = str_replace(trailingslashit($upload_dir['basedir']), '', $svg_path);
    (Or something like that). This is working for me, can you check on your end and add this fix to the next version of the add-on?
    Thank you.

    • This topic was modified 2 years, 10 months ago by Klemart3D.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Klemart3D

    (@klemart3d)

    Useful SQL query (for comparison):
    SELECT * FROM wp_postmeta WHERE meta_key = "_wp_attachment_metadata"

    Thread Starter Klemart3D

    (@klemart3d)

    And may me you need to add a patch with the fix to update all corrupted metadatas of previously uploaded SVG files.

    Plugin Author Benbodhi

    (@benbodhi)

    Interesting, thanks for pointing this out.
    I’ll look into it this week and will get it sorted.

    Thread Starter Klemart3D

    (@klemart3d)

    Here is a patch I wrote to fix previously uploaded SVG files metadata :

    
    /**
     * Patch to remove slash in file name metadata for SVG files previously uploaded from admin
     * An admin page need to be loaded to execute this function
     *  !! Once executed, this function must be removed !!
     */
    function patch_file_metadata_trailing_slash() {
    	global $wpdb;
    	$sql = $wpdb->prepare( "SELECT 'post_id' FROM $wpdb->postmeta WHERE 'meta_key' = '_wp_attachment_metadata'"; );
    	$results = $wpdb->get_results( $sql );
    	$wpdb->flush();
    	if ( ! empty( $results ) ) {
    		foreach ( $results as $meta ) {
    			$metadata = wp_get_attachment_metadata($meta->post_id);
    			$trimmed_filename = ltrim($metadata['file'], '/');
    			if ($metadata['file'] != $trimmed_filename) {
    				$metadata['file'] = $trimmed_filename;
    				wp_update_attachment_metadata($meta->post_id, $metadata);
    			}
    		}
    	}
    	add_action( 'admin_notices', function(){ ?> <div class="notice notice-success"><p>SVG Patch successfully applied. You can delete the function !</p></div> <?php });
    }
    add_action( 'admin_init', 'patch_file_metadata_trailing_slash' );
    
    • This reply was modified 2 years, 10 months ago by Klemart3D.
    • This reply was modified 2 years, 10 months ago by Klemart3D.
    • This reply was modified 2 years, 10 months ago by Klemart3D.
    • This reply was modified 2 years, 10 months ago by Klemart3D.
    • This reply was modified 2 years, 10 months ago by Klemart3D.
    Plugin Author Benbodhi

    (@benbodhi)

    Wow, thank you for doing that and sharing ??
    I’ll see if there’s a way to deal with this automatically so no one has to do anything.
    I haven’t had a chance to verify in the database, but there’s some metadata work going on this week and I’ll look at this among the other things to do with image dimensions.

    Thanks again ??

    Plugin Author Benbodhi

    (@benbodhi)

    I believe this is fixed in version 2.4 which I’ll push out in the next few hours.

    Thank you for providing the patch as well, in case anyone wants to use it.

    If you notice issues still after update to 2.4, please do let me know. It’s available in trunk now, but will be updated as normal in the next few hours.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘IMPORTANT : Fix wrong file metadata in DB & srcset path for SVG files’ is closed to new replies.