/**
  * assuming we have an up-to-date database schema, this will populate it
  * with default and initial data. This should be called
  * upon activation of a new plugin, reactivation, and at the end
  * of running migration scripts
  */
 public static function initialize_db_content()
 {
     //		echo"init reg content";
     EEH_Activation::initialize_system_questions();
     //		EEH_Activation::insert_default_prices();
     //		EEH_Activation::insert_defaulinsert_default_pricest_price_types();
     //		EEH_Activation::insert_default_tickets();
     EEH_Activation::insert_default_status_codes();
     //		default countries and states actually takes place during data migration scripts
     //		because converting state and coutnry names to foreign keys must occur for venues, attendees, etc
     //		EEH_Activation::insert_default_countries();
     //		EEH_Activation::insert_default_states();
     EEH_Activation::generate_default_message_templates();
     EEH_Activation::create_no_ticket_prices_array();
     //also initialize payment settings, which is a side-effect of calling
     //EEM_Gateway::load_all_gateways()
     EEM_Gateways::instance(true)->load_all_gateways();
     //also, check for CAF default db content
     do_action('AHEE__EEH_Activation__initialize_db_content');
     //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
     //which users really won't care about on initial activation
     EE_Error::overwrite_success();
 }
 /**
  * assuming we have an up-to-date database schema, this will populate it
  * with default and initial data. This should be called
  * upon activation of a new plugin, reactivation, and at the end
  * of running migration scripts
  */
 public static function initialize_db_content()
 {
     //let's avoid doing all this logic repeatedly, especially when addons are requesting it
     if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
         return;
     }
     EEH_Activation::$_initialized_db_content_already_in_this_request = true;
     EEH_Activation::initialize_system_questions();
     EEH_Activation::insert_default_status_codes();
     EEH_Activation::generate_default_message_templates();
     EEH_Activation::create_no_ticket_prices_array();
     EE_Registry::instance()->CAP->init_caps();
     EEH_Activation::validate_messages_system();
     EEH_Activation::insert_default_payment_methods();
     //in case we've
     EEH_Activation::remove_cron_tasks();
     EEH_Activation::create_cron_tasks();
     //also, check for CAF default db content
     do_action('AHEE__EEH_Activation__initialize_db_content');
     //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
     //which users really won't care about on initial activation
     EE_Error::overwrite_success();
 }
 /**
  * Message triggers for a resend registration confirmation (in admin)
  *
  * @access public
  * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
  * @return bool          success/fail
  */
 public static function process_resend($req_data)
 {
     $regs_to_send = array();
     //first let's make sure we have the reg id (needed for resending!);
     if (!isset($req_data['_REG_ID'])) {
         EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     //if $req_data['_REG_ID'] is an array then let's group the registrations by transaction and reg status
     // so we can only trigger messages per group.
     if (is_array($req_data['_REG_ID'])) {
         foreach ($req_data['_REG_ID'] as $reg_id) {
             $reg = EE_Registry::instance()->load_model('Registration')->get_one_by_ID($reg_id);
             if (!$reg instanceof EE_Registration) {
                 EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $req_data['_REG_ID']));
                 return false;
             }
             $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
         }
     } else {
         //we have a single registration id, so let's see if we can get a EE_Registration from it, and if so set it up for sending.
         //get reg object from reg_id
         $reg = EE_Registry::instance()->load_model('Registration')->get_one_by_ID($req_data['_REG_ID']);
         //if no reg object then send error
         if (!$reg instanceof EE_Registration) {
             EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $req_data['_REG_ID']));
             return false;
         }
         $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg;
     }
     self::_load_controller();
     $status_match_array = self::_get_reg_status_array();
     $active_mts = self::$_EEMSG->get_active_message_types();
     $success = false;
     //loop through and send!
     foreach ($regs_to_send as $status_group) {
         foreach ($status_group as $status_id => $registrations) {
             if (!in_array($status_match_array[$status_id], $active_mts)) {
                 EE_Error::add_error(sprintf(__('Cannot resend the message for this registration because the corresponding message type (%1$s) is not active.  If you wish to send messages for this message type then please activate it by visiting the %2$sMessages Admin Page%3$s.', 'event_espresso'), $status_match_array[$reg->status_ID()], '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', '</a>'));
                 return false;
             }
             if (self::$_EEMSG->send_message($status_match_array[$status_id], array($registrations, $status_id))) {
                 EE_Error::overwrite_success();
                 EE_Error::add_success(__('The message for this registration has been re-sent', 'event_espresso'));
                 $success = true;
             } else {
                 EE_Error::add_error(__('Something went wrong and the message for this registration was NOT resent', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
             }
         }
     }
     /**
      * Note this returns true if ANY messages were sent successfully. So if client code wants to catch messages
      * that might not have sent successfully, it needs to check EE_Error for any errors.
      */
     return $success;
 }
 /**
  * 	_redirect_after_action
  *	@param int 		$success 	- whether success was for two or more records, or just one, or none
  *	@param string 	$what 		- what the action was performed on
  *	@param string 	$action_desc 	- what was done ie: updated, deleted, etc
  *	@param int 		$query_args		- an array of query_args to be added to the URL to redirect to after the admin action is completed
  *	@param BOOL     $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to override this so that they show.
  *	@access protected
  *	@return void
  */
 protected function _redirect_after_action($success = FALSE, $what = 'item', $action_desc = 'processed', $query_args = array(), $override_overwrite = FALSE)
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     //class name for actions/filters.
     $classname = get_class($this);
     //set redirect url. Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, otherwise we go with whatever is set as the _admin_base_url
     $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
     $notices = EE_Error::get_notices(FALSE);
     // overwrite default success messages //BUT ONLY if overwrite not overridden
     if (!$override_overwrite || !empty($notices['errors'])) {
         EE_Error::overwrite_success();
     }
     // how many records affected ? more than one record ? or just one ?
     if ($success > 1 && empty($notices['errors'])) {
         // set plural msg
         EE_Error::add_success(sprintf(__('The "%s" have been successfully %s.', 'event_espresso'), $what, $action_desc), __FILE__, __FUNCTION__, __LINE__);
     } else {
         if ($success == 1 && empty($notices['errors'])) {
             // set singular msg
             EE_Error::add_success(sprintf(__('The "%s" has been successfully %s.', 'event_espresso'), $what, $action_desc), __FILE__, __FUNCTION__, __LINE__);
         }
     }
     // check that $query_args isn't something crazy
     if (!is_array($query_args)) {
         $query_args = array();
     }
     /**
      * Allow injecting actions before the query_args are modified for possible different
      * redirections on save and close actions
      *
      * @since 4.2.0
      *
      * @param array $query_args   The original query_args array coming into the
      *                          		method.
      */
     do_action('AHEE__' . $classname . '___redirect_after_action__before_redirect_modification_' . $this->_req_action, $query_args);
     //calculate where we're going (if we have a "save and close" button pushed)
     if (isset($this->_req_data['save_and_close']) && isset($this->_req_data['save_and_close_referrer'])) {
         // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
         $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
         // regenerate query args array from refferer URL
         parse_str($parsed_url['query'], $query_args);
         // correct page and action will be in the query args now
         $redirect_url = admin_url('admin.php');
     }
     //merge any default query_args set in _default_route_query_args property
     if (!empty($this->_default_route_query_args) && !$this->_is_UI_request) {
         $args_to_merge = array();
         foreach ($this->_default_route_query_args as $query_param => $query_value) {
             //is there a wp_referer array in our _default_route_query_args property?
             if ($query_param == 'wp_referer') {
                 $query_value = (array) $query_value;
                 foreach ($query_value as $reference => $value) {
                     if (strpos($reference, 'nonce') !== false) {
                         continue;
                     }
                     //finally we will override any arguments in the referer with
                     //what might be set on the _default_route_query_args array.
                     if (isset($this->_default_route_query_args[$reference])) {
                         $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]);
                     } else {
                         $args_to_merge[$reference] = urlencode($value);
                     }
                 }
                 continue;
             }
             $args_to_merge[$query_param] = $query_value;
         }
         //now let's merge these arguments but override with what was specifically sent in to the
         //redirect.
         $query_args = array_merge($args_to_merge, $query_args);
     }
     $this->_process_notices($query_args);
     // generate redirect url
     // if redirecting to anything other than the main page, add a nonce
     if (isset($query_args['action'])) {
         // manually generate wp_nonce and merge that with the query vars becuz the wp_nonce_url function wrecks havoc on some vars
         $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
     }
     //we're adding some hooks and filters in here for processing any things just before redirects (example: an admin page has done an insert or update and we want to run something after that).
     do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
     $redirect_url = apply_filters('FHEE_redirect_' . $classname . $this->_req_action, self::add_query_args_and_nonce($query_args, $redirect_url), $query_args);
     // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
     if (defined('DOING_AJAX')) {
         $default_data = array('close' => TRUE, 'redirect_url' => $redirect_url, 'where' => 'main', 'what' => 'append');
         $this->_template_args['success'] = $success;
         $this->_template_args['data'] = !empty($this->_template_args['data']) ? array_merge($default_data, $this->_template_args['data']) : $default_data;
         $this->_return_json();
     }
     wp_safe_redirect($redirect_url);
     exit;
 }
 /**
  * This just updates the active_messengers usermeta field when a messenger or message type is activated/deactivated.
  * NOTE: deactivating will remove the messenger (or message type) from the active_messengers wp_options field so all saved settings WILL be lost for the messenger AND message_types associated with that messenger (or message type).
  *
  * @param  string  $messenger What messenger we're toggling
  * @param  boolean $deactivate if true then we deactivate
  * @param  mixed   $message_type if present what message type we're toggling
  * @return void
  */
 protected function _activate_messenger($messenger, $deactivate = FALSE, $message_type = FALSE)
 {
     global $espresso_wp_user;
     $templates = TRUE;
     $this->_set_m_mt_settings();
     if (!$deactivate) {
         //we are activating.  we can use $this->_m_mt_settings to get all the installed messengers
         $this->_active_messengers[$messenger]['settings'] = !isset($this->_active_messengers[$messenger]['settings']) ? array() : $this->_active_messengers[$messenger]['settings'];
         $this->_active_messengers[$messenger]['obj'] = $this->_m_mt_settings['messenger_tabs'][$messenger]['obj'];
         //get has_active so we can sure its kept up to date.
         $has_activated = get_option('ee_has_activated_messages');
         if (empty($has_activated[$messenger])) {
             $has_activated[$messenger] = array();
         }
         //k we need to get what default message types are to be associated with the messenger that's been activated.
         $default_types = $message_type ? (array) $message_type : $this->_active_messengers[$messenger]['obj']->get_default_message_types();
         foreach ($default_types as $type) {
             $settings_fields = $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$type]['obj']->get_admin_settings_fields();
             if (!empty($settings_fields)) {
                 //we have fields for this message type so let's get the defaults for saving.
                 foreach ($settings_fields as $field => $values) {
                     $settings[$field] = $values['default'];
                 }
                 //let's set the data for reloading this message type form in ajax
                 $this->_template_args['data']['mt_reload'][] = $type;
             } else {
                 $settings = array();
             }
             $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$type]['settings'] = $settings;
             if (!in_array($type, $has_activated[$messenger])) {
                 $has_activated[$messenger][] = $type;
             }
         }
         //any default settings for the messenger?
         $msgr_settings = $this->_active_messengers[$messenger]['obj']->get_admin_settings_fields();
         if (!empty($msgr_settings)) {
             foreach ($msgr_settings as $field => $value) {
                 $this->_active_messengers[$messenger]['settings'][$field] = $value;
             }
         }
         //update settings in database
         EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         update_option('ee_has_activated_messages', $has_activated);
         //generate new templates (if necessary)
         $templates = $this->_generate_new_templates($messenger, $default_types, 0, TRUE);
         EE_Error::overwrite_success();
         //if generation failed then we need to remove the active messenger.
         if (!$templates) {
             unset($this->_active_messengers[$messenger]);
             EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         } else {
             //all is good let's do a success message
             if ($message_type) {
                 EE_Error::add_success(sprintf(__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$message_type]['obj']->label['singular']), ucwords($this->_active_messengers[$messenger]['obj']->label['singular'])));
                 //if message type was invoice then let's make sure we activate the invoice payment method.
                 if ($message_type == 'invoice') {
                     EE_Registry::instance()->load_lib('Payment_Method_Manager');
                     $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
                     if ($pm instanceof EE_Payment_Method) {
                         EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.', 'event_espresso'));
                     }
                 }
             } else {
                 EE_Error::add_success(sprintf(__('%s messenger has been successfully activated', 'event_espresso'), ucwords($this->_active_messengers[$messenger]['obj']->label['singular'])));
             }
         }
         $this->_template_args['data']['active_mts'] = $default_types;
     } else {
         //we're deactivating
         $MTP = EEM_Message_Template_Group::instance();
         //okay let's update the message templates that match this messenger so that they are deactivated in the database as well.
         $update_array = array('MTP_messenger' => $messenger);
         if ($message_type) {
             $update_array['MTP_message_type'] = $message_type;
         }
         $success = $MTP->update(array('MTP_is_active' => 0), array($update_array));
         $messenger_obj = $this->_active_messengers[$messenger]['obj'];
         //if this is a message type deactivation then we're only unsetting the message type otherwise unset the messenger
         if ($message_type) {
             unset($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type]);
         } else {
             unset($this->_active_messengers[$messenger]);
         }
         EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         EE_Error::overwrite_success();
         if ($message_type) {
             EE_Error::add_success(sprintf(__('%s message type has been successfully deactivated', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['active'][$message_type]['obj']->label['singular'])));
         } else {
             EE_Error::add_success(sprintf(__('%s messenger has been successfully deactivated', 'event_espresso'), ucwords($messenger_obj->label['singular'])));
         }
         //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
         if ($messenger == 'html' || $message_type == 'invoice') {
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
             $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
             if ($count_updated > 0) {
                 $msg = $message_type == 'invoice' ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then vist the payment methods admin page to reactivate the invoice payment method.', 'event_espresso') : __('Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso');
                 EE_Error::add_attention($msg);
             }
         }
     }
     return true;
 }
 /**
  * This just updates the active_messengers usermeta field when a messenger or message type is activated/deactivated.
  * NOTE: deactivating will remove the messenger (or message type) from the active_messengers wp_options field so all saved settings WILL be lost for the messenger AND message_types associated with that messenger (or message type).
  *
  * @param  string  $messenger What messenger we're toggling
  * @param  boolean $deactivate if true then we deactivate
  * @param  mixed   $message_type if present what message type we're toggling
  * @return void
  */
 protected function _activate_messenger($messenger, $deactivate = FALSE, $message_type = FALSE)
 {
     global $espresso_wp_user;
     $success_msg = array();
     $templates = TRUE;
     $this->_set_m_mt_settings();
     if (!$deactivate) {
         //we are activating.  we can use $this->_m_mt_settings to get all the installed messengers.
         $this->_active_messengers[$messenger]['settings'] = !isset($this->_active_messengers[$messenger]['settings']) ? array() : $this->_active_messengers[$messenger]['settings'];
         $this->_active_messengers[$messenger]['obj'] = $this->_m_mt_settings['messenger_tabs'][$messenger]['obj'];
         //k we need to get what default message types are to be associated with the messenger that's been activated.
         $default_types = $message_type ? (array) $message_type : $this->_active_messengers[$messenger]['obj']->get_default_message_types();
         foreach ($default_types as $type) {
             $settings_fields = $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$type]['obj']->get_admin_settings_fields();
             if (!empty($settings_fields)) {
                 //we have fields for this message type so let's get the defaults for saving.
                 foreach ($settings_fields as $field => $values) {
                     $settings[$field] = $values['default'];
                 }
                 //let's set the data for reloading this message type form in ajax
                 $this->_template_args['data']['mt_reload'][] = $type;
             } else {
                 $settings = array();
             }
             $this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$type]['settings'] = $settings;
         }
         //any default settings for the messenger?
         $msgr_settings = $this->_active_messengers[$messenger]['obj']->get_admin_settings_fields();
         if (!empty($msgr_settings)) {
             foreach ($msgr_settings as $field => $value) {
                 $this->_active_messengers[$messenger]['settings'][$field] = $value;
             }
         }
         //update settings in database
         EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         //generate new templates (if necessary)
         $templates = $this->_generate_new_templates($messenger, $default_types, 0, TRUE);
         EE_Error::overwrite_success();
         //if generation failed then we need to remove the active messenger.
         if (!$templates) {
             unset($this->_active_messengers[$messenger]);
             EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         } else {
             //all is good let's do a success message
             $success_msg = $message_type ? sprintf(__('%s message type has been successfully activated with the %s messenger', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'][$message_type]['obj']->label['singular']), ucwords($this->_active_messengers[$messenger]['obj']->label['singular'])) : sprintf(__('%s messenger has been successfully activated', 'event_espresso'), ucwords($this->_active_messengers[$messenger]['obj']->label['singular']));
         }
         $this->_template_args['data']['active_mts'] = $default_types;
     } else {
         //we're deactivating
         $MTP = EEM_Message_Template_Group::instance();
         //okay let's update the message templates that match this messenger so that they are deactivated in the database as well.
         $update_array = array('MTP_messenger' => $messenger);
         if ($message_type) {
             $update_array['MTP_message_type'] = $message_type;
         }
         $success = $MTP->update(array('MTP_is_active' => 0), array($update_array));
         $messenger_obj = $this->_active_messengers[$messenger]['obj'];
         //if this is a message type deactivation then we're only unsetting the message type otherwise unset the messenger
         if ($message_type) {
             unset($this->_active_messengers[$messenger]['settings'][$messenger . '-message_types'][$message_type]);
         } else {
             unset($this->_active_messengers[$messenger]);
         }
         EEH_MSG_Template::update_active_messengers_in_db($this->_active_messengers);
         $success_msg = $message_type ? sprintf(__('%s %s has been successfully deactivated', 'event_espresso'), ucwords($this->_m_mt_settings['message_type_tabs'][$messenger]['active'][$message_type]['obj']->label['singular']), __('Message Type', 'event_espresso')) : sprintf(__('%s %s has been successfully deactivated', 'event_espresso'), ucwords($messenger_obj->label['singular']), __('Messenger', 'event_espresso'));
     }
     EE_Error::overwrite_success();
     if ($templates) {
         EE_Error::add_success($success_msg);
     }
     return true;
 }
 /**
  * Message triggers for a resend registration confirmation (in admin)
  *
  * @access public
  * @param  bool $success incoming success value (we return true or false on success/fail)
  * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
  * @return bool          success/fail
  */
 public function process_resend($success, $req_data)
 {
     $success = TRUE;
     //first let's make sure we have the reg id (needed for resending!);
     if (!isset($req_data['_REG_ID'])) {
         EE_Error::add_error(__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         $success = FALSE;
     }
     //get reg object from reg_id
     $reg = EE_Registry::instance()->load_model('Registration')->get_one_by_ID($req_data['_REG_ID']);
     //if no reg object then send error
     if (empty($reg)) {
         EE_Error::add_error(sprintf(__('Unable to retrieve a registration object for the given reg id (%s)', 'event_espresso'), $req_data['_REG_ID']), __FILE__, __FUNCTION__, __LINE__);
         $success = FALSE;
     }
     if ($success) {
         $this->_load_controller();
         //get status_match_array
         $status_match_array = $this->_get_reg_status_array();
         $active_mts = $this->_EEMSG->get_active_message_types();
         if (!in_array($status_match_array[$reg->status_ID()], $active_mts)) {
             $success = FALSE;
             EE_Error::add_error(sprintf(__('Cannot resend the message for this registration because the corresponding message type (%s) is not active.  If you wish to send messages for this message type then please activate it by %sgoing here%s.', 'event_espresso'), $status_match_array[$reg->status_ID()], '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', '</a>'), __FILE__, __FUNCTION__, __LINE__);
             return $success;
         }
         $success = $this->_EEMSG->send_message($status_match_array[$reg->status_ID()], $reg);
     }
     if ($success) {
         EE_Error::overwrite_success();
         EE_Error::add_success(__('The message for this registration has been re-sent', 'event_espresso'));
     } else {
         EE_Error::add_error(__('Something went wrong and the message for this registration was NOT resent', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
     }
     return $success;
 }
 /**
  * This sets up the appropriate response for deactivating a messenger and/or message type.
  *
  * @param EE_messenger         $messenger
  * @param EE_message_type|null $message_type
  *
  * @return bool
  */
 protected function _setup_response_message_for_deactivating_messenger_with_message_types($messenger, EE_message_type $message_type = null)
 {
     EE_Error::overwrite_success();
     //if $messenger isn't a valid messenger object then get out.
     if (!$messenger instanceof EE_Messenger) {
         EE_Error::add_error(__('The messenger being deactivated is not a valid messenger', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
         return false;
     }
     if ($message_type instanceof EE_message_type) {
         $message_type_name = $message_type->name;
         EE_Error::add_success(sprintf(__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'), ucwords($message_type->label['singular']), ucwords($messenger->label['singular'])));
     } else {
         $message_type_name = '';
         EE_Error::add_success(sprintf(__('%s messenger has been successfully deactivated.', 'event_espresso'), ucwords($messenger->label['singular'])));
     }
     //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
     if ($messenger->name == 'html' || $message_type_name == 'invoice') {
         EE_Registry::instance()->load_lib('Payment_Method_Manager');
         $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
         if ($count_updated > 0) {
             $msg = $message_type_name == 'invoice' ? __('Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso') : __('Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.', 'event_espresso');
             EE_Error::add_attention($msg);
         }
     }
     return true;
 }