• Resolved fabriziomazzei

    (@fabriziomazzei)


    Hi,

    the plugin is very useful, thank you.

    Just wondering if there is a way to filter also by extension.
    In my specific case, it finds a lot of stuff not in the media library, but I would like to give me only .PNG and .JPG as results.

    I cannot see any filter, so maybe I can use some parameter in the URL?

    Thank you
    Fabrizio

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter fabriziomazzei

    (@fabriziomazzei)

    Oh,

    by the way, I use SG optimizer to generate the .WEBP copies of the images.

    Plugin Contributor Simon Kane

    (@simonkane)

    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.

    Plugin Author erolsk8

    (@erolsk8)

    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 ??

    Plugin Author erolsk8

    (@erolsk8)

    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);
    Thread Starter fabriziomazzei

    (@fabriziomazzei)

    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

    Plugin Author erolsk8

    (@erolsk8)

    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 ??

    Thread Starter fabriziomazzei

    (@fabriziomazzei)

    Yea, thank you, a filter for the extensions would make this plugin perfect.

    Fabrizio

    Plugin Contributor Simon Kane

    (@simonkane)

    Great!

    Dunno how I missed that existing filter.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Selecting extension’ is closed to new replies.