Advertisement
verygoodplugins

Untitled

Jun 16th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. function notification_emails_from_tag( $notification, $form, $entry ) {
  2.  
  3.     // only change notification to address for this specific notification
  4.     if ( $notification['name'] == 'User Notification' ) {
  5.  
  6.         $tag = 'Tag Name';
  7.  
  8.         $args = array(
  9.             'meta_query' => array(
  10.                 array(
  11.                     'key'     => wp_fusion()->crm->slug . '_tags',
  12.                     'value'   => '"' . $tag . '"',
  13.                     'compare' => 'LIKE',
  14.                 ),
  15.             ),
  16.         );
  17.  
  18.         $users = get_users( $args );
  19.  
  20.         $emails = array();
  21.  
  22.         if ( ! empty( $users ) ) {
  23.  
  24.             foreach ( $users as $user ) {
  25.  
  26.                 $emails[] = $user->user_email;
  27.  
  28.             }
  29.         }
  30.  
  31.         // replace the to address with a comma separated list of emails
  32.         $notification['to'] = GFCommon::implode_non_blank( ',', $emails );
  33.  
  34.     }
  35.  
  36.     return $notification;
  37. }
  38.  
  39. add_filter( 'gform_notification_1', 'notification_emails_from_tag', 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement