/** * Executes sending a message via the given sending messenger (but generated via the given generating messenger). * * @since 4.5.0 * * @param EE_messenger $generating_messenger The messenger used for generating messages * @param EE_message_type $message_type The message type used for generating messages * @param mixed $data Data provided for parsing shortcodes in message templates. * @param EE_messenger $sending_messenger The messenger that will be used for SENDING the messages. * @param bool $context If provided, then a specific context for a given template will be sent. * @param bool $send Default TRUE. If false, then this will just return the generated EE_Messages std_Class objects which might be used by the trigger to setup a batch message (typically html messenger uses it). * * @return mixed(bool|std_Class[]) */ private function _send_message(EE_messenger $generating_messenger, EE_message_type $message_type, $data, EE_messenger $sending_messenger, $context = FALSE, $send = TRUE) { //can't even get started yo! if ($message_type === FALSE || is_wp_error($message_type) || $message_type->set_messages($data, $generating_messenger, $context) === FALSE) { return FALSE; } // if the generating messenger and the sending messengers are different... // then are there any hooks that the generating messenger sets for the sending messenger (i.e. css file swap outs etc.) if ($sending_messenger != $generating_messenger) { $generating_messenger->do_secondary_messenger_hooks($sending_messenger->name); } //it is possible that the user has the messenger turned off for this type. if ($message_type->count === 0) { return FALSE; } //are we just sending the EE_Messages stdClass objects back? if (!$send) { return $message_type->messages; } //TODO: check count (at some point we'll use this to decide whether we send to queue or not i.e. //if ( $message_type->count > 1000 ) ... do something //else... $success = TRUE; // $success is a flag for the loop. If there is NO error then everything is a success (true) otherwise it wasn't a success (false) foreach ($message_type->messages as $message) { //todo: should we do some reporting on messages gone out at some point? I think we could have the $active_messenger object return bool for whether message was sent or not and we can compile a report based on that. // if messages send successfully then $success retains it's value, but a single fail will toggle it to FALSE $success = $sending_messenger->send_message($message, $message_type) === TRUE ? $success : FALSE; } unset($message_type); return $success; }
/** * Executes the send method on the provided messenger * *@param EE_Message $message * @param EE_messenger $messenger * @param EE_message_type $message_type * @return bool true means all went well, false means, not so much. */ protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) { if ($messenger->send_message($message, $message_type)) { $message->set_STS_ID(EEM_Message::status_sent); return true; } else { $message->set_STS_ID(EEM_Message::status_retry); return false; } }