Renaming Files as they are uploaded

I'm trying to have a little more control over the media uploaded to wordpress posts. I installed WP Smush Pro to compress images as they are uploaded, and I will be enabling media protection in Membership 2 Pro to basic protection to change the file path.

The last addition I would like is automatic file renaming based on post or page title (and obviously no renaming if manually uploaded to the media library).

Since Smush directly deals with the file server and image files, and M2P simply rewrites the paths, I figured this would be my best place. If it could be tied in to the plugin, I would be thrilled. However in the meantime I can alter code. I'm just looking for verification on the process, whether or not the post data is available to this plugin code.

The function:

function do_smushit( $file_path = '', $file_url = '' ) {

handles the file processing. I'd like to change the last few lines along these lines to rename the files:

//replace the file
$success = @rename( $tempfile, $file_path );

//if tempfile still exists, unlink it
if ( file_exists( $tempfile ) ) {
unlink( $tempfile );
}

//If file renaming was successful
if ( ! $success ) {
copy( $tempfile, $file_path );
unlink( $tempfile );
}

//rename file after post title
global $post;
$info = pathinfo($file_path);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$new = sanitize_file_name( $post->post_title . $ext");
$success2 = @rename($file_path, $new);

//If file renaming was successful
if ( ! $success2 ) {
copy( $file_path, $new );
unlink( $file_path );
}

Would that work? If not, would making a separate function in my child theme to handle this interfere with either Smush or M2P media protection?