#51841 closed feature request (worksforme)
Please add a wordpress function to convert a given file name string into what it would turn into if uploaded to the media library
| Reported by: | tannerm | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Media | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
When writing import scripts, it can be very difficult trying to set post thumbnails on posts if the client gives us files named things like:
Ranked Choice Voting and Women_s Representation. Cambridge, MA THUMBNAIL.png
I'd like to be able to take that string and put it into a wordpress function that converts it to the filename that wordpress creates when it is successfully added to the media library:
Ranked-Choice-Voting-and-Women_s-Representation.-Cambridge-MA-THUMBNAIL.png
If this function already exists somewhere I would greatly appreciate being directed to it.
Change History (4)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Nevermind, here it is!
https://developer.wordpress.org/reference/functions/sanitize_file_name/