Support » Plugin: Gravity Forms Advanced File Uploader » How to make the uploaded picture as Featured Picture directly

  • Resolved shawnchan

    (@shawnchan)


    Hi

    at first , I want to say thank you for this amazing plugin. The format and size limitation function are very useful.

    And My question,

    The reason I am using gravity forms is for the contributor to make a post easily.
    I only allow the user to upload one picture per post. Is any function can make their first uploaded picture to be the featured picture directly?

    I cant find it under the plugin function. I know the gravity forms has this function directly but it lacks two most important thing which only your plugins provided, format and size option.

    https://wordpress.org/plugins/gravity-forms-advanced-file-uploader/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author ben.moody

    (@benmoody)

    Hi thanks for the feedback.

    You will have to make use of one of my plugin’s action hooks to do this.

    add_action( ‘prso_gform_pluploader_processed_uploads’, ‘You_Function’ );

    function Your_Function( $wp_attachment_data, $entry, $form ) {

    // $wp_attachment_data will contain all info on the uploaded file
    // $entry and $form contain data from gravity forms e.g you should find the post id in $entry[‘post_id’]

    // You will then have to update post meta value ‘_thumbnail_id’ to match the attachment id for your new post, you should find the attachment id in $wp_attachment_data array

    }

    Hope this helps

    Hey, I need the same, but my users should be able to upload up to 5 files.
    I want to choosethe first as featured image, but I’m not an expert and I don’t know how to customize and where to put the code above.

    If there is a way to do that, is there also a way to set it for all forms, not just for a specific ID?

    I would be happy if you could help me out.

    Thanks in advance.

    P.S. Thanks for the latest update, it does not kill the WP Uploader anymore 🙂

    Plugin Author ben.moody

    (@benmoody)

    Hi

    What you ask is a little advanced but not a problem if you are comfortable with wordpress action hooks.

    Put this in your themes functions.php file and it should trigger every time a file is processed by the plugin and gravity forms creates a new post with the form data:

    add_action( ‘prso_gform_pluploader_processed_uploads’, ‘prso_adv_upload_featured_image’, 10, 3 );
    function prso_adv_upload_featured_image( $wp_attachment_data, $entry, $form ) {

    //Init vars
    $post_id = NULL;
    $post_attachment_id = NULL;

    //Check that gravity forms created a new post
    if( isset($entry[‘post_id’]) ) {

    //Cache post id from gravity forms
    $post_id = $entry[‘post_id’];

    //Get first uploaded attachment id
    $post_attachment_id = current( $wp_attachment_data )[0];

    //Update post thumbnail id meta with first uploaded file
    update_post_meta($post_id, ‘_thumbnail_id’, $post_attachment_id);

    }

    }

    Thanks

    Ben

    Great, thank you very, very much.

    No my new question is: Is it possible to add the other images as a gallery in the post?

    Thanks

    Found a really simple solution. Sorry for asking.

    Just add [gallery] to the form.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to make the uploaded picture as Featured Picture directly’ is closed to new replies.