Obfuscate uploaded file names for MediaPress Uploads
Do you want to obfuscate/clean up the file names for the files uploaded via MediaPress? I got a few requests about it on the MediaPress plugin's blog post. Here is a small tip to do it.
We will be using UploadPlus plugin that already handles the file name cleanup/obfuscation very well.
Step 1:- Install UploadPlus plugin
UploadPlus is a free plugin available from WordPress.org Install uploadplus plugin from WordPress.org.
Link: https://wordpress.org/plugins/uploadplus/
Once you have installed it, Visit Dashboard->Settings->Media and you will see the UploadPlus plugin settings there like below.
Make sure that you have ticked the "Random File Name". You can configure other options as you want.
Step 2:- Add MediaPress compatibility for UploadPlus.
Put this code in your bp-custom.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | //obfuscate MediaPress uploaded file names with uploadplus plugin function mpp_custom_uploadplus_bridge() { if( class_exists( 'SWER_uploadplus' ) && is_object( $GLOBALS['swer-uploadplus'] ) ) { $object = $GLOBALS['swer-uploadplus']; if( method_exists( $object, 'wp_handle_upload_prefilter' ) ) { //force media press to use the processed file name in title add_filter( 'mpp_use_processed_file_name_as_media_title', '__return_true' ); //allow uploadplus to process the file name add_filter( 'mpp_upload_prefilter', array( $object, 'wp_handle_upload_prefilter' ) ); } } } add_action( 'mpp_init', 'mpp_custom_uploadplus_bridge' ); |
That's all. Try uploading a new file and the file names will be obfuscated as per your UploadPlus settings.
Hope that helps 🙂