I’ve come up with my own solution. I used the publish_post action instead of the transition_post_status action.
$this->loader->add_action( 'publish_cursussen', $plugin_admin, 'save_cursus_meta', 10, 2);
The problem before was the data not being saved yet.. with this new functions i can get the ID and with that ID the title
public function add_new_form( $cursus_title ){
$form_id = 2; //Standard form
$form = GFAPI::get_form($form_id);
$form['title'] = $cursus_title;
$form['limitEntriesCount'] = 100;
$result = GFAPI::add_form( $form );
return $result;
}
public function save_cursus_meta( $ID, $post ){
$post_type = get_post_type($ID);
$cursus_title = get_the_title($ID);
// If this isn't a 'book' post, don't update it.
if ( "cursussen" != $post_type) return;
$myPost = get_post($ID);
if( $myPost->post_modified_gmt == $myPost->post_date_gmt ){
$this->add_new_form($cursus_title);
}else{
return;
}
}
Hope this can help somebody in the future!