Yes, you are correct.
You may want to subscribe to nmr_create_attachment_file_name filter, call wp_unique_filename and change the file name before the file is saved.
Thread Starter
jishua
(@jishua)
Thanks a lot for confirming. Just wondering if there’s a reason that’s not implemented.
I’m happy to contribute that update if you like. Just let me know.
I’ve briefly consider it, now when you mentioned it.
Looking at the code, something is not yet clear to me:
- user uploads a file in CF7
- this plugin gets the filename
- should we change the filename here, if the filename already exists in the media library?
- raise this event/filter:
nmr_create_attachment_file_name – send the potentially new filename to subscribers – remember this might not be the same filename the user uploaded. Does it matter? I don’t know, but it’s solvable by everyone with a bit of code as pointed above
So, I haven’t implemented it yet. Please consider the reach of this change, how it might affect other websites using it and if you are confident you may contribute the solution.
Thread Starter
jishua
(@jishua)
That’s a very good point. I wouldn’t want to break anything for other users of the plugin if they’re always expecting the same filename. Maybe an option to enable it at some point.
Hello!
You may want to subscribe to nmr_create_attachment_file_name filter, call wp_unique_filename and change the file name before the file is saved.
Any clue about how to do that? I have not PHP/wordpress experience and don’t know how to apply the filter/subscribers mechanism.
Thanks in advance.
Hello!
Answering this is a bit out of scope of this plugin and this thread.
Here is a ‘quick and dirty’ untested solution:
– edit a file called functions.php on your active theme
– add code:
‘
function on_nmr_create_attachment_file_name($filename)
{
$path_parts = pathinfo($filename); //get details about file name
//make sure that file name is unique and return it.
return wp_unique_filename($path_parts[‘dirname’], $path_parts[‘filename’]);
}
add_filter(‘nmr_create_attachment_file_name’, ‘on_nmr_create_attachment_file_name’);
‘
-
This reply was modified 3 years, 6 months ago by
mirceatm.
-
This reply was modified 3 years, 6 months ago by
mirceatm.