• Resolved ashmozza89

    (@ashmozza89)


    Hi

    For some reason the plugin is importing all image thumbnail sizes, even though it is meant to ignore them?

    Thanks

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

    (@ashmozza89)

    Found this code from another thread seems to be working

    /**
     * Overwrite Media Sync plugin rules for skipping scanned files or folders.
     *
     * File/folder contains:
     * $fileOrFolder->getFilename()
     * $fileOrFolder->getPathname())
     * $fileOrFolder->isDir())
     *
     * Should return bool value.
     *
     * @param boolean $is_ignored Default rules for this file/folder (skipping thumbnails, index.php, hidden files, etc.)
     * @param RecursiveDirectoryIterator $fileOrFolder Each scanned file/folder
     * @return boolean
     */
    function my_custom_media_sync_additional_file_skip($is_ignored, $fileOrFolder)
    {
        $name = $fileOrFolder->getFilename();
    
        // Check if it is optimized .webp file
        $is_optimized_webp = preg_match('/.[a-z]{3,4}.webp/i', $file_name) == true;
    
        // Already ignored files or webp
        return $is_ignored || $is_optimized_webp;
    }

    UPDATE: Still importing thumbnail webp versions unfortunately

    • This reply was modified 3 years, 1 month ago by ashmozza89.
    Plugin Author erolsk8

    (@erolsk8)

    Hi @ashmozza89, yes, this code should work for ignoring all .webp files. Maybe it needs to be tweaked a bit. How are those file names ending?

    Thread Starter ashmozza89

    (@ashmozza89)

    Hi, They are named as follows
    Main image .jpg.webp
    Thumbnails example -1024×1024.jpg.webp

    • This reply was modified 3 years, 1 month ago by ashmozza89.
    • This reply was modified 3 years, 1 month ago by ashmozza89.
    Plugin Author erolsk8

    (@erolsk8)

    Hmm that’s strange, both of those should be ignored with that code snippet. Maybe it wasn’t being applied.

    I currently don’t have any better idea, unfortunately.

    I hope I’ll find some time to make all of this configurable, with some UI.

    Thread Starter ashmozza89

    (@ashmozza89)

    I actually noticed I missed this part when copy pasting the code

    add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);

    So add it, Initiated scan and it just gives the following error

    There has been a critical error on this website. Please check your site admin email inbox for instructions.

    Remove it, re-scan and it scan fine, tho shows webp images.

    Thread Starter ashmozza89

    (@ashmozza89)

    Found another code and changed it, seems to ignore webp now

    function my_custom_media_sync_additional_file_skip($is_ignored, $full_path, $file_name)
    {
        $is_this_webp_thumbnail = strpos($file_name, '.webp') !== false;
    
        return $is_ignored || $is_this_webp_thumbnail;
    }
    add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);
    
    Plugin Author erolsk8

    (@erolsk8)

    Hey @ashmozza89,

    Great news, I’m glad you found the solution. But just so you know, this last code will ignore all .webp files, not just thumbnails. I mean, that’s fine if you don’t need to import any original .webp file.

    First code you sent was checking if file ends with two extensions (e.g. .jpg.webp, .jpeg.webp, etc.). And now I see what was wrong with the original code you sent, that was working in older versions of this plugin, and in order to work with the current version it should be something like this:

    /**
     * Overwrite Media Sync plugin rules for skipping scanned files or folders.
     *
     * Should return bool value.
     *
     * @param boolean $is_ignored Default rules for this file/folder (skipping thumbnails, index.php, hidden files, etc.)
     * @param string $full_path Each scanned file/folder absolute path
     * @param string $file_name Each scanned file/folder name
     * @return boolean
     */
    function my_custom_media_sync_additional_file_skip($is_ignored, $full_path, $file_name)
    {
        // Check if it is optimized .webp file
        $is_optimized_webp = preg_match('/.[a-z]{3,4}.webp/i', $file_name) == true;
    
        // Already ignored files or webp
        return $is_ignored || $is_optimized_webp;
    }
    add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);

    Sorry for the confusion ??

    Erol

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Importing Thumbnails’ is closed to new replies.