Hey @taisa1984 thanks for the feedback. Could you please let me know which plugin you used? So I can check which files it creates.
Because this plugin should skip those thumbnails. At lease those created by WordPress – files ending with for example -100×100.jpg or some other extension with 3 or 4 characters, here is the regex for that: /[_-]\d+x\d+(?=\.[a-z]{3,4}$)/im
Thanks
Erol
Hi!
I am using Imagify that creates files with .jpg.webp extension.
I wanted to make it easier for me to really link and clean the media, so I tried to edit the code, added this and it worked for me to MediaSync.class.php. 🙂
// Only file name
$file_name = $file->getFilename();
// 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;
<strong>//Check if it is a .webp file
$is_webp=preg_match('/webp/i', $file_name) == true;</strong>
if ($obj_rdi->isDot() || $file_name == ".DS_Store" || $file_name == ".htaccess" || $file_name == "index.php" || $is_thumb <strong>|| $is_webp)</strong> {
continue;
}
-
This reply was modified 9 months, 3 weeks ago by
taisa1984.
-
This reply was modified 9 months, 3 weeks ago by
taisa1984.
Hi @taisa1984, I just pushed a new version (1.1.3) which accepts custom hook function to overwrite or improve which files are ignored.
I wrote an example that you can add to your theme’s functions.php file or wherever it works for you.
And your regex will actually skip all files containing “webp” text, so not just as an extension. And I guess you also don’t want to skip actual .webp files, but only those which are optimized (e.g. .jpg.webp). So I tweaked that regex a bit 🙂
/**
* 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;
}
add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);
Hope this will help until there are proper options for this. Please let me know if it works 🙂
Thanks
Erol
Hi! Thanks for trying.
I was managing with the code I pasted before fine. Only I had to make it on batches from 5 or 10. I think it had problems with the largest files and PNG, some of them only worked on importing them 1 at a time. But maybe it was something on my server.
Anyway I just tried with your code and didn’t work, the .jpg.webp files still showed, and also it loaded the interface quite slow.
I am now almost done. It was a really great help anyway. Thanks!
Oh ok, too bad it didn’t work perfectly for you, but I’m glad you figure it out.
So I’m close this topic for now and we can open it if needed.