How can i get "post id" in post edit area for add_filter in functions.php?
I want to change file name automatically during upload. so i need to obtain post id.
the code is as follows:
add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' );
function custom_upload_name($file)
{
list($name, $ext) = explode('.', $file['name']);
$file['name'] = $post_ID.'.'.$ext;
return $file;
}
Edited:
the final and working code:
add_filter( 'wp_handle_upload_prefilter', 'custom_upload_name' );
function custom_upload_name($file)
{
$post_ID = $_POST['post_id'];
list($name, $ext) = explode('.', $file['name']);
$file['name'] = $post_ID.'.'.$ext;
return $file;
}