Title: Selecting extension
Last modified: March 16, 2021

---

# Selecting extension

 *  Resolved [fabriziomazzei](https://wordpress.org/support/users/fabriziomazzei/)
 * (@fabriziomazzei)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/)
 * 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](https://wordpress.org/support/users/fabriziomazzei/)
 * (@fabriziomazzei)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14191194)
 * Oh,
 * by the way, I use SG optimizer to generate the .WEBP copies of the images.
 *  Plugin Contributor [Simon Kane](https://wordpress.org/support/users/simonkane/)
 * (@simonkane)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14192181)
 * 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](https://codex.wordpress.org/the_name)‘,
   $is_in_db, [useful vars](https://codex.wordpress.org/useful_vars) );
 * would give you what’s needed.
 *  Plugin Author [erolsk8](https://wordpress.org/support/users/erolsk8/)
 * (@erolsk8)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14192565)
 * Hi [@fabriziomazzei](https://wordpress.org/support/users/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](https://wordpress.org/support/users/erolsk8/)
 * (@erolsk8)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14192625)
 * 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](https://wordpress.org/support/users/fabriziomazzei/)
 * (@fabriziomazzei)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14192752)
 * Hi guys,
 * thank you to both of you for your help!
 * Eventually, [@erolsk8](https://wordpress.org/support/users/erolsk8/) the first
   solution you gave me worked like a charm! 🙂
 * Thanks
    Fabrizio
 *  Plugin Author [erolsk8](https://wordpress.org/support/users/erolsk8/)
 * (@erolsk8)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14194519)
 * 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](https://wordpress.org/support/users/fabriziomazzei/)
 * (@fabriziomazzei)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14194614)
 * Yea, thank you, a filter for the extensions would make this plugin perfect.
 * Fabrizio
 *  Plugin Contributor [Simon Kane](https://wordpress.org/support/users/simonkane/)
 * (@simonkane)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14195572)
 * 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.

 * ![](https://ps.w.org/media-sync/assets/icon.svg?rev=2021152)
 * [Media Sync](https://wordpress.org/plugins/media-sync/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-sync/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-sync/)
 * [Active Topics](https://wordpress.org/support/plugin/media-sync/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-sync/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-sync/reviews/)

## Tags

 * [extensions](https://wordpress.org/support/topic-tag/extensions/)

 * 8 replies
 * 3 participants
 * Last reply from: [Simon Kane](https://wordpress.org/support/users/simonkane/)
 * Last activity: [5 years, 2 months ago](https://wordpress.org/support/topic/selecting-extension/#post-14195572)
 * Status: resolved