Skip Navigation

[Resolved] cred_notification_recipients not firing

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by julieE-2 4 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1868289

I'm following the documentation to add more recipients to a post form, however the filter does not seem to fire.

This is the code:


<?php
/**
 * Send email notifications to all connected lawyers when a document is submitted
 * @filter cred_notification_recipients
 */

toolset_snippet_security_check() or die( 'Direct access is not allowed' );

/****  testing ok *****/
function cred_submit_complete_timestamp( $arg ){
 
    error_log("cred_submit_complete: " . microtime() );
 
    return $arg;
}
add_filter( 'cred_submit_complete', 'cred_submit_complete_timestamp' );
 
/****  testing no output *****/ 
function cred_notification_recipients_timestamp( $arg ){
 
    error_log("cred_notification_recipients: " . microtime() );
 
    return $arg;
}
add_filter( 'cred_notification_recipients', 'cred_notification_recipients_timestamp' );



/**
 * Customise CRED notification recipients by adding a BCC 
 * to the the notification "Content submitted"
 */
add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
  
// no output
  error_log('modify_recipients');
  
      // Check notification name matches target notification
    if ( isset($notification['name']) && 'Document submitted' == $notification['name'] ) {


  
    // get case from cookie
    $origin_id = $_COOKIE['db_case'];

    // error check validate case

                      
    // if case
    $relationship_slug = 'case-lawyer';

    $child_posts = toolset_get_related_posts(
        $origin_id, // get posts connected to this one
        $relationship_slug, // in this relationship
        array(
            'query_by_role' => 'parent', // origin post role
            'role_to_return' => 'child', // role of posts to return
            'return' => 'post_id', // return array of IDs (post_id) or post objects (post_object)
            'limit' => 999, // max number of results
            'offset' => 0, // starting from
            'orderby' => 'title', 
            'order' => 'ASC',
            'need_found_rows' => false, // also return count of results
            'args' => null // for adding meta queries etc.
        )
    );
  
 
 
        // Start with an empty list of email addresses and empty list of post author IDs
        $emails = "";
 
      // Loop over each child post and get the post authors
        foreach ($child_posts as $child_post) {
            $author = $child_post->post_author;
            $emails .= get_the_author_meta( "user_email", $author ) . ',';
        }
       
        // Add recipients by BCC
        if ( $emails != '' ) {
            $recipients[] = array(
                'to'        =>  'cc',
                'address'   => $emails,
                'name'      =>  '',
                'lastname'  =>  ''
            );            
        }
    }
  
   print_r($recipients); 
  
  	error_log($recipients);
  
    return $recipients;
}
  
   


#1868599

Hi,

Thank you for contacting us and I'd be happy to assist.

I've checked the first two functions ( i.e. "cred_submit_complete_timestamp" and "cred_notification_recipients_timestamp" ) on my website and the filters "cred_submit_complete" and "cred_notification_recipients" both seem to be firing correctly.

My recommendation would be to use the step-by-step debugging approach in the actual function "modify_recipients", by adding the "error_log" with the processed values at each step. This will help in knowing exactly which part is working and from where it fails.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1872683

My issue is resolved now. Thank you!

I needed to return the post object instead of just the id

'return' => 'post_object', // return array of IDs (post_id) or post objects (post_object)