I have long been using some code in my functions.php of my child theme that was sending an email to the author of the GRANDFATHER of the post being submitted. This was working fine until the recent TOOLSET updates.
Is it broken because of the grandparent situation being different now because of the new relationship structure?
Can you have a look at my code below and let me know if it should still work or not?
Thanks!
Elise
// Change notification email to evaluator author when submitting assignment
add_filter( 'cred_mail_header', 'notify_grandparent', 10, 4 );
function notify_grandparent( $headers, $formid, $postid, $num_notification ) {
if($formid != 704 ) return;
$num_notification = 0;
$current_user = get_current_user_id();
//get the "lab-categories" terms of current "ASSIGNMENTRESULTS" post
$terms = get_the_terms( $postid, 'lab-categories' );
$term_slugs = array();
foreach ( $terms as $key => $taxonomy ){
$term_slugs[] = $taxonomy->slug ;
}
//with above terms, pass it to get_posts function as parameter "tax_query":
$registrations = get_posts( array(
'author' => $current_user,
'post_type' => 'registration',
'tax_query' => array(
array(
'taxonomy' => 'lab-categories',
'field' => 'slug',
'terms' => $term_slugs,
),
),
));
$evaluator_id = get_post_meta( $registrations[0]->ID, "_wpcf_belongs_evaluator_id", true); // assumes Evaluator CPT slug is 'evaluator'
$evaluator = get_post( $evaluator_id );
$evaluator_author = get_user_by( 'ID', $evaluator->post_author );
$newheaders = array( 'To: ' . $evaluator_author->user_email );
return array_merge($headers, $newheaders);
}