public static function triggerNotifications($post_id, $data, $attachedData = null) { $form_id = $data['form_id']; $is_user_form = self::get_form_type($form_id) == CRED_USER_FORMS_CUSTOM_POST_NAME; if ($is_user_form) { $post = get_userdata($post_id)->data; } else { if (isset($data['post'])) { $post = $data['post']; } else { $post = get_post($post_id); } } if (!$post) { return; } $model = CRED_Loader::get($is_user_form ? 'MODEL/UserForms' : 'MODEL/Forms'); if (empty($attachedData)) { $attachedData = $model->getAttachedData($post_id); } // trigger for this event, if set if (isset($data['event'])) { self::$event = $data['event']; } else { self::$event = false; } $notification = isset($data['notification']) ? $data['notification'] : false; if (!$attachedData && !$is_user_form || !$notification || !isset($notification->enable) || !$notification->enable || empty($notification->notifications)) { return; } $notificationsToSent = array(); foreach ($notification->notifications as $ii => $notif) { $send_notification = false; if (isset($notif['event'])) { $conditionFields = array(); $_conditionFields = array(); if (isset($notif['event']['condition']) && !empty($notif['event']['condition'])) { foreach ($notif['event']['condition'] as $jj => $condition) { $conditionFields[] = $condition['field']; } $_conditionFields = $model->getPostFields($post_id, $conditionFields); } $send_notification = self::evaluate(array('form_id' => $form_id, 'post' => $post, 'notification' => $notif, 'fields' => $_conditionFields, 'snapshot' => isset($attachedData[$form_id]) ? $attachedData[$form_id]['current'] : array())); } if ($send_notification) { $notificationsToSent[] = $notif; } } //cred_log($notificationsToSent); // removed but it's necessary further debugging 'Notification is being sent when visit the post edit screen' // if (!is_admin()&&!empty($notificationsToSent)) if (!empty($notificationsToSent)) { self::sendNotifications($post_id, $form_id, $notificationsToSent); } }