Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter Ben Cary

    (@bencary9)

    I tested some changes to the plugin on my local. I’ve only done some very limited tests but it seems to have worked.

    Original Code:

    <?php
    $old_name = basename( $this->image['link'] );
    $old_name_clean = substr( $old_name, 0, -4 );
    $new_name = basename( $this->image['new_url'] );
    $new_name_clean = substr( $new_name, 0, -4 );

    $replaces = array( $old_name => $new_name );
    <?php
    $replaces[ $img['file'] ] = $new_thumb;

    Updated Code For Testing:

    <?php
    $upload_dir = wp_get_upload_dir();
    $old_name = ltrim( str_replace( trailingslashit( $upload_dir['baseurl'] ), '', $this->image['link'] ), '/' );
    $old_name_clean = pathinfo( basename( $old_name ), PATHINFO_FILENAME );
    $new_name = ltrim( str_replace( trailingslashit( $upload_dir['baseurl'] ), '', $this->image['new_url'] ), '/' );
    $new_name_clean = pathinfo( basename( $new_name ), PATHINFO_FILENAME );

    $replaces = array( $old_name => $new_name );
    <?php
    $replaces[ dirname( $old_name ) . '/' . $img['file'] ] = dirname( $new_name ) . '/' . $new_thumb;

    Will need to test much further but I’m out of time for the weekend. Hopefully on the right track though.

    Thread Starter Ben Cary

    (@bencary9)

    Taking a closer look at your plugin code.

    convert_single_image() Properly receives one attachment ID. And it seems to work properly, it converts the single physical file from PNG to JPG as expected.

    update_image_data() Seems to discard the directory. It begins to only identify the file by the basename:

    <?php
    $old_name = basename( $this->image['link'] );
    $new_name = basename( $this->image['new_url'] );

    Then it performs the global replacements:

    <?php
    WHERE meta_value LIKE '%/filename.png%'
    REPLACE( meta_value, '/filename.png', '/filename.jpg' )

    It looks like this would impact:

    • Other attachments’ _wp_attached_file metadata
    • Other attachments’ serialized image metadata
    • Post content and excerpts
    • Options and third-party plugin tables
    • Any URL ending with the same filename, regardless of directory

    So one physical PNG file is converted and then several unrelated files are changed to .jpg resulting in 404’s.

    Thread Starter Ben Cary

    (@bencary9)

    I also forgot to add… When I’m seeing the image 404’s in the posts after only converting a single PNG file to JPG – and all of the files with the same filenames end up with a .jpg extension – these are just standard post images. They aren’t stored in any special database tables by page builders or anything like that. These are just core WP image blocks within standard posts.

    Thread Starter Ben Cary

    (@bencary9)

    Appreciate your quick responses.

    I have done some further troubleshooting and confirmed that when we have files that use the same filename and convert a single file from PNG to JPG, the plugin is changing the file extension of all the filenames to end in .jpg in the Media Library.

    Here’s an example:

    /wp-content/uploads/2023/11/Screen-Shot-2023-10-31-at-3.53.44-PM.png
    /wp-content/uploads/2023/10/Screen-Shot-2023-10-31-at-3.53.44-PM.png
    /wp-content/uploads/2017/07/Screen-Shot-2023-10-31-at-3.53.44-PM.png

    Those are the 3 original files. They all exist in different directories, they all have unique IDs. It’s a bit of a mess because this client is essentially uploading the same image with same filename (a mess we are attempting to clean up – and your plugin has come in very handy btw).

    But when I only convert one file, say:

    /wp-content/uploads/2023/11/Screen-Shot-2023-10-31-at-3.53.44-PM.png

    That will convert all of the files to have the .jpg extension when viewing the Media Library. And this is resulting in some 404’s because I believe the plugin is actually only converting one file to JPG (as it should). But it seems to be changing the URLs in the DB for all of the images, pointing to .jpg files that don’t exist for 2 of the images.

    In regard to the issue where the plugin would display the ‘server is not powerful enough’ message – I knew this was not directly related to server resources. I can throw an abundance of resources at the server and still get the same results. I think this is happening when files are corrupted or have a .png extension and may not actually be PNG files. I’m still looking into this further and it’s possible the message may occur for various reasons. I’ll keep looking at this & checking the logs to see what I find. I believe it was just coincidence that when I originally ran into the issue it was only on these files that had the same filename.

    • This reply was modified 6 days, 4 hours ago by Ben Cary.
    Thread Starter Ben Cary

    (@bencary9)

    Upon further inspection & also crawling the site for 404’s we found more problems…

    Both can exist as different PNG files, both have the same basename, example: feature-2.png.

    When the first image is converted to JPG the plugin does a broad DB replacement: /feature-2.png → /feature-2.jpg

    That can change both database URLs, even if a JPG was created in only one of the two directories. The directory remains visible in the URL, but the extension is changed without confirming that the corresponding JPG exists there. The crawler tries to load /wp-content/uploads/2022/06/feature-2.png and it’s not there because it hasn’t been created.

    We encountered lots of these 404s with duplicate basenames:

    /wp-content/uploads/2021/09/feature-2.jpg
    /wp-content/uploads/2022/06/feature-2.jpg
    
    /wp-content/uploads/2023/10/Screen-Shot-2023-10-31-at-3.02.31-PM.jpg
    /wp-content/uploads/2023/11/Screen-Shot-2023-10-31-at-3.02.31-PM.jpg
    
    /wp-content/uploads/2023/10/Screen-Shot-2023-10-31-at-3.53.44-PM.jpg
    /wp-content/uploads/2023/11/Screen-Shot-2023-10-31-at-3.53.44-PM.jpg
    
    /wp-content/uploads/2022/10/image.jpg
    /wp-content/uploads/2025/05/image.jpg
    Thread Starter Ben Cary

    (@bencary9)

    Double checked my local sever and I’m definitely running PHP 7 via MAMP. Went ahead and restarted the server and tried again. Still receiving the following error:

    Fatal error: Cannot use BracketSpace\Notification\Core\Notification as Notification because the name is already in use in /Applications/MAMP/htdocs/wh/wp-content/plugins/notification/class/Abstracts/Trigger.php on line 14
    The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.

    Thanks,
    Ben

    I’m also experiencing an issue with some emails displaying properly and others are missing CSS styling.

    In my case, the WooCommerce New Order, Invoices, Canceled Orders and New Account emails are working fine.

    CSS is not working properly for the Order Completed or Customer Note emails though.

    Not sure if this helps debug but the Order Completed and Customer Note emails in my situation are triggered when I print a label in ShipStation. The other emails wouldn’t involve a third-party triggering them.

    I’m using the WPSMTP plugin to send emails – not the post-smtp plugin mentioned above. Also running a custom theme (not storefront).

    Running WP 5.2.1 and WooCommerce 3.6.4

    Thanks,
    Ben

Viewing 7 replies - 1 through 7 (of 7 total)