Hi Alex, custom prefix are actually static only ( = plain text) for both security and performance reasons.
The issue is that this plugin acts on a very low level on files uploading, so loop variables and the like won’t probably be available at the time our plugin is triggered in about 9 out of 10 runs. We too couldn’t recognize a lot of use cases and we’re learning about them almost daily! 🙂
That said, we’re considering a couple of enhancements on custom prefixes and I’d like to know more about your use case: maybe it’s something we can achieve in a different way.
Thank you for caring!
Thanks Paolo, no problem, in my case I’d like to have the file renamed using the post title,
In the mean time I managed to rename the file using the post title by adding the following code to the core.class.php and admin.class.php files.
In core.class.php, on line 100:
case “C”: $file_name = str_replace( array(“.”,”_”,”-“,” “) ,$sep, sanitize_title( get_the_title() ) ).$sep.$file_name; break;
In admin.class.php, line 85:
“C” => ‘Post title and the filename’
So far it works really well by adding the post name before the filename which is pretty much what I need. I did not looked into the “demo string” feature and I realise that I have to use an IF somewhere to intercept situations where the post does not have a name defined.
But so far so good, I’m happy with this. That’s why open source rocks. And that’s why I thank you again 😉
The issue with this approach – as you already know – is that it won’t work with media uploads from outside a post/page (i.e. direct upload in the media library) : they can’t have that context if no new post/page is hosting this uploaded file.
We need to think a bit more about it, find out something a bit more comprehensive for the average user out there. But that’s open source: if you’re fine with that solution go for it! 🙂
- The topic ‘Custom prefix options?’ is closed to new replies.