Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload

Assuming that you’re providing upload functionality via WordPress’ native functions, lik wp_handle_upload or something more high-level, we come to the conclusion that several hooks are going to be pulled. http://core.trac.wordpress.org/browser/tags/3.3/wp-admin/includes/file.php#L212 The wp_handle_upload function would probably be the last native function to touch the file, and would know all the information that is necessary to keep … Read more

Allowing WebP uploads?

It’s necessary to use the wp_check_filetype_and_ext filter to set the mime type and extension for webp files in addition to using the upload_mimes filter to add the mime type to the list of uploadable mimes. /** * Sets the extension and mime type for .webp files. * * @param array $wp_check_filetype_and_ext File data array containing … Read more

how to upload and allow downloads of .mobi and .epub formats

Assuming that you are using the WordPress native Media uploader then you can use the upload_mimes filter hook to add or remove allowed file types, for example: function custom_myme_types($mime_types){ //Adding avi extension $mime_types[‘avi’] = ‘video/avi’; //Removing the pdf extension unset($mime_types[‘pdf’]); return $mime_types; } add_filter(‘upload_mimes’, ‘custom_myme_types’, 1, 1); You can see that to add a file … Read more

How to show all available images in WP’s media library when using the Polylang plugin?

From this post at wordpress.org/support, the user Chrystl points out: If don’t need to translate your media titles, uncheck this option: In Languages > Settings tab > Media: “Activate languages and translations for media”. And you will access to your entire library by clicking on “Add media” and “Set featured image”. And that indeed did … Read more

Reject upload of wrong-sized images using the Media Uploader

In your handler, if you set ‘error’, the error message will be displayed and will cancel the upload add_filter( ‘wp_handle_upload_prefilter’, ‘custom_upload_filter’ ); function custom_upload_filter( $file ) { $image_info = getimagesize( $file[‘tmp_name’] ); $image_width = $image_info[0]; $image_height = $image_info[1]; if ( $image_with !== 800 || $image_height !== 600 ) { $file[‘error’] = __( ‘Images must be … Read more

simple solution for restricting access to (some) uploads/downloads

I’m hereby answering my own question, because i found a solution, but I’m really interested in your opinions towards it. Or maybe you have a much better solution, if so, I really would like to here about it. Research result My research results were: 1. get the files outside of the document root, www folder; … Read more

Get $image_id after uploading with media_sideload_image()

Here is an example of how to bypass this limitation using actions/hooks: function new_attachment( $att_id ){ // the post this was sideloaded into is the attachments parent! // fetch the attachment post $att = get_post( $att_id ); // grab it’s parent $post_id = $att->post_parent; // set the featured post set_post_thumbnail( $post_id, $att_id ); } // … Read more