plugins – How to process uploaded images in new 5.4 version of Contact Form 7?

I am using Contact Form 7 (5.4) and CF7 Smart Grid Design Extension (4.10.0) in a submit form on my WordPress site to construct draft Custom Post Types. The original inspiration for this was this awesome SO post.

The submission form has worked well and reliably for over a year, but with the new CF7 5.4 version, something has changed internally and broken image uploads. All of the other fields have remained unchanged.

The CF7 field with which I am uploading appears as

(file* field_image limit:10000000 filetypes:jpg|gif|png|jpeg class:field-image)

The images get mailed, so the form is uploading the file properly. But something has changed that breaks my attempts to nab the images before they are deleted after emailing.

Here’s the relevant PHP in functions.php that handles uploaded images within the function that constructs a WP CPT.

// Retrieving and inserting uploaded image as featured image
// CF7 uploads the image and puts it in a temporary directory,
//      deleting it after the mail is sent
// Before it deletes it, we will move into our media library,
//      and attach it to our post
// get file upload info from form
$uploadedFiles = $submission->uploaded_files();
// if we have an uploaded image...
if( isset($posted_data('field_image')) ){
    // move image from temp folder to upload folder
    $imageUpload = wp_upload_bits($posted_data('field_image'), null,
    // PC::debug("imageUpload:", print_r($imageUpload, True));
    // echo ("imageUpload:", print_r($imageUpload, True));
    require_once(ABSPATH . 'wp-admin/includes/admin.php');
    // construct array to register this image
    $filename = $imageUpload('file');
    $attachment = array(
        'post_mime_type' => $imageUpload('type'),
        'post_parent' => $post_id,
        'post_title' => $posted_data('field_title') . ' - ' .
        'post_content' => $posted_data('field_info'),
        'post_status' => 'inherit'
    // attach image to this post
    $attachment_id = wp_insert_attachment( $attachment, $filename, $post_id );
    // PC::debug("attachment_id:", print_r($attachment_id, True));
    // echo ("attachment_id:", print_r($attachment_id, True));
    // if we succeeded...
    if (!is_wp_error($attachment_id)) {
        require_once(ABSPATH . 'wp-admin/includes/image.php');
        $attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
        // PC::debug("attachment_data:", print_r($attachment_data, True));
        wp_update_attachment_metadata( $attachment_id,  $attachment_data );
        set_post_thumbnail( $post_id, $attachment_id );
        // add image id (attchment id) to ad_image field
        update_field( 'ad_image', $attachment_id, $post_id );

This is called by:

add_action('wpcf7_before_send_mail', 'save_my_form_data_to_my_cpt', 10, 3);

When the uploaded images appear in the media library, they are blank gray squares.

Gray Boxes

Details in the media library slow no file name, no file type, no file size. I have tested dropping media directly into the media library and that works fine.

No metadata

While the problem could lie in the post submit code that handles the submission, none of that has changed in a year. Only CF7 has changed.

Any hints?