[Smush Pro] Directory Smush -- need some way to override the uploads/sites folder restriction

Since Smush seems to restrict from action in uploads/sites/... and if there are things that are in users' upload path but that are not Smushed by Bulk Smush (bcs not uploaded via WP media library) then I need a way to get these things Smushed that doesn't involve a lot of manual actions... Ideas?

irl use-case: if using CobaltApps' Dynamik Website Builder theme or their Extender Pro plugin, then they use a folder located in uploads/ to store custom code and, esp. for Dynamik, also stores images used in the theme project at path like uploads/sites/2/dynamik-gen/...

Please advise :slight_smile:

Cheers, Max

  • Adam Czajczyk
    • Support Gorilla

    Hi wp.network

    I hope you're well today and thank you for your question!

    The "/wp-content/uploads/sites" folder is "by design" a Media Library folder on multisite. It's not really a common and expected practice to use it (by the theme or plugin) for storing other data and that's why it's by default excluded - in most cases images stored there would be included in a regular "bulk smush".

    However, there's a filter built-in into Smush Pro plugin that can be used for this. Below is the code that should "unlock" the "sites" folder for "Directory Smushing" tool in Smush plugin:

    <?php 
    
    add_filter( 'wp_smush_skip_folder', function( $skip, $path ) {
    
    	$upload_dir = wp_upload_dir();
    	$base_dir   = $upload_dir['basedir'];
       if ( false !== strpos( $path, $base_dir . '/sites' ) ) {
    		$skip = false;
    	}
    
        return $skip;
    }, 10, 2 );

    To apply it to your setup simply:

    - create an empty file with a .php extension (e.g. "unlock-site-folder-smushing.php")
    - copy and past the code into it
    - save the file and upload it to the "/wp-content'/mu-plugins" folder of your Multisite WP install; if there's no "mu-plugins" folder inside "wp-content" folder, just create an empty one.

    I have tested this on my own and and it seems to be working as expected, unlocking the access to the "site" folder and its sub-folder in Directory Smushing.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.