Oh,
by the way, I use SG optimizer to generate the .WEBP copies of the images.
Hi!
I don’t see a filter for this, but I suspect that’s how he’ll want to do this – if he thinks it’s a good idea.
I think the filter call would go in the media_sync_import_files function of MediaSync.class.php just after the set of $is_in_db at line 568.
Looks like doing:
$is_in_db = apply_filters( ‘the name‘, $is_in_db, useful vars );
would give you what’s needed.
Hi @fabriziomazzei, this is currently possible if you place this code somewhere in your template (e.g. functions.php):
/**
* 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)
{
// Skip what's skipped by plugin
if ($is_ignored) {
return true;
}
// Do not skip folders
if (is_dir($full_path)) {
return false;
}
$is_image = in_array(strtolower(pathinfo($full_path, PATHINFO_EXTENSION)), array('jpg', 'jpeg', 'png'));
// $is_image = preg_match("/^.*\.(jpg|jpeg|png)$/i", $file_name) == true;
// Skip if not image
return !$is_image;
}
add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);
Not sure about performance, so I also added regex version (commented out). But this should show only jpg, jpeg, and png files.
—
Thanks for the suggestion Simon, but this hook filter already exists, so he doesn’t even need to edit the plugin 🙂
Or if only .webp files need to be skiped, this can be used:
/**
* 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)
{
// Skip what's skipped by plugin
if ($is_ignored) {
return true;
}
return strtolower(pathinfo($full_path, PATHINFO_EXTENSION)) == 'webp';
}
add_filter('media_sync_filter_is_scan_object_ignored', 'my_custom_media_sync_additional_file_skip', 10, 3);
Hi guys,
thank you to both of you for your help!
Eventually, @erolsk8 the first solution you gave me worked like a charm! 🙂
Thanks
Fabrizio
Great! I’ll have to find some time to create UI for this, but who knows when that might be. So I’m glad this solution worked 🙂
Yea, thank you, a filter for the extensions would make this plugin perfect.
Fabrizio
Great!
Dunno how I missed that existing filter.