Change file name on upload in Media Page

The best way of doing this might be to attach a custom field to each post to keep the increment {n}. Something to the effect of: $attach_inc = 1; if ( is_single() ) { if ( $attach_inc = get_post_meta( $post_id, ‘attachment_inc’, true ) ) { $attach_inc++; update_post_meta( $post_id, ‘attachment_inc’, $attach_inc ); } else { add_post_meta( … Read more

wp_upload_bits() is not giving the file path right in localhost

I ran into the same exact issue (getting paths like ‘X:xampphtdocswordpress/wp-content/uploads/2017/05/filename.jpg’ on WAMP on Windows). The issue seems to be due to update_post_meta() passing values through stripslashes() when storing the data. The workaround is to add wp_slash() around your value you pass to update_post_meta(). You’re probably calling update_post_meta() something like this: update_post_meta( $id, ‘doesnt_work’, $data … Read more

Resize uploaded original images to a minimum automatically

From purely WordPress point of view you want add_image_size() with a “hard” crop mode. That will ensure that any significantly large image will be sized to fit into those dimensions exactly, cropping some parts if necessary. The problem is usually that WP won’t upsize small images to fit, as far as I remember. It is … Read more

Send an e-mail notification to custom user role when a file is uploaded to uploads folder

You could use the wp_mail function https://developer.wordpress.org/reference/functions/wp_mail/ to send an email to anyone after the file is successfully uploaded in your directory. You do not need any action here Add it your code after the file is uploaded successfully if(empty($errors)==true){ move_uploaded_file($file_tmp,”/$user_dirname/”.$document); echo “The file was uploaded successfully!”; wp_mail(..); }else{ print_r($errors); } }

How to allow .bin files upload?

This code would allow you to upload .bin files. /** * Allow upload bin mime type */ add_filter( ‘upload_mimes’, ‘wpse_287673_allow_upload_bin_mime_type’, 1, 1 ); function wpse_287673_allow_upload_bin_mime_type( $mime_types ) { $mime_types[‘bin’] = ‘application/octet-stream’; return $mime_types; } This code is tested and is working for me, but it might be some differences for you since we are allowing … Read more