Support » Plugin: Media Sync » Plugin ignores -scaled files

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author erolsk8

    (@erolsk8)

    Hi @sevlad, thank you for pointing that out, but this is actually intentional. Please check out this topic:
    https://wordpress.org/support/topic/issue-with-scaled-media-files/

    Until that’s made optional, you could try to download and install 1.1.7 version of this plugin: https://wordpress.org/plugins/media-sync/advanced/

    Or if you want to keep the latest version, you can overwrite which files are ignored using this hook function:

    /**
     * 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)
    {
        // If it contains image size at the end (i.e. -100x100.jpg)
        $is_thumb = preg_match('/[_-]\d+x\d+(?=\.[a-z]{3,4}$)/im', $file_name) == true;
    
        // Default file/folder skipping rules
        $is_ignored = $file_name == ".DS_Store" || $file_name == ".htaccess" || $file_name == "index.php" || $is_thumb;
    
        return $is_ignored;
    }
    add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);

    You can of course modify it to ignore whatever you want.

    Thread Starter SeVlad

    (@sevlad)

    Thanks for the suggestion, but I have already used another plugin.

    However, it is very strange that this was done on purpose. Thus, many files are lost and other problems appear. @nudeworldorder writes about this in the topic shown.

    For example, for me this led to the creation of copies when importing content and changing their names. And I didn’t notice it right away. As a result, several days of work were in vain and had to be redone.

    Maybe then you should make such a setting so that you can control it?

    Plugin Author erolsk8

    (@erolsk8)

    Making that optional would be great if I just had time to do it 😅

    And if you look through the topics, everyone wants to filter out different files (by file name, file type, etc.). So I’ll definitely need to make that configurable at some point. Currently, it can only be done with that hook function I mentioned.

    Thanks for the feedback 🙌

    Thread Starter SeVlad

    (@sevlad)

    Hmm … I don’t think we understood each other.

    I’m talking about the fact that your plugin does not add files with -scaled in the name to the library. And this is necessary.

    Plugin Author erolsk8

    (@erolsk8)

    Yes, I know it does not add those scaled images in Media Library. I did this intentionally because those files are auto-generated by WordPress, the same way thumbnail files are auto-generated, so these are not original files.

    If I was letting those -scaled files be listed, selected, and imported, you would end up with 2 items in Media Library for 1 original file.

    For example, if you upload: img.jpg in Media Library (without this plugin), you will have something like this in the directory:

    
    img.jpg
    img-38x38.jpg
    img-100x100.jpg
    ...
    img-scaled.jpg
    

    If I then let this plugin import both of those files, you’ll end up with 2 items in the Media Library (of two origin files: img.jpg and img-scaled.jpg). And then when WordPress regenerates thumbnails and everything, you would probably have something like this:

    
    img.jpg
    img-38x38.jpg
    img-100x100.jpg
    ...
    img-scaled.jpg
    img-scaled-38x38.jpg
    img-scaled-100x100.jpg
    ...
    img-scaled-scaled.jpg
    

    Hope this makes sense 🙂

    Thread Starter SeVlad

    (@sevlad)

    img-scaled-scaled.jpg

    This is not possible unless you change the size.
    And there can be a lot of files with -scaled.
    https://i.imgur.com/RWroH7o.jpeg

    In this case, it is possible to get img-scaled-1.jpg due to the fact that the file is physically located in the directory, but not registered.

    Think about it.

    Plugin Author erolsk8

    (@erolsk8)

    Sorry, but I don’t think I understand what you are trying to say.

    I’m not even sure what was the exact issue you had. I’d need some more details to understand your situation. I don’t know if you were transferring your website to new server and lost the database or just trying to import large files to Media Library. I mean there are endless scenarios and configurations one can have.

    Thread Starter SeVlad

    (@sevlad)

    The screenshot is the same as on the old site. So, as it should turn out on the new one.

    If these files are physically located in the directory, but will not be registered, then they will not be taken into account during import, but new ones will be uploaded and renamed by adding the -1 suffix.

    Plugin Author erolsk8

    (@erolsk8)

    Sorry again, but I’m completely lost now 🙂

    I’m not sure if you’re trying to explain how this plugin currently works or how you think it should work. But to me, it looks like you’re expecting some totally different functionality from what this plugin is meant for. I still didn’t see an explanation of your situation (story, scenario, process, etc.).

    But in any case, I understood that you found some other plugin, and it would be cool if you could share it here. So that if someone else stumbles upon this topic, they can try it out.

    Thank you

    It’s been quite some time since I wrestled with this, but since I was mentioned, as best I can remember, due to the way the WordPress feature is implemented, it’s actually the original file that should be excluded, with the -scaled image treated as the main one.

    But take it with a grain of salt, since I’m not able to easily retest this. Someone who’s got a local WordPress install for testing could probably clear up exactly what the correct behavior is fairly easily.

    Plugin Contributor Simon Kane

    (@simonkane)

    I disagree. This plugin is designedto import items that do not already exist in WordPress. A “-scaled” file, just like a 100×100, has been processed. Because the WP site that the item is being imported to may not have the same settings as the WP site where the deserived files were created, using anything other than the original file could cause both confusion, and incorrect results.

    And we haven’t even touched on “-rotated” yet. 😉
    Nor whatever other WP special things might crop up in the future.

    If you really need special handling and ignores, the filters are definitely what you need to use. I created one that does special handling for attaching series of images to WooCommerce products and tagging that in the Media Library so it’s even cross-referenced — it is not difficult to create any kind of unique handler you might need.

    • This reply was modified 10 months, 3 weeks ago by Simon Kane. Reason: typos
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Plugin ignores -scaled files’ is closed to new replies.