Using PHP hooks with Wordpress Gravity Form

Hi everyone

I’ve been developing Wordpress sites for years but never had to go into PHP until now.

I have a Gravity form and another plugin called Gravity Advanced File Uploader. What I am trying to do is retrieve a YouTube ID when the user uploads a video via the form and store it in another field automatically. The video currently uploads using a YouTube API key before the form is submitted.

The plugin developer has supplied the hook needed but being new to PHP I have no idea how to integrate this.

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

}

I’m assuming I also need to use something like gform_field_value as well to store the retrieved video ID.

Sorry if this seems confusing, I really am new to all this code!

Thanks in advance.


add_action( 'gform_after_submission', 'add_custom_data', 10, 2 );

function add_custom_data($entry, $form) {

// Get the video URL
$video_url = rgar( $entry, '4' );

// Parse the URL to get the YouTube ID
$youtube_id = parse_yturl($video_url);

// Update the entry
GFAPI::update_entry_field( $entry['id'], '5', $youtube_id );

}

$youtube_link = $response['youtube_link'];

$video_id = extractYoutubeIdFromUrl($youtube_link);

$response['video_id'] = $video_id;

return $response;
Sponsor our Newsletter | Privacy Policy | Terms of Service