我有一个使用附加上传字段的重力表格,提交后做了一些后台工作,将视频文件发送到YouTube,然后返回YouTube视频ID。
我正在尝试在存储帖子ID的gform提交上设置一个临时值,因此与此YouTube上传过程相关的另一个钩子可以获取它获得的YouTube ID,然后更新上述帖子的自定义字段。
设置瞬态工作,我可以在wp_options中看到它,但是当我试图获得瞬态时,尽管键值相同,它仍会不断返回空。
function action_prso_gform_youtube_uploader_pre_update_meta( $field_values, $this_data ) {
//vars
$gforms_entry_title = strtolower(preg_replace('/-+/', '-', preg_replace('/[^\wáéíóú]/', '-', $this_data['gforms_entry'][1])));
//Get new post id so we can update it's meta
$transient_post_id = NULL;
$key = 'adv_' . $gforms_entry_title;
$transient_post_id = get_transient($key);
//You have the post id, save the youtube id as post meta
$yt_video_id = $field_values[6][0]['video_id'];
update_post_meta( $transient_post_id, 'video_testimonial_youtube_data', $yt_video_id );
}
add_action( 'prso_gform_youtube_uploader_pre_update_meta', 'action_prso_gform_youtube_uploader_pre_update_meta', 10, 2 );
add_action("gform_after_submission_19", "submit_video_testimonial_from_submission", 5, 2);
function submit_video_testimonial_from_submission($entry, $form) {
// Create a new post under the "video-testimonial" post-type
$new_video_testimonal = array(
'post_title' => ucwords($entry[1]),
'post_status' => 'draft',
'post_date' => date('Y-m-d H:i:s'),
'post_type' => 'video-testimonial'
);
$gforms_entry_title = strtolower(preg_replace('/-+/', '-', preg_replace('/[^\wáéíóú]/', '-', $entry[1])));
$theId = wp_insert_post($new_video_testimonal);
// Now we add the meta to the custom fields
$thePrefix = 'video_testimonial_';
update_post_meta($theId, $thePrefix.'title', ucwords($entry[1]));
update_post_meta($theId, $thePrefix.'description', ucwords($entry[2]));
update_post_meta($theId, $thePrefix.'name', ucwords($entry[3]));
update_post_meta($theId, $thePrefix.'location', ucwords($entry[5]));
// Set a transient to pass post ID for YouTube api function
set_transient('adv_'.$gforms_entry_title, $theId, 500);
}
我在每个字段上设置了error_log,包括$ transient_post_id和;它没有记录任何内容。