private function notify($post_id, $attachedData = null) { $form =& $this->_formData; $_fields = $form->getFields(); // init notification manager if needed if (isset($_fields['notification']->enable) && $_fields['notification']->enable && !empty($_fields['notification']->notifications)) { // add extra plceholder codes add_filter('cred_subject_notification_codes', array(&$this, 'extraSubjectNotificationCodes'), 5, 3); add_filter('cred_body_notification_codes', array(&$this, 'extraBodyNotificationCodes'), 5, 3); CRED_Loader::load('CLASS/Notification_Manager'); if ($form->getForm()->post_type == CRED_USER_FORMS_CUSTOM_POST_NAME) { CRED_Notification_Manager::set_user_fields(); } // add the post to notification management CRED_Notification_Manager::add($post_id, $form->getForm()->ID, $_fields['notification']->notifications); // send any notifications now if needed CRED_Notification_Manager::triggerNotifications($post_id, array('event' => 'form_submit', 'form_id' => $form->getForm()->ID, 'notification' => $_fields['notification']), $attachedData); // remove extra plceholder codes remove_filter('cred_subject_notification_codes', array(&$this, 'extraSubjectNotificationCodes'), 5, 3); remove_filter('cred_body_notification_codes', array(&$this, 'extraBodyNotificationCodes'), 5, 3); } }
public function onOrderChange($data) { // HOOKS API //do_action('cred_commerce_before_send_notifications', $data); // send notifications if (!isset($data['new_status']) || !in_array($data['new_status'], array('pending', 'failed', 'processing', 'completed', 'on-hold', 'cancelled', 'refunded'))) { return; } // not spam with useless notifications ;) if (isset($data['cred_meta']) && $data['cred_meta']) { $model = CREDC_Loader::get('MODEL/Main'); CRED_Loader::load('CLASS/Notification_Manager'); foreach ($data['cred_meta'] as $ii => $meta) { if (!isset($meta['cred_form_id'])) { continue; } $form_id = $meta['cred_form_id']; $form_slug = ''; $cred_form_post = get_post($form_id); if ($cred_form_post) { $form_slug = $cred_form_post->post_name; } $post_id = $meta['cred_post_id']; $form = $model->getForm($form_id, true); if ($form->isCommerce && isset($form->fields['notification'])) { $this->_data = array('order_id' => $data['order_id'], 'previous_status' => $data['previous_status'], 'new_status' => $data['new_status'], 'cred_meta' => $meta); add_filter('cred_custom_notification_event', array(&$this, 'notificationOrderEvent'), 1, 4); CRED_Notification_Manager::triggerNotifications($post_id, array('event' => 'order_modified', 'form_id' => $form_id, 'notification' => $form->fields['notification'])); remove_filter('cred_custom_notification_event', array(&$this, 'notificationOrderEvent'), 1, 4); $this->_data = false; } } } // HOOKS API do_action('cred_commerce_after_send_notifications_form_' . $form_slug, $data); do_action('cred_commerce_after_send_notifications', $data); }