Restrict file types to be uploaded WCFM Code snippet

Table of Contents

Code Snippet Overview:

This WCFM code snippet will Restrict store owners to upload the filetypes that you establish. This snippet is great when the admin of the Marketplace wants to have the same file type of image in the product pages. When you install the WCFM plugin of WCLovers the default General settings allow the user to upload the same filetypes that WordPress allows when he or she creates a product.

Result

Now, after you have added this WCFM code snippet the seller won’t be able to upload your defined filetype, in this case is .PNG:

png not allowed min Maxkinon

Code Snippet

/*WCFM Code Snippet to restrict the upload certain filetypes*/
add_filter('upload_mimes','restrict_mime'); 
function restrict_mime($mimes) { 
$mimes = array( 
                'png' => 'application/octet-stream', 
);
return $mimes;
}

Implementation

  1. Copy WCFM code snippet by clicking on the right upper corner of the code.
  2. Download the Code Snippets plugin.
  3. Click on Add new snippet.
  4. Paste the code that you have copied in step 1.
Add custom field in store details - WCFM Code snippet

Customize according to your needs:

In this example, we are restricting .PNG files, but, suppose you need to restrict another type of files. You just need to change png in this line:

'png' => 'application/octet-stream',

In case you need to restrict more than one type of file, the syntaxis will be:

'jpg|jpeg|jpe' => 'application/octet-stream',

 

Another post: 

 

 

Check out our categories: Android Update, Elementor, flutter, Guide, Game, Plugin, Theme, webmaster, SEO, Woocommerce, WCFM

 

Leave a Reply

Your email address will not be published. Required fields are marked *