Support » Plugin: Gravity Forms Advanced File Uploader » Get YouTube Video ID Hook

  • Hi Ben.

    In a previous support post, you mentioned a hook to retrieve the YouTube video ID (this hook is called after the YouTube upload and just before the ID is saved into gravity forms):

    add_action(‘prso_gform_youtube_uploader_pre_update_meta’, ‘prso_get_youtube_id’);

    function prso_get_youtube_id( $field_values, $form_data ) {

    //$field_values is an array containing array of field_ids and video ids

    //$form_data contains info on the submitted form and entries


    Can you explain in a little further detail how to go about saving that ID to a custom field? I have a GravityForm set up now which uses all post fields, and those post to a custom post type. The last piece I need is to get my YouTube video ID and post that into a custom field so I can then display the video on the front end (per entry).

    Any help is greatly appreciated!

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



    The video upload happens asynchronously via a cURL request after form submission. This means that the users doesn’t have to wait until the video upload and api transfer is complete before the form submits.

    You can take a look at this action which triggers just before the plugin updates the form entry data in the gforms table with the new urls for videos uploaded via the api:

    do_action(‘prso_gform_youtube_uploader_pre_update_meta’, $field_values, $this->data);

    $field_values – should contain array of uploads by form field_id, in which you can get the video_id and video_url from youtube

    $this->data – passes an array which contains the gforms_entry and gforms_form objects. With these you should be able to get the ID of the post you created with the form submission and then add the video data as post meta.

    If you can’t get the post id from the gforms data what i would do is on creation of your new post during form submission save the form entry id as post meta for the new post, then you can get that post later after the video upload using the gforms_entry object passed the the action above in the 2nd param.

    Hi Ben, this plugin is exactly what I have been looking for! However, I have got a bit stuck with getting the youtube meta – could you help me out?

    I have this function:
    add_action( ‘gform_after_submission_1’, ‘process_upload’, 10, 2 );
    function process_upload( $entry, $form ) {


    which processes my $entry data after submission then saves the data to meta fields in a custom post type – that all works fine.

    What I can’t work out from your post above is how I then get the youtube data from within my function, could you provide an example? – your help would be most appreciated! 🙂

    Sorry if i’m missing the obvious 🙁

    jimdestruct101, were you able to figure this out? I’m also having troubles getting the youtube video ID.

    This is what worked for me

    add_action('prso_gform_youtube_uploader_pre_update_meta', 'prso_get_youtube_id', 10, 2);
    function prso_get_youtube_id( $field_values, $form_data ) {
    $postID = $form_data[ 'gforms_entry' ]['post_id'];
    $videoID = $field_values[2][0]['video_id'];
    update_post_meta($postID, 'vidid', $videoID);
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get YouTube Video ID Hook’ is closed to new replies.