Gravity Forms Advanced File Uploader
Rename File after uploading (6 posts)

  1. martin.kreativermoment
    Posted 2 years ago #

    I'm using yout plugin to create Posts. Is it possible to set the posttitle as imagename after uploading?

    It would be perfect, if there is more than one image that they are named as posttitle.jpg, postitle1.jpg and so on...


  2. Connor
    Posted 2 years ago #

    I would like to know how to do this as well.

  3. Connor
    Posted 2 years ago #

    After much tinkering I have resolved my own issue. Thank you.

  4. ben.moody
    Plugin Author

    Posted 2 years ago #


    I'm afraid you are going to have to get you hands dirty with some wordpress action hook creation for this one.

    This is more of a gravity form api question. Once the post has been created my plugin simply attaches the files to the post created by gravity forms.

    If this was me i would:
    1. Find a gravity forms hook called after a post is created, 'gform_after_submission' for example.

    2. Call the action with a very low priority to be sure it runs after all other actions

    3. 'gform_after_submission' action passes the param $entry which contains the new post id $entry['post_id'].

    4. Great, we use the post id to get all the post's attachments.

    5. Loop over the attachments and build a new post title from their names.

    6. Update the post with the new title created from the attachment names.

    7. Done, your new post now has a custom title based on it's file attachments

    Here's the gravity forms action doc: http://www.gravityhelp.com/documentation/page/Gform_after_submission

  5. martin.kreativermoment
    Posted 2 years ago #

    Thanks, but this is the opposite of what I need :)

    I want to rename the images using the post title.

    Is that possible too?

  6. ben.moody
    Plugin Author

    Posted 2 years ago #

    The 'prso_gform_pluploader_processed_uploads' action hook passed an array of all the files that have been uploaded into the wordpress media library.

    You can loop through the $wp_attachment_data array using this hook and see an array of all attachment id's for that form field. You can use these attachment id's to update the attachment data using the wordpress API.

    Below is an example, depending on how you want to select the new attachment title you can use the $entry and $form parameters to get info from gravity forms for that form submission such as data on other fields, ect. Refer to the gravity forms api doc s for that stuff.


    add_action( 'prso_gform_pluploader_processed_uploads', 'your_function_name', 10, 3 );
    function your_function_name( $wp_attachment_data, $entry, $form ) {

    foreach( $wp_attachment_data as $field_id => $attachments ) {
    //Loop attachments to get id's
    foreach( $attachments as $attachment_id ) {
    // Update attachment title
    $my_post = array(
    'ID' => $attachment_id,
    'post_title' => 'new title'

    // Update the post into the database
    wp_update_post( $my_post );


Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic


No tags yet.