0

I have a plugin, in this case it's Woocommerce Product Add-on which has an ability to allow folks to upload a file for the item being purchased. However, there is no restriction and I'm looking for a way to restrict.

Since all plugins are handled by Wordpress natively, how can I utilize the wp_handle_upload() and wp_max_upload_size() fuctions to control/restrict file uploads? I would very much like some direction please!

0

You use upload_mimes filter to restrict the image type as :

add_filter('upload_mimes','restict_image_type'); 

function restict_image_type($mimes) { 
    $mimes = array( 
                'jpg|jpeg|jpe' => 'image/jpeg', 
                'gif' => 'image/gif', 
                'png' => 'image/png', 
    ); 
    return $mimes;
}

For upload limit you can set in .htaccess one of the following;

LimitRequestBody 1048576 //( 1MB)
php_value upload_max_filesize 1M
php_value post_max_size 1M
  • Thanks for this. Silly question: I know that the function goes into the wp-includes/function.php, however where do I place the "add_filter" function to call up on it? – Humble Val May 7 '17 at 10:51
  • find the functions.php on your installed theme. – Aishan May 7 '17 at 11:03
  • Ah, so I basically add the whole code block above into that file. Gotcha. – Humble Val May 7 '17 at 11:05
  • As for the LimitRequestBody function, wouldn't 1MB be 1048576 instead of 1073741824? – Humble Val May 7 '17 at 11:05
  • Oh yes mistake.. please rectify .. – Aishan May 7 '17 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.