Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

screamapillar on "Rename files based on post meta upon upload"

$
0
0

I'm trying to rename image files:

  • upon upload
  • to a specific post type
  • using that post's custom fields.

I'm creating a custom field contains the IDs of multiple uploaded images. The interface for adding them uses this method for invoking the media uploader.

In the plugin I'm making, it's critical to rename the uploaded image files. This post type has another custom field called "Reference ID", which is unique and is not the post ID. This reference number must prefix the image filename.

I have tried adding filters to wp_handle_upload_prefilter and sanitize_file_name, but the problem is that I cannot get post information to these functions. If this is possible, that would probably solve the problem.

The only other alternative I see is to create my own upload interface and use wp_insert_attachment which will easily allow me to rename files based on post meta. I'd rather stick to WP's own media uploader but it's looking like that may not be possible.

I'm sure there must be some alternative I haven't thought of. Input and ideas of any kind are much appreciated.

Many thanks to those who respond.


Viewing all articles
Browse latest Browse all 8245

Trending Articles