Viewing 5 replies - 1 through 5 (of 5 total)
  • I would like to know how to do this as well.

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

    Plugin Author ben.moody

    (@benmoody)

    Hi

    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

    Thread Starter martin.kreativermoment

    (@martinkreativermoment)

    Thanks, but this is the opposite of what I need 🙂

    I want to rename the images using the post title.

    Is that possible too?

    Plugin Author ben.moody

    (@benmoody)

    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.

    EXAMPLE::

    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 );
    }
    }

    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Rename File after uploading’ is closed to new replies.