Hi Jason
I tested the code on my local copy of your site and it seems to be working okay, except I didn't allow for the possibility of uploading multiple images (including the featured image).
So I made a few edits to the code to handle that. This is the code that works on the copy of your site (including Form IDs):
<?php
/**
* Disable ajax uploads of images in Toolset Forms (global)
*/
add_filter( 'cred_file_upload_disable_progress_bar', '__return_true' );
/**
* For specified forms set up file rename to post title
*/
function tssupp_prepare_to_rename_upload( $form_data ){
if ( in_array( $form_data['id'], array( 49, 141 ) ) ) { // Edit Form IDs
add_filter( 'wp_handle_upload', 'tssupp_handle_rename_upload', 10, 2 );
}
}
add_action( 'cred_before_save_data', 'tssupp_prepare_to_rename_upload' );
/**
* Handle file rename taking title from $_REQUEST object
*/
function tssupp_handle_rename_upload( $upload, $context ){
$post_title = $_REQUEST['post_title'];
$post_slug = sanitize_title( $post_title, 'empty title' );
$path = pathinfo( $upload['file'] );
$newfile = $path['dirname']."/".$post_slug.".".$path['extension'];
$dir = wp_upload_dir();
$newurl = $dir['url'].'/'.$post_slug.".".$path['extension'];
// handle multiple uploads or if filename already exists
$index = 1;
while ( file_exists($newfile) ) {
$newfile = $path['dirname']."/".$post_slug.'-'.($index ++).".".$path['extension'];
$newurl = $dir['url'].'/'.$post_slug.'-'.$index.".".$path['extension'];
}
rename( $upload['file'], $newfile );
$upload['file'] = $newfile;
$upload['url'] = $newurl;
return $upload;
}
You can see the results in the uploads folder in the screenshot.
The first time I uploaded just a featured image to a post titled "Farmyard equipment".
The second time I uploaded a bunch of images to a post titled "Construction kit", where each additional image had an index number appended.
I checked in the backend for the newly created listing and everything appears correct in terms of featured image and image fields assigned.
That's about as far as I can take this. Writing custom code falls outside our support policy, so if you can't get it working on your own install you'll need to see if you can work out why yourself, or hire a developer to work on it.
As I say, I double-checked that the featured images were correctly assigned.
If you are still having problems with this, could you comment on the original thread, and keep this one about renaming the file uploads, thanks.