@@ -17,2683 +17,2683 @@ discard block  | 
                                                    ||
| 17 | 17 | */  | 
                                                        
| 18 | 18 | class Messages_Admin_Page extends EE_Admin_Page  | 
                                                        
| 19 | 19 |  { | 
                                                        
| 20 | - /**  | 
                                                        |
| 21 | - * @var EEM_Message  | 
                                                        |
| 22 | - */  | 
                                                        |
| 23 | - private $MSG_MODEL;  | 
                                                        |
| 24 | -  | 
                                                        |
| 25 | - /**  | 
                                                        |
| 26 | - * @var EEM_Message_Template  | 
                                                        |
| 27 | - */  | 
                                                        |
| 28 | - private $MTP_MODEL;  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - /**  | 
                                                        |
| 31 | - * @var EEM_Message_Template_Group  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - private $MTG_MODEL;  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | - /**  | 
                                                        |
| 36 | - * @var EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 37 | - */  | 
                                                        |
| 38 | - protected $_message_resource_manager;  | 
                                                        |
| 39 | -  | 
                                                        |
| 40 | - /**  | 
                                                        |
| 41 | - * @var string  | 
                                                        |
| 42 | - */  | 
                                                        |
| 43 | - protected $_active_message_type_name = '';  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /**  | 
                                                        |
| 46 | - * @var string  | 
                                                        |
| 47 | - */  | 
                                                        |
| 48 | - protected $_active_messenger_name = '';  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - /**  | 
                                                        |
| 51 | - * @var EE_messenger $_active_messenger  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - protected $_active_messenger;  | 
                                                        |
| 54 | -  | 
                                                        |
| 55 | - protected $_activate_meta_box_type;  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - protected $_current_message_meta_box;  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | - protected $_current_message_meta_box_object;  | 
                                                        |
| 60 | -  | 
                                                        |
| 61 | - protected $_context_switcher;  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - protected $_shortcodes = [];  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - protected $_active_messengers = [];  | 
                                                        |
| 66 | -  | 
                                                        |
| 67 | - protected $_active_message_types = [];  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | - /**  | 
                                                        |
| 70 | - * @var EE_Message_Template_Group $_message_template_group  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | - protected $_message_template_group;  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - protected $_m_mt_settings = [];  | 
                                                        |
| 75 | -  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | - /**  | 
                                                        |
| 78 | - * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.  | 
                                                        |
| 79 | - * IF there is no group then it gets automatically set to the Default template pack.  | 
                                                        |
| 80 | - *  | 
                                                        |
| 81 | - * @since 4.5.0  | 
                                                        |
| 82 | - *  | 
                                                        |
| 83 | - * @var EE_Messages_Template_Pack  | 
                                                        |
| 84 | - */  | 
                                                        |
| 85 | - protected $_template_pack;  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - /**  | 
                                                        |
| 89 | - * This is set via the _set_message_template_group method and holds whatever the template pack variation for the  | 
                                                        |
| 90 | - * group is. If there is no group then it automatically gets set to default.  | 
                                                        |
| 91 | - *  | 
                                                        |
| 92 | - * @since 4.5.0  | 
                                                        |
| 93 | - *  | 
                                                        |
| 94 | - * @var string  | 
                                                        |
| 95 | - */  | 
                                                        |
| 96 | - protected $_variation;  | 
                                                        |
| 97 | -  | 
                                                        |
| 98 | -  | 
                                                        |
| 99 | - /**  | 
                                                        |
| 100 | - * @param bool $routing  | 
                                                        |
| 101 | - * @throws EE_Error  | 
                                                        |
| 102 | - * @throws ReflectionException  | 
                                                        |
| 103 | - */  | 
                                                        |
| 104 | - public function __construct($routing = true)  | 
                                                        |
| 105 | -    { | 
                                                        |
| 106 | - // make sure messages autoloader is running  | 
                                                        |
| 107 | - EED_Messages::set_autoloaders();  | 
                                                        |
| 108 | - parent::__construct($routing);  | 
                                                        |
| 109 | - }  | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | -  | 
                                                        |
| 112 | - /**  | 
                                                        |
| 113 | - * @return EEM_Message  | 
                                                        |
| 114 | - * @throws EE_Error  | 
                                                        |
| 115 | - */  | 
                                                        |
| 116 | - public function getMsgModel()  | 
                                                        |
| 117 | -    { | 
                                                        |
| 118 | -        if (! $this->MSG_MODEL instanceof EEM_Message) { | 
                                                        |
| 119 | - $this->MSG_MODEL = EEM_Message::instance();  | 
                                                        |
| 120 | - }  | 
                                                        |
| 121 | - return $this->MSG_MODEL;  | 
                                                        |
| 122 | - }  | 
                                                        |
| 123 | -  | 
                                                        |
| 124 | -  | 
                                                        |
| 125 | - /**  | 
                                                        |
| 126 | - * @return EEM_Message_Template  | 
                                                        |
| 127 | - * @throws EE_Error  | 
                                                        |
| 128 | - */  | 
                                                        |
| 129 | - public function getMtpModel()  | 
                                                        |
| 130 | -    { | 
                                                        |
| 131 | -        if (! $this->MTP_MODEL instanceof EEM_Message_Template) { | 
                                                        |
| 132 | - $this->MTP_MODEL = EEM_Message_Template::instance();  | 
                                                        |
| 133 | - }  | 
                                                        |
| 134 | - return $this->MTP_MODEL;  | 
                                                        |
| 135 | - }  | 
                                                        |
| 136 | -  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | - /**  | 
                                                        |
| 139 | - * @return EEM_Message_Template_Group  | 
                                                        |
| 140 | - * @throws EE_Error  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | - public function getMtgModel()  | 
                                                        |
| 143 | -    { | 
                                                        |
| 144 | -        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) { | 
                                                        |
| 145 | - $this->MTG_MODEL = EEM_Message_Template_Group::instance();  | 
                                                        |
| 146 | - }  | 
                                                        |
| 147 | - return $this->MTG_MODEL;  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | -  | 
                                                        |
| 150 | -  | 
                                                        |
| 151 | - /**  | 
                                                        |
| 152 | - * @throws EE_Error  | 
                                                        |
| 153 | - * @throws ReflectionException  | 
                                                        |
| 154 | - */  | 
                                                        |
| 155 | - protected function _init_page_props()  | 
                                                        |
| 156 | -    { | 
                                                        |
| 157 | - $this->page_slug = EE_MSG_PG_SLUG;  | 
                                                        |
| 158 | -        $this->page_label       = esc_html__('Messages Settings', 'event_espresso'); | 
                                                        |
| 159 | - $this->_admin_base_url = EE_MSG_ADMIN_URL;  | 
                                                        |
| 160 | - $this->_admin_base_path = EE_MSG_ADMIN;  | 
                                                        |
| 161 | -  | 
                                                        |
| 162 | -        $messenger    = $this->request->getRequestParam('messenger', ''); | 
                                                        |
| 163 | -        $message_type = $this->request->getRequestParam('message_type', ''); | 
                                                        |
| 164 | -        $this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger); | 
                                                        |
| 165 | -        $this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type); | 
                                                        |
| 166 | -  | 
                                                        |
| 167 | - $this->_load_message_resource_manager();  | 
                                                        |
| 168 | - }  | 
                                                        |
| 169 | -  | 
                                                        |
| 170 | -  | 
                                                        |
| 171 | - /**  | 
                                                        |
| 172 | - * loads messenger objects into the $_active_messengers property (so we can access the needed methods)  | 
                                                        |
| 173 | - *  | 
                                                        |
| 174 | - * @throws EE_Error  | 
                                                        |
| 175 | - * @throws InvalidDataTypeException  | 
                                                        |
| 176 | - * @throws InvalidInterfaceException  | 
                                                        |
| 177 | - * @throws InvalidArgumentException  | 
                                                        |
| 178 | - * @throws ReflectionException  | 
                                                        |
| 179 | - */  | 
                                                        |
| 180 | - protected function _load_message_resource_manager()  | 
                                                        |
| 181 | -    { | 
                                                        |
| 182 | -        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 183 | - }  | 
                                                        |
| 184 | -  | 
                                                        |
| 185 | -  | 
                                                        |
| 186 | - /**  | 
                                                        |
| 187 | - * @return array  | 
                                                        |
| 188 | - * @throws EE_Error  | 
                                                        |
| 189 | - * @throws InvalidArgumentException  | 
                                                        |
| 190 | - * @throws InvalidDataTypeException  | 
                                                        |
| 191 | - * @throws InvalidInterfaceException  | 
                                                        |
| 192 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 193 | - */  | 
                                                        |
| 194 | - public function get_messengers_for_list_table()  | 
                                                        |
| 195 | -    { | 
                                                        |
| 196 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 197 | - __METHOD__,  | 
                                                        |
| 198 | - sprintf(  | 
                                                        |
| 199 | - esc_html__(  | 
                                                        |
| 200 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',  | 
                                                        |
| 201 | - 'event_espresso'  | 
                                                        |
| 202 | - ),  | 
                                                        |
| 203 | - 'Messages_Admin_Page::get_messengers_select_input()'  | 
                                                        |
| 204 | - ),  | 
                                                        |
| 205 | - '4.9.9.rc.014'  | 
                                                        |
| 206 | - );  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | - $m_values = [];  | 
                                                        |
| 209 | - $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);  | 
                                                        |
| 210 | - // setup messengers for selects  | 
                                                        |
| 211 | - $i = 1;  | 
                                                        |
| 212 | -        foreach ($active_messengers as $active_messenger) { | 
                                                        |
| 213 | -            if ($active_messenger instanceof EE_Message) { | 
                                                        |
| 214 | - $m_values[ $i ]['id'] = $active_messenger->messenger();  | 
                                                        |
| 215 | - $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 216 | - $i++;  | 
                                                        |
| 217 | - }  | 
                                                        |
| 218 | - }  | 
                                                        |
| 219 | -  | 
                                                        |
| 220 | - return $m_values;  | 
                                                        |
| 221 | - }  | 
                                                        |
| 222 | -  | 
                                                        |
| 223 | -  | 
                                                        |
| 224 | - /**  | 
                                                        |
| 225 | - * @return array  | 
                                                        |
| 226 | - * @throws EE_Error  | 
                                                        |
| 227 | - * @throws InvalidArgumentException  | 
                                                        |
| 228 | - * @throws InvalidDataTypeException  | 
                                                        |
| 229 | - * @throws InvalidInterfaceException  | 
                                                        |
| 230 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 231 | - */  | 
                                                        |
| 232 | - public function get_message_types_for_list_table()  | 
                                                        |
| 233 | -    { | 
                                                        |
| 234 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 235 | - __METHOD__,  | 
                                                        |
| 236 | - sprintf(  | 
                                                        |
| 237 | - esc_html__(  | 
                                                        |
| 238 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',  | 
                                                        |
| 239 | - 'event_espresso'  | 
                                                        |
| 240 | - ),  | 
                                                        |
| 241 | - 'Messages_Admin_Page::get_message_types_select_input()'  | 
                                                        |
| 242 | - ),  | 
                                                        |
| 243 | - '4.9.9.rc.014'  | 
                                                        |
| 244 | - );  | 
                                                        |
| 245 | -  | 
                                                        |
| 246 | - $mt_values = [];  | 
                                                        |
| 247 | - $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);  | 
                                                        |
| 248 | - $i = 1;  | 
                                                        |
| 249 | -        foreach ($active_messages as $active_message) { | 
                                                        |
| 250 | -            if ($active_message instanceof EE_Message) { | 
                                                        |
| 251 | - $mt_values[ $i ]['id'] = $active_message->message_type();  | 
                                                        |
| 252 | - $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 253 | - $i++;  | 
                                                        |
| 254 | - }  | 
                                                        |
| 255 | - }  | 
                                                        |
| 256 | -  | 
                                                        |
| 257 | - return $mt_values;  | 
                                                        |
| 258 | - }  | 
                                                        |
| 259 | -  | 
                                                        |
| 260 | -  | 
                                                        |
| 261 | - /**  | 
                                                        |
| 262 | - * @return array  | 
                                                        |
| 263 | - * @throws EE_Error  | 
                                                        |
| 264 | - * @throws InvalidArgumentException  | 
                                                        |
| 265 | - * @throws InvalidDataTypeException  | 
                                                        |
| 266 | - * @throws InvalidInterfaceException  | 
                                                        |
| 267 | - * @deprecated 4.9.9.rc.014  | 
                                                        |
| 268 | - */  | 
                                                        |
| 269 | - public function get_contexts_for_message_types_for_list_table()  | 
                                                        |
| 270 | -    { | 
                                                        |
| 271 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 272 | - __METHOD__,  | 
                                                        |
| 273 | - sprintf(  | 
                                                        |
| 274 | - esc_html__(  | 
                                                        |
| 275 | - 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',  | 
                                                        |
| 276 | - 'event_espresso'  | 
                                                        |
| 277 | - ),  | 
                                                        |
| 278 | - 'Messages_Admin_Page::get_contexts_for_message_types_select_input()'  | 
                                                        |
| 279 | - ),  | 
                                                        |
| 280 | - '4.9.9.rc.014'  | 
                                                        |
| 281 | - );  | 
                                                        |
| 282 | -  | 
                                                        |
| 283 | - $contexts = [];  | 
                                                        |
| 284 | - $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);  | 
                                                        |
| 285 | -        foreach ($active_message_contexts as $active_message) { | 
                                                        |
| 286 | -            if ($active_message instanceof EE_Message) { | 
                                                        |
| 287 | - $message_type = $active_message->message_type_object();  | 
                                                        |
| 288 | -                if ($message_type instanceof EE_message_type) { | 
                                                        |
| 289 | - $message_type_contexts = $message_type->get_contexts();  | 
                                                        |
| 290 | -                    foreach ($message_type_contexts as $context => $context_details) { | 
                                                        |
| 291 | - $contexts[ $context ] = $context_details['label'];  | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | - }  | 
                                                        |
| 294 | - }  | 
                                                        |
| 295 | - }  | 
                                                        |
| 296 | -  | 
                                                        |
| 297 | - return $contexts;  | 
                                                        |
| 298 | - }  | 
                                                        |
| 299 | -  | 
                                                        |
| 300 | -  | 
                                                        |
| 301 | - /**  | 
                                                        |
| 302 | - * Generate select input with provided messenger options array.  | 
                                                        |
| 303 | - *  | 
                                                        |
| 304 | - * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger  | 
                                                        |
| 305 | - * labels.  | 
                                                        |
| 306 | - * @return string  | 
                                                        |
| 307 | - * @throws EE_Error  | 
                                                        |
| 308 | - */  | 
                                                        |
| 309 | - public function get_messengers_select_input($messenger_options)  | 
                                                        |
| 310 | -    { | 
                                                        |
| 311 | - // if empty or just one value then just return an empty string  | 
                                                        |
| 312 | - if (  | 
                                                        |
| 313 | - empty($messenger_options)  | 
                                                        |
| 314 | - || ! is_array($messenger_options)  | 
                                                        |
| 315 | - || count($messenger_options) === 1  | 
                                                        |
| 316 | -        ) { | 
                                                        |
| 317 | - return '';  | 
                                                        |
| 318 | - }  | 
                                                        |
| 319 | - // merge in default  | 
                                                        |
| 320 | - $messenger_options = array_merge(  | 
                                                        |
| 321 | -            ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')], | 
                                                        |
| 322 | - $messenger_options  | 
                                                        |
| 323 | - );  | 
                                                        |
| 324 | - $input = new EE_Select_Input(  | 
                                                        |
| 325 | - $messenger_options,  | 
                                                        |
| 326 | - [  | 
                                                        |
| 327 | - 'html_name' => 'ee_messenger_filter_by',  | 
                                                        |
| 328 | - 'html_id' => 'ee_messenger_filter_by',  | 
                                                        |
| 329 | - 'html_class' => 'wide',  | 
                                                        |
| 330 | -                'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'), | 
                                                        |
| 331 | - ]  | 
                                                        |
| 332 | - );  | 
                                                        |
| 333 | -  | 
                                                        |
| 334 | - return $input->get_html_for_input();  | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | -  | 
                                                        |
| 338 | - /**  | 
                                                        |
| 339 | - * Generate select input with provided message type options array.  | 
                                                        |
| 340 | - *  | 
                                                        |
| 341 | - * @param array $message_type_options Array of message types indexed by message type slug, and values are the  | 
                                                        |
| 342 | - * message type labels  | 
                                                        |
| 343 | - * @return string  | 
                                                        |
| 344 | - * @throws EE_Error  | 
                                                        |
| 345 | - */  | 
                                                        |
| 346 | - public function get_message_types_select_input($message_type_options)  | 
                                                        |
| 347 | -    { | 
                                                        |
| 348 | - // if empty or count of options is 1 then just return an empty string  | 
                                                        |
| 349 | - if (  | 
                                                        |
| 350 | - empty($message_type_options)  | 
                                                        |
| 351 | - || ! is_array($message_type_options)  | 
                                                        |
| 352 | - || count($message_type_options) === 1  | 
                                                        |
| 353 | -        ) { | 
                                                        |
| 354 | - return '';  | 
                                                        |
| 355 | - }  | 
                                                        |
| 356 | - // merge in default  | 
                                                        |
| 357 | - $message_type_options = array_merge(  | 
                                                        |
| 358 | -            ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')], | 
                                                        |
| 359 | - $message_type_options  | 
                                                        |
| 360 | - );  | 
                                                        |
| 361 | - $input = new EE_Select_Input(  | 
                                                        |
| 362 | - $message_type_options,  | 
                                                        |
| 363 | - [  | 
                                                        |
| 364 | - 'html_name' => 'ee_message_type_filter_by',  | 
                                                        |
| 365 | - 'html_id' => 'ee_message_type_filter_by',  | 
                                                        |
| 366 | - 'html_class' => 'wide',  | 
                                                        |
| 367 | -                'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'), | 
                                                        |
| 368 | - ]  | 
                                                        |
| 369 | - );  | 
                                                        |
| 370 | -  | 
                                                        |
| 371 | - return $input->get_html_for_input();  | 
                                                        |
| 372 | - }  | 
                                                        |
| 373 | -  | 
                                                        |
| 374 | -  | 
                                                        |
| 375 | - /**  | 
                                                        |
| 376 | - * Generate select input with provide message type contexts array.  | 
                                                        |
| 377 | - *  | 
                                                        |
| 378 | - * @param array $context_options Array of message type contexts indexed by context slug, and values are the  | 
                                                        |
| 379 | - * context label.  | 
                                                        |
| 380 | - * @return string  | 
                                                        |
| 381 | - * @throws EE_Error  | 
                                                        |
| 382 | - */  | 
                                                        |
| 383 | - public function get_contexts_for_message_types_select_input($context_options)  | 
                                                        |
| 384 | -    { | 
                                                        |
| 385 | - // if empty or count of options is one then just return empty string  | 
                                                        |
| 386 | - if (  | 
                                                        |
| 387 | - empty($context_options)  | 
                                                        |
| 388 | - || ! is_array($context_options)  | 
                                                        |
| 389 | - || count($context_options) === 1  | 
                                                        |
| 390 | -        ) { | 
                                                        |
| 391 | - return '';  | 
                                                        |
| 392 | - }  | 
                                                        |
| 393 | - // merge in default  | 
                                                        |
| 394 | - $context_options = array_merge(  | 
                                                        |
| 395 | -            ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')], | 
                                                        |
| 396 | - $context_options  | 
                                                        |
| 397 | - );  | 
                                                        |
| 398 | - $input = new EE_Select_Input(  | 
                                                        |
| 399 | - $context_options,  | 
                                                        |
| 400 | - [  | 
                                                        |
| 401 | - 'html_name' => 'ee_context_filter_by',  | 
                                                        |
| 402 | - 'html_id' => 'ee_context_filter_by',  | 
                                                        |
| 403 | - 'html_class' => 'wide',  | 
                                                        |
| 404 | -                'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'), | 
                                                        |
| 405 | - ]  | 
                                                        |
| 406 | - );  | 
                                                        |
| 407 | -  | 
                                                        |
| 408 | - return $input->get_html_for_input();  | 
                                                        |
| 409 | - }  | 
                                                        |
| 410 | -  | 
                                                        |
| 411 | -  | 
                                                        |
| 412 | - protected function _ajax_hooks()  | 
                                                        |
| 413 | -    { | 
                                                        |
| 414 | -        add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']); | 
                                                        |
| 415 | -        add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']); | 
                                                        |
| 416 | -        add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']); | 
                                                        |
| 417 | -        add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']); | 
                                                        |
| 418 | -        add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']); | 
                                                        |
| 419 | -        add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']); | 
                                                        |
| 420 | - }  | 
                                                        |
| 421 | -  | 
                                                        |
| 422 | -  | 
                                                        |
| 423 | - protected function _define_page_props()  | 
                                                        |
| 424 | -    { | 
                                                        |
| 425 | - $this->_admin_page_title = $this->page_label;  | 
                                                        |
| 426 | - $this->_labels = [  | 
                                                        |
| 427 | - 'buttons' => [  | 
                                                        |
| 428 | -                'add'    => esc_html__('Add New Message Template', 'event_espresso'), | 
                                                        |
| 429 | -                'edit'   => esc_html__('Edit Message Template', 'event_espresso'), | 
                                                        |
| 430 | -                'delete' => esc_html__('Delete Message Template', 'event_espresso'), | 
                                                        |
| 431 | - ],  | 
                                                        |
| 432 | -            'publishbox' => esc_html__('Update Actions', 'event_espresso'), | 
                                                        |
| 433 | - ];  | 
                                                        |
| 434 | - }  | 
                                                        |
| 435 | -  | 
                                                        |
| 436 | -  | 
                                                        |
| 437 | - /**  | 
                                                        |
| 438 | - * an array for storing key => value pairs of request actions and their corresponding methods  | 
                                                        |
| 439 | - *  | 
                                                        |
| 440 | - * @access protected  | 
                                                        |
| 441 | - * @return void  | 
                                                        |
| 442 | - */  | 
                                                        |
| 443 | - protected function _set_page_routes()  | 
                                                        |
| 444 | -    { | 
                                                        |
| 445 | -        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 446 | -        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int'); | 
                                                        |
| 447 | -        $MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int'); | 
                                                        |
| 448 | -  | 
                                                        |
| 449 | - $this->_page_routes = [  | 
                                                        |
| 450 | - 'default' => [  | 
                                                        |
| 451 | - 'func' => '_message_queue_list_table',  | 
                                                        |
| 452 | - 'capability' => 'ee_read_global_messages',  | 
                                                        |
| 453 | - ],  | 
                                                        |
| 454 | - 'global_mtps' => [  | 
                                                        |
| 455 | - 'func' => '_ee_default_messages_overview_list_table',  | 
                                                        |
| 456 | - 'capability' => 'ee_read_global_messages',  | 
                                                        |
| 457 | - ],  | 
                                                        |
| 458 | - 'custom_mtps' => [  | 
                                                        |
| 459 | - 'func' => '_custom_mtps_preview',  | 
                                                        |
| 460 | - 'capability' => 'ee_read_messages',  | 
                                                        |
| 461 | - ],  | 
                                                        |
| 462 | - 'add_new_message_template' => [  | 
                                                        |
| 463 | - 'func' => 'add_message_template',  | 
                                                        |
| 464 | - 'capability' => 'ee_edit_messages',  | 
                                                        |
| 465 | - 'noheader' => true,  | 
                                                        |
| 466 | - ],  | 
                                                        |
| 467 | - 'edit_message_template' => [  | 
                                                        |
| 468 | - 'func' => '_edit_message_template',  | 
                                                        |
| 469 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 470 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 471 | - ],  | 
                                                        |
| 472 | - 'preview_message' => [  | 
                                                        |
| 473 | - 'func' => '_preview_message',  | 
                                                        |
| 474 | - 'capability' => 'ee_read_message',  | 
                                                        |
| 475 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 476 | - 'noheader' => true,  | 
                                                        |
| 477 | - 'headers_sent_route' => 'display_preview_message',  | 
                                                        |
| 478 | - ],  | 
                                                        |
| 479 | - 'display_preview_message' => [  | 
                                                        |
| 480 | - 'func' => '_display_preview_message',  | 
                                                        |
| 481 | - 'capability' => 'ee_read_message',  | 
                                                        |
| 482 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 483 | - ],  | 
                                                        |
| 484 | - 'insert_message_template' => [  | 
                                                        |
| 485 | - 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 486 | - 'capability' => 'ee_edit_messages',  | 
                                                        |
| 487 | - 'args' => ['new' => true],  | 
                                                        |
| 488 | - 'noheader' => true,  | 
                                                        |
| 489 | - ],  | 
                                                        |
| 490 | - 'update_message_template' => [  | 
                                                        |
| 491 | - 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 492 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 493 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 494 | - 'args' => ['new' => false],  | 
                                                        |
| 495 | - 'noheader' => true,  | 
                                                        |
| 496 | - ],  | 
                                                        |
| 497 | - 'trash_message_template' => [  | 
                                                        |
| 498 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 499 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 500 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 501 | - 'args' => ['trash' => true, 'all' => true],  | 
                                                        |
| 502 | - 'noheader' => true,  | 
                                                        |
| 503 | - ],  | 
                                                        |
| 504 | - 'trash_message_template_context' => [  | 
                                                        |
| 505 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 506 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 507 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 508 | - 'args' => ['trash' => true],  | 
                                                        |
| 509 | - 'noheader' => true,  | 
                                                        |
| 510 | - ],  | 
                                                        |
| 511 | - 'restore_message_template' => [  | 
                                                        |
| 512 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 513 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 514 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 515 | - 'args' => ['trash' => false, 'all' => true],  | 
                                                        |
| 516 | - 'noheader' => true,  | 
                                                        |
| 517 | - ],  | 
                                                        |
| 518 | - 'restore_message_template_context' => [  | 
                                                        |
| 519 | - 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 520 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 521 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 522 | - 'args' => ['trash' => false],  | 
                                                        |
| 523 | - 'noheader' => true,  | 
                                                        |
| 524 | - ],  | 
                                                        |
| 525 | - 'delete_message_template' => [  | 
                                                        |
| 526 | - 'func' => '_delete_message_template',  | 
                                                        |
| 527 | - 'capability' => 'ee_delete_message',  | 
                                                        |
| 528 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 529 | - 'noheader' => true,  | 
                                                        |
| 530 | - ],  | 
                                                        |
| 531 | - 'reset_to_default' => [  | 
                                                        |
| 532 | - 'func' => '_reset_to_default_template',  | 
                                                        |
| 533 | - 'capability' => 'ee_edit_message',  | 
                                                        |
| 534 | - 'obj_id' => $GRP_ID,  | 
                                                        |
| 535 | - 'noheader' => true,  | 
                                                        |
| 536 | - ],  | 
                                                        |
| 537 | - 'settings' => [  | 
                                                        |
| 538 | - 'func' => '_settings',  | 
                                                        |
| 539 | - 'capability' => 'manage_options',  | 
                                                        |
| 540 | - ],  | 
                                                        |
| 541 | - 'update_global_settings' => [  | 
                                                        |
| 542 | - 'func' => '_update_global_settings',  | 
                                                        |
| 543 | - 'capability' => 'manage_options',  | 
                                                        |
| 544 | - 'noheader' => true,  | 
                                                        |
| 545 | - ],  | 
                                                        |
| 546 | - 'generate_now' => [  | 
                                                        |
| 547 | - 'func' => '_generate_now',  | 
                                                        |
| 548 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 549 | - 'noheader' => true,  | 
                                                        |
| 550 | - ],  | 
                                                        |
| 551 | - 'generate_and_send_now' => [  | 
                                                        |
| 552 | - 'func' => '_generate_and_send_now',  | 
                                                        |
| 553 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 554 | - 'noheader' => true,  | 
                                                        |
| 555 | - ],  | 
                                                        |
| 556 | - 'queue_for_resending' => [  | 
                                                        |
| 557 | - 'func' => '_queue_for_resending',  | 
                                                        |
| 558 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 559 | - 'noheader' => true,  | 
                                                        |
| 560 | - ],  | 
                                                        |
| 561 | - 'send_now' => [  | 
                                                        |
| 562 | - 'func' => '_send_now',  | 
                                                        |
| 563 | - 'capability' => 'ee_send_message',  | 
                                                        |
| 564 | - 'noheader' => true,  | 
                                                        |
| 565 | - ],  | 
                                                        |
| 566 | - 'delete_ee_message' => [  | 
                                                        |
| 567 | - 'func' => '_delete_ee_messages',  | 
                                                        |
| 568 | - 'capability' => 'ee_delete_messages',  | 
                                                        |
| 569 | - 'noheader' => true,  | 
                                                        |
| 570 | - ],  | 
                                                        |
| 571 | - 'delete_ee_messages' => [  | 
                                                        |
| 572 | - 'func' => '_delete_ee_messages',  | 
                                                        |
| 573 | - 'capability' => 'ee_delete_messages',  | 
                                                        |
| 574 | - 'noheader' => true,  | 
                                                        |
| 575 | - 'obj_id' => $MSG_ID,  | 
                                                        |
| 576 | - ],  | 
                                                        |
| 577 | - ];  | 
                                                        |
| 578 | - }  | 
                                                        |
| 579 | -  | 
                                                        |
| 580 | -  | 
                                                        |
| 581 | - protected function _set_page_config()  | 
                                                        |
| 582 | -    { | 
                                                        |
| 583 | - $this->_page_config = [  | 
                                                        |
| 584 | - 'default' => [  | 
                                                        |
| 585 | - 'nav' => [  | 
                                                        |
| 586 | -                    'label' => esc_html__('Message Activity', 'event_espresso'), | 
                                                        |
| 587 | - 'icon' => 'dashicons-email',  | 
                                                        |
| 588 | - 'order' => 10,  | 
                                                        |
| 589 | - ],  | 
                                                        |
| 590 | - 'list_table' => 'EE_Message_List_Table',  | 
                                                        |
| 591 | - // 'qtips' => array( 'EE_Message_List_Table_Tips' ),  | 
                                                        |
| 592 | - 'require_nonce' => false,  | 
                                                        |
| 593 | - ],  | 
                                                        |
| 594 | - 'global_mtps' => [  | 
                                                        |
| 595 | - 'nav' => [  | 
                                                        |
| 596 | -                    'label' => esc_html__('Default Message Templates', 'event_espresso'), | 
                                                        |
| 597 | - 'icon' => 'dashicons-layout',  | 
                                                        |
| 598 | - 'order' => 20,  | 
                                                        |
| 599 | - ],  | 
                                                        |
| 600 | - 'list_table' => 'Messages_Template_List_Table',  | 
                                                        |
| 601 | - 'help_tabs' => [  | 
                                                        |
| 602 | - 'messages_overview_help_tab' => [  | 
                                                        |
| 603 | -                        'title'    => esc_html__('Messages Overview', 'event_espresso'), | 
                                                        |
| 604 | - 'filename' => 'messages_overview',  | 
                                                        |
| 605 | - ],  | 
                                                        |
| 606 | - 'messages_overview_messages_table_column_headings_help_tab' => [  | 
                                                        |
| 607 | -                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'), | 
                                                        |
| 608 | - 'filename' => 'messages_overview_table_column_headings',  | 
                                                        |
| 609 | - ],  | 
                                                        |
| 610 | - 'messages_overview_messages_filters_help_tab' => [  | 
                                                        |
| 611 | -                        'title'    => esc_html__('Message Filters', 'event_espresso'), | 
                                                        |
| 612 | - 'filename' => 'messages_overview_filters',  | 
                                                        |
| 613 | - ],  | 
                                                        |
| 614 | - 'messages_overview_messages_views_help_tab' => [  | 
                                                        |
| 615 | -                        'title'    => esc_html__('Message Views', 'event_espresso'), | 
                                                        |
| 616 | - 'filename' => 'messages_overview_views',  | 
                                                        |
| 617 | - ],  | 
                                                        |
| 618 | - 'message_overview_message_types_help_tab' => [  | 
                                                        |
| 619 | -                        'title'    => esc_html__('Message Types', 'event_espresso'), | 
                                                        |
| 620 | - 'filename' => 'messages_overview_types',  | 
                                                        |
| 621 | - ],  | 
                                                        |
| 622 | - 'messages_overview_messengers_help_tab' => [  | 
                                                        |
| 623 | -                        'title'    => esc_html__('Messengers', 'event_espresso'), | 
                                                        |
| 624 | - 'filename' => 'messages_overview_messengers',  | 
                                                        |
| 625 | - ],  | 
                                                        |
| 626 | - ],  | 
                                                        |
| 627 | - 'require_nonce' => false,  | 
                                                        |
| 628 | - ],  | 
                                                        |
| 629 | - 'custom_mtps' => [  | 
                                                        |
| 630 | - 'nav' => [  | 
                                                        |
| 631 | -                    'label' => esc_html__('Custom Message Templates', 'event_espresso'), | 
                                                        |
| 632 | - 'icon' => 'dashicons-admin-customizer',  | 
                                                        |
| 633 | - 'order' => 30,  | 
                                                        |
| 634 | - ],  | 
                                                        |
| 635 | - 'help_tabs' => [],  | 
                                                        |
| 636 | - 'require_nonce' => false,  | 
                                                        |
| 637 | - ],  | 
                                                        |
| 638 | - 'add_new_message_template' => [  | 
                                                        |
| 639 | - 'nav' => [  | 
                                                        |
| 640 | -                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'), | 
                                                        |
| 641 | - 'icon' => 'dashicons-plus-alt',  | 
                                                        |
| 642 | - 'order' => 5,  | 
                                                        |
| 643 | - 'persistent' => false,  | 
                                                        |
| 644 | - ],  | 
                                                        |
| 645 | - 'require_nonce' => false,  | 
                                                        |
| 646 | - ],  | 
                                                        |
| 647 | - 'edit_message_template' => [  | 
                                                        |
| 648 | - 'labels' => [  | 
                                                        |
| 649 | - 'buttons' => [  | 
                                                        |
| 650 | -                        'reset' => esc_html__('Reset Templates', 'event_espresso'), | 
                                                        |
| 651 | - ],  | 
                                                        |
| 652 | -                    'publishbox' => esc_html__('Update Actions', 'event_espresso'), | 
                                                        |
| 653 | - ],  | 
                                                        |
| 654 | - 'nav' => [  | 
                                                        |
| 655 | -                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'), | 
                                                        |
| 656 | - 'icon' => 'dashicons-edit-large',  | 
                                                        |
| 657 | - 'order' => 5,  | 
                                                        |
| 658 | - 'persistent' => false,  | 
                                                        |
| 659 | - 'url' => '',  | 
                                                        |
| 660 | - ],  | 
                                                        |
| 661 | - 'metaboxes' => ['_publish_post_box', '_register_edit_meta_boxes'],  | 
                                                        |
| 662 | - 'has_metaboxes' => true,  | 
                                                        |
| 663 | - 'help_tabs' => [  | 
                                                        |
| 664 | - 'edit_message_template' => [  | 
                                                        |
| 665 | -                        'title'    => esc_html__('Message Template Editor', 'event_espresso'), | 
                                                        |
| 666 | - 'callback' => 'edit_message_template_help_tab',  | 
                                                        |
| 667 | - ],  | 
                                                        |
| 668 | - 'message_templates_help_tab' => [  | 
                                                        |
| 669 | -                        'title'    => esc_html__('Message Templates', 'event_espresso'), | 
                                                        |
| 670 | - 'filename' => 'messages_templates',  | 
                                                        |
| 671 | - ],  | 
                                                        |
| 672 | - 'message_template_shortcodes' => [  | 
                                                        |
| 673 | -                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'), | 
                                                        |
| 674 | - 'callback' => 'message_template_shortcodes_help_tab',  | 
                                                        |
| 675 | - ],  | 
                                                        |
| 676 | - 'message_preview_help_tab' => [  | 
                                                        |
| 677 | -                        'title'    => esc_html__('Message Preview', 'event_espresso'), | 
                                                        |
| 678 | - 'filename' => 'messages_preview',  | 
                                                        |
| 679 | - ],  | 
                                                        |
| 680 | - 'messages_overview_other_help_tab' => [  | 
                                                        |
| 681 | -                        'title'    => esc_html__('Messages Other', 'event_espresso'), | 
                                                        |
| 682 | - 'filename' => 'messages_overview_other',  | 
                                                        |
| 683 | - ],  | 
                                                        |
| 684 | - ],  | 
                                                        |
| 685 | - 'require_nonce' => false,  | 
                                                        |
| 686 | - ],  | 
                                                        |
| 687 | - 'display_preview_message' => [  | 
                                                        |
| 688 | - 'nav' => [  | 
                                                        |
| 689 | -                    'label'      => esc_html__('Message Preview', 'event_espresso'), | 
                                                        |
| 690 | - 'icon' => 'dashicons-visibility-bar',  | 
                                                        |
| 691 | - 'order' => 5,  | 
                                                        |
| 692 | - 'url' => '',  | 
                                                        |
| 693 | - 'persistent' => false,  | 
                                                        |
| 694 | - ],  | 
                                                        |
| 695 | - 'help_tabs' => [  | 
                                                        |
| 696 | - 'preview_message' => [  | 
                                                        |
| 697 | -                        'title'    => esc_html__('About Previews', 'event_espresso'), | 
                                                        |
| 698 | - 'callback' => 'preview_message_help_tab',  | 
                                                        |
| 699 | - ],  | 
                                                        |
| 700 | - ],  | 
                                                        |
| 701 | - 'require_nonce' => false,  | 
                                                        |
| 702 | - ],  | 
                                                        |
| 703 | - 'settings' => [  | 
                                                        |
| 704 | - 'nav' => [  | 
                                                        |
| 705 | -                    'label' => esc_html__('Settings', 'event_espresso'), | 
                                                        |
| 706 | - 'icon' => 'dashicons-admin-generic',  | 
                                                        |
| 707 | - 'order' => 40,  | 
                                                        |
| 708 | - ],  | 
                                                        |
| 709 | - 'metaboxes' => ['_messages_settings_metaboxes'],  | 
                                                        |
| 710 | - 'help_tabs' => [  | 
                                                        |
| 711 | - 'messages_settings_help_tab' => [  | 
                                                        |
| 712 | -                        'title'    => esc_html__('Messages Settings', 'event_espresso'), | 
                                                        |
| 713 | - 'filename' => 'messages_settings',  | 
                                                        |
| 714 | - ],  | 
                                                        |
| 715 | - 'messages_settings_message_types_help_tab' => [  | 
                                                        |
| 716 | -                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), | 
                                                        |
| 717 | - 'filename' => 'messages_settings_message_types',  | 
                                                        |
| 718 | - ],  | 
                                                        |
| 719 | - 'messages_settings_messengers_help_tab' => [  | 
                                                        |
| 720 | -                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), | 
                                                        |
| 721 | - 'filename' => 'messages_settings_messengers',  | 
                                                        |
| 722 | - ],  | 
                                                        |
| 723 | - ],  | 
                                                        |
| 724 | - 'require_nonce' => false,  | 
                                                        |
| 725 | - ],  | 
                                                        |
| 726 | - ];  | 
                                                        |
| 727 | - }  | 
                                                        |
| 728 | -  | 
                                                        |
| 729 | -  | 
                                                        |
| 730 | - protected function _add_screen_options()  | 
                                                        |
| 731 | -    { | 
                                                        |
| 732 | - // todo  | 
                                                        |
| 733 | - }  | 
                                                        |
| 734 | -  | 
                                                        |
| 735 | -  | 
                                                        |
| 736 | - protected function _add_screen_options_global_mtps()  | 
                                                        |
| 737 | -    { | 
                                                        |
| 738 | - /**  | 
                                                        |
| 739 | - * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options  | 
                                                        |
| 740 | - * uses the $_admin_page_title property and we want different outputs in the different spots.  | 
                                                        |
| 741 | - */  | 
                                                        |
| 742 | - $page_title = $this->_admin_page_title;  | 
                                                        |
| 743 | -        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); | 
                                                        |
| 744 | - $this->_per_page_screen_option();  | 
                                                        |
| 745 | - $this->_admin_page_title = $page_title;  | 
                                                        |
| 746 | - }  | 
                                                        |
| 747 | -  | 
                                                        |
| 748 | -  | 
                                                        |
| 749 | - protected function _add_screen_options_default()  | 
                                                        |
| 750 | -    { | 
                                                        |
| 751 | -        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); | 
                                                        |
| 752 | - $this->_per_page_screen_option();  | 
                                                        |
| 753 | - }  | 
                                                        |
| 754 | -  | 
                                                        |
| 755 | -  | 
                                                        |
| 756 | - // none of the below group are currently used for Messages  | 
                                                        |
| 757 | - protected function _add_feature_pointers()  | 
                                                        |
| 758 | -    { | 
                                                        |
| 759 | - }  | 
                                                        |
| 760 | -  | 
                                                        |
| 761 | -  | 
                                                        |
| 762 | - public function admin_init()  | 
                                                        |
| 763 | -    { | 
                                                        |
| 764 | - }  | 
                                                        |
| 765 | -  | 
                                                        |
| 766 | -  | 
                                                        |
| 767 | - public function admin_notices()  | 
                                                        |
| 768 | -    { | 
                                                        |
| 769 | - }  | 
                                                        |
| 770 | -  | 
                                                        |
| 771 | -  | 
                                                        |
| 772 | - public function admin_footer_scripts()  | 
                                                        |
| 773 | -    { | 
                                                        |
| 774 | - }  | 
                                                        |
| 775 | -  | 
                                                        |
| 776 | -  | 
                                                        |
| 777 | - public function messages_help_tab()  | 
                                                        |
| 778 | -    { | 
                                                        |
| 779 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 780 | - }  | 
                                                        |
| 781 | -  | 
                                                        |
| 782 | -  | 
                                                        |
| 783 | - public function messengers_help_tab()  | 
                                                        |
| 784 | -    { | 
                                                        |
| 785 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 786 | - }  | 
                                                        |
| 787 | -  | 
                                                        |
| 788 | -  | 
                                                        |
| 789 | - public function message_types_help_tab()  | 
                                                        |
| 790 | -    { | 
                                                        |
| 791 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 792 | - }  | 
                                                        |
| 793 | -  | 
                                                        |
| 794 | -  | 
                                                        |
| 795 | - public function messages_overview_help_tab()  | 
                                                        |
| 796 | -    { | 
                                                        |
| 797 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 798 | - }  | 
                                                        |
| 799 | -  | 
                                                        |
| 800 | -  | 
                                                        |
| 801 | - public function message_templates_help_tab()  | 
                                                        |
| 802 | -    { | 
                                                        |
| 803 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 804 | - }  | 
                                                        |
| 805 | -  | 
                                                        |
| 806 | -  | 
                                                        |
| 807 | - public function edit_message_template_help_tab()  | 
                                                        |
| 808 | -    { | 
                                                        |
| 809 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'  | 
                                                        |
| 810 | -                        . esc_attr__('Editor Title', 'event_espresso') | 
                                                        |
| 811 | - . '" />';  | 
                                                        |
| 812 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'  | 
                                                        |
| 813 | -                        . esc_attr__('Context Switcher and Preview', 'event_espresso') | 
                                                        |
| 814 | - . '" />';  | 
                                                        |
| 815 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'  | 
                                                        |
| 816 | -                        . esc_attr__('Message Template Form Fields', 'event_espresso') | 
                                                        |
| 817 | - . '" />';  | 
                                                        |
| 818 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'  | 
                                                        |
| 819 | -                        . esc_attr__('Shortcodes Metabox', 'event_espresso') | 
                                                        |
| 820 | - . '" />';  | 
                                                        |
| 821 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'  | 
                                                        |
| 822 | -                        . esc_attr__('Publish Metabox', 'event_espresso') | 
                                                        |
| 823 | - . '" />';  | 
                                                        |
| 824 | - EEH_Template::display_template(  | 
                                                        |
| 825 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 826 | - $args  | 
                                                        |
| 827 | - );  | 
                                                        |
| 828 | - }  | 
                                                        |
| 829 | -  | 
                                                        |
| 830 | -  | 
                                                        |
| 831 | - /**  | 
                                                        |
| 832 | - * @throws ReflectionException  | 
                                                        |
| 833 | - * @throws EE_Error  | 
                                                        |
| 834 | - */  | 
                                                        |
| 835 | - public function message_template_shortcodes_help_tab()  | 
                                                        |
| 836 | -    { | 
                                                        |
| 837 | - $this->_set_shortcodes();  | 
                                                        |
| 838 | - $args['shortcodes'] = $this->_shortcodes;  | 
                                                        |
| 839 | - EEH_Template::display_template(  | 
                                                        |
| 840 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 841 | - $args  | 
                                                        |
| 842 | - );  | 
                                                        |
| 843 | - }  | 
                                                        |
| 844 | -  | 
                                                        |
| 845 | -  | 
                                                        |
| 846 | - public function preview_message_help_tab()  | 
                                                        |
| 847 | -    { | 
                                                        |
| 848 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 849 | - }  | 
                                                        |
| 850 | -  | 
                                                        |
| 851 | -  | 
                                                        |
| 852 | - public function settings_help_tab()  | 
                                                        |
| 853 | -    { | 
                                                        |
| 854 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'  | 
                                                        |
| 855 | -                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 856 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'  | 
                                                        |
| 857 | -                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 858 | - $args['img3'] = '<div class="ee-switch">'  | 
                                                        |
| 859 | - . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'  | 
                                                        |
| 860 | - . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'  | 
                                                        |
| 861 | - . '</div>';  | 
                                                        |
| 862 | - $args['img4'] = '<div class="switch">'  | 
                                                        |
| 863 | - . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'  | 
                                                        |
| 864 | - . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'  | 
                                                        |
| 865 | - . '</div>';  | 
                                                        |
| 866 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 867 | - }  | 
                                                        |
| 868 | -  | 
                                                        |
| 869 | -  | 
                                                        |
| 870 | - public function load_scripts_styles()  | 
                                                        |
| 871 | -    { | 
                                                        |
| 872 | -        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 873 | -        wp_enqueue_style('espresso_ee_msg'); | 
                                                        |
| 874 | -  | 
                                                        |
| 875 | - wp_register_script(  | 
                                                        |
| 876 | - 'ee-messages-settings',  | 
                                                        |
| 877 | - EE_MSG_ASSETS_URL . 'ee-messages-settings.js',  | 
                                                        |
| 878 | - ['jquery-ui-droppable', 'ee-serialize-full-array'],  | 
                                                        |
| 879 | - EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 880 | - true  | 
                                                        |
| 881 | - );  | 
                                                        |
| 882 | - wp_register_script(  | 
                                                        |
| 883 | - 'ee-msg-list-table-js',  | 
                                                        |
| 884 | - EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',  | 
                                                        |
| 885 | - ['ee-dialog'],  | 
                                                        |
| 886 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 887 | - );  | 
                                                        |
| 888 | - }  | 
                                                        |
| 889 | -  | 
                                                        |
| 890 | -  | 
                                                        |
| 891 | - public function load_scripts_styles_default()  | 
                                                        |
| 892 | -    { | 
                                                        |
| 893 | -        wp_enqueue_script('ee-msg-list-table-js'); | 
                                                        |
| 894 | - }  | 
                                                        |
| 895 | -  | 
                                                        |
| 896 | -  | 
                                                        |
| 897 | - public function wp_editor_css($mce_css)  | 
                                                        |
| 898 | -    { | 
                                                        |
| 899 | - // if we're on the edit_message_template route  | 
                                                        |
| 900 | -        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | 
                                                        |
| 901 | - $message_type_name = $this->_active_message_type_name;  | 
                                                        |
| 902 | -  | 
                                                        |
| 903 | - // we're going to REPLACE the existing mce css  | 
                                                        |
| 904 | - // we need to get the css file location from the active messenger  | 
                                                        |
| 905 | - $mce_css = $this->_active_messenger->get_variation(  | 
                                                        |
| 906 | - $this->_template_pack,  | 
                                                        |
| 907 | - $message_type_name,  | 
                                                        |
| 908 | - true,  | 
                                                        |
| 909 | - 'wpeditor',  | 
                                                        |
| 910 | - $this->_variation  | 
                                                        |
| 911 | - );  | 
                                                        |
| 912 | - }  | 
                                                        |
| 913 | -  | 
                                                        |
| 914 | - return $mce_css;  | 
                                                        |
| 915 | - }  | 
                                                        |
| 916 | -  | 
                                                        |
| 917 | -  | 
                                                        |
| 918 | - /**  | 
                                                        |
| 919 | - * @throws EE_Error  | 
                                                        |
| 920 | - * @throws ReflectionException  | 
                                                        |
| 921 | - */  | 
                                                        |
| 922 | - public function load_scripts_styles_edit_message_template()  | 
                                                        |
| 923 | -    { | 
                                                        |
| 924 | -  | 
                                                        |
| 925 | - $this->_set_shortcodes();  | 
                                                        |
| 926 | -  | 
                                                        |
| 927 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 928 | - esc_html__(  | 
                                                        |
| 929 | - 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.',  | 
                                                        |
| 930 | - 'event_espresso'  | 
                                                        |
| 931 | - ),  | 
                                                        |
| 932 | - $this->_message_template_group->messenger_obj()->label['singular'],  | 
                                                        |
| 933 | - $this->_message_template_group->message_type_obj()->label['singular']  | 
                                                        |
| 934 | - );  | 
                                                        |
| 935 | - EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(  | 
                                                        |
| 936 | - 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?',  | 
                                                        |
| 937 | - 'event_espresso'  | 
                                                        |
| 938 | - );  | 
                                                        |
| 939 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__(  | 
                                                        |
| 940 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',  | 
                                                        |
| 941 | - 'event_espresso'  | 
                                                        |
| 942 | - );  | 
                                                        |
| 943 | -  | 
                                                        |
| 944 | - wp_register_script(  | 
                                                        |
| 945 | - 'ee_msgs_edit_js',  | 
                                                        |
| 946 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js',  | 
                                                        |
| 947 | - ['jquery'],  | 
                                                        |
| 948 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 949 | - );  | 
                                                        |
| 950 | -  | 
                                                        |
| 951 | -        wp_enqueue_script('ee_admin_js'); | 
                                                        |
| 952 | -        wp_enqueue_script('ee_msgs_edit_js'); | 
                                                        |
| 953 | -  | 
                                                        |
| 954 | - // add in special css for tiny_mce  | 
                                                        |
| 955 | -        add_filter('mce_css', [$this, 'wp_editor_css']); | 
                                                        |
| 956 | - }  | 
                                                        |
| 957 | -  | 
                                                        |
| 958 | -  | 
                                                        |
| 959 | - /**  | 
                                                        |
| 960 | - * @throws EE_Error  | 
                                                        |
| 961 | - * @throws ReflectionException  | 
                                                        |
| 962 | - */  | 
                                                        |
| 963 | - public function load_scripts_styles_display_preview_message()  | 
                                                        |
| 964 | -    { | 
                                                        |
| 965 | - $this->_set_message_template_group();  | 
                                                        |
| 966 | -        if ($this->_active_messenger_name) { | 
                                                        |
| 967 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 968 | - $this->_active_messenger_name  | 
                                                        |
| 969 | - );  | 
                                                        |
| 970 | - }  | 
                                                        |
| 971 | -  | 
                                                        |
| 972 | - wp_enqueue_style(  | 
                                                        |
| 973 | - 'espresso_preview_css',  | 
                                                        |
| 974 | - $this->_active_messenger->get_variation(  | 
                                                        |
| 975 | - $this->_template_pack,  | 
                                                        |
| 976 | - $this->_active_message_type_name,  | 
                                                        |
| 977 | - true,  | 
                                                        |
| 978 | - 'preview',  | 
                                                        |
| 979 | - $this->_variation  | 
                                                        |
| 980 | - )  | 
                                                        |
| 981 | - );  | 
                                                        |
| 982 | - }  | 
                                                        |
| 983 | -  | 
                                                        |
| 984 | -  | 
                                                        |
| 985 | - public function load_scripts_styles_settings()  | 
                                                        |
| 986 | -    { | 
                                                        |
| 987 | - wp_register_style(  | 
                                                        |
| 988 | - 'ee-message-settings',  | 
                                                        |
| 989 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css',  | 
                                                        |
| 990 | - [],  | 
                                                        |
| 991 | - EVENT_ESPRESSO_VERSION  | 
                                                        |
| 992 | - );  | 
                                                        |
| 993 | -        wp_enqueue_style('ee-text-links'); | 
                                                        |
| 994 | -        wp_enqueue_style('ee-message-settings'); | 
                                                        |
| 995 | -        wp_enqueue_script('ee-messages-settings'); | 
                                                        |
| 996 | - }  | 
                                                        |
| 997 | -  | 
                                                        |
| 998 | -  | 
                                                        |
| 999 | - /**  | 
                                                        |
| 1000 | - * set views array for List Table  | 
                                                        |
| 1001 | - */  | 
                                                        |
| 1002 | - public function _set_list_table_views_global_mtps()  | 
                                                        |
| 1003 | -    { | 
                                                        |
| 1004 | - $this->_views = [  | 
                                                        |
| 1005 | - 'in_use' => [  | 
                                                        |
| 1006 | - 'slug' => 'in_use',  | 
                                                        |
| 1007 | -                'label' => esc_html__('In Use', 'event_espresso'), | 
                                                        |
| 1008 | - 'count' => 0,  | 
                                                        |
| 1009 | - ],  | 
                                                        |
| 1010 | - ];  | 
                                                        |
| 1011 | - }  | 
                                                        |
| 1012 | -  | 
                                                        |
| 1013 | -  | 
                                                        |
| 1014 | - /**  | 
                                                        |
| 1015 | - * Set views array for the Custom Template List Table  | 
                                                        |
| 1016 | - */  | 
                                                        |
| 1017 | - public function _set_list_table_views_custom_mtps()  | 
                                                        |
| 1018 | -    { | 
                                                        |
| 1019 | - $this->_set_list_table_views_global_mtps();  | 
                                                        |
| 1020 | - $this->_views['in_use']['bulk_action'] = [  | 
                                                        |
| 1021 | -            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 1022 | - ];  | 
                                                        |
| 1023 | - }  | 
                                                        |
| 1024 | -  | 
                                                        |
| 1025 | -  | 
                                                        |
| 1026 | - /**  | 
                                                        |
| 1027 | - * set views array for message queue list table  | 
                                                        |
| 1028 | - *  | 
                                                        |
| 1029 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1030 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1031 | - * @throws InvalidArgumentException  | 
                                                        |
| 1032 | - * @throws EE_Error  | 
                                                        |
| 1033 | - * @throws ReflectionException  | 
                                                        |
| 1034 | - */  | 
                                                        |
| 1035 | - public function _set_list_table_views_default()  | 
                                                        |
| 1036 | -    { | 
                                                        |
| 1037 | -        EE_Registry::instance()->load_helper('Template'); | 
                                                        |
| 1038 | -  | 
                                                        |
| 1039 | - $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 1040 | - 'ee_send_message',  | 
                                                        |
| 1041 | - 'message_list_table_bulk_actions'  | 
                                                        |
| 1042 | - )  | 
                                                        |
| 1043 | - ? [  | 
                                                        |
| 1044 | -                'generate_now'          => esc_html__('Generate Now', 'event_espresso'), | 
                                                        |
| 1045 | -                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), | 
                                                        |
| 1046 | -                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'), | 
                                                        |
| 1047 | -                'send_now'              => esc_html__('Send Now', 'event_espresso'), | 
                                                        |
| 1048 | - ]  | 
                                                        |
| 1049 | - : [];  | 
                                                        |
| 1050 | -  | 
                                                        |
| 1051 | - $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 1052 | - 'ee_delete_messages',  | 
                                                        |
| 1053 | - 'message_list_table_bulk_actions'  | 
                                                        |
| 1054 | - )  | 
                                                        |
| 1055 | -            ? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')] | 
                                                        |
| 1056 | - : [];  | 
                                                        |
| 1057 | -  | 
                                                        |
| 1058 | -  | 
                                                        |
| 1059 | - $this->_views = [  | 
                                                        |
| 1060 | - 'all' => [  | 
                                                        |
| 1061 | - 'slug' => 'all',  | 
                                                        |
| 1062 | -                'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 1063 | - 'count' => 0,  | 
                                                        |
| 1064 | - 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),  | 
                                                        |
| 1065 | - ],  | 
                                                        |
| 1066 | - ];  | 
                                                        |
| 1067 | -  | 
                                                        |
| 1068 | -  | 
                                                        |
| 1069 | -        foreach ($this->getMsgModel()->all_statuses() as $status) { | 
                                                        |
| 1070 | -            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | 
                                                        |
| 1071 | - continue;  | 
                                                        |
| 1072 | - }  | 
                                                        |
| 1073 | - $status_bulk_actions = $common_bulk_actions;  | 
                                                        |
| 1074 | - // unset bulk actions not applying to status  | 
                                                        |
| 1075 | -            if (! empty($status_bulk_actions)) { | 
                                                        |
| 1076 | -                switch ($status) { | 
                                                        |
| 1077 | - case EEM_Message::status_idle:  | 
                                                        |
| 1078 | - case EEM_Message::status_resend:  | 
                                                        |
| 1079 | - $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];  | 
                                                        |
| 1080 | - break;  | 
                                                        |
| 1081 | -  | 
                                                        |
| 1082 | - case EEM_Message::status_failed:  | 
                                                        |
| 1083 | - case EEM_Message::status_debug_only:  | 
                                                        |
| 1084 | - case EEM_Message::status_messenger_executing:  | 
                                                        |
| 1085 | - $status_bulk_actions = [];  | 
                                                        |
| 1086 | - break;  | 
                                                        |
| 1087 | -  | 
                                                        |
| 1088 | - case EEM_Message::status_incomplete:  | 
                                                        |
| 1089 | - unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);  | 
                                                        |
| 1090 | - break;  | 
                                                        |
| 1091 | -  | 
                                                        |
| 1092 | - case EEM_Message::status_retry:  | 
                                                        |
| 1093 | - case EEM_Message::status_sent:  | 
                                                        |
| 1094 | - unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);  | 
                                                        |
| 1095 | - break;  | 
                                                        |
| 1096 | - }  | 
                                                        |
| 1097 | - }  | 
                                                        |
| 1098 | -  | 
                                                        |
| 1099 | - // skip adding messenger executing status to views because it will be included with the Failed view.  | 
                                                        |
| 1100 | -            if ($status === EEM_Message::status_messenger_executing) { | 
                                                        |
| 1101 | - continue;  | 
                                                        |
| 1102 | - }  | 
                                                        |
| 1103 | -  | 
                                                        |
| 1104 | - $this->_views[ strtolower($status) ] = [  | 
                                                        |
| 1105 | - 'slug' => strtolower($status),  | 
                                                        |
| 1106 | - 'label' => EEH_Template::pretty_status($status, false, 'sentence'),  | 
                                                        |
| 1107 | - 'count' => 0,  | 
                                                        |
| 1108 | - 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),  | 
                                                        |
| 1109 | - ];  | 
                                                        |
| 1110 | - }  | 
                                                        |
| 1111 | - }  | 
                                                        |
| 1112 | -  | 
                                                        |
| 1113 | -  | 
                                                        |
| 1114 | - /**  | 
                                                        |
| 1115 | - * @throws EE_Error  | 
                                                        |
| 1116 | - */  | 
                                                        |
| 1117 | - protected function _ee_default_messages_overview_list_table()  | 
                                                        |
| 1118 | -    { | 
                                                        |
| 1119 | -        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); | 
                                                        |
| 1120 | - $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 1121 | - }  | 
                                                        |
| 1122 | -  | 
                                                        |
| 1123 | -  | 
                                                        |
| 1124 | - /**  | 
                                                        |
| 1125 | - * @throws EE_Error  | 
                                                        |
| 1126 | - * @throws ReflectionException  | 
                                                        |
| 1127 | - */  | 
                                                        |
| 1128 | - protected function _message_queue_list_table()  | 
                                                        |
| 1129 | -    { | 
                                                        |
| 1130 | -        $this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso'); | 
                                                        |
| 1131 | - $this->_template_args['per_column'] = 6;  | 
                                                        |
| 1132 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());  | 
                                                        |
| 1133 | - $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());  | 
                                                        |
| 1134 | -        $this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : ''; | 
                                                        |
| 1135 | - $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 1136 | - }  | 
                                                        |
| 1137 | -  | 
                                                        |
| 1138 | -  | 
                                                        |
| 1139 | - /**  | 
                                                        |
| 1140 | - * @throws EE_Error  | 
                                                        |
| 1141 | - */  | 
                                                        |
| 1142 | - protected function _message_legend_items()  | 
                                                        |
| 1143 | -    { | 
                                                        |
| 1144 | -  | 
                                                        |
| 1145 | - $action_css_classes = EEH_MSG_Template::get_message_action_icons();  | 
                                                        |
| 1146 | - $action_items = [];  | 
                                                        |
| 1147 | -  | 
                                                        |
| 1148 | -        foreach ($action_css_classes as $action_item => $action_details) { | 
                                                        |
| 1149 | -            if ($action_item === 'see_notifications_for') { | 
                                                        |
| 1150 | - continue;  | 
                                                        |
| 1151 | - }  | 
                                                        |
| 1152 | - $action_items[ $action_item ] = [  | 
                                                        |
| 1153 | - 'class' => $action_details['css_class'],  | 
                                                        |
| 1154 | - 'desc' => $action_details['label'],  | 
                                                        |
| 1155 | - ];  | 
                                                        |
| 1156 | - }  | 
                                                        |
| 1157 | -  | 
                                                        |
| 1158 | - /** @var array $status_items status legend setup */  | 
                                                        |
| 1159 | - $status_items = [  | 
                                                        |
| 1160 | - 'sent_status' => [  | 
                                                        |
| 1161 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,  | 
                                                        |
| 1162 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),  | 
                                                        |
| 1163 | - ],  | 
                                                        |
| 1164 | - 'idle_status' => [  | 
                                                        |
| 1165 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,  | 
                                                        |
| 1166 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),  | 
                                                        |
| 1167 | - ],  | 
                                                        |
| 1168 | - 'failed_status' => [  | 
                                                        |
| 1169 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,  | 
                                                        |
| 1170 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),  | 
                                                        |
| 1171 | - ],  | 
                                                        |
| 1172 | - 'messenger_executing_status' => [  | 
                                                        |
| 1173 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 1174 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),  | 
                                                        |
| 1175 | - ],  | 
                                                        |
| 1176 | - 'resend_status' => [  | 
                                                        |
| 1177 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,  | 
                                                        |
| 1178 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),  | 
                                                        |
| 1179 | - ],  | 
                                                        |
| 1180 | - 'incomplete_status' => [  | 
                                                        |
| 1181 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,  | 
                                                        |
| 1182 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),  | 
                                                        |
| 1183 | - ],  | 
                                                        |
| 1184 | - 'retry_status' => [  | 
                                                        |
| 1185 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,  | 
                                                        |
| 1186 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),  | 
                                                        |
| 1187 | - ],  | 
                                                        |
| 1188 | - ];  | 
                                                        |
| 1189 | -        if (EEM_Message::debug()) { | 
                                                        |
| 1190 | - $status_items['debug_only_status'] = [  | 
                                                        |
| 1191 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,  | 
                                                        |
| 1192 | - 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),  | 
                                                        |
| 1193 | - ];  | 
                                                        |
| 1194 | - }  | 
                                                        |
| 1195 | -  | 
                                                        |
| 1196 | - return array_merge($action_items, $status_items);  | 
                                                        |
| 1197 | - }  | 
                                                        |
| 1198 | -  | 
                                                        |
| 1199 | -  | 
                                                        |
| 1200 | - /**  | 
                                                        |
| 1201 | - * @throws EE_Error  | 
                                                        |
| 1202 | - */  | 
                                                        |
| 1203 | - protected function _custom_mtps_preview()  | 
                                                        |
| 1204 | -    { | 
                                                        |
| 1205 | -        $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        |
| 1206 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'  | 
                                                        |
| 1207 | - . ' alt="' . esc_attr__(  | 
                                                        |
| 1208 | - 'Preview Custom Message Templates screenshot',  | 
                                                        |
| 1209 | - 'event_espresso'  | 
                                                        |
| 1210 | - ) . '" />';  | 
                                                        |
| 1211 | - $this->_template_args['preview_text'] = '<strong>'  | 
                                                        |
| 1212 | - . esc_html__(  | 
                                                        |
| 1213 | - 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',  | 
                                                        |
| 1214 | - 'event_espresso'  | 
                                                        |
| 1215 | - )  | 
                                                        |
| 1216 | - . '</strong>';  | 
                                                        |
| 1217 | -  | 
                                                        |
| 1218 | -        $this->display_admin_caf_preview_page('custom_message_types', false); | 
                                                        |
| 1219 | - }  | 
                                                        |
| 1220 | -  | 
                                                        |
| 1221 | -  | 
                                                        |
| 1222 | - /**  | 
                                                        |
| 1223 | - * get_message_templates  | 
                                                        |
| 1224 | - * This gets all the message templates for listing on the overview list.  | 
                                                        |
| 1225 | - *  | 
                                                        |
| 1226 | - * @access public  | 
                                                        |
| 1227 | - * @param int $per_page the amount of templates groups to show per page  | 
                                                        |
| 1228 | - * @param string $type the current _view we're getting templates for  | 
                                                        |
| 1229 | - * @param bool $count return count?  | 
                                                        |
| 1230 | - * @param bool $all disregard any paging info (get all data);  | 
                                                        |
| 1231 | - * @param bool $global whether to return just global (true) or custom templates (false)  | 
                                                        |
| 1232 | - * @return array  | 
                                                        |
| 1233 | - * @throws EE_Error  | 
                                                        |
| 1234 | - * @throws InvalidArgumentException  | 
                                                        |
| 1235 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1236 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1237 | - */  | 
                                                        |
| 1238 | - public function get_message_templates(  | 
                                                        |
| 1239 | - $per_page = 10,  | 
                                                        |
| 1240 | - $type = 'in_use',  | 
                                                        |
| 1241 | - $count = false,  | 
                                                        |
| 1242 | - $all = false,  | 
                                                        |
| 1243 | - $global = true  | 
                                                        |
| 1244 | -    ) { | 
                                                        |
| 1245 | -        $orderby = $this->request->getRequestParam('orderby', 'GRP_ID'); | 
                                                        |
| 1246 | -        $this->request->setRequestParam('orderby', $orderby); | 
                                                        |
| 1247 | -  | 
                                                        |
| 1248 | -        $order        = $this->request->getRequestParam('order', 'ASC'); | 
                                                        |
| 1249 | -        $current_page = $this->request->getRequestParam('paged', 1, 'int'); | 
                                                        |
| 1250 | -        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int'); | 
                                                        |
| 1251 | -  | 
                                                        |
| 1252 | - $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1253 | - $limit = $all ? null : [$offset, $per_page];  | 
                                                        |
| 1254 | -  | 
                                                        |
| 1255 | - // options will match what is in the _views array property  | 
                                                        |
| 1256 | - return $type === 'in_use'  | 
                                                        |
| 1257 | - ? $this->getMtgModel()->get_all_active_message_templates(  | 
                                                        |
| 1258 | - $orderby,  | 
                                                        |
| 1259 | - $order,  | 
                                                        |
| 1260 | - $limit,  | 
                                                        |
| 1261 | - $count,  | 
                                                        |
| 1262 | - $global,  | 
                                                        |
| 1263 | - true  | 
                                                        |
| 1264 | - )  | 
                                                        |
| 1265 | - : $this->getMtgModel()->get_all_trashed_grouped_message_templates(  | 
                                                        |
| 1266 | - $orderby,  | 
                                                        |
| 1267 | - $order,  | 
                                                        |
| 1268 | - $limit,  | 
                                                        |
| 1269 | - $count,  | 
                                                        |
| 1270 | - $global  | 
                                                        |
| 1271 | - );  | 
                                                        |
| 1272 | - }  | 
                                                        |
| 1273 | -  | 
                                                        |
| 1274 | -  | 
                                                        |
| 1275 | - /**  | 
                                                        |
| 1276 | - * filters etc might need a list of installed message_types  | 
                                                        |
| 1277 | - *  | 
                                                        |
| 1278 | - * @return array an array of message type objects  | 
                                                        |
| 1279 | - */  | 
                                                        |
| 1280 | - public function get_installed_message_types()  | 
                                                        |
| 1281 | -    { | 
                                                        |
| 1282 | - $installed_message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 1283 | - $installed = [];  | 
                                                        |
| 1284 | -  | 
                                                        |
| 1285 | -        foreach ($installed_message_types as $message_type) { | 
                                                        |
| 1286 | - $installed[ $message_type->name ] = $message_type;  | 
                                                        |
| 1287 | - }  | 
                                                        |
| 1288 | -  | 
                                                        |
| 1289 | - return $installed;  | 
                                                        |
| 1290 | - }  | 
                                                        |
| 1291 | -  | 
                                                        |
| 1292 | -  | 
                                                        |
| 1293 | - /**  | 
                                                        |
| 1294 | - * This is used when creating a custom template. All Custom Templates start based off another template.  | 
                                                        |
| 1295 | - *  | 
                                                        |
| 1296 | - * @param string $message_type  | 
                                                        |
| 1297 | - * @param string $messenger  | 
                                                        |
| 1298 | - * @param string $GRP_ID  | 
                                                        |
| 1299 | - *  | 
                                                        |
| 1300 | - * @throws EE_error  | 
                                                        |
| 1301 | - * @throws ReflectionException  | 
                                                        |
| 1302 | - */  | 
                                                        |
| 1303 | - public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')  | 
                                                        |
| 1304 | -    { | 
                                                        |
| 1305 | - // set values override any request data  | 
                                                        |
| 1306 | - $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;  | 
                                                        |
| 1307 | - $messenger = ! empty($messenger) ? $messenger : $this->_active_messenger_name;  | 
                                                        |
| 1308 | -        $GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 1309 | -  | 
                                                        |
| 1310 | - // we need messenger and message type. They should be coming from the event editor. If not here then return error  | 
                                                        |
| 1311 | -        if (empty($message_type) || empty($messenger)) { | 
                                                        |
| 1312 | - throw new EE_Error(  | 
                                                        |
| 1313 | - esc_html__(  | 
                                                        |
| 1314 | - 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',  | 
                                                        |
| 1315 | - 'event_espresso'  | 
                                                        |
| 1316 | - )  | 
                                                        |
| 1317 | - );  | 
                                                        |
| 1318 | - }  | 
                                                        |
| 1319 | -  | 
                                                        |
| 1320 | - // we need the GRP_ID for the template being used as the base for the new template  | 
                                                        |
| 1321 | -        if (empty($GRP_ID)) { | 
                                                        |
| 1322 | - throw new EE_Error(  | 
                                                        |
| 1323 | - esc_html__(  | 
                                                        |
| 1324 | - 'In order to create a custom message template the GRP_ID of the template being used as a base is needed',  | 
                                                        |
| 1325 | - 'event_espresso'  | 
                                                        |
| 1326 | - )  | 
                                                        |
| 1327 | - );  | 
                                                        |
| 1328 | - }  | 
                                                        |
| 1329 | -  | 
                                                        |
| 1330 | - // let's just make sure the template gets generated!  | 
                                                        |
| 1331 | -  | 
                                                        |
| 1332 | - // we need to reassign some variables for what the insert is expecting  | 
                                                        |
| 1333 | -        $this->request->setRequestParam('MTP_messenger', $messenger); | 
                                                        |
| 1334 | -        $this->request->setRequestParam('MTP_message_type', $message_type); | 
                                                        |
| 1335 | -        $this->request->setRequestParam('GRP_ID', $GRP_ID); | 
                                                        |
| 1336 | -  | 
                                                        |
| 1337 | - $this->_insert_or_update_message_template(true);  | 
                                                        |
| 1338 | - }  | 
                                                        |
| 1339 | -  | 
                                                        |
| 1340 | -  | 
                                                        |
| 1341 | - /**  | 
                                                        |
| 1342 | - * @param string $message_type message type slug  | 
                                                        |
| 1343 | - * @param string $messenger messenger slug  | 
                                                        |
| 1344 | - * @param int $GRP_ID GRP_ID for the related message template group this new template will be based  | 
                                                        |
| 1345 | - * off of.  | 
                                                        |
| 1346 | - * @throws EE_error  | 
                                                        |
| 1347 | - * @throws ReflectionException  | 
                                                        |
| 1348 | - * @deprecated 4.10.29.p  | 
                                                        |
| 1349 | - */  | 
                                                        |
| 1350 | - protected function _add_message_template($message_type, $messenger, $GRP_ID)  | 
                                                        |
| 1351 | -    { | 
                                                        |
| 1352 | - $this->add_message_template($message_type, $messenger, $GRP_ID);  | 
                                                        |
| 1353 | - }  | 
                                                        |
| 1354 | -  | 
                                                        |
| 1355 | -  | 
                                                        |
| 1356 | - /**  | 
                                                        |
| 1357 | - * _edit_message_template  | 
                                                        |
| 1358 | - *  | 
                                                        |
| 1359 | - * @access protected  | 
                                                        |
| 1360 | - * @return void  | 
                                                        |
| 1361 | - * @throws InvalidIdentifierException  | 
                                                        |
| 1362 | - * @throws DomainException  | 
                                                        |
| 1363 | - * @throws EE_Error  | 
                                                        |
| 1364 | - * @throws InvalidArgumentException  | 
                                                        |
| 1365 | - * @throws ReflectionException  | 
                                                        |
| 1366 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1367 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1368 | - */  | 
                                                        |
| 1369 | - protected function _edit_message_template()  | 
                                                        |
| 1370 | -    { | 
                                                        |
| 1371 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1372 | - $template_fields = '';  | 
                                                        |
| 1373 | - $sidebar_fields = '';  | 
                                                        |
| 1374 | - // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have  | 
                                                        |
| 1375 | - // valid html in the templates.  | 
                                                        |
| 1376 | -        add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2); | 
                                                        |
| 1377 | -  | 
                                                        |
| 1378 | -        $GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 1379 | -        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int'); | 
                                                        |
| 1380 | -  | 
                                                        |
| 1381 | - $this->_set_shortcodes(); // this also sets the _message_template property.  | 
                                                        |
| 1382 | - $message_template_group = $this->_message_template_group;  | 
                                                        |
| 1383 | - $c_label = $message_template_group->context_label();  | 
                                                        |
| 1384 | - $c_config = $message_template_group->contexts_config();  | 
                                                        |
| 1385 | -  | 
                                                        |
| 1386 | - reset($c_config);  | 
                                                        |
| 1387 | -        $context = $this->request->getRequestParam('context', key($c_config)); | 
                                                        |
| 1388 | - $context = strtolower($context);  | 
                                                        |
| 1389 | -  | 
                                                        |
| 1390 | - $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';  | 
                                                        |
| 1391 | -  | 
                                                        |
| 1392 | - $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1393 | - ['action' => $action, 'noheader' => true],  | 
                                                        |
| 1394 | - EE_MSG_ADMIN_URL  | 
                                                        |
| 1395 | - );  | 
                                                        |
| 1396 | -  | 
                                                        |
| 1397 | - // set active messenger for this view  | 
                                                        |
| 1398 | - $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 1399 | - $message_template_group->messenger()  | 
                                                        |
| 1400 | - );  | 
                                                        |
| 1401 | - $this->_active_message_type_name = $message_template_group->message_type();  | 
                                                        |
| 1402 | -  | 
                                                        |
| 1403 | -  | 
                                                        |
| 1404 | - // Do we have any validation errors?  | 
                                                        |
| 1405 | - $validators = $this->_get_transient();  | 
                                                        |
| 1406 | - $v_fields = ! empty($validators) ? array_keys($validators) : [];  | 
                                                        |
| 1407 | -  | 
                                                        |
| 1408 | -  | 
                                                        |
| 1409 | - // we need to assemble the title from Various details  | 
                                                        |
| 1410 | - $context_label = sprintf(  | 
                                                        |
| 1411 | -            esc_html__('(%s %s)', 'event_espresso'), | 
                                                        |
| 1412 | - $c_config[ $context ]['label'],  | 
                                                        |
| 1413 | - ucwords($c_label['label'])  | 
                                                        |
| 1414 | - );  | 
                                                        |
| 1415 | -  | 
                                                        |
| 1416 | - $title = sprintf(  | 
                                                        |
| 1417 | -            esc_html__(' %s %s Template %s', 'event_espresso'), | 
                                                        |
| 1418 | - ucwords($message_template_group->messenger_obj()->label['singular']),  | 
                                                        |
| 1419 | - ucwords($message_template_group->message_type_obj()->label['singular']),  | 
                                                        |
| 1420 | - $context_label  | 
                                                        |
| 1421 | - );  | 
                                                        |
| 1422 | -  | 
                                                        |
| 1423 | - $this->_template_args['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1424 | - $this->_template_args['message_template'] = $message_template_group;  | 
                                                        |
| 1425 | - $this->_template_args['is_extra_fields'] = false;  | 
                                                        |
| 1426 | -  | 
                                                        |
| 1427 | -  | 
                                                        |
| 1428 | - // let's get EEH_MSG_Template so we can get template form fields  | 
                                                        |
| 1429 | - $template_field_structure = EEH_MSG_Template::get_fields(  | 
                                                        |
| 1430 | - $message_template_group->messenger(),  | 
                                                        |
| 1431 | - $message_template_group->message_type(),  | 
                                                        |
| 1432 | - $context  | 
                                                        |
| 1433 | - );  | 
                                                        |
| 1434 | -  | 
                                                        |
| 1435 | -        if (! $template_field_structure) { | 
                                                        |
| 1436 | - $template_field_structure = false;  | 
                                                        |
| 1437 | - $template_fields = esc_html__(  | 
                                                        |
| 1438 | - 'There was an error in assembling the fields for this display (you should see an error message)',  | 
                                                        |
| 1439 | - 'event_espresso'  | 
                                                        |
| 1440 | - );  | 
                                                        |
| 1441 | - }  | 
                                                        |
| 1442 | -  | 
                                                        |
| 1443 | -  | 
                                                        |
| 1444 | - $message_templates = $message_template_group->context_templates();  | 
                                                        |
| 1445 | -  | 
                                                        |
| 1446 | -  | 
                                                        |
| 1447 | - // if we have the extra key.. then we need to remove the content index from the template_field_structure as it  | 
                                                        |
| 1448 | - // will get handled in the "extra" array.  | 
                                                        |
| 1449 | -        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { | 
                                                        |
| 1450 | -            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1451 | - unset($template_field_structure[ $context ][ $reference_field ]);  | 
                                                        |
| 1452 | - }  | 
                                                        |
| 1453 | - }  | 
                                                        |
| 1454 | -  | 
                                                        |
| 1455 | - // let's loop through the template_field_structure and actually assemble the input fields!  | 
                                                        |
| 1456 | -        if (! empty($template_field_structure)) { | 
                                                        |
| 1457 | -            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { | 
                                                        |
| 1458 | - // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in  | 
                                                        |
| 1459 | - // the extra array and reset them.  | 
                                                        |
| 1460 | -                if ($template_field === 'extra') { | 
                                                        |
| 1461 | - $this->_template_args['is_extra_fields'] = true;  | 
                                                        |
| 1462 | -                    foreach ($field_setup_array as $reference_field => $new_fields_array) { | 
                                                        |
| 1463 | - $message_template = $message_templates[ $context ][ $reference_field ];  | 
                                                        |
| 1464 | - $content = $message_template instanceof EE_Message_Template  | 
                                                        |
| 1465 | -                            ? $message_template->get('MTP_content') | 
                                                        |
| 1466 | - : '';  | 
                                                        |
| 1467 | -                        foreach ($new_fields_array as $extra_field => $extra_array) { | 
                                                        |
| 1468 | - // let's verify if we need this extra field via the shortcodes parameter.  | 
                                                        |
| 1469 | - $continue = false;  | 
                                                        |
| 1470 | -                            if (isset($extra_array['shortcodes_required'])) { | 
                                                        |
| 1471 | -                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1472 | -                                    if (! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1473 | - $continue = true;  | 
                                                        |
| 1474 | - }  | 
                                                        |
| 1475 | - }  | 
                                                        |
| 1476 | -                                if ($continue) { | 
                                                        |
| 1477 | - continue;  | 
                                                        |
| 1478 | - }  | 
                                                        |
| 1479 | - }  | 
                                                        |
| 1480 | -  | 
                                                        |
| 1481 | - $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1482 | -  | 
                                                        |
| 1483 | - $template_form_fields[ $field_id ] = $extra_array;  | 
                                                        |
| 1484 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['  | 
                                                        |
| 1485 | - . $reference_field  | 
                                                        |
| 1486 | - . '][content]['  | 
                                                        |
| 1487 | - . $extra_field . ']';  | 
                                                        |
| 1488 | - $css_class = $extra_array['css_class'] ?? '';  | 
                                                        |
| 1489 | -  | 
                                                        |
| 1490 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1491 | - && in_array($extra_field, $v_fields, true)  | 
                                                        |
| 1492 | - && (  | 
                                                        |
| 1493 | - is_array($validators[ $extra_field ])  | 
                                                        |
| 1494 | - && isset($validators[ $extra_field ]['msg'])  | 
                                                        |
| 1495 | - )  | 
                                                        |
| 1496 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1497 | - : $css_class;  | 
                                                        |
| 1498 | -  | 
                                                        |
| 1499 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1500 | - && isset($content[ $extra_field ])  | 
                                                        |
| 1501 | - ? $content[ $extra_field ]  | 
                                                        |
| 1502 | - : '';  | 
                                                        |
| 1503 | -  | 
                                                        |
| 1504 | - // do we have a validation error? if we do then let's use that value instead  | 
                                                        |
| 1505 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])  | 
                                                        |
| 1506 | - ? $validators[ $extra_field ]['value']  | 
                                                        |
| 1507 | - : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1508 | -  | 
                                                        |
| 1509 | -  | 
                                                        |
| 1510 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1511 | -  | 
                                                        |
| 1512 | - // shortcode selector  | 
                                                        |
| 1513 | - $field_name_to_use = $extra_field === 'main'  | 
                                                        |
| 1514 | - ? 'content'  | 
                                                        |
| 1515 | - : $extra_field;  | 
                                                        |
| 1516 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1517 | - $field_name_to_use,  | 
                                                        |
| 1518 | - $field_id  | 
                                                        |
| 1519 | - );  | 
                                                        |
| 1520 | - }  | 
                                                        |
| 1521 | - $template_field_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1522 | - $template_field_template_name_id = $reference_field . '-name';  | 
                                                        |
| 1523 | -  | 
                                                        |
| 1524 | - $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1525 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1526 | - 'label' => null,  | 
                                                        |
| 1527 | - 'input' => 'hidden',  | 
                                                        |
| 1528 | - 'type' => 'int',  | 
                                                        |
| 1529 | - 'required' => false,  | 
                                                        |
| 1530 | - 'validation' => false,  | 
                                                        |
| 1531 | - 'value' => ! empty($message_templates) ? $message_template->ID() : '',  | 
                                                        |
| 1532 | - 'css_class' => '',  | 
                                                        |
| 1533 | - 'format' => '%d',  | 
                                                        |
| 1534 | - 'db-col' => 'MTP_ID',  | 
                                                        |
| 1535 | - ];  | 
                                                        |
| 1536 | -  | 
                                                        |
| 1537 | - $template_form_fields[ $template_field_template_name_id ] = [  | 
                                                        |
| 1538 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1539 | - 'label' => null,  | 
                                                        |
| 1540 | - 'input' => 'hidden',  | 
                                                        |
| 1541 | - 'type' => 'string',  | 
                                                        |
| 1542 | - 'required' => false,  | 
                                                        |
| 1543 | - 'validation' => true,  | 
                                                        |
| 1544 | - 'value' => $reference_field,  | 
                                                        |
| 1545 | - 'css_class' => '',  | 
                                                        |
| 1546 | - 'format' => '%s',  | 
                                                        |
| 1547 | - 'db-col' => 'MTP_template_field',  | 
                                                        |
| 1548 | - ];  | 
                                                        |
| 1549 | - }  | 
                                                        |
| 1550 | - continue; // skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        |
| 1551 | -                } else { | 
                                                        |
| 1552 | - $field_id = $template_field . '-content';  | 
                                                        |
| 1553 | - $template_form_fields[ $field_id ] = $field_setup_array;  | 
                                                        |
| 1554 | - $template_form_fields[ $field_id ]['name'] =  | 
                                                        |
| 1555 | - 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1556 | - $message_template = $message_templates[ $context ][ $template_field ]  | 
                                                        |
| 1557 | - ?? null;  | 
                                                        |
| 1558 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1559 | - && is_array($message_templates[ $context ])  | 
                                                        |
| 1560 | - && $message_template instanceof EE_Message_Template  | 
                                                        |
| 1561 | -                        ? $message_template->get('MTP_content') | 
                                                        |
| 1562 | - : '';  | 
                                                        |
| 1563 | -  | 
                                                        |
| 1564 | - // do we have a validator error for this field? if we do then we'll use that value instead  | 
                                                        |
| 1565 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])  | 
                                                        |
| 1566 | - ? $validators[ $template_field ]['value']  | 
                                                        |
| 1567 | - : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1568 | -  | 
                                                        |
| 1569 | -  | 
                                                        |
| 1570 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1571 | - $css_class = $field_setup_array['css_class'] ?? '';  | 
                                                        |
| 1572 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1573 | - && in_array($template_field, $v_fields, true)  | 
                                                        |
| 1574 | - && isset($validators[ $template_field ]['msg'])  | 
                                                        |
| 1575 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1576 | - : $css_class;  | 
                                                        |
| 1577 | -  | 
                                                        |
| 1578 | - // shortcode selector  | 
                                                        |
| 1579 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1580 | - $template_field,  | 
                                                        |
| 1581 | - $field_id  | 
                                                        |
| 1582 | - );  | 
                                                        |
| 1583 | - }  | 
                                                        |
| 1584 | -  | 
                                                        |
| 1585 | - // k took care of content field(s) now let's take care of others.  | 
                                                        |
| 1586 | -  | 
                                                        |
| 1587 | - $template_field_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1588 | - $template_field_field_template_name_id = $template_field . '-name';  | 
                                                        |
| 1589 | -  | 
                                                        |
| 1590 | - // foreach template field there are actually two form fields created  | 
                                                        |
| 1591 | - $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1592 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1593 | - 'label' => null,  | 
                                                        |
| 1594 | - 'input' => 'hidden',  | 
                                                        |
| 1595 | - 'type' => 'int',  | 
                                                        |
| 1596 | - 'required' => false,  | 
                                                        |
| 1597 | - 'validation' => true,  | 
                                                        |
| 1598 | - 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',  | 
                                                        |
| 1599 | - 'css_class' => '',  | 
                                                        |
| 1600 | - 'format' => '%d',  | 
                                                        |
| 1601 | - 'db-col' => 'MTP_ID',  | 
                                                        |
| 1602 | - ];  | 
                                                        |
| 1603 | -  | 
                                                        |
| 1604 | - $template_form_fields[ $template_field_field_template_name_id ] = [  | 
                                                        |
| 1605 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1606 | - 'label' => null,  | 
                                                        |
| 1607 | - 'input' => 'hidden',  | 
                                                        |
| 1608 | - 'type' => 'string',  | 
                                                        |
| 1609 | - 'required' => false,  | 
                                                        |
| 1610 | - 'validation' => true,  | 
                                                        |
| 1611 | - 'value' => $template_field,  | 
                                                        |
| 1612 | - 'css_class' => '',  | 
                                                        |
| 1613 | - 'format' => '%s',  | 
                                                        |
| 1614 | - 'db-col' => 'MTP_template_field',  | 
                                                        |
| 1615 | - ];  | 
                                                        |
| 1616 | - }  | 
                                                        |
| 1617 | -  | 
                                                        |
| 1618 | - // add other fields  | 
                                                        |
| 1619 | - $template_form_fields['ee-msg-current-context'] = [  | 
                                                        |
| 1620 | - 'name' => 'MTP_context',  | 
                                                        |
| 1621 | - 'label' => null,  | 
                                                        |
| 1622 | - 'input' => 'hidden',  | 
                                                        |
| 1623 | - 'type' => 'string',  | 
                                                        |
| 1624 | - 'required' => false,  | 
                                                        |
| 1625 | - 'validation' => true,  | 
                                                        |
| 1626 | - 'value' => $context,  | 
                                                        |
| 1627 | - 'css_class' => '',  | 
                                                        |
| 1628 | - 'format' => '%s',  | 
                                                        |
| 1629 | - 'db-col' => 'MTP_context',  | 
                                                        |
| 1630 | - ];  | 
                                                        |
| 1631 | -  | 
                                                        |
| 1632 | - $template_form_fields['ee-msg-grp-id'] = [  | 
                                                        |
| 1633 | - 'name' => 'GRP_ID',  | 
                                                        |
| 1634 | - 'label' => null,  | 
                                                        |
| 1635 | - 'input' => 'hidden',  | 
                                                        |
| 1636 | - 'type' => 'int',  | 
                                                        |
| 1637 | - 'required' => false,  | 
                                                        |
| 1638 | - 'validation' => true,  | 
                                                        |
| 1639 | - 'value' => $GRP_ID,  | 
                                                        |
| 1640 | - 'css_class' => '',  | 
                                                        |
| 1641 | - 'format' => '%d',  | 
                                                        |
| 1642 | - 'db-col' => 'GRP_ID',  | 
                                                        |
| 1643 | - ];  | 
                                                        |
| 1644 | -  | 
                                                        |
| 1645 | - $template_form_fields['ee-msg-messenger'] = [  | 
                                                        |
| 1646 | - 'name' => 'MTP_messenger',  | 
                                                        |
| 1647 | - 'label' => null,  | 
                                                        |
| 1648 | - 'input' => 'hidden',  | 
                                                        |
| 1649 | - 'type' => 'string',  | 
                                                        |
| 1650 | - 'required' => false,  | 
                                                        |
| 1651 | - 'validation' => true,  | 
                                                        |
| 1652 | - 'value' => $message_template_group->messenger(),  | 
                                                        |
| 1653 | - 'css_class' => '',  | 
                                                        |
| 1654 | - 'format' => '%s',  | 
                                                        |
| 1655 | - 'db-col' => 'MTP_messenger',  | 
                                                        |
| 1656 | - ];  | 
                                                        |
| 1657 | -  | 
                                                        |
| 1658 | - $template_form_fields['ee-msg-message-type'] = [  | 
                                                        |
| 1659 | - 'name' => 'MTP_message_type',  | 
                                                        |
| 1660 | - 'label' => null,  | 
                                                        |
| 1661 | - 'input' => 'hidden',  | 
                                                        |
| 1662 | - 'type' => 'string',  | 
                                                        |
| 1663 | - 'required' => false,  | 
                                                        |
| 1664 | - 'validation' => true,  | 
                                                        |
| 1665 | - 'value' => $message_template_group->message_type(),  | 
                                                        |
| 1666 | - 'css_class' => '',  | 
                                                        |
| 1667 | - 'format' => '%s',  | 
                                                        |
| 1668 | - 'db-col' => 'MTP_message_type',  | 
                                                        |
| 1669 | - ];  | 
                                                        |
| 1670 | -  | 
                                                        |
| 1671 | - $sidebar_form_fields['ee-msg-is-global'] = [  | 
                                                        |
| 1672 | - 'name' => 'MTP_is_global',  | 
                                                        |
| 1673 | -                'label'      => esc_html__('Global Template', 'event_espresso'), | 
                                                        |
| 1674 | - 'input' => 'hidden',  | 
                                                        |
| 1675 | - 'type' => 'int',  | 
                                                        |
| 1676 | - 'required' => false,  | 
                                                        |
| 1677 | - 'validation' => true,  | 
                                                        |
| 1678 | -                'value'      => $message_template_group->get('MTP_is_global'), | 
                                                        |
| 1679 | - 'css_class' => '',  | 
                                                        |
| 1680 | - 'format' => '%d',  | 
                                                        |
| 1681 | - 'db-col' => 'MTP_is_global',  | 
                                                        |
| 1682 | - ];  | 
                                                        |
| 1683 | -  | 
                                                        |
| 1684 | - $sidebar_form_fields['ee-msg-is-override'] = [  | 
                                                        |
| 1685 | - 'name' => 'MTP_is_override',  | 
                                                        |
| 1686 | -                'label'      => esc_html__('Override all custom', 'event_espresso'), | 
                                                        |
| 1687 | - 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden',  | 
                                                        |
| 1688 | - 'type' => 'int',  | 
                                                        |
| 1689 | - 'required' => false,  | 
                                                        |
| 1690 | - 'validation' => true,  | 
                                                        |
| 1691 | -                'value'      => $message_template_group->get('MTP_is_override'), | 
                                                        |
| 1692 | - 'css_class' => '',  | 
                                                        |
| 1693 | - 'format' => '%d',  | 
                                                        |
| 1694 | - 'db-col' => 'MTP_is_override',  | 
                                                        |
| 1695 | - ];  | 
                                                        |
| 1696 | -  | 
                                                        |
| 1697 | - $sidebar_form_fields['ee-msg-is-active'] = [  | 
                                                        |
| 1698 | - 'name' => 'MTP_is_active',  | 
                                                        |
| 1699 | -                'label'      => esc_html__('Active Template', 'event_espresso'), | 
                                                        |
| 1700 | - 'input' => 'hidden',  | 
                                                        |
| 1701 | - 'type' => 'int',  | 
                                                        |
| 1702 | - 'required' => false,  | 
                                                        |
| 1703 | - 'validation' => true,  | 
                                                        |
| 1704 | - 'value' => $message_template_group->is_active(),  | 
                                                        |
| 1705 | - 'css_class' => '',  | 
                                                        |
| 1706 | - 'format' => '%d',  | 
                                                        |
| 1707 | - 'db-col' => 'MTP_is_active',  | 
                                                        |
| 1708 | - ];  | 
                                                        |
| 1709 | -  | 
                                                        |
| 1710 | - $sidebar_form_fields['ee-msg-deleted'] = [  | 
                                                        |
| 1711 | - 'name' => 'MTP_deleted',  | 
                                                        |
| 1712 | - 'label' => null,  | 
                                                        |
| 1713 | - 'input' => 'hidden',  | 
                                                        |
| 1714 | - 'type' => 'int',  | 
                                                        |
| 1715 | - 'required' => false,  | 
                                                        |
| 1716 | - 'validation' => true,  | 
                                                        |
| 1717 | -                'value'      => $message_template_group->get('MTP_deleted'), | 
                                                        |
| 1718 | - 'css_class' => '',  | 
                                                        |
| 1719 | - 'format' => '%d',  | 
                                                        |
| 1720 | - 'db-col' => 'MTP_deleted',  | 
                                                        |
| 1721 | - ];  | 
                                                        |
| 1722 | - $sidebar_form_fields['ee-msg-author'] = [  | 
                                                        |
| 1723 | - 'name' => 'MTP_user_id',  | 
                                                        |
| 1724 | -                'label'      => esc_html__('Author', 'event_espresso'), | 
                                                        |
| 1725 | - 'input' => 'hidden',  | 
                                                        |
| 1726 | - 'type' => 'int',  | 
                                                        |
| 1727 | - 'required' => false,  | 
                                                        |
| 1728 | - 'validation' => false,  | 
                                                        |
| 1729 | - 'value' => $message_template_group->user(),  | 
                                                        |
| 1730 | - 'format' => '%d',  | 
                                                        |
| 1731 | - 'db-col' => 'MTP_user_id',  | 
                                                        |
| 1732 | - ];  | 
                                                        |
| 1733 | -  | 
                                                        |
| 1734 | - $sidebar_form_fields['ee-msg-route'] = [  | 
                                                        |
| 1735 | - 'name' => 'action',  | 
                                                        |
| 1736 | - 'input' => 'hidden',  | 
                                                        |
| 1737 | - 'type' => 'string',  | 
                                                        |
| 1738 | - 'value' => $action,  | 
                                                        |
| 1739 | - ];  | 
                                                        |
| 1740 | -  | 
                                                        |
| 1741 | - $sidebar_form_fields['ee-msg-id'] = [  | 
                                                        |
| 1742 | - 'name' => 'id',  | 
                                                        |
| 1743 | - 'input' => 'hidden',  | 
                                                        |
| 1744 | - 'type' => 'int',  | 
                                                        |
| 1745 | - 'value' => $GRP_ID,  | 
                                                        |
| 1746 | - ];  | 
                                                        |
| 1747 | - $sidebar_form_fields['ee-msg-evt-nonce'] = [  | 
                                                        |
| 1748 | - 'name' => $action . '_nonce',  | 
                                                        |
| 1749 | - 'input' => 'hidden',  | 
                                                        |
| 1750 | - 'type' => 'string',  | 
                                                        |
| 1751 | - 'value' => wp_create_nonce($action . '_nonce'),  | 
                                                        |
| 1752 | - ];  | 
                                                        |
| 1753 | -  | 
                                                        |
| 1754 | -            $template_switch = $this->request->getRequestParam('template_switch'); | 
                                                        |
| 1755 | -            if ($template_switch) { | 
                                                        |
| 1756 | - $sidebar_form_fields['ee-msg-template-switch'] = [  | 
                                                        |
| 1757 | - 'name' => 'template_switch',  | 
                                                        |
| 1758 | - 'input' => 'hidden',  | 
                                                        |
| 1759 | - 'type' => 'int',  | 
                                                        |
| 1760 | - 'value' => 1,  | 
                                                        |
| 1761 | - ];  | 
                                                        |
| 1762 | - }  | 
                                                        |
| 1763 | -  | 
                                                        |
| 1764 | -  | 
                                                        |
| 1765 | - $template_fields = $this->_generate_admin_form_fields($template_form_fields);  | 
                                                        |
| 1766 | - $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);  | 
                                                        |
| 1767 | - } //end if ( !empty($template_field_structure) )  | 
                                                        |
| 1768 | -  | 
                                                        |
| 1769 | - // set extra content for publish box  | 
                                                        |
| 1770 | - $this->_template_args['publish_box_extra_content'] = $sidebar_fields;  | 
                                                        |
| 1771 | - $this->_set_publish_post_box_vars(  | 
                                                        |
| 1772 | - 'id',  | 
                                                        |
| 1773 | - $GRP_ID,  | 
                                                        |
| 1774 | - false,  | 
                                                        |
| 1775 | - add_query_arg(  | 
                                                        |
| 1776 | - ['action' => 'global_mtps'],  | 
                                                        |
| 1777 | - $this->_admin_base_url  | 
                                                        |
| 1778 | - )  | 
                                                        |
| 1779 | - );  | 
                                                        |
| 1780 | -  | 
                                                        |
| 1781 | - // add preview button  | 
                                                        |
| 1782 | - $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1783 | - [  | 
                                                        |
| 1784 | - 'message_type' => $message_template_group->message_type(),  | 
                                                        |
| 1785 | - 'messenger' => $message_template_group->messenger(),  | 
                                                        |
| 1786 | - 'context' => $context,  | 
                                                        |
| 1787 | - 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 1788 | - 'evt_id' => $EVT_ID ?: false,  | 
                                                        |
| 1789 | - 'action' => 'preview_message',  | 
                                                        |
| 1790 | - ],  | 
                                                        |
| 1791 | - $this->_admin_base_url  | 
                                                        |
| 1792 | - );  | 
                                                        |
| 1793 | - $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'  | 
                                                        |
| 1794 | -                          . esc_html__('Preview', 'event_espresso') | 
                                                        |
| 1795 | - . '</a>';  | 
                                                        |
| 1796 | -  | 
                                                        |
| 1797 | -  | 
                                                        |
| 1798 | - // setup context switcher  | 
                                                        |
| 1799 | - $this->_set_context_switcher(  | 
                                                        |
| 1800 | - $message_template_group,  | 
                                                        |
| 1801 | - [  | 
                                                        |
| 1802 | - 'page' => 'espresso_messages',  | 
                                                        |
| 1803 | - 'action' => 'edit_message_template',  | 
                                                        |
| 1804 | - 'id' => $GRP_ID,  | 
                                                        |
| 1805 | - 'evt_id' => $EVT_ID,  | 
                                                        |
| 1806 | - 'context' => $context,  | 
                                                        |
| 1807 | - 'extra' => $preview_button,  | 
                                                        |
| 1808 | - ]  | 
                                                        |
| 1809 | - );  | 
                                                        |
| 1810 | -  | 
                                                        |
| 1811 | -  | 
                                                        |
| 1812 | - // main box  | 
                                                        |
| 1813 | - $this->_template_args['template_fields'] = $template_fields;  | 
                                                        |
| 1814 | - $this->_template_args['sidebar_box_id'] = 'details';  | 
                                                        |
| 1815 | - $this->_template_args['action'] = $action;  | 
                                                        |
| 1816 | - $this->_template_args['context'] = $context;  | 
                                                        |
| 1817 | - $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;  | 
                                                        |
| 1818 | - $this->_template_args['learn_more_about_message_templates_link'] =  | 
                                                        |
| 1819 | - $this->_learn_more_about_message_templates_link();  | 
                                                        |
| 1820 | -  | 
                                                        |
| 1821 | -  | 
                                                        |
| 1822 | - $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';  | 
                                                        |
| 1823 | - $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(  | 
                                                        |
| 1824 | - $message_template_group,  | 
                                                        |
| 1825 | - $context,  | 
                                                        |
| 1826 | - $context_label  | 
                                                        |
| 1827 | - );  | 
                                                        |
| 1828 | - $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();  | 
                                                        |
| 1829 | - $this->_template_args['before_admin_page_content'] .= '</div>';  | 
                                                        |
| 1830 | - $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();  | 
                                                        |
| 1831 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1832 | -  | 
                                                        |
| 1833 | - $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        |
| 1834 | - ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        |
| 1835 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1836 | -  | 
                                                        |
| 1837 | - // send along EE_Message_Template_Group object for further template use.  | 
                                                        |
| 1838 | - $this->_template_args['MTP'] = $message_template_group;  | 
                                                        |
| 1839 | -  | 
                                                        |
| 1840 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 1841 | - $this->_template_path,  | 
                                                        |
| 1842 | - $this->_template_args,  | 
                                                        |
| 1843 | - true  | 
                                                        |
| 1844 | - );  | 
                                                        |
| 1845 | -  | 
                                                        |
| 1846 | -  | 
                                                        |
| 1847 | - // finally, let's set the admin_page title  | 
                                                        |
| 1848 | -        $this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title); | 
                                                        |
| 1849 | -  | 
                                                        |
| 1850 | -  | 
                                                        |
| 1851 | - // we need to take care of setting the shortcodes property for use elsewhere.  | 
                                                        |
| 1852 | - $this->_set_shortcodes();  | 
                                                        |
| 1853 | -  | 
                                                        |
| 1854 | -  | 
                                                        |
| 1855 | - // final template wrapper  | 
                                                        |
| 1856 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1857 | - }  | 
                                                        |
| 1858 | -  | 
                                                        |
| 1859 | -  | 
                                                        |
| 1860 | - public function filter_tinymce_init($mceInit, $editor_id)  | 
                                                        |
| 1861 | -    { | 
                                                        |
| 1862 | - return $mceInit;  | 
                                                        |
| 1863 | - }  | 
                                                        |
| 1864 | -  | 
                                                        |
| 1865 | -  | 
                                                        |
| 1866 | - public function add_context_switcher()  | 
                                                        |
| 1867 | -    { | 
                                                        |
| 1868 | - return $this->_context_switcher;  | 
                                                        |
| 1869 | - }  | 
                                                        |
| 1870 | -  | 
                                                        |
| 1871 | -  | 
                                                        |
| 1872 | - /**  | 
                                                        |
| 1873 | - * Adds the activation/deactivation toggle for the message template context.  | 
                                                        |
| 1874 | - *  | 
                                                        |
| 1875 | - * @param EE_Message_Template_Group $message_template_group  | 
                                                        |
| 1876 | - * @param string $context  | 
                                                        |
| 1877 | - * @param string $context_label  | 
                                                        |
| 1878 | - * @return string  | 
                                                        |
| 1879 | - * @throws DomainException  | 
                                                        |
| 1880 | - * @throws EE_Error  | 
                                                        |
| 1881 | - * @throws InvalidIdentifierException  | 
                                                        |
| 1882 | - * @throws ReflectionException  | 
                                                        |
| 1883 | - */  | 
                                                        |
| 1884 | - protected function add_active_context_element(  | 
                                                        |
| 1885 | - EE_Message_Template_Group $message_template_group,  | 
                                                        |
| 1886 | - $context,  | 
                                                        |
| 1887 | - $context_label  | 
                                                        |
| 1888 | -    ) { | 
                                                        |
| 1889 | - $template_args = [  | 
                                                        |
| 1890 | - 'context' => $context,  | 
                                                        |
| 1891 | -            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'), | 
                                                        |
| 1892 | - 'is_active' => $message_template_group->is_context_active($context),  | 
                                                        |
| 1893 | - 'on_off_action' => $message_template_group->is_context_active($context)  | 
                                                        |
| 1894 | - ? 'context-off'  | 
                                                        |
| 1895 | - : 'context-on',  | 
                                                        |
| 1896 | -            'context_label'             => str_replace(['(', ')'], '', $context_label), | 
                                                        |
| 1897 | - 'message_template_group_id' => $message_template_group->ID(),  | 
                                                        |
| 1898 | - ];  | 
                                                        |
| 1899 | - return EEH_Template::display_template(  | 
                                                        |
| 1900 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',  | 
                                                        |
| 1901 | - $template_args,  | 
                                                        |
| 1902 | - true  | 
                                                        |
| 1903 | - );  | 
                                                        |
| 1904 | - }  | 
                                                        |
| 1905 | -  | 
                                                        |
| 1906 | -  | 
                                                        |
| 1907 | - /**  | 
                                                        |
| 1908 | - * Ajax callback for `toggle_context_template` ajax action.  | 
                                                        |
| 1909 | - * Handles toggling the message context on or off.  | 
                                                        |
| 1910 | - *  | 
                                                        |
| 1911 | - * @throws EE_Error  | 
                                                        |
| 1912 | - * @throws InvalidArgumentException  | 
                                                        |
| 1913 | - * @throws InvalidDataTypeException  | 
                                                        |
| 1914 | - * @throws InvalidIdentifierException  | 
                                                        |
| 1915 | - * @throws InvalidInterfaceException  | 
                                                        |
| 1916 | - */  | 
                                                        |
| 1917 | - public function toggle_context_template()  | 
                                                        |
| 1918 | -    { | 
                                                        |
| 1919 | - $success = true;  | 
                                                        |
| 1920 | - // check for required data  | 
                                                        |
| 1921 | - if (  | 
                                                        |
| 1922 | - ! (  | 
                                                        |
| 1923 | -                $this->request->requestParamIsSet('message_template_group_id') | 
                                                        |
| 1924 | -                && $this->request->requestParamIsSet('context') | 
                                                        |
| 1925 | -                && $this->request->requestParamIsSet('status') | 
                                                        |
| 1926 | - )  | 
                                                        |
| 1927 | -        ) { | 
                                                        |
| 1928 | - EE_Error::add_error(  | 
                                                        |
| 1929 | -                esc_html__('Required data for doing this action is not available.', 'event_espresso'), | 
                                                        |
| 1930 | - __FILE__,  | 
                                                        |
| 1931 | - __FUNCTION__,  | 
                                                        |
| 1932 | - __LINE__  | 
                                                        |
| 1933 | - );  | 
                                                        |
| 1934 | - $success = false;  | 
                                                        |
| 1935 | - }  | 
                                                        |
| 1936 | -  | 
                                                        |
| 1937 | -        $nonce   = $this->request->getRequestParam('toggle_context_nonce', ''); | 
                                                        |
| 1938 | -        $context = $this->request->getRequestParam('context', ''); | 
                                                        |
| 1939 | -        $status  = $this->request->getRequestParam('status', ''); | 
                                                        |
| 1940 | -  | 
                                                        |
| 1941 | -        $this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce"); | 
                                                        |
| 1942 | -  | 
                                                        |
| 1943 | -        if ($status !== 'off' && $status !== 'on') { | 
                                                        |
| 1944 | - EE_Error::add_error(  | 
                                                        |
| 1945 | - sprintf(  | 
                                                        |
| 1946 | -                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 1947 | - $status  | 
                                                        |
| 1948 | - ),  | 
                                                        |
| 1949 | - __FILE__,  | 
                                                        |
| 1950 | - __FUNCTION__,  | 
                                                        |
| 1951 | - __LINE__  | 
                                                        |
| 1952 | - );  | 
                                                        |
| 1953 | - $success = false;  | 
                                                        |
| 1954 | - }  | 
                                                        |
| 1955 | -        $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int'); | 
                                                        |
| 1956 | - $message_template_group = $this->getMtgModel()->get_one_by_ID($message_template_group_id);  | 
                                                        |
| 1957 | -        if (! $message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1958 | - EE_Error::add_error(  | 
                                                        |
| 1959 | - sprintf(  | 
                                                        |
| 1960 | - esc_html__(  | 
                                                        |
| 1961 | - 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',  | 
                                                        |
| 1962 | - 'event_espresso'  | 
                                                        |
| 1963 | - ),  | 
                                                        |
| 1964 | - $message_template_group_id,  | 
                                                        |
| 1965 | - 'EE_Message_Template_Group'  | 
                                                        |
| 1966 | - ),  | 
                                                        |
| 1967 | - __FILE__,  | 
                                                        |
| 1968 | - __FUNCTION__,  | 
                                                        |
| 1969 | - __LINE__  | 
                                                        |
| 1970 | - );  | 
                                                        |
| 1971 | - $success = false;  | 
                                                        |
| 1972 | - }  | 
                                                        |
| 1973 | -        if ($success) { | 
                                                        |
| 1974 | - $success = $status === 'off'  | 
                                                        |
| 1975 | - ? $message_template_group->deactivate_context($context)  | 
                                                        |
| 1976 | - : $message_template_group->activate_context($context);  | 
                                                        |
| 1977 | - }  | 
                                                        |
| 1978 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 1979 | - $this->_return_json();  | 
                                                        |
| 1980 | - }  | 
                                                        |
| 1981 | -  | 
                                                        |
| 1982 | -  | 
                                                        |
| 1983 | - public function _add_form_element_before()  | 
                                                        |
| 1984 | -    { | 
                                                        |
| 1985 | - return '<form method="post" action="'  | 
                                                        |
| 1986 | - . $this->_template_args['edit_message_template_form_url']  | 
                                                        |
| 1987 | - . '" id="ee-msg-edit-frm">';  | 
                                                        |
| 1988 | - }  | 
                                                        |
| 1989 | -  | 
                                                        |
| 1990 | -  | 
                                                        |
| 1991 | - public function _add_form_element_after()  | 
                                                        |
| 1992 | -    { | 
                                                        |
| 1993 | - return '</form>';  | 
                                                        |
| 1994 | - }  | 
                                                        |
| 1995 | -  | 
                                                        |
| 1996 | -  | 
                                                        |
| 1997 | - /**  | 
                                                        |
| 1998 | - * This executes switching the template pack for a message template.  | 
                                                        |
| 1999 | - *  | 
                                                        |
| 2000 | - * @throws EE_Error  | 
                                                        |
| 2001 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2002 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2003 | - * @throws InvalidArgumentException  | 
                                                        |
| 2004 | - * @throws ReflectionException  | 
                                                        |
| 2005 | - * @since 4.5.0  | 
                                                        |
| 2006 | - */  | 
                                                        |
| 2007 | - public function switch_template_pack()  | 
                                                        |
| 2008 | -    { | 
                                                        |
| 2009 | -  | 
                                                        |
| 2010 | -        $GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2011 | -        $template_pack = $this->request->getRequestParam('template_pack', ''); | 
                                                        |
| 2012 | -  | 
                                                        |
| 2013 | - // verify we have needed values.  | 
                                                        |
| 2014 | -        if (empty($GRP_ID) || empty($template_pack)) { | 
                                                        |
| 2015 | - $this->_template_args['error'] = true;  | 
                                                        |
| 2016 | - EE_Error::add_error(  | 
                                                        |
| 2017 | -                esc_html__('The required date for switching templates is not available.', 'event_espresso'), | 
                                                        |
| 2018 | - __FILE__,  | 
                                                        |
| 2019 | - __FUNCTION__,  | 
                                                        |
| 2020 | - __LINE__  | 
                                                        |
| 2021 | - );  | 
                                                        |
| 2022 | -        } else { | 
                                                        |
| 2023 | - // get template, set the new template_pack and then reset to default  | 
                                                        |
| 2024 | - /** @var EE_Message_Template_Group $message_template_group */  | 
                                                        |
| 2025 | - $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2026 | -  | 
                                                        |
| 2027 | - $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 2028 | -            $this->request->setRequestParam('msgr', $message_template_group->messenger()); | 
                                                        |
| 2029 | -            $this->request->setRequestParam('mt', $message_template_group->message_type()); | 
                                                        |
| 2030 | -  | 
                                                        |
| 2031 | - $query_args = $this->_reset_to_default_template();  | 
                                                        |
| 2032 | -  | 
                                                        |
| 2033 | -            if (empty($query_args['id'])) { | 
                                                        |
| 2034 | - EE_Error::add_error(  | 
                                                        |
| 2035 | - esc_html__(  | 
                                                        |
| 2036 | - 'Something went wrong with switching the template pack. Please try again or contact EE support',  | 
                                                        |
| 2037 | - 'event_espresso'  | 
                                                        |
| 2038 | - ),  | 
                                                        |
| 2039 | - __FILE__,  | 
                                                        |
| 2040 | - __FUNCTION__,  | 
                                                        |
| 2041 | - __LINE__  | 
                                                        |
| 2042 | - );  | 
                                                        |
| 2043 | - $this->_template_args['error'] = true;  | 
                                                        |
| 2044 | -            } else { | 
                                                        |
| 2045 | - $template_label = $message_template_group->get_template_pack()->label;  | 
                                                        |
| 2046 | - $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 2047 | - EE_Error::add_success(  | 
                                                        |
| 2048 | - sprintf(  | 
                                                        |
| 2049 | - esc_html__(  | 
                                                        |
| 2050 | - 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.',  | 
                                                        |
| 2051 | - 'event_espresso'  | 
                                                        |
| 2052 | - ),  | 
                                                        |
| 2053 | - $template_label,  | 
                                                        |
| 2054 | - $template_pack_labels->template_pack  | 
                                                        |
| 2055 | - )  | 
                                                        |
| 2056 | - );  | 
                                                        |
| 2057 | - // generate the redirect url for js.  | 
                                                        |
| 2058 | - $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 2059 | -  | 
                                                        |
| 2060 | - $this->_template_args['data']['redirect_url'] = $url;  | 
                                                        |
| 2061 | - $this->_template_args['success'] = true;  | 
                                                        |
| 2062 | - }  | 
                                                        |
| 2063 | -  | 
                                                        |
| 2064 | - $this->_return_json();  | 
                                                        |
| 2065 | - }  | 
                                                        |
| 2066 | - }  | 
                                                        |
| 2067 | -  | 
                                                        |
| 2068 | -  | 
                                                        |
| 2069 | - /**  | 
                                                        |
| 2070 | - * This handles resetting the template for the given messenger/message_type so that users can start from scratch if  | 
                                                        |
| 2071 | - * they want.  | 
                                                        |
| 2072 | - *  | 
                                                        |
| 2073 | - * @access protected  | 
                                                        |
| 2074 | - * @return array|void  | 
                                                        |
| 2075 | - * @throws EE_Error  | 
                                                        |
| 2076 | - * @throws InvalidArgumentException  | 
                                                        |
| 2077 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2078 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2079 | - * @throws ReflectionException  | 
                                                        |
| 2080 | - */  | 
                                                        |
| 2081 | - protected function _reset_to_default_template()  | 
                                                        |
| 2082 | -    { | 
                                                        |
| 2083 | - $templates = [];  | 
                                                        |
| 2084 | -        $GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2085 | -        $messenger    = $this->request->getRequestParam('msgr'); | 
                                                        |
| 2086 | -        $message_type = $this->request->getRequestParam('mt'); | 
                                                        |
| 2087 | - // we need to make sure we've got the info we need.  | 
                                                        |
| 2088 | -        if (! ($GRP_ID && $messenger && $message_type)) { | 
                                                        |
| 2089 | - EE_Error::add_error(  | 
                                                        |
| 2090 | - esc_html__(  | 
                                                        |
| 2091 | - 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.',  | 
                                                        |
| 2092 | - 'event_espresso'  | 
                                                        |
| 2093 | - ),  | 
                                                        |
| 2094 | - __FILE__,  | 
                                                        |
| 2095 | - __FUNCTION__,  | 
                                                        |
| 2096 | - __LINE__  | 
                                                        |
| 2097 | - );  | 
                                                        |
| 2098 | - }  | 
                                                        |
| 2099 | -  | 
                                                        |
| 2100 | - // all templates will be reset to whatever the defaults are  | 
                                                        |
| 2101 | - // for the global template matching the messenger and message type.  | 
                                                        |
| 2102 | - $success = ! empty($GRP_ID);  | 
                                                        |
| 2103 | -  | 
                                                        |
| 2104 | -        if ($success) { | 
                                                        |
| 2105 | - // let's first determine if the incoming template is a global template,  | 
                                                        |
| 2106 | - // if it isn't then we need to get the global template matching messenger and message type.  | 
                                                        |
| 2107 | - // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );  | 
                                                        |
| 2108 | -  | 
                                                        |
| 2109 | -  | 
                                                        |
| 2110 | - // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.  | 
                                                        |
| 2111 | - $success = $this->_delete_mtp_permanently($GRP_ID, false);  | 
                                                        |
| 2112 | -  | 
                                                        |
| 2113 | -            if ($success) { | 
                                                        |
| 2114 | - // if successfully deleted, lets generate the new ones.  | 
                                                        |
| 2115 | - // Note. We set GLOBAL to true, because resets on ANY template  | 
                                                        |
| 2116 | - // will use the related global template defaults for regeneration.  | 
                                                        |
| 2117 | - // This means that if a custom template is reset it resets to whatever the related global template is.  | 
                                                        |
| 2118 | - // HOWEVER, we DO keep the template pack and template variation set  | 
                                                        |
| 2119 | - // for the current custom template when resetting.  | 
                                                        |
| 2120 | - $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);  | 
                                                        |
| 2121 | - }  | 
                                                        |
| 2122 | - }  | 
                                                        |
| 2123 | -  | 
                                                        |
| 2124 | - // any error messages?  | 
                                                        |
| 2125 | -        if (! $success) { | 
                                                        |
| 2126 | - EE_Error::add_error(  | 
                                                        |
| 2127 | - esc_html__(  | 
                                                        |
| 2128 | - 'Something went wrong with deleting existing templates. Unable to reset to default',  | 
                                                        |
| 2129 | - 'event_espresso'  | 
                                                        |
| 2130 | - ),  | 
                                                        |
| 2131 | - __FILE__,  | 
                                                        |
| 2132 | - __FUNCTION__,  | 
                                                        |
| 2133 | - __LINE__  | 
                                                        |
| 2134 | - );  | 
                                                        |
| 2135 | - }  | 
                                                        |
| 2136 | -  | 
                                                        |
| 2137 | - // all good, let's add a success message!  | 
                                                        |
| 2138 | -        if ($success && ! empty($templates)) { | 
                                                        |
| 2139 | - // the info for the template we generated is the first element in the returned array  | 
                                                        |
| 2140 | - EE_Error::overwrite_success();  | 
                                                        |
| 2141 | -            EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso')); | 
                                                        |
| 2142 | - }  | 
                                                        |
| 2143 | -  | 
                                                        |
| 2144 | -  | 
                                                        |
| 2145 | - $query_args = [  | 
                                                        |
| 2146 | - 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,  | 
                                                        |
| 2147 | - 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,  | 
                                                        |
| 2148 | - 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',  | 
                                                        |
| 2149 | - ];  | 
                                                        |
| 2150 | -  | 
                                                        |
| 2151 | - // if called via ajax then we return query args otherwise redirect  | 
                                                        |
| 2152 | -        if ($this->request->isAjax()) { | 
                                                        |
| 2153 | - return $query_args;  | 
                                                        |
| 2154 | - }  | 
                                                        |
| 2155 | - $this->_redirect_after_action(false, '', '', $query_args, true);  | 
                                                        |
| 2156 | - }  | 
                                                        |
| 2157 | -  | 
                                                        |
| 2158 | -  | 
                                                        |
| 2159 | - /**  | 
                                                        |
| 2160 | - * Retrieve and set the message preview for display.  | 
                                                        |
| 2161 | - *  | 
                                                        |
| 2162 | - * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.  | 
                                                        |
| 2163 | - * @return string  | 
                                                        |
| 2164 | - * @throws ReflectionException  | 
                                                        |
| 2165 | - * @throws EE_Error  | 
                                                        |
| 2166 | - * @throws InvalidArgumentException  | 
                                                        |
| 2167 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2168 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2169 | - */  | 
                                                        |
| 2170 | - public function _preview_message($send = false)  | 
                                                        |
| 2171 | -    { | 
                                                        |
| 2172 | - // first make sure we've got the necessary parameters  | 
                                                        |
| 2173 | -        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2174 | -        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) { | 
                                                        |
| 2175 | - EE_Error::add_error(  | 
                                                        |
| 2176 | -                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), | 
                                                        |
| 2177 | - __FILE__,  | 
                                                        |
| 2178 | - __FUNCTION__,  | 
                                                        |
| 2179 | - __LINE__  | 
                                                        |
| 2180 | - );  | 
                                                        |
| 2181 | - }  | 
                                                        |
| 2182 | -  | 
                                                        |
| 2183 | -        $context = $this->request->getRequestParam('context'); | 
                                                        |
| 2184 | - // get the preview!  | 
                                                        |
| 2185 | - $preview = EED_Messages::preview_message(  | 
                                                        |
| 2186 | - $this->_active_message_type_name,  | 
                                                        |
| 2187 | - $context,  | 
                                                        |
| 2188 | - $this->_active_messenger_name,  | 
                                                        |
| 2189 | - $send  | 
                                                        |
| 2190 | - );  | 
                                                        |
| 2191 | -  | 
                                                        |
| 2192 | -        if ($send) { | 
                                                        |
| 2193 | - return $preview;  | 
                                                        |
| 2194 | - }  | 
                                                        |
| 2195 | -  | 
                                                        |
| 2196 | - // if we have an evt_id set on the request, use it.  | 
                                                        |
| 2197 | -        $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int'); | 
                                                        |
| 2198 | -  | 
                                                        |
| 2199 | - // let's add a button to go back to the edit view  | 
                                                        |
| 2200 | - $query_args = [  | 
                                                        |
| 2201 | - 'id' => $GRP_ID,  | 
                                                        |
| 2202 | - 'evt_id' => $EVT_ID,  | 
                                                        |
| 2203 | - 'context' => $context,  | 
                                                        |
| 2204 | - 'action' => 'edit_message_template',  | 
                                                        |
| 2205 | - ];  | 
                                                        |
| 2206 | - $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 2207 | - $preview_button = '<a href="'  | 
                                                        |
| 2208 | - . $go_back_url  | 
                                                        |
| 2209 | - . '" class="button--secondary messages-preview-go-back-button">'  | 
                                                        |
| 2210 | -                                  . esc_html__('Go Back to Edit', 'event_espresso') | 
                                                        |
| 2211 | - . '</a>';  | 
                                                        |
| 2212 | - $message_types = $this->get_installed_message_types();  | 
                                                        |
| 2213 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);  | 
                                                        |
| 2214 | - $active_messenger_label = $active_messenger instanceof EE_messenger  | 
                                                        |
| 2215 | - ? ucwords($active_messenger->label['singular'])  | 
                                                        |
| 2216 | -            : esc_html__('Unknown Messenger', 'event_espresso'); | 
                                                        |
| 2217 | - // let's provide a helpful title for context  | 
                                                        |
| 2218 | - $preview_title = sprintf(  | 
                                                        |
| 2219 | -            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), | 
                                                        |
| 2220 | - $active_messenger_label,  | 
                                                        |
| 2221 | - ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])  | 
                                                        |
| 2222 | - );  | 
                                                        |
| 2223 | -        if (empty($preview)) { | 
                                                        |
| 2224 | - $this->noEventsErrorMessage();  | 
                                                        |
| 2225 | - }  | 
                                                        |
| 2226 | - // setup display of preview.  | 
                                                        |
| 2227 | - $this->_admin_page_title = $preview_title;  | 
                                                        |
| 2228 | - $this->_template_args['admin_page_title'] = $preview_title;  | 
                                                        |
| 2229 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;  | 
                                                        |
| 2230 | - $this->_template_args['data']['force_json'] = true;  | 
                                                        |
| 2231 | -  | 
                                                        |
| 2232 | - return '';  | 
                                                        |
| 2233 | - }  | 
                                                        |
| 2234 | -  | 
                                                        |
| 2235 | -  | 
                                                        |
| 2236 | - /**  | 
                                                        |
| 2237 | - * Used to set an error if there are no events available for generating a preview/test send.  | 
                                                        |
| 2238 | - *  | 
                                                        |
| 2239 | - * @param bool $test_send Whether the error should be generated for the context of a test send.  | 
                                                        |
| 2240 | - */  | 
                                                        |
| 2241 | - protected function noEventsErrorMessage($test_send = false)  | 
                                                        |
| 2242 | -    { | 
                                                        |
| 2243 | - $events_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 2244 | - [  | 
                                                        |
| 2245 | - 'action' => 'default',  | 
                                                        |
| 2246 | - 'page' => 'espresso_events',  | 
                                                        |
| 2247 | - ],  | 
                                                        |
| 2248 | -            admin_url('admin.php') | 
                                                        |
| 2249 | - );  | 
                                                        |
| 2250 | - $message = $test_send  | 
                                                        |
| 2251 | - ? esc_html__(  | 
                                                        |
| 2252 | - 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',  | 
                                                        |
| 2253 | - 'event_espresso'  | 
                                                        |
| 2254 | - )  | 
                                                        |
| 2255 | - : esc_html__(  | 
                                                        |
| 2256 | - 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',  | 
                                                        |
| 2257 | - 'event_espresso'  | 
                                                        |
| 2258 | - );  | 
                                                        |
| 2259 | -  | 
                                                        |
| 2260 | - EE_Error::add_attention(  | 
                                                        |
| 2261 | - sprintf(  | 
                                                        |
| 2262 | - $message,  | 
                                                        |
| 2263 | -                "<a href='{$events_url}'>", | 
                                                        |
| 2264 | - '</a>'  | 
                                                        |
| 2265 | - )  | 
                                                        |
| 2266 | - );  | 
                                                        |
| 2267 | - }  | 
                                                        |
| 2268 | -  | 
                                                        |
| 2269 | -  | 
                                                        |
| 2270 | - /**  | 
                                                        |
| 2271 | - * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it  | 
                                                        |
| 2272 | - * gets called automatically.  | 
                                                        |
| 2273 | - *  | 
                                                        |
| 2274 | - * @return void  | 
                                                        |
| 2275 | - * @throws EE_Error  | 
                                                        |
| 2276 | - * @since 4.5.0  | 
                                                        |
| 2277 | - *  | 
                                                        |
| 2278 | - */  | 
                                                        |
| 2279 | - protected function _display_preview_message()  | 
                                                        |
| 2280 | -    { | 
                                                        |
| 2281 | - $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 2282 | - }  | 
                                                        |
| 2283 | -  | 
                                                        |
| 2284 | -  | 
                                                        |
| 2285 | - /**  | 
                                                        |
| 2286 | - * registers metaboxes that should show up on the "edit_message_template" page  | 
                                                        |
| 2287 | - *  | 
                                                        |
| 2288 | - * @access protected  | 
                                                        |
| 2289 | - * @return void  | 
                                                        |
| 2290 | - */  | 
                                                        |
| 2291 | - protected function _register_edit_meta_boxes()  | 
                                                        |
| 2292 | -    { | 
                                                        |
| 2293 | - $this->addMetaBox(  | 
                                                        |
| 2294 | - 'mtp_valid_shortcodes',  | 
                                                        |
| 2295 | -            esc_html__('Valid Shortcodes', 'event_espresso'), | 
                                                        |
| 2296 | - [$this, 'shortcode_meta_box'],  | 
                                                        |
| 2297 | - $this->_current_screen->id,  | 
                                                        |
| 2298 | - 'side'  | 
                                                        |
| 2299 | - );  | 
                                                        |
| 2300 | - $this->addMetaBox(  | 
                                                        |
| 2301 | - 'mtp_extra_actions',  | 
                                                        |
| 2302 | -            esc_html__('Extra Actions', 'event_espresso'), | 
                                                        |
| 2303 | - [$this, 'extra_actions_meta_box'],  | 
                                                        |
| 2304 | - $this->_current_screen->id,  | 
                                                        |
| 2305 | - 'side',  | 
                                                        |
| 2306 | - 'high'  | 
                                                        |
| 2307 | - );  | 
                                                        |
| 2308 | - $this->addMetaBox(  | 
                                                        |
| 2309 | - 'mtp_templates',  | 
                                                        |
| 2310 | -            esc_html__('Template Styles', 'event_espresso'), | 
                                                        |
| 2311 | - [$this, 'template_pack_meta_box'],  | 
                                                        |
| 2312 | - $this->_current_screen->id,  | 
                                                        |
| 2313 | - 'side',  | 
                                                        |
| 2314 | - 'high'  | 
                                                        |
| 2315 | - );  | 
                                                        |
| 2316 | - }  | 
                                                        |
| 2317 | -  | 
                                                        |
| 2318 | -  | 
                                                        |
| 2319 | - /**  | 
                                                        |
| 2320 | - * metabox content for all template pack and variation selection.  | 
                                                        |
| 2321 | - *  | 
                                                        |
| 2322 | - * @return void  | 
                                                        |
| 2323 | - * @throws DomainException  | 
                                                        |
| 2324 | - * @throws EE_Error  | 
                                                        |
| 2325 | - * @throws InvalidArgumentException  | 
                                                        |
| 2326 | - * @throws ReflectionException  | 
                                                        |
| 2327 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2328 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2329 | - * @since 4.5.0  | 
                                                        |
| 2330 | - */  | 
                                                        |
| 2331 | - public function template_pack_meta_box()  | 
                                                        |
| 2332 | -    { | 
                                                        |
| 2333 | - $this->_set_message_template_group();  | 
                                                        |
| 2334 | -  | 
                                                        |
| 2335 | - $tp_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 2336 | -  | 
                                                        |
| 2337 | - $tp_select_values = [];  | 
                                                        |
| 2338 | -  | 
                                                        |
| 2339 | -        foreach ($tp_collection as $tp) { | 
                                                        |
| 2340 | - // only include template packs that support this messenger and message type!  | 
                                                        |
| 2341 | - $supports = $tp->get_supports();  | 
                                                        |
| 2342 | - if (  | 
                                                        |
| 2343 | - ! isset($supports[ $this->_message_template_group->messenger() ])  | 
                                                        |
| 2344 | - || ! in_array(  | 
                                                        |
| 2345 | - $this->_message_template_group->message_type(),  | 
                                                        |
| 2346 | - $supports[ $this->_message_template_group->messenger() ],  | 
                                                        |
| 2347 | - true  | 
                                                        |
| 2348 | - )  | 
                                                        |
| 2349 | -            ) { | 
                                                        |
| 2350 | - // not supported  | 
                                                        |
| 2351 | - continue;  | 
                                                        |
| 2352 | - }  | 
                                                        |
| 2353 | -  | 
                                                        |
| 2354 | - $tp_select_values[] = [  | 
                                                        |
| 2355 | - 'text' => $tp->label,  | 
                                                        |
| 2356 | - 'id' => $tp->dbref,  | 
                                                        |
| 2357 | - ];  | 
                                                        |
| 2358 | - }  | 
                                                        |
| 2359 | -  | 
                                                        |
| 2360 | - // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by  | 
                                                        |
| 2361 | - // the default template pack. This still allows for the odd template pack to override.  | 
                                                        |
| 2362 | -        if (empty($tp_select_values)) { | 
                                                        |
| 2363 | - $tp_select_values[] = [  | 
                                                        |
| 2364 | -                'text' => esc_html__('Default', 'event_espresso'), | 
                                                        |
| 2365 | - 'id' => 'default',  | 
                                                        |
| 2366 | - ];  | 
                                                        |
| 2367 | - }  | 
                                                        |
| 2368 | -  | 
                                                        |
| 2369 | - // setup variation select values for the currently selected template.  | 
                                                        |
| 2370 | - $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 2371 | - $this->_message_template_group->messenger(),  | 
                                                        |
| 2372 | - $this->_message_template_group->message_type()  | 
                                                        |
| 2373 | - );  | 
                                                        |
| 2374 | - $variations_select_values = [];  | 
                                                        |
| 2375 | -        foreach ($variations as $variation => $label) { | 
                                                        |
| 2376 | - $variations_select_values[] = [  | 
                                                        |
| 2377 | - 'text' => $label,  | 
                                                        |
| 2378 | - 'id' => $variation,  | 
                                                        |
| 2379 | - ];  | 
                                                        |
| 2380 | - }  | 
                                                        |
| 2381 | -  | 
                                                        |
| 2382 | - $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 2383 | -  | 
                                                        |
| 2384 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2385 | - 'MTP_template_pack',  | 
                                                        |
| 2386 | - $tp_select_values,  | 
                                                        |
| 2387 | - $this->_message_template_group->get_template_pack_name()  | 
                                                        |
| 2388 | - );  | 
                                                        |
| 2389 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2390 | - 'MTP_template_variation',  | 
                                                        |
| 2391 | - $variations_select_values,  | 
                                                        |
| 2392 | - $this->_message_template_group->get_template_pack_variation()  | 
                                                        |
| 2393 | - );  | 
                                                        |
| 2394 | - $template_args['template_pack_label'] = $template_pack_labels->template_pack;  | 
                                                        |
| 2395 | - $template_args['template_variation_label'] = $template_pack_labels->template_variation;  | 
                                                        |
| 2396 | - $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        |
| 2397 | - $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        |
| 2398 | -  | 
                                                        |
| 2399 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 2400 | -  | 
                                                        |
| 2401 | - EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 2402 | - }  | 
                                                        |
| 2403 | -  | 
                                                        |
| 2404 | -  | 
                                                        |
| 2405 | - /**  | 
                                                        |
| 2406 | - * This meta box holds any extra actions related to Message Templates  | 
                                                        |
| 2407 | - * For now, this includes Resetting templates to defaults and sending a test email.  | 
                                                        |
| 2408 | - *  | 
                                                        |
| 2409 | - * @access public  | 
                                                        |
| 2410 | - * @return void  | 
                                                        |
| 2411 | - * @throws EE_Error  | 
                                                        |
| 2412 | - */  | 
                                                        |
| 2413 | - public function extra_actions_meta_box()  | 
                                                        |
| 2414 | -    { | 
                                                        |
| 2415 | - $template_form_fields = [];  | 
                                                        |
| 2416 | -  | 
                                                        |
| 2417 | - $extra_args = [  | 
                                                        |
| 2418 | - 'msgr' => $this->_message_template_group->messenger(),  | 
                                                        |
| 2419 | - 'mt' => $this->_message_template_group->message_type(),  | 
                                                        |
| 2420 | - 'GRP_ID' => $this->_message_template_group->GRP_ID(),  | 
                                                        |
| 2421 | - ];  | 
                                                        |
| 2422 | - // first we need to see if there are any fields  | 
                                                        |
| 2423 | - $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();  | 
                                                        |
| 2424 | -  | 
                                                        |
| 2425 | -        if (! empty($fields)) { | 
                                                        |
| 2426 | - // yup there be fields  | 
                                                        |
| 2427 | -            foreach ($fields as $field => $config) { | 
                                                        |
| 2428 | - $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2429 | - $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        |
| 2430 | - $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        |
| 2431 | - $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        |
| 2432 | -  | 
                                                        |
| 2433 | - // if type is hidden and the value is empty  | 
                                                        |
| 2434 | - // something may have gone wrong so let's correct with the defaults  | 
                                                        |
| 2435 | - $fix = $config['input'] === 'hidden'  | 
                                                        |
| 2436 | - && isset($existing[ $field ])  | 
                                                        |
| 2437 | - && empty($existing[ $field ])  | 
                                                        |
| 2438 | - ? $default  | 
                                                        |
| 2439 | - : '';  | 
                                                        |
| 2440 | - $existing[ $field ] = isset($existing[ $field ]) && empty($fix)  | 
                                                        |
| 2441 | - ? $existing[ $field ]  | 
                                                        |
| 2442 | - : $fix;  | 
                                                        |
| 2443 | -  | 
                                                        |
| 2444 | - $template_form_fields[ $field_id ] = [  | 
                                                        |
| 2445 | - 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2446 | - 'label' => $config['label'],  | 
                                                        |
| 2447 | - 'input' => $config['input'],  | 
                                                        |
| 2448 | - 'type' => $config['type'],  | 
                                                        |
| 2449 | - 'required' => $config['required'],  | 
                                                        |
| 2450 | - 'validation' => $config['validation'],  | 
                                                        |
| 2451 | - 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default,  | 
                                                        |
| 2452 | - 'css_class' => $config['css_class'],  | 
                                                        |
| 2453 | - 'options' => isset($config['options']) ? $config['options'] : [],  | 
                                                        |
| 2454 | - 'default' => $default,  | 
                                                        |
| 2455 | - 'format' => $config['format'],  | 
                                                        |
| 2456 | - ];  | 
                                                        |
| 2457 | - }  | 
                                                        |
| 2458 | - }  | 
                                                        |
| 2459 | -  | 
                                                        |
| 2460 | - $test_settings_html = ! empty($template_form_fields)  | 
                                                        |
| 2461 | - ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')  | 
                                                        |
| 2462 | - : '';  | 
                                                        |
| 2463 | -  | 
                                                        |
| 2464 | - // print out $test_settings_fields  | 
                                                        |
| 2465 | -        if (! empty($test_settings_html)) { | 
                                                        |
| 2466 | - $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';  | 
                                                        |
| 2467 | - $test_settings_html .= 'name="test_button" value="';  | 
                                                        |
| 2468 | -            $test_settings_html .= esc_html__('Test Send', 'event_espresso'); | 
                                                        |
| 2469 | - $test_settings_html .= '" /><div style="clear:both"></div>';  | 
                                                        |
| 2470 | - }  | 
                                                        |
| 2471 | -  | 
                                                        |
| 2472 | - // and button  | 
                                                        |
| 2473 | - $test_settings_html .= '<div class="publishing-action alignright resetbutton">';  | 
                                                        |
| 2474 | - $test_settings_html .= '<p>';  | 
                                                        |
| 2475 | -        $test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso'); | 
                                                        |
| 2476 | - $test_settings_html .= '</p>';  | 
                                                        |
| 2477 | - $test_settings_html .= $this->get_action_link_or_button(  | 
                                                        |
| 2478 | - 'reset_to_default',  | 
                                                        |
| 2479 | - 'reset',  | 
                                                        |
| 2480 | - $extra_args,  | 
                                                        |
| 2481 | - 'button--primary reset-default-button'  | 
                                                        |
| 2482 | - );  | 
                                                        |
| 2483 | - $test_settings_html .= '</div><div style="clear:both"></div>';  | 
                                                        |
| 2484 | - echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());  | 
                                                        |
| 2485 | - }  | 
                                                        |
| 2486 | -  | 
                                                        |
| 2487 | -  | 
                                                        |
| 2488 | - /**  | 
                                                        |
| 2489 | - * This returns the shortcode selector skeleton for a given context and field.  | 
                                                        |
| 2490 | - *  | 
                                                        |
| 2491 | - * @param string $field The name of the field retrieving shortcodes for.  | 
                                                        |
| 2492 | - * @param string $linked_input_id The css id of the input that the shortcodes get added to.  | 
                                                        |
| 2493 | - * @return string  | 
                                                        |
| 2494 | - * @throws DomainException  | 
                                                        |
| 2495 | - * @throws EE_Error  | 
                                                        |
| 2496 | - * @throws InvalidArgumentException  | 
                                                        |
| 2497 | - * @throws ReflectionException  | 
                                                        |
| 2498 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2499 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2500 | - * @since 4.9.rc.000  | 
                                                        |
| 2501 | - */  | 
                                                        |
| 2502 | - protected function _get_shortcode_selector($field, $linked_input_id)  | 
                                                        |
| 2503 | -    { | 
                                                        |
| 2504 | - $template_args = [  | 
                                                        |
| 2505 | - 'shortcodes' => $this->_get_shortcodes([$field]),  | 
                                                        |
| 2506 | - 'fieldname' => $field,  | 
                                                        |
| 2507 | - 'linked_input_id' => $linked_input_id,  | 
                                                        |
| 2508 | - ];  | 
                                                        |
| 2509 | -  | 
                                                        |
| 2510 | - return EEH_Template::display_template(  | 
                                                        |
| 2511 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2512 | - $template_args,  | 
                                                        |
| 2513 | - true  | 
                                                        |
| 2514 | - );  | 
                                                        |
| 2515 | - }  | 
                                                        |
| 2516 | -  | 
                                                        |
| 2517 | -  | 
                                                        |
| 2518 | - /**  | 
                                                        |
| 2519 | - * This just takes care of returning the meta box content for shortcodes (only used on the edit message template  | 
                                                        |
| 2520 | - * page)  | 
                                                        |
| 2521 | - *  | 
                                                        |
| 2522 | - * @access public  | 
                                                        |
| 2523 | - * @return void  | 
                                                        |
| 2524 | - * @throws EE_Error  | 
                                                        |
| 2525 | - * @throws InvalidArgumentException  | 
                                                        |
| 2526 | - * @throws ReflectionException  | 
                                                        |
| 2527 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2528 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2529 | - */  | 
                                                        |
| 2530 | - public function shortcode_meta_box()  | 
                                                        |
| 2531 | -    { | 
                                                        |
| 2532 | - $shortcodes = $this->_get_shortcodes([], false);  | 
                                                        |
| 2533 | - // just make sure the shortcodes property is set  | 
                                                        |
| 2534 | - // $messenger = $this->_message_template_group->messenger_obj();  | 
                                                        |
| 2535 | - // now let's set the content depending on the status of the shortcodes array  | 
                                                        |
| 2536 | -        if (empty($shortcodes)) { | 
                                                        |
| 2537 | -            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2538 | - return;  | 
                                                        |
| 2539 | - }  | 
                                                        |
| 2540 | - ?>  | 
                                                        |
| 20 | + /**  | 
                                                        |
| 21 | + * @var EEM_Message  | 
                                                        |
| 22 | + */  | 
                                                        |
| 23 | + private $MSG_MODEL;  | 
                                                        |
| 24 | +  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * @var EEM_Message_Template  | 
                                                        |
| 27 | + */  | 
                                                        |
| 28 | + private $MTP_MODEL;  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * @var EEM_Message_Template_Group  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + private $MTG_MODEL;  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | + /**  | 
                                                        |
| 36 | + * @var EE_Message_Resource_Manager $_message_resource_manager  | 
                                                        |
| 37 | + */  | 
                                                        |
| 38 | + protected $_message_resource_manager;  | 
                                                        |
| 39 | +  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * @var string  | 
                                                        |
| 42 | + */  | 
                                                        |
| 43 | + protected $_active_message_type_name = '';  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /**  | 
                                                        |
| 46 | + * @var string  | 
                                                        |
| 47 | + */  | 
                                                        |
| 48 | + protected $_active_messenger_name = '';  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + /**  | 
                                                        |
| 51 | + * @var EE_messenger $_active_messenger  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + protected $_active_messenger;  | 
                                                        |
| 54 | +  | 
                                                        |
| 55 | + protected $_activate_meta_box_type;  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + protected $_current_message_meta_box;  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | + protected $_current_message_meta_box_object;  | 
                                                        |
| 60 | +  | 
                                                        |
| 61 | + protected $_context_switcher;  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + protected $_shortcodes = [];  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + protected $_active_messengers = [];  | 
                                                        |
| 66 | +  | 
                                                        |
| 67 | + protected $_active_message_types = [];  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | + /**  | 
                                                        |
| 70 | + * @var EE_Message_Template_Group $_message_template_group  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | + protected $_message_template_group;  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + protected $_m_mt_settings = [];  | 
                                                        |
| 75 | +  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | + /**  | 
                                                        |
| 78 | + * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.  | 
                                                        |
| 79 | + * IF there is no group then it gets automatically set to the Default template pack.  | 
                                                        |
| 80 | + *  | 
                                                        |
| 81 | + * @since 4.5.0  | 
                                                        |
| 82 | + *  | 
                                                        |
| 83 | + * @var EE_Messages_Template_Pack  | 
                                                        |
| 84 | + */  | 
                                                        |
| 85 | + protected $_template_pack;  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + /**  | 
                                                        |
| 89 | + * This is set via the _set_message_template_group method and holds whatever the template pack variation for the  | 
                                                        |
| 90 | + * group is. If there is no group then it automatically gets set to default.  | 
                                                        |
| 91 | + *  | 
                                                        |
| 92 | + * @since 4.5.0  | 
                                                        |
| 93 | + *  | 
                                                        |
| 94 | + * @var string  | 
                                                        |
| 95 | + */  | 
                                                        |
| 96 | + protected $_variation;  | 
                                                        |
| 97 | +  | 
                                                        |
| 98 | +  | 
                                                        |
| 99 | + /**  | 
                                                        |
| 100 | + * @param bool $routing  | 
                                                        |
| 101 | + * @throws EE_Error  | 
                                                        |
| 102 | + * @throws ReflectionException  | 
                                                        |
| 103 | + */  | 
                                                        |
| 104 | + public function __construct($routing = true)  | 
                                                        |
| 105 | +	{ | 
                                                        |
| 106 | + // make sure messages autoloader is running  | 
                                                        |
| 107 | + EED_Messages::set_autoloaders();  | 
                                                        |
| 108 | + parent::__construct($routing);  | 
                                                        |
| 109 | + }  | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | +  | 
                                                        |
| 112 | + /**  | 
                                                        |
| 113 | + * @return EEM_Message  | 
                                                        |
| 114 | + * @throws EE_Error  | 
                                                        |
| 115 | + */  | 
                                                        |
| 116 | + public function getMsgModel()  | 
                                                        |
| 117 | +	{ | 
                                                        |
| 118 | +		if (! $this->MSG_MODEL instanceof EEM_Message) { | 
                                                        |
| 119 | + $this->MSG_MODEL = EEM_Message::instance();  | 
                                                        |
| 120 | + }  | 
                                                        |
| 121 | + return $this->MSG_MODEL;  | 
                                                        |
| 122 | + }  | 
                                                        |
| 123 | +  | 
                                                        |
| 124 | +  | 
                                                        |
| 125 | + /**  | 
                                                        |
| 126 | + * @return EEM_Message_Template  | 
                                                        |
| 127 | + * @throws EE_Error  | 
                                                        |
| 128 | + */  | 
                                                        |
| 129 | + public function getMtpModel()  | 
                                                        |
| 130 | +	{ | 
                                                        |
| 131 | +		if (! $this->MTP_MODEL instanceof EEM_Message_Template) { | 
                                                        |
| 132 | + $this->MTP_MODEL = EEM_Message_Template::instance();  | 
                                                        |
| 133 | + }  | 
                                                        |
| 134 | + return $this->MTP_MODEL;  | 
                                                        |
| 135 | + }  | 
                                                        |
| 136 | +  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | + /**  | 
                                                        |
| 139 | + * @return EEM_Message_Template_Group  | 
                                                        |
| 140 | + * @throws EE_Error  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | + public function getMtgModel()  | 
                                                        |
| 143 | +	{ | 
                                                        |
| 144 | +		if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) { | 
                                                        |
| 145 | + $this->MTG_MODEL = EEM_Message_Template_Group::instance();  | 
                                                        |
| 146 | + }  | 
                                                        |
| 147 | + return $this->MTG_MODEL;  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | +  | 
                                                        |
| 150 | +  | 
                                                        |
| 151 | + /**  | 
                                                        |
| 152 | + * @throws EE_Error  | 
                                                        |
| 153 | + * @throws ReflectionException  | 
                                                        |
| 154 | + */  | 
                                                        |
| 155 | + protected function _init_page_props()  | 
                                                        |
| 156 | +	{ | 
                                                        |
| 157 | + $this->page_slug = EE_MSG_PG_SLUG;  | 
                                                        |
| 158 | +		$this->page_label       = esc_html__('Messages Settings', 'event_espresso'); | 
                                                        |
| 159 | + $this->_admin_base_url = EE_MSG_ADMIN_URL;  | 
                                                        |
| 160 | + $this->_admin_base_path = EE_MSG_ADMIN;  | 
                                                        |
| 161 | +  | 
                                                        |
| 162 | +		$messenger    = $this->request->getRequestParam('messenger', ''); | 
                                                        |
| 163 | +		$message_type = $this->request->getRequestParam('message_type', ''); | 
                                                        |
| 164 | +		$this->_active_messenger_name    = $this->request->getRequestParam('MTP_messenger', $messenger); | 
                                                        |
| 165 | +		$this->_active_message_type_name = $this->request->getRequestParam('MTP_message_type', $message_type); | 
                                                        |
| 166 | +  | 
                                                        |
| 167 | + $this->_load_message_resource_manager();  | 
                                                        |
| 168 | + }  | 
                                                        |
| 169 | +  | 
                                                        |
| 170 | +  | 
                                                        |
| 171 | + /**  | 
                                                        |
| 172 | + * loads messenger objects into the $_active_messengers property (so we can access the needed methods)  | 
                                                        |
| 173 | + *  | 
                                                        |
| 174 | + * @throws EE_Error  | 
                                                        |
| 175 | + * @throws InvalidDataTypeException  | 
                                                        |
| 176 | + * @throws InvalidInterfaceException  | 
                                                        |
| 177 | + * @throws InvalidArgumentException  | 
                                                        |
| 178 | + * @throws ReflectionException  | 
                                                        |
| 179 | + */  | 
                                                        |
| 180 | + protected function _load_message_resource_manager()  | 
                                                        |
| 181 | +	{ | 
                                                        |
| 182 | +		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 183 | + }  | 
                                                        |
| 184 | +  | 
                                                        |
| 185 | +  | 
                                                        |
| 186 | + /**  | 
                                                        |
| 187 | + * @return array  | 
                                                        |
| 188 | + * @throws EE_Error  | 
                                                        |
| 189 | + * @throws InvalidArgumentException  | 
                                                        |
| 190 | + * @throws InvalidDataTypeException  | 
                                                        |
| 191 | + * @throws InvalidInterfaceException  | 
                                                        |
| 192 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 193 | + */  | 
                                                        |
| 194 | + public function get_messengers_for_list_table()  | 
                                                        |
| 195 | +	{ | 
                                                        |
| 196 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 197 | + __METHOD__,  | 
                                                        |
| 198 | + sprintf(  | 
                                                        |
| 199 | + esc_html__(  | 
                                                        |
| 200 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',  | 
                                                        |
| 201 | + 'event_espresso'  | 
                                                        |
| 202 | + ),  | 
                                                        |
| 203 | + 'Messages_Admin_Page::get_messengers_select_input()'  | 
                                                        |
| 204 | + ),  | 
                                                        |
| 205 | + '4.9.9.rc.014'  | 
                                                        |
| 206 | + );  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | + $m_values = [];  | 
                                                        |
| 209 | + $active_messengers = $this->getMsgModel()->get_all(['group_by' => 'MSG_messenger']);  | 
                                                        |
| 210 | + // setup messengers for selects  | 
                                                        |
| 211 | + $i = 1;  | 
                                                        |
| 212 | +		foreach ($active_messengers as $active_messenger) { | 
                                                        |
| 213 | +			if ($active_messenger instanceof EE_Message) { | 
                                                        |
| 214 | + $m_values[ $i ]['id'] = $active_messenger->messenger();  | 
                                                        |
| 215 | + $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 216 | + $i++;  | 
                                                        |
| 217 | + }  | 
                                                        |
| 218 | + }  | 
                                                        |
| 219 | +  | 
                                                        |
| 220 | + return $m_values;  | 
                                                        |
| 221 | + }  | 
                                                        |
| 222 | +  | 
                                                        |
| 223 | +  | 
                                                        |
| 224 | + /**  | 
                                                        |
| 225 | + * @return array  | 
                                                        |
| 226 | + * @throws EE_Error  | 
                                                        |
| 227 | + * @throws InvalidArgumentException  | 
                                                        |
| 228 | + * @throws InvalidDataTypeException  | 
                                                        |
| 229 | + * @throws InvalidInterfaceException  | 
                                                        |
| 230 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 231 | + */  | 
                                                        |
| 232 | + public function get_message_types_for_list_table()  | 
                                                        |
| 233 | +	{ | 
                                                        |
| 234 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 235 | + __METHOD__,  | 
                                                        |
| 236 | + sprintf(  | 
                                                        |
| 237 | + esc_html__(  | 
                                                        |
| 238 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',  | 
                                                        |
| 239 | + 'event_espresso'  | 
                                                        |
| 240 | + ),  | 
                                                        |
| 241 | + 'Messages_Admin_Page::get_message_types_select_input()'  | 
                                                        |
| 242 | + ),  | 
                                                        |
| 243 | + '4.9.9.rc.014'  | 
                                                        |
| 244 | + );  | 
                                                        |
| 245 | +  | 
                                                        |
| 246 | + $mt_values = [];  | 
                                                        |
| 247 | + $active_messages = $this->getMsgModel()->get_all(['group_by' => 'MSG_message_type']);  | 
                                                        |
| 248 | + $i = 1;  | 
                                                        |
| 249 | +		foreach ($active_messages as $active_message) { | 
                                                        |
| 250 | +			if ($active_message instanceof EE_Message) { | 
                                                        |
| 251 | + $mt_values[ $i ]['id'] = $active_message->message_type();  | 
                                                        |
| 252 | + $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 253 | + $i++;  | 
                                                        |
| 254 | + }  | 
                                                        |
| 255 | + }  | 
                                                        |
| 256 | +  | 
                                                        |
| 257 | + return $mt_values;  | 
                                                        |
| 258 | + }  | 
                                                        |
| 259 | +  | 
                                                        |
| 260 | +  | 
                                                        |
| 261 | + /**  | 
                                                        |
| 262 | + * @return array  | 
                                                        |
| 263 | + * @throws EE_Error  | 
                                                        |
| 264 | + * @throws InvalidArgumentException  | 
                                                        |
| 265 | + * @throws InvalidDataTypeException  | 
                                                        |
| 266 | + * @throws InvalidInterfaceException  | 
                                                        |
| 267 | + * @deprecated 4.9.9.rc.014  | 
                                                        |
| 268 | + */  | 
                                                        |
| 269 | + public function get_contexts_for_message_types_for_list_table()  | 
                                                        |
| 270 | +	{ | 
                                                        |
| 271 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 272 | + __METHOD__,  | 
                                                        |
| 273 | + sprintf(  | 
                                                        |
| 274 | + esc_html__(  | 
                                                        |
| 275 | + 'This method is no longer in use. There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',  | 
                                                        |
| 276 | + 'event_espresso'  | 
                                                        |
| 277 | + ),  | 
                                                        |
| 278 | + 'Messages_Admin_Page::get_contexts_for_message_types_select_input()'  | 
                                                        |
| 279 | + ),  | 
                                                        |
| 280 | + '4.9.9.rc.014'  | 
                                                        |
| 281 | + );  | 
                                                        |
| 282 | +  | 
                                                        |
| 283 | + $contexts = [];  | 
                                                        |
| 284 | + $active_message_contexts = $this->getMsgModel()->get_all(['group_by' => 'MSG_context']);  | 
                                                        |
| 285 | +		foreach ($active_message_contexts as $active_message) { | 
                                                        |
| 286 | +			if ($active_message instanceof EE_Message) { | 
                                                        |
| 287 | + $message_type = $active_message->message_type_object();  | 
                                                        |
| 288 | +				if ($message_type instanceof EE_message_type) { | 
                                                        |
| 289 | + $message_type_contexts = $message_type->get_contexts();  | 
                                                        |
| 290 | +					foreach ($message_type_contexts as $context => $context_details) { | 
                                                        |
| 291 | + $contexts[ $context ] = $context_details['label'];  | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | + }  | 
                                                        |
| 294 | + }  | 
                                                        |
| 295 | + }  | 
                                                        |
| 296 | +  | 
                                                        |
| 297 | + return $contexts;  | 
                                                        |
| 298 | + }  | 
                                                        |
| 299 | +  | 
                                                        |
| 300 | +  | 
                                                        |
| 301 | + /**  | 
                                                        |
| 302 | + * Generate select input with provided messenger options array.  | 
                                                        |
| 303 | + *  | 
                                                        |
| 304 | + * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger  | 
                                                        |
| 305 | + * labels.  | 
                                                        |
| 306 | + * @return string  | 
                                                        |
| 307 | + * @throws EE_Error  | 
                                                        |
| 308 | + */  | 
                                                        |
| 309 | + public function get_messengers_select_input($messenger_options)  | 
                                                        |
| 310 | +	{ | 
                                                        |
| 311 | + // if empty or just one value then just return an empty string  | 
                                                        |
| 312 | + if (  | 
                                                        |
| 313 | + empty($messenger_options)  | 
                                                        |
| 314 | + || ! is_array($messenger_options)  | 
                                                        |
| 315 | + || count($messenger_options) === 1  | 
                                                        |
| 316 | +		) { | 
                                                        |
| 317 | + return '';  | 
                                                        |
| 318 | + }  | 
                                                        |
| 319 | + // merge in default  | 
                                                        |
| 320 | + $messenger_options = array_merge(  | 
                                                        |
| 321 | +			['none_selected' => esc_html__('Show All Messengers', 'event_espresso')], | 
                                                        |
| 322 | + $messenger_options  | 
                                                        |
| 323 | + );  | 
                                                        |
| 324 | + $input = new EE_Select_Input(  | 
                                                        |
| 325 | + $messenger_options,  | 
                                                        |
| 326 | + [  | 
                                                        |
| 327 | + 'html_name' => 'ee_messenger_filter_by',  | 
                                                        |
| 328 | + 'html_id' => 'ee_messenger_filter_by',  | 
                                                        |
| 329 | + 'html_class' => 'wide',  | 
                                                        |
| 330 | +				'default'    => $this->request->getRequestParam('ee_messenger_filter_by', 'none_selected', 'title'), | 
                                                        |
| 331 | + ]  | 
                                                        |
| 332 | + );  | 
                                                        |
| 333 | +  | 
                                                        |
| 334 | + return $input->get_html_for_input();  | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | +  | 
                                                        |
| 338 | + /**  | 
                                                        |
| 339 | + * Generate select input with provided message type options array.  | 
                                                        |
| 340 | + *  | 
                                                        |
| 341 | + * @param array $message_type_options Array of message types indexed by message type slug, and values are the  | 
                                                        |
| 342 | + * message type labels  | 
                                                        |
| 343 | + * @return string  | 
                                                        |
| 344 | + * @throws EE_Error  | 
                                                        |
| 345 | + */  | 
                                                        |
| 346 | + public function get_message_types_select_input($message_type_options)  | 
                                                        |
| 347 | +	{ | 
                                                        |
| 348 | + // if empty or count of options is 1 then just return an empty string  | 
                                                        |
| 349 | + if (  | 
                                                        |
| 350 | + empty($message_type_options)  | 
                                                        |
| 351 | + || ! is_array($message_type_options)  | 
                                                        |
| 352 | + || count($message_type_options) === 1  | 
                                                        |
| 353 | +		) { | 
                                                        |
| 354 | + return '';  | 
                                                        |
| 355 | + }  | 
                                                        |
| 356 | + // merge in default  | 
                                                        |
| 357 | + $message_type_options = array_merge(  | 
                                                        |
| 358 | +			['none_selected' => esc_html__('Show All Message Types', 'event_espresso')], | 
                                                        |
| 359 | + $message_type_options  | 
                                                        |
| 360 | + );  | 
                                                        |
| 361 | + $input = new EE_Select_Input(  | 
                                                        |
| 362 | + $message_type_options,  | 
                                                        |
| 363 | + [  | 
                                                        |
| 364 | + 'html_name' => 'ee_message_type_filter_by',  | 
                                                        |
| 365 | + 'html_id' => 'ee_message_type_filter_by',  | 
                                                        |
| 366 | + 'html_class' => 'wide',  | 
                                                        |
| 367 | +				'default'    => $this->request->getRequestParam('ee_message_type_filter_by', 'none_selected', 'title'), | 
                                                        |
| 368 | + ]  | 
                                                        |
| 369 | + );  | 
                                                        |
| 370 | +  | 
                                                        |
| 371 | + return $input->get_html_for_input();  | 
                                                        |
| 372 | + }  | 
                                                        |
| 373 | +  | 
                                                        |
| 374 | +  | 
                                                        |
| 375 | + /**  | 
                                                        |
| 376 | + * Generate select input with provide message type contexts array.  | 
                                                        |
| 377 | + *  | 
                                                        |
| 378 | + * @param array $context_options Array of message type contexts indexed by context slug, and values are the  | 
                                                        |
| 379 | + * context label.  | 
                                                        |
| 380 | + * @return string  | 
                                                        |
| 381 | + * @throws EE_Error  | 
                                                        |
| 382 | + */  | 
                                                        |
| 383 | + public function get_contexts_for_message_types_select_input($context_options)  | 
                                                        |
| 384 | +	{ | 
                                                        |
| 385 | + // if empty or count of options is one then just return empty string  | 
                                                        |
| 386 | + if (  | 
                                                        |
| 387 | + empty($context_options)  | 
                                                        |
| 388 | + || ! is_array($context_options)  | 
                                                        |
| 389 | + || count($context_options) === 1  | 
                                                        |
| 390 | +		) { | 
                                                        |
| 391 | + return '';  | 
                                                        |
| 392 | + }  | 
                                                        |
| 393 | + // merge in default  | 
                                                        |
| 394 | + $context_options = array_merge(  | 
                                                        |
| 395 | +			['none_selected' => esc_html__('Show all Contexts', 'event_espresso')], | 
                                                        |
| 396 | + $context_options  | 
                                                        |
| 397 | + );  | 
                                                        |
| 398 | + $input = new EE_Select_Input(  | 
                                                        |
| 399 | + $context_options,  | 
                                                        |
| 400 | + [  | 
                                                        |
| 401 | + 'html_name' => 'ee_context_filter_by',  | 
                                                        |
| 402 | + 'html_id' => 'ee_context_filter_by',  | 
                                                        |
| 403 | + 'html_class' => 'wide',  | 
                                                        |
| 404 | +				'default'    => $this->request->getRequestParam('ee_context_filter_by', 'none_selected', 'title'), | 
                                                        |
| 405 | + ]  | 
                                                        |
| 406 | + );  | 
                                                        |
| 407 | +  | 
                                                        |
| 408 | + return $input->get_html_for_input();  | 
                                                        |
| 409 | + }  | 
                                                        |
| 410 | +  | 
                                                        |
| 411 | +  | 
                                                        |
| 412 | + protected function _ajax_hooks()  | 
                                                        |
| 413 | +	{ | 
                                                        |
| 414 | +		add_action('wp_ajax_activate_messenger', [$this, 'activate_messenger_toggle']); | 
                                                        |
| 415 | +		add_action('wp_ajax_activate_mt', [$this, 'activate_mt_toggle']); | 
                                                        |
| 416 | +		add_action('wp_ajax_ee_msgs_save_settings', [$this, 'save_settings']); | 
                                                        |
| 417 | +		add_action('wp_ajax_ee_msgs_update_mt_form', [$this, 'update_mt_form']); | 
                                                        |
| 418 | +		add_action('wp_ajax_switch_template_pack', [$this, 'switch_template_pack']); | 
                                                        |
| 419 | +		add_action('wp_ajax_toggle_context_template', [$this, 'toggle_context_template']); | 
                                                        |
| 420 | + }  | 
                                                        |
| 421 | +  | 
                                                        |
| 422 | +  | 
                                                        |
| 423 | + protected function _define_page_props()  | 
                                                        |
| 424 | +	{ | 
                                                        |
| 425 | + $this->_admin_page_title = $this->page_label;  | 
                                                        |
| 426 | + $this->_labels = [  | 
                                                        |
| 427 | + 'buttons' => [  | 
                                                        |
| 428 | +				'add'    => esc_html__('Add New Message Template', 'event_espresso'), | 
                                                        |
| 429 | +				'edit'   => esc_html__('Edit Message Template', 'event_espresso'), | 
                                                        |
| 430 | +				'delete' => esc_html__('Delete Message Template', 'event_espresso'), | 
                                                        |
| 431 | + ],  | 
                                                        |
| 432 | +			'publishbox' => esc_html__('Update Actions', 'event_espresso'), | 
                                                        |
| 433 | + ];  | 
                                                        |
| 434 | + }  | 
                                                        |
| 435 | +  | 
                                                        |
| 436 | +  | 
                                                        |
| 437 | + /**  | 
                                                        |
| 438 | + * an array for storing key => value pairs of request actions and their corresponding methods  | 
                                                        |
| 439 | + *  | 
                                                        |
| 440 | + * @access protected  | 
                                                        |
| 441 | + * @return void  | 
                                                        |
| 442 | + */  | 
                                                        |
| 443 | + protected function _set_page_routes()  | 
                                                        |
| 444 | +	{ | 
                                                        |
| 445 | +		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 446 | +		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int'); | 
                                                        |
| 447 | +		$MSG_ID = $this->request->getRequestParam('MSG_ID', 0, 'int'); | 
                                                        |
| 448 | +  | 
                                                        |
| 449 | + $this->_page_routes = [  | 
                                                        |
| 450 | + 'default' => [  | 
                                                        |
| 451 | + 'func' => '_message_queue_list_table',  | 
                                                        |
| 452 | + 'capability' => 'ee_read_global_messages',  | 
                                                        |
| 453 | + ],  | 
                                                        |
| 454 | + 'global_mtps' => [  | 
                                                        |
| 455 | + 'func' => '_ee_default_messages_overview_list_table',  | 
                                                        |
| 456 | + 'capability' => 'ee_read_global_messages',  | 
                                                        |
| 457 | + ],  | 
                                                        |
| 458 | + 'custom_mtps' => [  | 
                                                        |
| 459 | + 'func' => '_custom_mtps_preview',  | 
                                                        |
| 460 | + 'capability' => 'ee_read_messages',  | 
                                                        |
| 461 | + ],  | 
                                                        |
| 462 | + 'add_new_message_template' => [  | 
                                                        |
| 463 | + 'func' => 'add_message_template',  | 
                                                        |
| 464 | + 'capability' => 'ee_edit_messages',  | 
                                                        |
| 465 | + 'noheader' => true,  | 
                                                        |
| 466 | + ],  | 
                                                        |
| 467 | + 'edit_message_template' => [  | 
                                                        |
| 468 | + 'func' => '_edit_message_template',  | 
                                                        |
| 469 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 470 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 471 | + ],  | 
                                                        |
| 472 | + 'preview_message' => [  | 
                                                        |
| 473 | + 'func' => '_preview_message',  | 
                                                        |
| 474 | + 'capability' => 'ee_read_message',  | 
                                                        |
| 475 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 476 | + 'noheader' => true,  | 
                                                        |
| 477 | + 'headers_sent_route' => 'display_preview_message',  | 
                                                        |
| 478 | + ],  | 
                                                        |
| 479 | + 'display_preview_message' => [  | 
                                                        |
| 480 | + 'func' => '_display_preview_message',  | 
                                                        |
| 481 | + 'capability' => 'ee_read_message',  | 
                                                        |
| 482 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 483 | + ],  | 
                                                        |
| 484 | + 'insert_message_template' => [  | 
                                                        |
| 485 | + 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 486 | + 'capability' => 'ee_edit_messages',  | 
                                                        |
| 487 | + 'args' => ['new' => true],  | 
                                                        |
| 488 | + 'noheader' => true,  | 
                                                        |
| 489 | + ],  | 
                                                        |
| 490 | + 'update_message_template' => [  | 
                                                        |
| 491 | + 'func' => '_insert_or_update_message_template',  | 
                                                        |
| 492 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 493 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 494 | + 'args' => ['new' => false],  | 
                                                        |
| 495 | + 'noheader' => true,  | 
                                                        |
| 496 | + ],  | 
                                                        |
| 497 | + 'trash_message_template' => [  | 
                                                        |
| 498 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 499 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 500 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 501 | + 'args' => ['trash' => true, 'all' => true],  | 
                                                        |
| 502 | + 'noheader' => true,  | 
                                                        |
| 503 | + ],  | 
                                                        |
| 504 | + 'trash_message_template_context' => [  | 
                                                        |
| 505 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 506 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 507 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 508 | + 'args' => ['trash' => true],  | 
                                                        |
| 509 | + 'noheader' => true,  | 
                                                        |
| 510 | + ],  | 
                                                        |
| 511 | + 'restore_message_template' => [  | 
                                                        |
| 512 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 513 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 514 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 515 | + 'args' => ['trash' => false, 'all' => true],  | 
                                                        |
| 516 | + 'noheader' => true,  | 
                                                        |
| 517 | + ],  | 
                                                        |
| 518 | + 'restore_message_template_context' => [  | 
                                                        |
| 519 | + 'func' => '_trash_or_restore_message_template',  | 
                                                        |
| 520 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 521 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 522 | + 'args' => ['trash' => false],  | 
                                                        |
| 523 | + 'noheader' => true,  | 
                                                        |
| 524 | + ],  | 
                                                        |
| 525 | + 'delete_message_template' => [  | 
                                                        |
| 526 | + 'func' => '_delete_message_template',  | 
                                                        |
| 527 | + 'capability' => 'ee_delete_message',  | 
                                                        |
| 528 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 529 | + 'noheader' => true,  | 
                                                        |
| 530 | + ],  | 
                                                        |
| 531 | + 'reset_to_default' => [  | 
                                                        |
| 532 | + 'func' => '_reset_to_default_template',  | 
                                                        |
| 533 | + 'capability' => 'ee_edit_message',  | 
                                                        |
| 534 | + 'obj_id' => $GRP_ID,  | 
                                                        |
| 535 | + 'noheader' => true,  | 
                                                        |
| 536 | + ],  | 
                                                        |
| 537 | + 'settings' => [  | 
                                                        |
| 538 | + 'func' => '_settings',  | 
                                                        |
| 539 | + 'capability' => 'manage_options',  | 
                                                        |
| 540 | + ],  | 
                                                        |
| 541 | + 'update_global_settings' => [  | 
                                                        |
| 542 | + 'func' => '_update_global_settings',  | 
                                                        |
| 543 | + 'capability' => 'manage_options',  | 
                                                        |
| 544 | + 'noheader' => true,  | 
                                                        |
| 545 | + ],  | 
                                                        |
| 546 | + 'generate_now' => [  | 
                                                        |
| 547 | + 'func' => '_generate_now',  | 
                                                        |
| 548 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 549 | + 'noheader' => true,  | 
                                                        |
| 550 | + ],  | 
                                                        |
| 551 | + 'generate_and_send_now' => [  | 
                                                        |
| 552 | + 'func' => '_generate_and_send_now',  | 
                                                        |
| 553 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 554 | + 'noheader' => true,  | 
                                                        |
| 555 | + ],  | 
                                                        |
| 556 | + 'queue_for_resending' => [  | 
                                                        |
| 557 | + 'func' => '_queue_for_resending',  | 
                                                        |
| 558 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 559 | + 'noheader' => true,  | 
                                                        |
| 560 | + ],  | 
                                                        |
| 561 | + 'send_now' => [  | 
                                                        |
| 562 | + 'func' => '_send_now',  | 
                                                        |
| 563 | + 'capability' => 'ee_send_message',  | 
                                                        |
| 564 | + 'noheader' => true,  | 
                                                        |
| 565 | + ],  | 
                                                        |
| 566 | + 'delete_ee_message' => [  | 
                                                        |
| 567 | + 'func' => '_delete_ee_messages',  | 
                                                        |
| 568 | + 'capability' => 'ee_delete_messages',  | 
                                                        |
| 569 | + 'noheader' => true,  | 
                                                        |
| 570 | + ],  | 
                                                        |
| 571 | + 'delete_ee_messages' => [  | 
                                                        |
| 572 | + 'func' => '_delete_ee_messages',  | 
                                                        |
| 573 | + 'capability' => 'ee_delete_messages',  | 
                                                        |
| 574 | + 'noheader' => true,  | 
                                                        |
| 575 | + 'obj_id' => $MSG_ID,  | 
                                                        |
| 576 | + ],  | 
                                                        |
| 577 | + ];  | 
                                                        |
| 578 | + }  | 
                                                        |
| 579 | +  | 
                                                        |
| 580 | +  | 
                                                        |
| 581 | + protected function _set_page_config()  | 
                                                        |
| 582 | +	{ | 
                                                        |
| 583 | + $this->_page_config = [  | 
                                                        |
| 584 | + 'default' => [  | 
                                                        |
| 585 | + 'nav' => [  | 
                                                        |
| 586 | +					'label' => esc_html__('Message Activity', 'event_espresso'), | 
                                                        |
| 587 | + 'icon' => 'dashicons-email',  | 
                                                        |
| 588 | + 'order' => 10,  | 
                                                        |
| 589 | + ],  | 
                                                        |
| 590 | + 'list_table' => 'EE_Message_List_Table',  | 
                                                        |
| 591 | + // 'qtips' => array( 'EE_Message_List_Table_Tips' ),  | 
                                                        |
| 592 | + 'require_nonce' => false,  | 
                                                        |
| 593 | + ],  | 
                                                        |
| 594 | + 'global_mtps' => [  | 
                                                        |
| 595 | + 'nav' => [  | 
                                                        |
| 596 | +					'label' => esc_html__('Default Message Templates', 'event_espresso'), | 
                                                        |
| 597 | + 'icon' => 'dashicons-layout',  | 
                                                        |
| 598 | + 'order' => 20,  | 
                                                        |
| 599 | + ],  | 
                                                        |
| 600 | + 'list_table' => 'Messages_Template_List_Table',  | 
                                                        |
| 601 | + 'help_tabs' => [  | 
                                                        |
| 602 | + 'messages_overview_help_tab' => [  | 
                                                        |
| 603 | +						'title'    => esc_html__('Messages Overview', 'event_espresso'), | 
                                                        |
| 604 | + 'filename' => 'messages_overview',  | 
                                                        |
| 605 | + ],  | 
                                                        |
| 606 | + 'messages_overview_messages_table_column_headings_help_tab' => [  | 
                                                        |
| 607 | +						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'), | 
                                                        |
| 608 | + 'filename' => 'messages_overview_table_column_headings',  | 
                                                        |
| 609 | + ],  | 
                                                        |
| 610 | + 'messages_overview_messages_filters_help_tab' => [  | 
                                                        |
| 611 | +						'title'    => esc_html__('Message Filters', 'event_espresso'), | 
                                                        |
| 612 | + 'filename' => 'messages_overview_filters',  | 
                                                        |
| 613 | + ],  | 
                                                        |
| 614 | + 'messages_overview_messages_views_help_tab' => [  | 
                                                        |
| 615 | +						'title'    => esc_html__('Message Views', 'event_espresso'), | 
                                                        |
| 616 | + 'filename' => 'messages_overview_views',  | 
                                                        |
| 617 | + ],  | 
                                                        |
| 618 | + 'message_overview_message_types_help_tab' => [  | 
                                                        |
| 619 | +						'title'    => esc_html__('Message Types', 'event_espresso'), | 
                                                        |
| 620 | + 'filename' => 'messages_overview_types',  | 
                                                        |
| 621 | + ],  | 
                                                        |
| 622 | + 'messages_overview_messengers_help_tab' => [  | 
                                                        |
| 623 | +						'title'    => esc_html__('Messengers', 'event_espresso'), | 
                                                        |
| 624 | + 'filename' => 'messages_overview_messengers',  | 
                                                        |
| 625 | + ],  | 
                                                        |
| 626 | + ],  | 
                                                        |
| 627 | + 'require_nonce' => false,  | 
                                                        |
| 628 | + ],  | 
                                                        |
| 629 | + 'custom_mtps' => [  | 
                                                        |
| 630 | + 'nav' => [  | 
                                                        |
| 631 | +					'label' => esc_html__('Custom Message Templates', 'event_espresso'), | 
                                                        |
| 632 | + 'icon' => 'dashicons-admin-customizer',  | 
                                                        |
| 633 | + 'order' => 30,  | 
                                                        |
| 634 | + ],  | 
                                                        |
| 635 | + 'help_tabs' => [],  | 
                                                        |
| 636 | + 'require_nonce' => false,  | 
                                                        |
| 637 | + ],  | 
                                                        |
| 638 | + 'add_new_message_template' => [  | 
                                                        |
| 639 | + 'nav' => [  | 
                                                        |
| 640 | +					'label'      => esc_html__('Add New Message Templates', 'event_espresso'), | 
                                                        |
| 641 | + 'icon' => 'dashicons-plus-alt',  | 
                                                        |
| 642 | + 'order' => 5,  | 
                                                        |
| 643 | + 'persistent' => false,  | 
                                                        |
| 644 | + ],  | 
                                                        |
| 645 | + 'require_nonce' => false,  | 
                                                        |
| 646 | + ],  | 
                                                        |
| 647 | + 'edit_message_template' => [  | 
                                                        |
| 648 | + 'labels' => [  | 
                                                        |
| 649 | + 'buttons' => [  | 
                                                        |
| 650 | +						'reset' => esc_html__('Reset Templates', 'event_espresso'), | 
                                                        |
| 651 | + ],  | 
                                                        |
| 652 | +					'publishbox' => esc_html__('Update Actions', 'event_espresso'), | 
                                                        |
| 653 | + ],  | 
                                                        |
| 654 | + 'nav' => [  | 
                                                        |
| 655 | +					'label'      => esc_html__('Edit Message Templates', 'event_espresso'), | 
                                                        |
| 656 | + 'icon' => 'dashicons-edit-large',  | 
                                                        |
| 657 | + 'order' => 5,  | 
                                                        |
| 658 | + 'persistent' => false,  | 
                                                        |
| 659 | + 'url' => '',  | 
                                                        |
| 660 | + ],  | 
                                                        |
| 661 | + 'metaboxes' => ['_publish_post_box', '_register_edit_meta_boxes'],  | 
                                                        |
| 662 | + 'has_metaboxes' => true,  | 
                                                        |
| 663 | + 'help_tabs' => [  | 
                                                        |
| 664 | + 'edit_message_template' => [  | 
                                                        |
| 665 | +						'title'    => esc_html__('Message Template Editor', 'event_espresso'), | 
                                                        |
| 666 | + 'callback' => 'edit_message_template_help_tab',  | 
                                                        |
| 667 | + ],  | 
                                                        |
| 668 | + 'message_templates_help_tab' => [  | 
                                                        |
| 669 | +						'title'    => esc_html__('Message Templates', 'event_espresso'), | 
                                                        |
| 670 | + 'filename' => 'messages_templates',  | 
                                                        |
| 671 | + ],  | 
                                                        |
| 672 | + 'message_template_shortcodes' => [  | 
                                                        |
| 673 | +						'title'    => esc_html__('Message Shortcodes', 'event_espresso'), | 
                                                        |
| 674 | + 'callback' => 'message_template_shortcodes_help_tab',  | 
                                                        |
| 675 | + ],  | 
                                                        |
| 676 | + 'message_preview_help_tab' => [  | 
                                                        |
| 677 | +						'title'    => esc_html__('Message Preview', 'event_espresso'), | 
                                                        |
| 678 | + 'filename' => 'messages_preview',  | 
                                                        |
| 679 | + ],  | 
                                                        |
| 680 | + 'messages_overview_other_help_tab' => [  | 
                                                        |
| 681 | +						'title'    => esc_html__('Messages Other', 'event_espresso'), | 
                                                        |
| 682 | + 'filename' => 'messages_overview_other',  | 
                                                        |
| 683 | + ],  | 
                                                        |
| 684 | + ],  | 
                                                        |
| 685 | + 'require_nonce' => false,  | 
                                                        |
| 686 | + ],  | 
                                                        |
| 687 | + 'display_preview_message' => [  | 
                                                        |
| 688 | + 'nav' => [  | 
                                                        |
| 689 | +					'label'      => esc_html__('Message Preview', 'event_espresso'), | 
                                                        |
| 690 | + 'icon' => 'dashicons-visibility-bar',  | 
                                                        |
| 691 | + 'order' => 5,  | 
                                                        |
| 692 | + 'url' => '',  | 
                                                        |
| 693 | + 'persistent' => false,  | 
                                                        |
| 694 | + ],  | 
                                                        |
| 695 | + 'help_tabs' => [  | 
                                                        |
| 696 | + 'preview_message' => [  | 
                                                        |
| 697 | +						'title'    => esc_html__('About Previews', 'event_espresso'), | 
                                                        |
| 698 | + 'callback' => 'preview_message_help_tab',  | 
                                                        |
| 699 | + ],  | 
                                                        |
| 700 | + ],  | 
                                                        |
| 701 | + 'require_nonce' => false,  | 
                                                        |
| 702 | + ],  | 
                                                        |
| 703 | + 'settings' => [  | 
                                                        |
| 704 | + 'nav' => [  | 
                                                        |
| 705 | +					'label' => esc_html__('Settings', 'event_espresso'), | 
                                                        |
| 706 | + 'icon' => 'dashicons-admin-generic',  | 
                                                        |
| 707 | + 'order' => 40,  | 
                                                        |
| 708 | + ],  | 
                                                        |
| 709 | + 'metaboxes' => ['_messages_settings_metaboxes'],  | 
                                                        |
| 710 | + 'help_tabs' => [  | 
                                                        |
| 711 | + 'messages_settings_help_tab' => [  | 
                                                        |
| 712 | +						'title'    => esc_html__('Messages Settings', 'event_espresso'), | 
                                                        |
| 713 | + 'filename' => 'messages_settings',  | 
                                                        |
| 714 | + ],  | 
                                                        |
| 715 | + 'messages_settings_message_types_help_tab' => [  | 
                                                        |
| 716 | +						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'), | 
                                                        |
| 717 | + 'filename' => 'messages_settings_message_types',  | 
                                                        |
| 718 | + ],  | 
                                                        |
| 719 | + 'messages_settings_messengers_help_tab' => [  | 
                                                        |
| 720 | +						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'), | 
                                                        |
| 721 | + 'filename' => 'messages_settings_messengers',  | 
                                                        |
| 722 | + ],  | 
                                                        |
| 723 | + ],  | 
                                                        |
| 724 | + 'require_nonce' => false,  | 
                                                        |
| 725 | + ],  | 
                                                        |
| 726 | + ];  | 
                                                        |
| 727 | + }  | 
                                                        |
| 728 | +  | 
                                                        |
| 729 | +  | 
                                                        |
| 730 | + protected function _add_screen_options()  | 
                                                        |
| 731 | +	{ | 
                                                        |
| 732 | + // todo  | 
                                                        |
| 733 | + }  | 
                                                        |
| 734 | +  | 
                                                        |
| 735 | +  | 
                                                        |
| 736 | + protected function _add_screen_options_global_mtps()  | 
                                                        |
| 737 | +	{ | 
                                                        |
| 738 | + /**  | 
                                                        |
| 739 | + * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options  | 
                                                        |
| 740 | + * uses the $_admin_page_title property and we want different outputs in the different spots.  | 
                                                        |
| 741 | + */  | 
                                                        |
| 742 | + $page_title = $this->_admin_page_title;  | 
                                                        |
| 743 | +		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso'); | 
                                                        |
| 744 | + $this->_per_page_screen_option();  | 
                                                        |
| 745 | + $this->_admin_page_title = $page_title;  | 
                                                        |
| 746 | + }  | 
                                                        |
| 747 | +  | 
                                                        |
| 748 | +  | 
                                                        |
| 749 | + protected function _add_screen_options_default()  | 
                                                        |
| 750 | +	{ | 
                                                        |
| 751 | +		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso'); | 
                                                        |
| 752 | + $this->_per_page_screen_option();  | 
                                                        |
| 753 | + }  | 
                                                        |
| 754 | +  | 
                                                        |
| 755 | +  | 
                                                        |
| 756 | + // none of the below group are currently used for Messages  | 
                                                        |
| 757 | + protected function _add_feature_pointers()  | 
                                                        |
| 758 | +	{ | 
                                                        |
| 759 | + }  | 
                                                        |
| 760 | +  | 
                                                        |
| 761 | +  | 
                                                        |
| 762 | + public function admin_init()  | 
                                                        |
| 763 | +	{ | 
                                                        |
| 764 | + }  | 
                                                        |
| 765 | +  | 
                                                        |
| 766 | +  | 
                                                        |
| 767 | + public function admin_notices()  | 
                                                        |
| 768 | +	{ | 
                                                        |
| 769 | + }  | 
                                                        |
| 770 | +  | 
                                                        |
| 771 | +  | 
                                                        |
| 772 | + public function admin_footer_scripts()  | 
                                                        |
| 773 | +	{ | 
                                                        |
| 774 | + }  | 
                                                        |
| 775 | +  | 
                                                        |
| 776 | +  | 
                                                        |
| 777 | + public function messages_help_tab()  | 
                                                        |
| 778 | +	{ | 
                                                        |
| 779 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 780 | + }  | 
                                                        |
| 781 | +  | 
                                                        |
| 782 | +  | 
                                                        |
| 783 | + public function messengers_help_tab()  | 
                                                        |
| 784 | +	{ | 
                                                        |
| 785 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 786 | + }  | 
                                                        |
| 787 | +  | 
                                                        |
| 788 | +  | 
                                                        |
| 789 | + public function message_types_help_tab()  | 
                                                        |
| 790 | +	{ | 
                                                        |
| 791 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 792 | + }  | 
                                                        |
| 793 | +  | 
                                                        |
| 794 | +  | 
                                                        |
| 795 | + public function messages_overview_help_tab()  | 
                                                        |
| 796 | +	{ | 
                                                        |
| 797 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 798 | + }  | 
                                                        |
| 799 | +  | 
                                                        |
| 800 | +  | 
                                                        |
| 801 | + public function message_templates_help_tab()  | 
                                                        |
| 802 | +	{ | 
                                                        |
| 803 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 804 | + }  | 
                                                        |
| 805 | +  | 
                                                        |
| 806 | +  | 
                                                        |
| 807 | + public function edit_message_template_help_tab()  | 
                                                        |
| 808 | +	{ | 
                                                        |
| 809 | + $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'  | 
                                                        |
| 810 | +						. esc_attr__('Editor Title', 'event_espresso') | 
                                                        |
| 811 | + . '" />';  | 
                                                        |
| 812 | + $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'  | 
                                                        |
| 813 | +						. esc_attr__('Context Switcher and Preview', 'event_espresso') | 
                                                        |
| 814 | + . '" />';  | 
                                                        |
| 815 | + $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'  | 
                                                        |
| 816 | +						. esc_attr__('Message Template Form Fields', 'event_espresso') | 
                                                        |
| 817 | + . '" />';  | 
                                                        |
| 818 | + $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'  | 
                                                        |
| 819 | +						. esc_attr__('Shortcodes Metabox', 'event_espresso') | 
                                                        |
| 820 | + . '" />';  | 
                                                        |
| 821 | + $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'  | 
                                                        |
| 822 | +						. esc_attr__('Publish Metabox', 'event_espresso') | 
                                                        |
| 823 | + . '" />';  | 
                                                        |
| 824 | + EEH_Template::display_template(  | 
                                                        |
| 825 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 826 | + $args  | 
                                                        |
| 827 | + );  | 
                                                        |
| 828 | + }  | 
                                                        |
| 829 | +  | 
                                                        |
| 830 | +  | 
                                                        |
| 831 | + /**  | 
                                                        |
| 832 | + * @throws ReflectionException  | 
                                                        |
| 833 | + * @throws EE_Error  | 
                                                        |
| 834 | + */  | 
                                                        |
| 835 | + public function message_template_shortcodes_help_tab()  | 
                                                        |
| 836 | +	{ | 
                                                        |
| 837 | + $this->_set_shortcodes();  | 
                                                        |
| 838 | + $args['shortcodes'] = $this->_shortcodes;  | 
                                                        |
| 839 | + EEH_Template::display_template(  | 
                                                        |
| 840 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 841 | + $args  | 
                                                        |
| 842 | + );  | 
                                                        |
| 843 | + }  | 
                                                        |
| 844 | +  | 
                                                        |
| 845 | +  | 
                                                        |
| 846 | + public function preview_message_help_tab()  | 
                                                        |
| 847 | +	{ | 
                                                        |
| 848 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 849 | + }  | 
                                                        |
| 850 | +  | 
                                                        |
| 851 | +  | 
                                                        |
| 852 | + public function settings_help_tab()  | 
                                                        |
| 853 | +	{ | 
                                                        |
| 854 | + $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'  | 
                                                        |
| 855 | +						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 856 | + $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'  | 
                                                        |
| 857 | +						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 858 | + $args['img3'] = '<div class="ee-switch">'  | 
                                                        |
| 859 | + . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'  | 
                                                        |
| 860 | + . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'  | 
                                                        |
| 861 | + . '</div>';  | 
                                                        |
| 862 | + $args['img4'] = '<div class="switch">'  | 
                                                        |
| 863 | + . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'  | 
                                                        |
| 864 | + . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'  | 
                                                        |
| 865 | + . '</div>';  | 
                                                        |
| 866 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 867 | + }  | 
                                                        |
| 868 | +  | 
                                                        |
| 869 | +  | 
                                                        |
| 870 | + public function load_scripts_styles()  | 
                                                        |
| 871 | +	{ | 
                                                        |
| 872 | +		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 873 | +		wp_enqueue_style('espresso_ee_msg'); | 
                                                        |
| 874 | +  | 
                                                        |
| 875 | + wp_register_script(  | 
                                                        |
| 876 | + 'ee-messages-settings',  | 
                                                        |
| 877 | + EE_MSG_ASSETS_URL . 'ee-messages-settings.js',  | 
                                                        |
| 878 | + ['jquery-ui-droppable', 'ee-serialize-full-array'],  | 
                                                        |
| 879 | + EVENT_ESPRESSO_VERSION,  | 
                                                        |
| 880 | + true  | 
                                                        |
| 881 | + );  | 
                                                        |
| 882 | + wp_register_script(  | 
                                                        |
| 883 | + 'ee-msg-list-table-js',  | 
                                                        |
| 884 | + EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',  | 
                                                        |
| 885 | + ['ee-dialog'],  | 
                                                        |
| 886 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 887 | + );  | 
                                                        |
| 888 | + }  | 
                                                        |
| 889 | +  | 
                                                        |
| 890 | +  | 
                                                        |
| 891 | + public function load_scripts_styles_default()  | 
                                                        |
| 892 | +	{ | 
                                                        |
| 893 | +		wp_enqueue_script('ee-msg-list-table-js'); | 
                                                        |
| 894 | + }  | 
                                                        |
| 895 | +  | 
                                                        |
| 896 | +  | 
                                                        |
| 897 | + public function wp_editor_css($mce_css)  | 
                                                        |
| 898 | +	{ | 
                                                        |
| 899 | + // if we're on the edit_message_template route  | 
                                                        |
| 900 | +		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) { | 
                                                        |
| 901 | + $message_type_name = $this->_active_message_type_name;  | 
                                                        |
| 902 | +  | 
                                                        |
| 903 | + // we're going to REPLACE the existing mce css  | 
                                                        |
| 904 | + // we need to get the css file location from the active messenger  | 
                                                        |
| 905 | + $mce_css = $this->_active_messenger->get_variation(  | 
                                                        |
| 906 | + $this->_template_pack,  | 
                                                        |
| 907 | + $message_type_name,  | 
                                                        |
| 908 | + true,  | 
                                                        |
| 909 | + 'wpeditor',  | 
                                                        |
| 910 | + $this->_variation  | 
                                                        |
| 911 | + );  | 
                                                        |
| 912 | + }  | 
                                                        |
| 913 | +  | 
                                                        |
| 914 | + return $mce_css;  | 
                                                        |
| 915 | + }  | 
                                                        |
| 916 | +  | 
                                                        |
| 917 | +  | 
                                                        |
| 918 | + /**  | 
                                                        |
| 919 | + * @throws EE_Error  | 
                                                        |
| 920 | + * @throws ReflectionException  | 
                                                        |
| 921 | + */  | 
                                                        |
| 922 | + public function load_scripts_styles_edit_message_template()  | 
                                                        |
| 923 | +	{ | 
                                                        |
| 924 | +  | 
                                                        |
| 925 | + $this->_set_shortcodes();  | 
                                                        |
| 926 | +  | 
                                                        |
| 927 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 928 | + esc_html__(  | 
                                                        |
| 929 | + 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.',  | 
                                                        |
| 930 | + 'event_espresso'  | 
                                                        |
| 931 | + ),  | 
                                                        |
| 932 | + $this->_message_template_group->messenger_obj()->label['singular'],  | 
                                                        |
| 933 | + $this->_message_template_group->message_type_obj()->label['singular']  | 
                                                        |
| 934 | + );  | 
                                                        |
| 935 | + EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(  | 
                                                        |
| 936 | + 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?',  | 
                                                        |
| 937 | + 'event_espresso'  | 
                                                        |
| 938 | + );  | 
                                                        |
| 939 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__(  | 
                                                        |
| 940 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',  | 
                                                        |
| 941 | + 'event_espresso'  | 
                                                        |
| 942 | + );  | 
                                                        |
| 943 | +  | 
                                                        |
| 944 | + wp_register_script(  | 
                                                        |
| 945 | + 'ee_msgs_edit_js',  | 
                                                        |
| 946 | + EE_MSG_ASSETS_URL . 'ee_message_editor.js',  | 
                                                        |
| 947 | + ['jquery'],  | 
                                                        |
| 948 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 949 | + );  | 
                                                        |
| 950 | +  | 
                                                        |
| 951 | +		wp_enqueue_script('ee_admin_js'); | 
                                                        |
| 952 | +		wp_enqueue_script('ee_msgs_edit_js'); | 
                                                        |
| 953 | +  | 
                                                        |
| 954 | + // add in special css for tiny_mce  | 
                                                        |
| 955 | +		add_filter('mce_css', [$this, 'wp_editor_css']); | 
                                                        |
| 956 | + }  | 
                                                        |
| 957 | +  | 
                                                        |
| 958 | +  | 
                                                        |
| 959 | + /**  | 
                                                        |
| 960 | + * @throws EE_Error  | 
                                                        |
| 961 | + * @throws ReflectionException  | 
                                                        |
| 962 | + */  | 
                                                        |
| 963 | + public function load_scripts_styles_display_preview_message()  | 
                                                        |
| 964 | +	{ | 
                                                        |
| 965 | + $this->_set_message_template_group();  | 
                                                        |
| 966 | +		if ($this->_active_messenger_name) { | 
                                                        |
| 967 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 968 | + $this->_active_messenger_name  | 
                                                        |
| 969 | + );  | 
                                                        |
| 970 | + }  | 
                                                        |
| 971 | +  | 
                                                        |
| 972 | + wp_enqueue_style(  | 
                                                        |
| 973 | + 'espresso_preview_css',  | 
                                                        |
| 974 | + $this->_active_messenger->get_variation(  | 
                                                        |
| 975 | + $this->_template_pack,  | 
                                                        |
| 976 | + $this->_active_message_type_name,  | 
                                                        |
| 977 | + true,  | 
                                                        |
| 978 | + 'preview',  | 
                                                        |
| 979 | + $this->_variation  | 
                                                        |
| 980 | + )  | 
                                                        |
| 981 | + );  | 
                                                        |
| 982 | + }  | 
                                                        |
| 983 | +  | 
                                                        |
| 984 | +  | 
                                                        |
| 985 | + public function load_scripts_styles_settings()  | 
                                                        |
| 986 | +	{ | 
                                                        |
| 987 | + wp_register_style(  | 
                                                        |
| 988 | + 'ee-message-settings',  | 
                                                        |
| 989 | + EE_MSG_ASSETS_URL . 'ee_message_settings.css',  | 
                                                        |
| 990 | + [],  | 
                                                        |
| 991 | + EVENT_ESPRESSO_VERSION  | 
                                                        |
| 992 | + );  | 
                                                        |
| 993 | +		wp_enqueue_style('ee-text-links'); | 
                                                        |
| 994 | +		wp_enqueue_style('ee-message-settings'); | 
                                                        |
| 995 | +		wp_enqueue_script('ee-messages-settings'); | 
                                                        |
| 996 | + }  | 
                                                        |
| 997 | +  | 
                                                        |
| 998 | +  | 
                                                        |
| 999 | + /**  | 
                                                        |
| 1000 | + * set views array for List Table  | 
                                                        |
| 1001 | + */  | 
                                                        |
| 1002 | + public function _set_list_table_views_global_mtps()  | 
                                                        |
| 1003 | +	{ | 
                                                        |
| 1004 | + $this->_views = [  | 
                                                        |
| 1005 | + 'in_use' => [  | 
                                                        |
| 1006 | + 'slug' => 'in_use',  | 
                                                        |
| 1007 | +				'label' => esc_html__('In Use', 'event_espresso'), | 
                                                        |
| 1008 | + 'count' => 0,  | 
                                                        |
| 1009 | + ],  | 
                                                        |
| 1010 | + ];  | 
                                                        |
| 1011 | + }  | 
                                                        |
| 1012 | +  | 
                                                        |
| 1013 | +  | 
                                                        |
| 1014 | + /**  | 
                                                        |
| 1015 | + * Set views array for the Custom Template List Table  | 
                                                        |
| 1016 | + */  | 
                                                        |
| 1017 | + public function _set_list_table_views_custom_mtps()  | 
                                                        |
| 1018 | +	{ | 
                                                        |
| 1019 | + $this->_set_list_table_views_global_mtps();  | 
                                                        |
| 1020 | + $this->_views['in_use']['bulk_action'] = [  | 
                                                        |
| 1021 | +			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'), | 
                                                        |
| 1022 | + ];  | 
                                                        |
| 1023 | + }  | 
                                                        |
| 1024 | +  | 
                                                        |
| 1025 | +  | 
                                                        |
| 1026 | + /**  | 
                                                        |
| 1027 | + * set views array for message queue list table  | 
                                                        |
| 1028 | + *  | 
                                                        |
| 1029 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1030 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1031 | + * @throws InvalidArgumentException  | 
                                                        |
| 1032 | + * @throws EE_Error  | 
                                                        |
| 1033 | + * @throws ReflectionException  | 
                                                        |
| 1034 | + */  | 
                                                        |
| 1035 | + public function _set_list_table_views_default()  | 
                                                        |
| 1036 | +	{ | 
                                                        |
| 1037 | +		EE_Registry::instance()->load_helper('Template'); | 
                                                        |
| 1038 | +  | 
                                                        |
| 1039 | + $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 1040 | + 'ee_send_message',  | 
                                                        |
| 1041 | + 'message_list_table_bulk_actions'  | 
                                                        |
| 1042 | + )  | 
                                                        |
| 1043 | + ? [  | 
                                                        |
| 1044 | +				'generate_now'          => esc_html__('Generate Now', 'event_espresso'), | 
                                                        |
| 1045 | +				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'), | 
                                                        |
| 1046 | +				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'), | 
                                                        |
| 1047 | +				'send_now'              => esc_html__('Send Now', 'event_espresso'), | 
                                                        |
| 1048 | + ]  | 
                                                        |
| 1049 | + : [];  | 
                                                        |
| 1050 | +  | 
                                                        |
| 1051 | + $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 1052 | + 'ee_delete_messages',  | 
                                                        |
| 1053 | + 'message_list_table_bulk_actions'  | 
                                                        |
| 1054 | + )  | 
                                                        |
| 1055 | +			? ['delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso')] | 
                                                        |
| 1056 | + : [];  | 
                                                        |
| 1057 | +  | 
                                                        |
| 1058 | +  | 
                                                        |
| 1059 | + $this->_views = [  | 
                                                        |
| 1060 | + 'all' => [  | 
                                                        |
| 1061 | + 'slug' => 'all',  | 
                                                        |
| 1062 | +				'label'       => esc_html__('All', 'event_espresso'), | 
                                                        |
| 1063 | + 'count' => 0,  | 
                                                        |
| 1064 | + 'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),  | 
                                                        |
| 1065 | + ],  | 
                                                        |
| 1066 | + ];  | 
                                                        |
| 1067 | +  | 
                                                        |
| 1068 | +  | 
                                                        |
| 1069 | +		foreach ($this->getMsgModel()->all_statuses() as $status) { | 
                                                        |
| 1070 | +			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) { | 
                                                        |
| 1071 | + continue;  | 
                                                        |
| 1072 | + }  | 
                                                        |
| 1073 | + $status_bulk_actions = $common_bulk_actions;  | 
                                                        |
| 1074 | + // unset bulk actions not applying to status  | 
                                                        |
| 1075 | +			if (! empty($status_bulk_actions)) { | 
                                                        |
| 1076 | +				switch ($status) { | 
                                                        |
| 1077 | + case EEM_Message::status_idle:  | 
                                                        |
| 1078 | + case EEM_Message::status_resend:  | 
                                                        |
| 1079 | + $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];  | 
                                                        |
| 1080 | + break;  | 
                                                        |
| 1081 | +  | 
                                                        |
| 1082 | + case EEM_Message::status_failed:  | 
                                                        |
| 1083 | + case EEM_Message::status_debug_only:  | 
                                                        |
| 1084 | + case EEM_Message::status_messenger_executing:  | 
                                                        |
| 1085 | + $status_bulk_actions = [];  | 
                                                        |
| 1086 | + break;  | 
                                                        |
| 1087 | +  | 
                                                        |
| 1088 | + case EEM_Message::status_incomplete:  | 
                                                        |
| 1089 | + unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);  | 
                                                        |
| 1090 | + break;  | 
                                                        |
| 1091 | +  | 
                                                        |
| 1092 | + case EEM_Message::status_retry:  | 
                                                        |
| 1093 | + case EEM_Message::status_sent:  | 
                                                        |
| 1094 | + unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);  | 
                                                        |
| 1095 | + break;  | 
                                                        |
| 1096 | + }  | 
                                                        |
| 1097 | + }  | 
                                                        |
| 1098 | +  | 
                                                        |
| 1099 | + // skip adding messenger executing status to views because it will be included with the Failed view.  | 
                                                        |
| 1100 | +			if ($status === EEM_Message::status_messenger_executing) { | 
                                                        |
| 1101 | + continue;  | 
                                                        |
| 1102 | + }  | 
                                                        |
| 1103 | +  | 
                                                        |
| 1104 | + $this->_views[ strtolower($status) ] = [  | 
                                                        |
| 1105 | + 'slug' => strtolower($status),  | 
                                                        |
| 1106 | + 'label' => EEH_Template::pretty_status($status, false, 'sentence'),  | 
                                                        |
| 1107 | + 'count' => 0,  | 
                                                        |
| 1108 | + 'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),  | 
                                                        |
| 1109 | + ];  | 
                                                        |
| 1110 | + }  | 
                                                        |
| 1111 | + }  | 
                                                        |
| 1112 | +  | 
                                                        |
| 1113 | +  | 
                                                        |
| 1114 | + /**  | 
                                                        |
| 1115 | + * @throws EE_Error  | 
                                                        |
| 1116 | + */  | 
                                                        |
| 1117 | + protected function _ee_default_messages_overview_list_table()  | 
                                                        |
| 1118 | +	{ | 
                                                        |
| 1119 | +		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso'); | 
                                                        |
| 1120 | + $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 1121 | + }  | 
                                                        |
| 1122 | +  | 
                                                        |
| 1123 | +  | 
                                                        |
| 1124 | + /**  | 
                                                        |
| 1125 | + * @throws EE_Error  | 
                                                        |
| 1126 | + * @throws ReflectionException  | 
                                                        |
| 1127 | + */  | 
                                                        |
| 1128 | + protected function _message_queue_list_table()  | 
                                                        |
| 1129 | +	{ | 
                                                        |
| 1130 | +		$this->_search_btn_label                   = esc_html__('Message Activity', 'event_espresso'); | 
                                                        |
| 1131 | + $this->_template_args['per_column'] = 6;  | 
                                                        |
| 1132 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());  | 
                                                        |
| 1133 | + $message_results = trim(EEM_Message::instance()->get_pretty_label_for_results());  | 
                                                        |
| 1134 | +		$this->_template_args['before_list_table'] = ! empty($message_results) ? "<h3>{$message_results}</h3>" : ''; | 
                                                        |
| 1135 | + $this->display_admin_list_table_page_with_no_sidebar();  | 
                                                        |
| 1136 | + }  | 
                                                        |
| 1137 | +  | 
                                                        |
| 1138 | +  | 
                                                        |
| 1139 | + /**  | 
                                                        |
| 1140 | + * @throws EE_Error  | 
                                                        |
| 1141 | + */  | 
                                                        |
| 1142 | + protected function _message_legend_items()  | 
                                                        |
| 1143 | +	{ | 
                                                        |
| 1144 | +  | 
                                                        |
| 1145 | + $action_css_classes = EEH_MSG_Template::get_message_action_icons();  | 
                                                        |
| 1146 | + $action_items = [];  | 
                                                        |
| 1147 | +  | 
                                                        |
| 1148 | +		foreach ($action_css_classes as $action_item => $action_details) { | 
                                                        |
| 1149 | +			if ($action_item === 'see_notifications_for') { | 
                                                        |
| 1150 | + continue;  | 
                                                        |
| 1151 | + }  | 
                                                        |
| 1152 | + $action_items[ $action_item ] = [  | 
                                                        |
| 1153 | + 'class' => $action_details['css_class'],  | 
                                                        |
| 1154 | + 'desc' => $action_details['label'],  | 
                                                        |
| 1155 | + ];  | 
                                                        |
| 1156 | + }  | 
                                                        |
| 1157 | +  | 
                                                        |
| 1158 | + /** @var array $status_items status legend setup */  | 
                                                        |
| 1159 | + $status_items = [  | 
                                                        |
| 1160 | + 'sent_status' => [  | 
                                                        |
| 1161 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,  | 
                                                        |
| 1162 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),  | 
                                                        |
| 1163 | + ],  | 
                                                        |
| 1164 | + 'idle_status' => [  | 
                                                        |
| 1165 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,  | 
                                                        |
| 1166 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),  | 
                                                        |
| 1167 | + ],  | 
                                                        |
| 1168 | + 'failed_status' => [  | 
                                                        |
| 1169 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,  | 
                                                        |
| 1170 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),  | 
                                                        |
| 1171 | + ],  | 
                                                        |
| 1172 | + 'messenger_executing_status' => [  | 
                                                        |
| 1173 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 1174 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),  | 
                                                        |
| 1175 | + ],  | 
                                                        |
| 1176 | + 'resend_status' => [  | 
                                                        |
| 1177 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,  | 
                                                        |
| 1178 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),  | 
                                                        |
| 1179 | + ],  | 
                                                        |
| 1180 | + 'incomplete_status' => [  | 
                                                        |
| 1181 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,  | 
                                                        |
| 1182 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),  | 
                                                        |
| 1183 | + ],  | 
                                                        |
| 1184 | + 'retry_status' => [  | 
                                                        |
| 1185 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,  | 
                                                        |
| 1186 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),  | 
                                                        |
| 1187 | + ],  | 
                                                        |
| 1188 | + ];  | 
                                                        |
| 1189 | +		if (EEM_Message::debug()) { | 
                                                        |
| 1190 | + $status_items['debug_only_status'] = [  | 
                                                        |
| 1191 | + 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,  | 
                                                        |
| 1192 | + 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),  | 
                                                        |
| 1193 | + ];  | 
                                                        |
| 1194 | + }  | 
                                                        |
| 1195 | +  | 
                                                        |
| 1196 | + return array_merge($action_items, $status_items);  | 
                                                        |
| 1197 | + }  | 
                                                        |
| 1198 | +  | 
                                                        |
| 1199 | +  | 
                                                        |
| 1200 | + /**  | 
                                                        |
| 1201 | + * @throws EE_Error  | 
                                                        |
| 1202 | + */  | 
                                                        |
| 1203 | + protected function _custom_mtps_preview()  | 
                                                        |
| 1204 | +	{ | 
                                                        |
| 1205 | +		$this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        |
| 1206 | + $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'  | 
                                                        |
| 1207 | + . ' alt="' . esc_attr__(  | 
                                                        |
| 1208 | + 'Preview Custom Message Templates screenshot',  | 
                                                        |
| 1209 | + 'event_espresso'  | 
                                                        |
| 1210 | + ) . '" />';  | 
                                                        |
| 1211 | + $this->_template_args['preview_text'] = '<strong>'  | 
                                                        |
| 1212 | + . esc_html__(  | 
                                                        |
| 1213 | + 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',  | 
                                                        |
| 1214 | + 'event_espresso'  | 
                                                        |
| 1215 | + )  | 
                                                        |
| 1216 | + . '</strong>';  | 
                                                        |
| 1217 | +  | 
                                                        |
| 1218 | +		$this->display_admin_caf_preview_page('custom_message_types', false); | 
                                                        |
| 1219 | + }  | 
                                                        |
| 1220 | +  | 
                                                        |
| 1221 | +  | 
                                                        |
| 1222 | + /**  | 
                                                        |
| 1223 | + * get_message_templates  | 
                                                        |
| 1224 | + * This gets all the message templates for listing on the overview list.  | 
                                                        |
| 1225 | + *  | 
                                                        |
| 1226 | + * @access public  | 
                                                        |
| 1227 | + * @param int $per_page the amount of templates groups to show per page  | 
                                                        |
| 1228 | + * @param string $type the current _view we're getting templates for  | 
                                                        |
| 1229 | + * @param bool $count return count?  | 
                                                        |
| 1230 | + * @param bool $all disregard any paging info (get all data);  | 
                                                        |
| 1231 | + * @param bool $global whether to return just global (true) or custom templates (false)  | 
                                                        |
| 1232 | + * @return array  | 
                                                        |
| 1233 | + * @throws EE_Error  | 
                                                        |
| 1234 | + * @throws InvalidArgumentException  | 
                                                        |
| 1235 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1236 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1237 | + */  | 
                                                        |
| 1238 | + public function get_message_templates(  | 
                                                        |
| 1239 | + $per_page = 10,  | 
                                                        |
| 1240 | + $type = 'in_use',  | 
                                                        |
| 1241 | + $count = false,  | 
                                                        |
| 1242 | + $all = false,  | 
                                                        |
| 1243 | + $global = true  | 
                                                        |
| 1244 | +	) { | 
                                                        |
| 1245 | +		$orderby = $this->request->getRequestParam('orderby', 'GRP_ID'); | 
                                                        |
| 1246 | +		$this->request->setRequestParam('orderby', $orderby); | 
                                                        |
| 1247 | +  | 
                                                        |
| 1248 | +		$order        = $this->request->getRequestParam('order', 'ASC'); | 
                                                        |
| 1249 | +		$current_page = $this->request->getRequestParam('paged', 1, 'int'); | 
                                                        |
| 1250 | +		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int'); | 
                                                        |
| 1251 | +  | 
                                                        |
| 1252 | + $offset = ($current_page - 1) * $per_page;  | 
                                                        |
| 1253 | + $limit = $all ? null : [$offset, $per_page];  | 
                                                        |
| 1254 | +  | 
                                                        |
| 1255 | + // options will match what is in the _views array property  | 
                                                        |
| 1256 | + return $type === 'in_use'  | 
                                                        |
| 1257 | + ? $this->getMtgModel()->get_all_active_message_templates(  | 
                                                        |
| 1258 | + $orderby,  | 
                                                        |
| 1259 | + $order,  | 
                                                        |
| 1260 | + $limit,  | 
                                                        |
| 1261 | + $count,  | 
                                                        |
| 1262 | + $global,  | 
                                                        |
| 1263 | + true  | 
                                                        |
| 1264 | + )  | 
                                                        |
| 1265 | + : $this->getMtgModel()->get_all_trashed_grouped_message_templates(  | 
                                                        |
| 1266 | + $orderby,  | 
                                                        |
| 1267 | + $order,  | 
                                                        |
| 1268 | + $limit,  | 
                                                        |
| 1269 | + $count,  | 
                                                        |
| 1270 | + $global  | 
                                                        |
| 1271 | + );  | 
                                                        |
| 1272 | + }  | 
                                                        |
| 1273 | +  | 
                                                        |
| 1274 | +  | 
                                                        |
| 1275 | + /**  | 
                                                        |
| 1276 | + * filters etc might need a list of installed message_types  | 
                                                        |
| 1277 | + *  | 
                                                        |
| 1278 | + * @return array an array of message type objects  | 
                                                        |
| 1279 | + */  | 
                                                        |
| 1280 | + public function get_installed_message_types()  | 
                                                        |
| 1281 | +	{ | 
                                                        |
| 1282 | + $installed_message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 1283 | + $installed = [];  | 
                                                        |
| 1284 | +  | 
                                                        |
| 1285 | +		foreach ($installed_message_types as $message_type) { | 
                                                        |
| 1286 | + $installed[ $message_type->name ] = $message_type;  | 
                                                        |
| 1287 | + }  | 
                                                        |
| 1288 | +  | 
                                                        |
| 1289 | + return $installed;  | 
                                                        |
| 1290 | + }  | 
                                                        |
| 1291 | +  | 
                                                        |
| 1292 | +  | 
                                                        |
| 1293 | + /**  | 
                                                        |
| 1294 | + * This is used when creating a custom template. All Custom Templates start based off another template.  | 
                                                        |
| 1295 | + *  | 
                                                        |
| 1296 | + * @param string $message_type  | 
                                                        |
| 1297 | + * @param string $messenger  | 
                                                        |
| 1298 | + * @param string $GRP_ID  | 
                                                        |
| 1299 | + *  | 
                                                        |
| 1300 | + * @throws EE_error  | 
                                                        |
| 1301 | + * @throws ReflectionException  | 
                                                        |
| 1302 | + */  | 
                                                        |
| 1303 | + public function add_message_template($message_type = '', $messenger = '', $GRP_ID = '')  | 
                                                        |
| 1304 | +	{ | 
                                                        |
| 1305 | + // set values override any request data  | 
                                                        |
| 1306 | + $message_type = ! empty($message_type) ? $message_type : $this->_active_message_type_name;  | 
                                                        |
| 1307 | + $messenger = ! empty($messenger) ? $messenger : $this->_active_messenger_name;  | 
                                                        |
| 1308 | +		$GRP_ID       = ! empty($GRP_ID) ? $GRP_ID : $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 1309 | +  | 
                                                        |
| 1310 | + // we need messenger and message type. They should be coming from the event editor. If not here then return error  | 
                                                        |
| 1311 | +		if (empty($message_type) || empty($messenger)) { | 
                                                        |
| 1312 | + throw new EE_Error(  | 
                                                        |
| 1313 | + esc_html__(  | 
                                                        |
| 1314 | + 'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',  | 
                                                        |
| 1315 | + 'event_espresso'  | 
                                                        |
| 1316 | + )  | 
                                                        |
| 1317 | + );  | 
                                                        |
| 1318 | + }  | 
                                                        |
| 1319 | +  | 
                                                        |
| 1320 | + // we need the GRP_ID for the template being used as the base for the new template  | 
                                                        |
| 1321 | +		if (empty($GRP_ID)) { | 
                                                        |
| 1322 | + throw new EE_Error(  | 
                                                        |
| 1323 | + esc_html__(  | 
                                                        |
| 1324 | + 'In order to create a custom message template the GRP_ID of the template being used as a base is needed',  | 
                                                        |
| 1325 | + 'event_espresso'  | 
                                                        |
| 1326 | + )  | 
                                                        |
| 1327 | + );  | 
                                                        |
| 1328 | + }  | 
                                                        |
| 1329 | +  | 
                                                        |
| 1330 | + // let's just make sure the template gets generated!  | 
                                                        |
| 1331 | +  | 
                                                        |
| 1332 | + // we need to reassign some variables for what the insert is expecting  | 
                                                        |
| 1333 | +		$this->request->setRequestParam('MTP_messenger', $messenger); | 
                                                        |
| 1334 | +		$this->request->setRequestParam('MTP_message_type', $message_type); | 
                                                        |
| 1335 | +		$this->request->setRequestParam('GRP_ID', $GRP_ID); | 
                                                        |
| 1336 | +  | 
                                                        |
| 1337 | + $this->_insert_or_update_message_template(true);  | 
                                                        |
| 1338 | + }  | 
                                                        |
| 1339 | +  | 
                                                        |
| 1340 | +  | 
                                                        |
| 1341 | + /**  | 
                                                        |
| 1342 | + * @param string $message_type message type slug  | 
                                                        |
| 1343 | + * @param string $messenger messenger slug  | 
                                                        |
| 1344 | + * @param int $GRP_ID GRP_ID for the related message template group this new template will be based  | 
                                                        |
| 1345 | + * off of.  | 
                                                        |
| 1346 | + * @throws EE_error  | 
                                                        |
| 1347 | + * @throws ReflectionException  | 
                                                        |
| 1348 | + * @deprecated 4.10.29.p  | 
                                                        |
| 1349 | + */  | 
                                                        |
| 1350 | + protected function _add_message_template($message_type, $messenger, $GRP_ID)  | 
                                                        |
| 1351 | +	{ | 
                                                        |
| 1352 | + $this->add_message_template($message_type, $messenger, $GRP_ID);  | 
                                                        |
| 1353 | + }  | 
                                                        |
| 1354 | +  | 
                                                        |
| 1355 | +  | 
                                                        |
| 1356 | + /**  | 
                                                        |
| 1357 | + * _edit_message_template  | 
                                                        |
| 1358 | + *  | 
                                                        |
| 1359 | + * @access protected  | 
                                                        |
| 1360 | + * @return void  | 
                                                        |
| 1361 | + * @throws InvalidIdentifierException  | 
                                                        |
| 1362 | + * @throws DomainException  | 
                                                        |
| 1363 | + * @throws EE_Error  | 
                                                        |
| 1364 | + * @throws InvalidArgumentException  | 
                                                        |
| 1365 | + * @throws ReflectionException  | 
                                                        |
| 1366 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1367 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1368 | + */  | 
                                                        |
| 1369 | + protected function _edit_message_template()  | 
                                                        |
| 1370 | +	{ | 
                                                        |
| 1371 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 1372 | + $template_fields = '';  | 
                                                        |
| 1373 | + $sidebar_fields = '';  | 
                                                        |
| 1374 | + // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have  | 
                                                        |
| 1375 | + // valid html in the templates.  | 
                                                        |
| 1376 | +		add_filter('tiny_mce_before_init', [$this, 'filter_tinymce_init'], 10, 2); | 
                                                        |
| 1377 | +  | 
                                                        |
| 1378 | +		$GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 1379 | +		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int'); | 
                                                        |
| 1380 | +  | 
                                                        |
| 1381 | + $this->_set_shortcodes(); // this also sets the _message_template property.  | 
                                                        |
| 1382 | + $message_template_group = $this->_message_template_group;  | 
                                                        |
| 1383 | + $c_label = $message_template_group->context_label();  | 
                                                        |
| 1384 | + $c_config = $message_template_group->contexts_config();  | 
                                                        |
| 1385 | +  | 
                                                        |
| 1386 | + reset($c_config);  | 
                                                        |
| 1387 | +		$context = $this->request->getRequestParam('context', key($c_config)); | 
                                                        |
| 1388 | + $context = strtolower($context);  | 
                                                        |
| 1389 | +  | 
                                                        |
| 1390 | + $action = empty($GRP_ID) ? 'insert_message_template' : 'update_message_template';  | 
                                                        |
| 1391 | +  | 
                                                        |
| 1392 | + $edit_message_template_form_url = add_query_arg(  | 
                                                        |
| 1393 | + ['action' => $action, 'noheader' => true],  | 
                                                        |
| 1394 | + EE_MSG_ADMIN_URL  | 
                                                        |
| 1395 | + );  | 
                                                        |
| 1396 | +  | 
                                                        |
| 1397 | + // set active messenger for this view  | 
                                                        |
| 1398 | + $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(  | 
                                                        |
| 1399 | + $message_template_group->messenger()  | 
                                                        |
| 1400 | + );  | 
                                                        |
| 1401 | + $this->_active_message_type_name = $message_template_group->message_type();  | 
                                                        |
| 1402 | +  | 
                                                        |
| 1403 | +  | 
                                                        |
| 1404 | + // Do we have any validation errors?  | 
                                                        |
| 1405 | + $validators = $this->_get_transient();  | 
                                                        |
| 1406 | + $v_fields = ! empty($validators) ? array_keys($validators) : [];  | 
                                                        |
| 1407 | +  | 
                                                        |
| 1408 | +  | 
                                                        |
| 1409 | + // we need to assemble the title from Various details  | 
                                                        |
| 1410 | + $context_label = sprintf(  | 
                                                        |
| 1411 | +			esc_html__('(%s %s)', 'event_espresso'), | 
                                                        |
| 1412 | + $c_config[ $context ]['label'],  | 
                                                        |
| 1413 | + ucwords($c_label['label'])  | 
                                                        |
| 1414 | + );  | 
                                                        |
| 1415 | +  | 
                                                        |
| 1416 | + $title = sprintf(  | 
                                                        |
| 1417 | +			esc_html__(' %s %s Template %s', 'event_espresso'), | 
                                                        |
| 1418 | + ucwords($message_template_group->messenger_obj()->label['singular']),  | 
                                                        |
| 1419 | + ucwords($message_template_group->message_type_obj()->label['singular']),  | 
                                                        |
| 1420 | + $context_label  | 
                                                        |
| 1421 | + );  | 
                                                        |
| 1422 | +  | 
                                                        |
| 1423 | + $this->_template_args['GRP_ID'] = $GRP_ID;  | 
                                                        |
| 1424 | + $this->_template_args['message_template'] = $message_template_group;  | 
                                                        |
| 1425 | + $this->_template_args['is_extra_fields'] = false;  | 
                                                        |
| 1426 | +  | 
                                                        |
| 1427 | +  | 
                                                        |
| 1428 | + // let's get EEH_MSG_Template so we can get template form fields  | 
                                                        |
| 1429 | + $template_field_structure = EEH_MSG_Template::get_fields(  | 
                                                        |
| 1430 | + $message_template_group->messenger(),  | 
                                                        |
| 1431 | + $message_template_group->message_type(),  | 
                                                        |
| 1432 | + $context  | 
                                                        |
| 1433 | + );  | 
                                                        |
| 1434 | +  | 
                                                        |
| 1435 | +		if (! $template_field_structure) { | 
                                                        |
| 1436 | + $template_field_structure = false;  | 
                                                        |
| 1437 | + $template_fields = esc_html__(  | 
                                                        |
| 1438 | + 'There was an error in assembling the fields for this display (you should see an error message)',  | 
                                                        |
| 1439 | + 'event_espresso'  | 
                                                        |
| 1440 | + );  | 
                                                        |
| 1441 | + }  | 
                                                        |
| 1442 | +  | 
                                                        |
| 1443 | +  | 
                                                        |
| 1444 | + $message_templates = $message_template_group->context_templates();  | 
                                                        |
| 1445 | +  | 
                                                        |
| 1446 | +  | 
                                                        |
| 1447 | + // if we have the extra key.. then we need to remove the content index from the template_field_structure as it  | 
                                                        |
| 1448 | + // will get handled in the "extra" array.  | 
                                                        |
| 1449 | +		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { | 
                                                        |
| 1450 | +			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1451 | + unset($template_field_structure[ $context ][ $reference_field ]);  | 
                                                        |
| 1452 | + }  | 
                                                        |
| 1453 | + }  | 
                                                        |
| 1454 | +  | 
                                                        |
| 1455 | + // let's loop through the template_field_structure and actually assemble the input fields!  | 
                                                        |
| 1456 | +		if (! empty($template_field_structure)) { | 
                                                        |
| 1457 | +			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { | 
                                                        |
| 1458 | + // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in  | 
                                                        |
| 1459 | + // the extra array and reset them.  | 
                                                        |
| 1460 | +				if ($template_field === 'extra') { | 
                                                        |
| 1461 | + $this->_template_args['is_extra_fields'] = true;  | 
                                                        |
| 1462 | +					foreach ($field_setup_array as $reference_field => $new_fields_array) { | 
                                                        |
| 1463 | + $message_template = $message_templates[ $context ][ $reference_field ];  | 
                                                        |
| 1464 | + $content = $message_template instanceof EE_Message_Template  | 
                                                        |
| 1465 | +							? $message_template->get('MTP_content') | 
                                                        |
| 1466 | + : '';  | 
                                                        |
| 1467 | +						foreach ($new_fields_array as $extra_field => $extra_array) { | 
                                                        |
| 1468 | + // let's verify if we need this extra field via the shortcodes parameter.  | 
                                                        |
| 1469 | + $continue = false;  | 
                                                        |
| 1470 | +							if (isset($extra_array['shortcodes_required'])) { | 
                                                        |
| 1471 | +								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | 
                                                        |
| 1472 | +									if (! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1473 | + $continue = true;  | 
                                                        |
| 1474 | + }  | 
                                                        |
| 1475 | + }  | 
                                                        |
| 1476 | +								if ($continue) { | 
                                                        |
| 1477 | + continue;  | 
                                                        |
| 1478 | + }  | 
                                                        |
| 1479 | + }  | 
                                                        |
| 1480 | +  | 
                                                        |
| 1481 | + $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1482 | +  | 
                                                        |
| 1483 | + $template_form_fields[ $field_id ] = $extra_array;  | 
                                                        |
| 1484 | + $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['  | 
                                                        |
| 1485 | + . $reference_field  | 
                                                        |
| 1486 | + . '][content]['  | 
                                                        |
| 1487 | + . $extra_field . ']';  | 
                                                        |
| 1488 | + $css_class = $extra_array['css_class'] ?? '';  | 
                                                        |
| 1489 | +  | 
                                                        |
| 1490 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1491 | + && in_array($extra_field, $v_fields, true)  | 
                                                        |
| 1492 | + && (  | 
                                                        |
| 1493 | + is_array($validators[ $extra_field ])  | 
                                                        |
| 1494 | + && isset($validators[ $extra_field ]['msg'])  | 
                                                        |
| 1495 | + )  | 
                                                        |
| 1496 | + ? 'validate-error ' . $css_class  | 
                                                        |
| 1497 | + : $css_class;  | 
                                                        |
| 1498 | +  | 
                                                        |
| 1499 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1500 | + && isset($content[ $extra_field ])  | 
                                                        |
| 1501 | + ? $content[ $extra_field ]  | 
                                                        |
| 1502 | + : '';  | 
                                                        |
| 1503 | +  | 
                                                        |
| 1504 | + // do we have a validation error? if we do then let's use that value instead  | 
                                                        |
| 1505 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])  | 
                                                        |
| 1506 | + ? $validators[ $extra_field ]['value']  | 
                                                        |
| 1507 | + : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1508 | +  | 
                                                        |
| 1509 | +  | 
                                                        |
| 1510 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1511 | +  | 
                                                        |
| 1512 | + // shortcode selector  | 
                                                        |
| 1513 | + $field_name_to_use = $extra_field === 'main'  | 
                                                        |
| 1514 | + ? 'content'  | 
                                                        |
| 1515 | + : $extra_field;  | 
                                                        |
| 1516 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1517 | + $field_name_to_use,  | 
                                                        |
| 1518 | + $field_id  | 
                                                        |
| 1519 | + );  | 
                                                        |
| 1520 | + }  | 
                                                        |
| 1521 | + $template_field_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1522 | + $template_field_template_name_id = $reference_field . '-name';  | 
                                                        |
| 1523 | +  | 
                                                        |
| 1524 | + $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1525 | + 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1526 | + 'label' => null,  | 
                                                        |
| 1527 | + 'input' => 'hidden',  | 
                                                        |
| 1528 | + 'type' => 'int',  | 
                                                        |
| 1529 | + 'required' => false,  | 
                                                        |
| 1530 | + 'validation' => false,  | 
                                                        |
| 1531 | + 'value' => ! empty($message_templates) ? $message_template->ID() : '',  | 
                                                        |
| 1532 | + 'css_class' => '',  | 
                                                        |
| 1533 | + 'format' => '%d',  | 
                                                        |
| 1534 | + 'db-col' => 'MTP_ID',  | 
                                                        |
| 1535 | + ];  | 
                                                        |
| 1536 | +  | 
                                                        |
| 1537 | + $template_form_fields[ $template_field_template_name_id ] = [  | 
                                                        |
| 1538 | + 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1539 | + 'label' => null,  | 
                                                        |
| 1540 | + 'input' => 'hidden',  | 
                                                        |
| 1541 | + 'type' => 'string',  | 
                                                        |
| 1542 | + 'required' => false,  | 
                                                        |
| 1543 | + 'validation' => true,  | 
                                                        |
| 1544 | + 'value' => $reference_field,  | 
                                                        |
| 1545 | + 'css_class' => '',  | 
                                                        |
| 1546 | + 'format' => '%s',  | 
                                                        |
| 1547 | + 'db-col' => 'MTP_template_field',  | 
                                                        |
| 1548 | + ];  | 
                                                        |
| 1549 | + }  | 
                                                        |
| 1550 | + continue; // skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        |
| 1551 | +				} else { | 
                                                        |
| 1552 | + $field_id = $template_field . '-content';  | 
                                                        |
| 1553 | + $template_form_fields[ $field_id ] = $field_setup_array;  | 
                                                        |
| 1554 | + $template_form_fields[ $field_id ]['name'] =  | 
                                                        |
| 1555 | + 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1556 | + $message_template = $message_templates[ $context ][ $template_field ]  | 
                                                        |
| 1557 | + ?? null;  | 
                                                        |
| 1558 | + $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1559 | + && is_array($message_templates[ $context ])  | 
                                                        |
| 1560 | + && $message_template instanceof EE_Message_Template  | 
                                                        |
| 1561 | +						? $message_template->get('MTP_content') | 
                                                        |
| 1562 | + : '';  | 
                                                        |
| 1563 | +  | 
                                                        |
| 1564 | + // do we have a validator error for this field? if we do then we'll use that value instead  | 
                                                        |
| 1565 | + $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])  | 
                                                        |
| 1566 | + ? $validators[ $template_field ]['value']  | 
                                                        |
| 1567 | + : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1568 | +  | 
                                                        |
| 1569 | +  | 
                                                        |
| 1570 | + $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1571 | + $css_class = $field_setup_array['css_class'] ?? '';  | 
                                                        |
| 1572 | + $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1573 | + && in_array($template_field, $v_fields, true)  | 
                                                        |
| 1574 | + && isset($validators[ $template_field ]['msg'])  | 
                                                        |
| 1575 | + ? 'validate-error ' . $css_class  | 
                                                        |
| 1576 | + : $css_class;  | 
                                                        |
| 1577 | +  | 
                                                        |
| 1578 | + // shortcode selector  | 
                                                        |
| 1579 | + $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1580 | + $template_field,  | 
                                                        |
| 1581 | + $field_id  | 
                                                        |
| 1582 | + );  | 
                                                        |
| 1583 | + }  | 
                                                        |
| 1584 | +  | 
                                                        |
| 1585 | + // k took care of content field(s) now let's take care of others.  | 
                                                        |
| 1586 | +  | 
                                                        |
| 1587 | + $template_field_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1588 | + $template_field_field_template_name_id = $template_field . '-name';  | 
                                                        |
| 1589 | +  | 
                                                        |
| 1590 | + // foreach template field there are actually two form fields created  | 
                                                        |
| 1591 | + $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1592 | + 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1593 | + 'label' => null,  | 
                                                        |
| 1594 | + 'input' => 'hidden',  | 
                                                        |
| 1595 | + 'type' => 'int',  | 
                                                        |
| 1596 | + 'required' => false,  | 
                                                        |
| 1597 | + 'validation' => true,  | 
                                                        |
| 1598 | + 'value' => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',  | 
                                                        |
| 1599 | + 'css_class' => '',  | 
                                                        |
| 1600 | + 'format' => '%d',  | 
                                                        |
| 1601 | + 'db-col' => 'MTP_ID',  | 
                                                        |
| 1602 | + ];  | 
                                                        |
| 1603 | +  | 
                                                        |
| 1604 | + $template_form_fields[ $template_field_field_template_name_id ] = [  | 
                                                        |
| 1605 | + 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1606 | + 'label' => null,  | 
                                                        |
| 1607 | + 'input' => 'hidden',  | 
                                                        |
| 1608 | + 'type' => 'string',  | 
                                                        |
| 1609 | + 'required' => false,  | 
                                                        |
| 1610 | + 'validation' => true,  | 
                                                        |
| 1611 | + 'value' => $template_field,  | 
                                                        |
| 1612 | + 'css_class' => '',  | 
                                                        |
| 1613 | + 'format' => '%s',  | 
                                                        |
| 1614 | + 'db-col' => 'MTP_template_field',  | 
                                                        |
| 1615 | + ];  | 
                                                        |
| 1616 | + }  | 
                                                        |
| 1617 | +  | 
                                                        |
| 1618 | + // add other fields  | 
                                                        |
| 1619 | + $template_form_fields['ee-msg-current-context'] = [  | 
                                                        |
| 1620 | + 'name' => 'MTP_context',  | 
                                                        |
| 1621 | + 'label' => null,  | 
                                                        |
| 1622 | + 'input' => 'hidden',  | 
                                                        |
| 1623 | + 'type' => 'string',  | 
                                                        |
| 1624 | + 'required' => false,  | 
                                                        |
| 1625 | + 'validation' => true,  | 
                                                        |
| 1626 | + 'value' => $context,  | 
                                                        |
| 1627 | + 'css_class' => '',  | 
                                                        |
| 1628 | + 'format' => '%s',  | 
                                                        |
| 1629 | + 'db-col' => 'MTP_context',  | 
                                                        |
| 1630 | + ];  | 
                                                        |
| 1631 | +  | 
                                                        |
| 1632 | + $template_form_fields['ee-msg-grp-id'] = [  | 
                                                        |
| 1633 | + 'name' => 'GRP_ID',  | 
                                                        |
| 1634 | + 'label' => null,  | 
                                                        |
| 1635 | + 'input' => 'hidden',  | 
                                                        |
| 1636 | + 'type' => 'int',  | 
                                                        |
| 1637 | + 'required' => false,  | 
                                                        |
| 1638 | + 'validation' => true,  | 
                                                        |
| 1639 | + 'value' => $GRP_ID,  | 
                                                        |
| 1640 | + 'css_class' => '',  | 
                                                        |
| 1641 | + 'format' => '%d',  | 
                                                        |
| 1642 | + 'db-col' => 'GRP_ID',  | 
                                                        |
| 1643 | + ];  | 
                                                        |
| 1644 | +  | 
                                                        |
| 1645 | + $template_form_fields['ee-msg-messenger'] = [  | 
                                                        |
| 1646 | + 'name' => 'MTP_messenger',  | 
                                                        |
| 1647 | + 'label' => null,  | 
                                                        |
| 1648 | + 'input' => 'hidden',  | 
                                                        |
| 1649 | + 'type' => 'string',  | 
                                                        |
| 1650 | + 'required' => false,  | 
                                                        |
| 1651 | + 'validation' => true,  | 
                                                        |
| 1652 | + 'value' => $message_template_group->messenger(),  | 
                                                        |
| 1653 | + 'css_class' => '',  | 
                                                        |
| 1654 | + 'format' => '%s',  | 
                                                        |
| 1655 | + 'db-col' => 'MTP_messenger',  | 
                                                        |
| 1656 | + ];  | 
                                                        |
| 1657 | +  | 
                                                        |
| 1658 | + $template_form_fields['ee-msg-message-type'] = [  | 
                                                        |
| 1659 | + 'name' => 'MTP_message_type',  | 
                                                        |
| 1660 | + 'label' => null,  | 
                                                        |
| 1661 | + 'input' => 'hidden',  | 
                                                        |
| 1662 | + 'type' => 'string',  | 
                                                        |
| 1663 | + 'required' => false,  | 
                                                        |
| 1664 | + 'validation' => true,  | 
                                                        |
| 1665 | + 'value' => $message_template_group->message_type(),  | 
                                                        |
| 1666 | + 'css_class' => '',  | 
                                                        |
| 1667 | + 'format' => '%s',  | 
                                                        |
| 1668 | + 'db-col' => 'MTP_message_type',  | 
                                                        |
| 1669 | + ];  | 
                                                        |
| 1670 | +  | 
                                                        |
| 1671 | + $sidebar_form_fields['ee-msg-is-global'] = [  | 
                                                        |
| 1672 | + 'name' => 'MTP_is_global',  | 
                                                        |
| 1673 | +				'label'      => esc_html__('Global Template', 'event_espresso'), | 
                                                        |
| 1674 | + 'input' => 'hidden',  | 
                                                        |
| 1675 | + 'type' => 'int',  | 
                                                        |
| 1676 | + 'required' => false,  | 
                                                        |
| 1677 | + 'validation' => true,  | 
                                                        |
| 1678 | +				'value'      => $message_template_group->get('MTP_is_global'), | 
                                                        |
| 1679 | + 'css_class' => '',  | 
                                                        |
| 1680 | + 'format' => '%d',  | 
                                                        |
| 1681 | + 'db-col' => 'MTP_is_global',  | 
                                                        |
| 1682 | + ];  | 
                                                        |
| 1683 | +  | 
                                                        |
| 1684 | + $sidebar_form_fields['ee-msg-is-override'] = [  | 
                                                        |
| 1685 | + 'name' => 'MTP_is_override',  | 
                                                        |
| 1686 | +				'label'      => esc_html__('Override all custom', 'event_espresso'), | 
                                                        |
| 1687 | + 'input' => $message_template_group->is_global() ? 'checkbox' : 'hidden',  | 
                                                        |
| 1688 | + 'type' => 'int',  | 
                                                        |
| 1689 | + 'required' => false,  | 
                                                        |
| 1690 | + 'validation' => true,  | 
                                                        |
| 1691 | +				'value'      => $message_template_group->get('MTP_is_override'), | 
                                                        |
| 1692 | + 'css_class' => '',  | 
                                                        |
| 1693 | + 'format' => '%d',  | 
                                                        |
| 1694 | + 'db-col' => 'MTP_is_override',  | 
                                                        |
| 1695 | + ];  | 
                                                        |
| 1696 | +  | 
                                                        |
| 1697 | + $sidebar_form_fields['ee-msg-is-active'] = [  | 
                                                        |
| 1698 | + 'name' => 'MTP_is_active',  | 
                                                        |
| 1699 | +				'label'      => esc_html__('Active Template', 'event_espresso'), | 
                                                        |
| 1700 | + 'input' => 'hidden',  | 
                                                        |
| 1701 | + 'type' => 'int',  | 
                                                        |
| 1702 | + 'required' => false,  | 
                                                        |
| 1703 | + 'validation' => true,  | 
                                                        |
| 1704 | + 'value' => $message_template_group->is_active(),  | 
                                                        |
| 1705 | + 'css_class' => '',  | 
                                                        |
| 1706 | + 'format' => '%d',  | 
                                                        |
| 1707 | + 'db-col' => 'MTP_is_active',  | 
                                                        |
| 1708 | + ];  | 
                                                        |
| 1709 | +  | 
                                                        |
| 1710 | + $sidebar_form_fields['ee-msg-deleted'] = [  | 
                                                        |
| 1711 | + 'name' => 'MTP_deleted',  | 
                                                        |
| 1712 | + 'label' => null,  | 
                                                        |
| 1713 | + 'input' => 'hidden',  | 
                                                        |
| 1714 | + 'type' => 'int',  | 
                                                        |
| 1715 | + 'required' => false,  | 
                                                        |
| 1716 | + 'validation' => true,  | 
                                                        |
| 1717 | +				'value'      => $message_template_group->get('MTP_deleted'), | 
                                                        |
| 1718 | + 'css_class' => '',  | 
                                                        |
| 1719 | + 'format' => '%d',  | 
                                                        |
| 1720 | + 'db-col' => 'MTP_deleted',  | 
                                                        |
| 1721 | + ];  | 
                                                        |
| 1722 | + $sidebar_form_fields['ee-msg-author'] = [  | 
                                                        |
| 1723 | + 'name' => 'MTP_user_id',  | 
                                                        |
| 1724 | +				'label'      => esc_html__('Author', 'event_espresso'), | 
                                                        |
| 1725 | + 'input' => 'hidden',  | 
                                                        |
| 1726 | + 'type' => 'int',  | 
                                                        |
| 1727 | + 'required' => false,  | 
                                                        |
| 1728 | + 'validation' => false,  | 
                                                        |
| 1729 | + 'value' => $message_template_group->user(),  | 
                                                        |
| 1730 | + 'format' => '%d',  | 
                                                        |
| 1731 | + 'db-col' => 'MTP_user_id',  | 
                                                        |
| 1732 | + ];  | 
                                                        |
| 1733 | +  | 
                                                        |
| 1734 | + $sidebar_form_fields['ee-msg-route'] = [  | 
                                                        |
| 1735 | + 'name' => 'action',  | 
                                                        |
| 1736 | + 'input' => 'hidden',  | 
                                                        |
| 1737 | + 'type' => 'string',  | 
                                                        |
| 1738 | + 'value' => $action,  | 
                                                        |
| 1739 | + ];  | 
                                                        |
| 1740 | +  | 
                                                        |
| 1741 | + $sidebar_form_fields['ee-msg-id'] = [  | 
                                                        |
| 1742 | + 'name' => 'id',  | 
                                                        |
| 1743 | + 'input' => 'hidden',  | 
                                                        |
| 1744 | + 'type' => 'int',  | 
                                                        |
| 1745 | + 'value' => $GRP_ID,  | 
                                                        |
| 1746 | + ];  | 
                                                        |
| 1747 | + $sidebar_form_fields['ee-msg-evt-nonce'] = [  | 
                                                        |
| 1748 | + 'name' => $action . '_nonce',  | 
                                                        |
| 1749 | + 'input' => 'hidden',  | 
                                                        |
| 1750 | + 'type' => 'string',  | 
                                                        |
| 1751 | + 'value' => wp_create_nonce($action . '_nonce'),  | 
                                                        |
| 1752 | + ];  | 
                                                        |
| 1753 | +  | 
                                                        |
| 1754 | +			$template_switch = $this->request->getRequestParam('template_switch'); | 
                                                        |
| 1755 | +			if ($template_switch) { | 
                                                        |
| 1756 | + $sidebar_form_fields['ee-msg-template-switch'] = [  | 
                                                        |
| 1757 | + 'name' => 'template_switch',  | 
                                                        |
| 1758 | + 'input' => 'hidden',  | 
                                                        |
| 1759 | + 'type' => 'int',  | 
                                                        |
| 1760 | + 'value' => 1,  | 
                                                        |
| 1761 | + ];  | 
                                                        |
| 1762 | + }  | 
                                                        |
| 1763 | +  | 
                                                        |
| 1764 | +  | 
                                                        |
| 1765 | + $template_fields = $this->_generate_admin_form_fields($template_form_fields);  | 
                                                        |
| 1766 | + $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);  | 
                                                        |
| 1767 | + } //end if ( !empty($template_field_structure) )  | 
                                                        |
| 1768 | +  | 
                                                        |
| 1769 | + // set extra content for publish box  | 
                                                        |
| 1770 | + $this->_template_args['publish_box_extra_content'] = $sidebar_fields;  | 
                                                        |
| 1771 | + $this->_set_publish_post_box_vars(  | 
                                                        |
| 1772 | + 'id',  | 
                                                        |
| 1773 | + $GRP_ID,  | 
                                                        |
| 1774 | + false,  | 
                                                        |
| 1775 | + add_query_arg(  | 
                                                        |
| 1776 | + ['action' => 'global_mtps'],  | 
                                                        |
| 1777 | + $this->_admin_base_url  | 
                                                        |
| 1778 | + )  | 
                                                        |
| 1779 | + );  | 
                                                        |
| 1780 | +  | 
                                                        |
| 1781 | + // add preview button  | 
                                                        |
| 1782 | + $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1783 | + [  | 
                                                        |
| 1784 | + 'message_type' => $message_template_group->message_type(),  | 
                                                        |
| 1785 | + 'messenger' => $message_template_group->messenger(),  | 
                                                        |
| 1786 | + 'context' => $context,  | 
                                                        |
| 1787 | + 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 1788 | + 'evt_id' => $EVT_ID ?: false,  | 
                                                        |
| 1789 | + 'action' => 'preview_message',  | 
                                                        |
| 1790 | + ],  | 
                                                        |
| 1791 | + $this->_admin_base_url  | 
                                                        |
| 1792 | + );  | 
                                                        |
| 1793 | + $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'  | 
                                                        |
| 1794 | +						  . esc_html__('Preview', 'event_espresso') | 
                                                        |
| 1795 | + . '</a>';  | 
                                                        |
| 1796 | +  | 
                                                        |
| 1797 | +  | 
                                                        |
| 1798 | + // setup context switcher  | 
                                                        |
| 1799 | + $this->_set_context_switcher(  | 
                                                        |
| 1800 | + $message_template_group,  | 
                                                        |
| 1801 | + [  | 
                                                        |
| 1802 | + 'page' => 'espresso_messages',  | 
                                                        |
| 1803 | + 'action' => 'edit_message_template',  | 
                                                        |
| 1804 | + 'id' => $GRP_ID,  | 
                                                        |
| 1805 | + 'evt_id' => $EVT_ID,  | 
                                                        |
| 1806 | + 'context' => $context,  | 
                                                        |
| 1807 | + 'extra' => $preview_button,  | 
                                                        |
| 1808 | + ]  | 
                                                        |
| 1809 | + );  | 
                                                        |
| 1810 | +  | 
                                                        |
| 1811 | +  | 
                                                        |
| 1812 | + // main box  | 
                                                        |
| 1813 | + $this->_template_args['template_fields'] = $template_fields;  | 
                                                        |
| 1814 | + $this->_template_args['sidebar_box_id'] = 'details';  | 
                                                        |
| 1815 | + $this->_template_args['action'] = $action;  | 
                                                        |
| 1816 | + $this->_template_args['context'] = $context;  | 
                                                        |
| 1817 | + $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;  | 
                                                        |
| 1818 | + $this->_template_args['learn_more_about_message_templates_link'] =  | 
                                                        |
| 1819 | + $this->_learn_more_about_message_templates_link();  | 
                                                        |
| 1820 | +  | 
                                                        |
| 1821 | +  | 
                                                        |
| 1822 | + $this->_template_args['before_admin_page_content'] = '<div class="ee-msg-admin-header">';  | 
                                                        |
| 1823 | + $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(  | 
                                                        |
| 1824 | + $message_template_group,  | 
                                                        |
| 1825 | + $context,  | 
                                                        |
| 1826 | + $context_label  | 
                                                        |
| 1827 | + );  | 
                                                        |
| 1828 | + $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();  | 
                                                        |
| 1829 | + $this->_template_args['before_admin_page_content'] .= '</div>';  | 
                                                        |
| 1830 | + $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();  | 
                                                        |
| 1831 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1832 | +  | 
                                                        |
| 1833 | + $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        |
| 1834 | + ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        |
| 1835 | + : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1836 | +  | 
                                                        |
| 1837 | + // send along EE_Message_Template_Group object for further template use.  | 
                                                        |
| 1838 | + $this->_template_args['MTP'] = $message_template_group;  | 
                                                        |
| 1839 | +  | 
                                                        |
| 1840 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(  | 
                                                        |
| 1841 | + $this->_template_path,  | 
                                                        |
| 1842 | + $this->_template_args,  | 
                                                        |
| 1843 | + true  | 
                                                        |
| 1844 | + );  | 
                                                        |
| 1845 | +  | 
                                                        |
| 1846 | +  | 
                                                        |
| 1847 | + // finally, let's set the admin_page title  | 
                                                        |
| 1848 | +		$this->_admin_page_title = sprintf(esc_html__('Editing %s', 'event_espresso'), $title); | 
                                                        |
| 1849 | +  | 
                                                        |
| 1850 | +  | 
                                                        |
| 1851 | + // we need to take care of setting the shortcodes property for use elsewhere.  | 
                                                        |
| 1852 | + $this->_set_shortcodes();  | 
                                                        |
| 1853 | +  | 
                                                        |
| 1854 | +  | 
                                                        |
| 1855 | + // final template wrapper  | 
                                                        |
| 1856 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 1857 | + }  | 
                                                        |
| 1858 | +  | 
                                                        |
| 1859 | +  | 
                                                        |
| 1860 | + public function filter_tinymce_init($mceInit, $editor_id)  | 
                                                        |
| 1861 | +	{ | 
                                                        |
| 1862 | + return $mceInit;  | 
                                                        |
| 1863 | + }  | 
                                                        |
| 1864 | +  | 
                                                        |
| 1865 | +  | 
                                                        |
| 1866 | + public function add_context_switcher()  | 
                                                        |
| 1867 | +	{ | 
                                                        |
| 1868 | + return $this->_context_switcher;  | 
                                                        |
| 1869 | + }  | 
                                                        |
| 1870 | +  | 
                                                        |
| 1871 | +  | 
                                                        |
| 1872 | + /**  | 
                                                        |
| 1873 | + * Adds the activation/deactivation toggle for the message template context.  | 
                                                        |
| 1874 | + *  | 
                                                        |
| 1875 | + * @param EE_Message_Template_Group $message_template_group  | 
                                                        |
| 1876 | + * @param string $context  | 
                                                        |
| 1877 | + * @param string $context_label  | 
                                                        |
| 1878 | + * @return string  | 
                                                        |
| 1879 | + * @throws DomainException  | 
                                                        |
| 1880 | + * @throws EE_Error  | 
                                                        |
| 1881 | + * @throws InvalidIdentifierException  | 
                                                        |
| 1882 | + * @throws ReflectionException  | 
                                                        |
| 1883 | + */  | 
                                                        |
| 1884 | + protected function add_active_context_element(  | 
                                                        |
| 1885 | + EE_Message_Template_Group $message_template_group,  | 
                                                        |
| 1886 | + $context,  | 
                                                        |
| 1887 | + $context_label  | 
                                                        |
| 1888 | +	) { | 
                                                        |
| 1889 | + $template_args = [  | 
                                                        |
| 1890 | + 'context' => $context,  | 
                                                        |
| 1891 | +			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'), | 
                                                        |
| 1892 | + 'is_active' => $message_template_group->is_context_active($context),  | 
                                                        |
| 1893 | + 'on_off_action' => $message_template_group->is_context_active($context)  | 
                                                        |
| 1894 | + ? 'context-off'  | 
                                                        |
| 1895 | + : 'context-on',  | 
                                                        |
| 1896 | +			'context_label'             => str_replace(['(', ')'], '', $context_label), | 
                                                        |
| 1897 | + 'message_template_group_id' => $message_template_group->ID(),  | 
                                                        |
| 1898 | + ];  | 
                                                        |
| 1899 | + return EEH_Template::display_template(  | 
                                                        |
| 1900 | + EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',  | 
                                                        |
| 1901 | + $template_args,  | 
                                                        |
| 1902 | + true  | 
                                                        |
| 1903 | + );  | 
                                                        |
| 1904 | + }  | 
                                                        |
| 1905 | +  | 
                                                        |
| 1906 | +  | 
                                                        |
| 1907 | + /**  | 
                                                        |
| 1908 | + * Ajax callback for `toggle_context_template` ajax action.  | 
                                                        |
| 1909 | + * Handles toggling the message context on or off.  | 
                                                        |
| 1910 | + *  | 
                                                        |
| 1911 | + * @throws EE_Error  | 
                                                        |
| 1912 | + * @throws InvalidArgumentException  | 
                                                        |
| 1913 | + * @throws InvalidDataTypeException  | 
                                                        |
| 1914 | + * @throws InvalidIdentifierException  | 
                                                        |
| 1915 | + * @throws InvalidInterfaceException  | 
                                                        |
| 1916 | + */  | 
                                                        |
| 1917 | + public function toggle_context_template()  | 
                                                        |
| 1918 | +	{ | 
                                                        |
| 1919 | + $success = true;  | 
                                                        |
| 1920 | + // check for required data  | 
                                                        |
| 1921 | + if (  | 
                                                        |
| 1922 | + ! (  | 
                                                        |
| 1923 | +				$this->request->requestParamIsSet('message_template_group_id') | 
                                                        |
| 1924 | +				&& $this->request->requestParamIsSet('context') | 
                                                        |
| 1925 | +				&& $this->request->requestParamIsSet('status') | 
                                                        |
| 1926 | + )  | 
                                                        |
| 1927 | +		) { | 
                                                        |
| 1928 | + EE_Error::add_error(  | 
                                                        |
| 1929 | +				esc_html__('Required data for doing this action is not available.', 'event_espresso'), | 
                                                        |
| 1930 | + __FILE__,  | 
                                                        |
| 1931 | + __FUNCTION__,  | 
                                                        |
| 1932 | + __LINE__  | 
                                                        |
| 1933 | + );  | 
                                                        |
| 1934 | + $success = false;  | 
                                                        |
| 1935 | + }  | 
                                                        |
| 1936 | +  | 
                                                        |
| 1937 | +		$nonce   = $this->request->getRequestParam('toggle_context_nonce', ''); | 
                                                        |
| 1938 | +		$context = $this->request->getRequestParam('context', ''); | 
                                                        |
| 1939 | +		$status  = $this->request->getRequestParam('status', ''); | 
                                                        |
| 1940 | +  | 
                                                        |
| 1941 | +		$this->_verify_nonce($nonce, "activate_{$context}_toggle_nonce"); | 
                                                        |
| 1942 | +  | 
                                                        |
| 1943 | +		if ($status !== 'off' && $status !== 'on') { | 
                                                        |
| 1944 | + EE_Error::add_error(  | 
                                                        |
| 1945 | + sprintf(  | 
                                                        |
| 1946 | +					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 1947 | + $status  | 
                                                        |
| 1948 | + ),  | 
                                                        |
| 1949 | + __FILE__,  | 
                                                        |
| 1950 | + __FUNCTION__,  | 
                                                        |
| 1951 | + __LINE__  | 
                                                        |
| 1952 | + );  | 
                                                        |
| 1953 | + $success = false;  | 
                                                        |
| 1954 | + }  | 
                                                        |
| 1955 | +		$message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int'); | 
                                                        |
| 1956 | + $message_template_group = $this->getMtgModel()->get_one_by_ID($message_template_group_id);  | 
                                                        |
| 1957 | +		if (! $message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1958 | + EE_Error::add_error(  | 
                                                        |
| 1959 | + sprintf(  | 
                                                        |
| 1960 | + esc_html__(  | 
                                                        |
| 1961 | + 'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',  | 
                                                        |
| 1962 | + 'event_espresso'  | 
                                                        |
| 1963 | + ),  | 
                                                        |
| 1964 | + $message_template_group_id,  | 
                                                        |
| 1965 | + 'EE_Message_Template_Group'  | 
                                                        |
| 1966 | + ),  | 
                                                        |
| 1967 | + __FILE__,  | 
                                                        |
| 1968 | + __FUNCTION__,  | 
                                                        |
| 1969 | + __LINE__  | 
                                                        |
| 1970 | + );  | 
                                                        |
| 1971 | + $success = false;  | 
                                                        |
| 1972 | + }  | 
                                                        |
| 1973 | +		if ($success) { | 
                                                        |
| 1974 | + $success = $status === 'off'  | 
                                                        |
| 1975 | + ? $message_template_group->deactivate_context($context)  | 
                                                        |
| 1976 | + : $message_template_group->activate_context($context);  | 
                                                        |
| 1977 | + }  | 
                                                        |
| 1978 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 1979 | + $this->_return_json();  | 
                                                        |
| 1980 | + }  | 
                                                        |
| 1981 | +  | 
                                                        |
| 1982 | +  | 
                                                        |
| 1983 | + public function _add_form_element_before()  | 
                                                        |
| 1984 | +	{ | 
                                                        |
| 1985 | + return '<form method="post" action="'  | 
                                                        |
| 1986 | + . $this->_template_args['edit_message_template_form_url']  | 
                                                        |
| 1987 | + . '" id="ee-msg-edit-frm">';  | 
                                                        |
| 1988 | + }  | 
                                                        |
| 1989 | +  | 
                                                        |
| 1990 | +  | 
                                                        |
| 1991 | + public function _add_form_element_after()  | 
                                                        |
| 1992 | +	{ | 
                                                        |
| 1993 | + return '</form>';  | 
                                                        |
| 1994 | + }  | 
                                                        |
| 1995 | +  | 
                                                        |
| 1996 | +  | 
                                                        |
| 1997 | + /**  | 
                                                        |
| 1998 | + * This executes switching the template pack for a message template.  | 
                                                        |
| 1999 | + *  | 
                                                        |
| 2000 | + * @throws EE_Error  | 
                                                        |
| 2001 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2002 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2003 | + * @throws InvalidArgumentException  | 
                                                        |
| 2004 | + * @throws ReflectionException  | 
                                                        |
| 2005 | + * @since 4.5.0  | 
                                                        |
| 2006 | + */  | 
                                                        |
| 2007 | + public function switch_template_pack()  | 
                                                        |
| 2008 | +	{ | 
                                                        |
| 2009 | +  | 
                                                        |
| 2010 | +		$GRP_ID        = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2011 | +		$template_pack = $this->request->getRequestParam('template_pack', ''); | 
                                                        |
| 2012 | +  | 
                                                        |
| 2013 | + // verify we have needed values.  | 
                                                        |
| 2014 | +		if (empty($GRP_ID) || empty($template_pack)) { | 
                                                        |
| 2015 | + $this->_template_args['error'] = true;  | 
                                                        |
| 2016 | + EE_Error::add_error(  | 
                                                        |
| 2017 | +				esc_html__('The required date for switching templates is not available.', 'event_espresso'), | 
                                                        |
| 2018 | + __FILE__,  | 
                                                        |
| 2019 | + __FUNCTION__,  | 
                                                        |
| 2020 | + __LINE__  | 
                                                        |
| 2021 | + );  | 
                                                        |
| 2022 | +		} else { | 
                                                        |
| 2023 | + // get template, set the new template_pack and then reset to default  | 
                                                        |
| 2024 | + /** @var EE_Message_Template_Group $message_template_group */  | 
                                                        |
| 2025 | + $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 2026 | +  | 
                                                        |
| 2027 | + $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 2028 | +			$this->request->setRequestParam('msgr', $message_template_group->messenger()); | 
                                                        |
| 2029 | +			$this->request->setRequestParam('mt', $message_template_group->message_type()); | 
                                                        |
| 2030 | +  | 
                                                        |
| 2031 | + $query_args = $this->_reset_to_default_template();  | 
                                                        |
| 2032 | +  | 
                                                        |
| 2033 | +			if (empty($query_args['id'])) { | 
                                                        |
| 2034 | + EE_Error::add_error(  | 
                                                        |
| 2035 | + esc_html__(  | 
                                                        |
| 2036 | + 'Something went wrong with switching the template pack. Please try again or contact EE support',  | 
                                                        |
| 2037 | + 'event_espresso'  | 
                                                        |
| 2038 | + ),  | 
                                                        |
| 2039 | + __FILE__,  | 
                                                        |
| 2040 | + __FUNCTION__,  | 
                                                        |
| 2041 | + __LINE__  | 
                                                        |
| 2042 | + );  | 
                                                        |
| 2043 | + $this->_template_args['error'] = true;  | 
                                                        |
| 2044 | +			} else { | 
                                                        |
| 2045 | + $template_label = $message_template_group->get_template_pack()->label;  | 
                                                        |
| 2046 | + $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 2047 | + EE_Error::add_success(  | 
                                                        |
| 2048 | + sprintf(  | 
                                                        |
| 2049 | + esc_html__(  | 
                                                        |
| 2050 | + 'This message template has been successfully switched to use the %1$s %2$s. Please wait while the page reloads with your new template.',  | 
                                                        |
| 2051 | + 'event_espresso'  | 
                                                        |
| 2052 | + ),  | 
                                                        |
| 2053 | + $template_label,  | 
                                                        |
| 2054 | + $template_pack_labels->template_pack  | 
                                                        |
| 2055 | + )  | 
                                                        |
| 2056 | + );  | 
                                                        |
| 2057 | + // generate the redirect url for js.  | 
                                                        |
| 2058 | + $url = self::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 2059 | +  | 
                                                        |
| 2060 | + $this->_template_args['data']['redirect_url'] = $url;  | 
                                                        |
| 2061 | + $this->_template_args['success'] = true;  | 
                                                        |
| 2062 | + }  | 
                                                        |
| 2063 | +  | 
                                                        |
| 2064 | + $this->_return_json();  | 
                                                        |
| 2065 | + }  | 
                                                        |
| 2066 | + }  | 
                                                        |
| 2067 | +  | 
                                                        |
| 2068 | +  | 
                                                        |
| 2069 | + /**  | 
                                                        |
| 2070 | + * This handles resetting the template for the given messenger/message_type so that users can start from scratch if  | 
                                                        |
| 2071 | + * they want.  | 
                                                        |
| 2072 | + *  | 
                                                        |
| 2073 | + * @access protected  | 
                                                        |
| 2074 | + * @return array|void  | 
                                                        |
| 2075 | + * @throws EE_Error  | 
                                                        |
| 2076 | + * @throws InvalidArgumentException  | 
                                                        |
| 2077 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2078 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2079 | + * @throws ReflectionException  | 
                                                        |
| 2080 | + */  | 
                                                        |
| 2081 | + protected function _reset_to_default_template()  | 
                                                        |
| 2082 | +	{ | 
                                                        |
| 2083 | + $templates = [];  | 
                                                        |
| 2084 | +		$GRP_ID       = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2085 | +		$messenger    = $this->request->getRequestParam('msgr'); | 
                                                        |
| 2086 | +		$message_type = $this->request->getRequestParam('mt'); | 
                                                        |
| 2087 | + // we need to make sure we've got the info we need.  | 
                                                        |
| 2088 | +		if (! ($GRP_ID && $messenger && $message_type)) { | 
                                                        |
| 2089 | + EE_Error::add_error(  | 
                                                        |
| 2090 | + esc_html__(  | 
                                                        |
| 2091 | + 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.',  | 
                                                        |
| 2092 | + 'event_espresso'  | 
                                                        |
| 2093 | + ),  | 
                                                        |
| 2094 | + __FILE__,  | 
                                                        |
| 2095 | + __FUNCTION__,  | 
                                                        |
| 2096 | + __LINE__  | 
                                                        |
| 2097 | + );  | 
                                                        |
| 2098 | + }  | 
                                                        |
| 2099 | +  | 
                                                        |
| 2100 | + // all templates will be reset to whatever the defaults are  | 
                                                        |
| 2101 | + // for the global template matching the messenger and message type.  | 
                                                        |
| 2102 | + $success = ! empty($GRP_ID);  | 
                                                        |
| 2103 | +  | 
                                                        |
| 2104 | +		if ($success) { | 
                                                        |
| 2105 | + // let's first determine if the incoming template is a global template,  | 
                                                        |
| 2106 | + // if it isn't then we need to get the global template matching messenger and message type.  | 
                                                        |
| 2107 | + // $MTPG = $this->getMtgModel()->get_one_by_ID( $GRP_ID );  | 
                                                        |
| 2108 | +  | 
                                                        |
| 2109 | +  | 
                                                        |
| 2110 | + // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.  | 
                                                        |
| 2111 | + $success = $this->_delete_mtp_permanently($GRP_ID, false);  | 
                                                        |
| 2112 | +  | 
                                                        |
| 2113 | +			if ($success) { | 
                                                        |
| 2114 | + // if successfully deleted, lets generate the new ones.  | 
                                                        |
| 2115 | + // Note. We set GLOBAL to true, because resets on ANY template  | 
                                                        |
| 2116 | + // will use the related global template defaults for regeneration.  | 
                                                        |
| 2117 | + // This means that if a custom template is reset it resets to whatever the related global template is.  | 
                                                        |
| 2118 | + // HOWEVER, we DO keep the template pack and template variation set  | 
                                                        |
| 2119 | + // for the current custom template when resetting.  | 
                                                        |
| 2120 | + $templates = $this->_generate_new_templates($messenger, $message_type, $GRP_ID, true);  | 
                                                        |
| 2121 | + }  | 
                                                        |
| 2122 | + }  | 
                                                        |
| 2123 | +  | 
                                                        |
| 2124 | + // any error messages?  | 
                                                        |
| 2125 | +		if (! $success) { | 
                                                        |
| 2126 | + EE_Error::add_error(  | 
                                                        |
| 2127 | + esc_html__(  | 
                                                        |
| 2128 | + 'Something went wrong with deleting existing templates. Unable to reset to default',  | 
                                                        |
| 2129 | + 'event_espresso'  | 
                                                        |
| 2130 | + ),  | 
                                                        |
| 2131 | + __FILE__,  | 
                                                        |
| 2132 | + __FUNCTION__,  | 
                                                        |
| 2133 | + __LINE__  | 
                                                        |
| 2134 | + );  | 
                                                        |
| 2135 | + }  | 
                                                        |
| 2136 | +  | 
                                                        |
| 2137 | + // all good, let's add a success message!  | 
                                                        |
| 2138 | +		if ($success && ! empty($templates)) { | 
                                                        |
| 2139 | + // the info for the template we generated is the first element in the returned array  | 
                                                        |
| 2140 | + EE_Error::overwrite_success();  | 
                                                        |
| 2141 | +			EE_Error::add_success(esc_html__('Templates have been reset to defaults.', 'event_espresso')); | 
                                                        |
| 2142 | + }  | 
                                                        |
| 2143 | +  | 
                                                        |
| 2144 | +  | 
                                                        |
| 2145 | + $query_args = [  | 
                                                        |
| 2146 | + 'id' => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,  | 
                                                        |
| 2147 | + 'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,  | 
                                                        |
| 2148 | + 'action' => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps',  | 
                                                        |
| 2149 | + ];  | 
                                                        |
| 2150 | +  | 
                                                        |
| 2151 | + // if called via ajax then we return query args otherwise redirect  | 
                                                        |
| 2152 | +		if ($this->request->isAjax()) { | 
                                                        |
| 2153 | + return $query_args;  | 
                                                        |
| 2154 | + }  | 
                                                        |
| 2155 | + $this->_redirect_after_action(false, '', '', $query_args, true);  | 
                                                        |
| 2156 | + }  | 
                                                        |
| 2157 | +  | 
                                                        |
| 2158 | +  | 
                                                        |
| 2159 | + /**  | 
                                                        |
| 2160 | + * Retrieve and set the message preview for display.  | 
                                                        |
| 2161 | + *  | 
                                                        |
| 2162 | + * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.  | 
                                                        |
| 2163 | + * @return string  | 
                                                        |
| 2164 | + * @throws ReflectionException  | 
                                                        |
| 2165 | + * @throws EE_Error  | 
                                                        |
| 2166 | + * @throws InvalidArgumentException  | 
                                                        |
| 2167 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2168 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2169 | + */  | 
                                                        |
| 2170 | + public function _preview_message($send = false)  | 
                                                        |
| 2171 | +	{ | 
                                                        |
| 2172 | + // first make sure we've got the necessary parameters  | 
                                                        |
| 2173 | +		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2174 | +		if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) { | 
                                                        |
| 2175 | + EE_Error::add_error(  | 
                                                        |
| 2176 | +				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), | 
                                                        |
| 2177 | + __FILE__,  | 
                                                        |
| 2178 | + __FUNCTION__,  | 
                                                        |
| 2179 | + __LINE__  | 
                                                        |
| 2180 | + );  | 
                                                        |
| 2181 | + }  | 
                                                        |
| 2182 | +  | 
                                                        |
| 2183 | +		$context = $this->request->getRequestParam('context'); | 
                                                        |
| 2184 | + // get the preview!  | 
                                                        |
| 2185 | + $preview = EED_Messages::preview_message(  | 
                                                        |
| 2186 | + $this->_active_message_type_name,  | 
                                                        |
| 2187 | + $context,  | 
                                                        |
| 2188 | + $this->_active_messenger_name,  | 
                                                        |
| 2189 | + $send  | 
                                                        |
| 2190 | + );  | 
                                                        |
| 2191 | +  | 
                                                        |
| 2192 | +		if ($send) { | 
                                                        |
| 2193 | + return $preview;  | 
                                                        |
| 2194 | + }  | 
                                                        |
| 2195 | +  | 
                                                        |
| 2196 | + // if we have an evt_id set on the request, use it.  | 
                                                        |
| 2197 | +		$EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int'); | 
                                                        |
| 2198 | +  | 
                                                        |
| 2199 | + // let's add a button to go back to the edit view  | 
                                                        |
| 2200 | + $query_args = [  | 
                                                        |
| 2201 | + 'id' => $GRP_ID,  | 
                                                        |
| 2202 | + 'evt_id' => $EVT_ID,  | 
                                                        |
| 2203 | + 'context' => $context,  | 
                                                        |
| 2204 | + 'action' => 'edit_message_template',  | 
                                                        |
| 2205 | + ];  | 
                                                        |
| 2206 | + $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);  | 
                                                        |
| 2207 | + $preview_button = '<a href="'  | 
                                                        |
| 2208 | + . $go_back_url  | 
                                                        |
| 2209 | + . '" class="button--secondary messages-preview-go-back-button">'  | 
                                                        |
| 2210 | +								  . esc_html__('Go Back to Edit', 'event_espresso') | 
                                                        |
| 2211 | + . '</a>';  | 
                                                        |
| 2212 | + $message_types = $this->get_installed_message_types();  | 
                                                        |
| 2213 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);  | 
                                                        |
| 2214 | + $active_messenger_label = $active_messenger instanceof EE_messenger  | 
                                                        |
| 2215 | + ? ucwords($active_messenger->label['singular'])  | 
                                                        |
| 2216 | +			: esc_html__('Unknown Messenger', 'event_espresso'); | 
                                                        |
| 2217 | + // let's provide a helpful title for context  | 
                                                        |
| 2218 | + $preview_title = sprintf(  | 
                                                        |
| 2219 | +			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), | 
                                                        |
| 2220 | + $active_messenger_label,  | 
                                                        |
| 2221 | + ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])  | 
                                                        |
| 2222 | + );  | 
                                                        |
| 2223 | +		if (empty($preview)) { | 
                                                        |
| 2224 | + $this->noEventsErrorMessage();  | 
                                                        |
| 2225 | + }  | 
                                                        |
| 2226 | + // setup display of preview.  | 
                                                        |
| 2227 | + $this->_admin_page_title = $preview_title;  | 
                                                        |
| 2228 | + $this->_template_args['admin_page_title'] = $preview_title;  | 
                                                        |
| 2229 | + $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;  | 
                                                        |
| 2230 | + $this->_template_args['data']['force_json'] = true;  | 
                                                        |
| 2231 | +  | 
                                                        |
| 2232 | + return '';  | 
                                                        |
| 2233 | + }  | 
                                                        |
| 2234 | +  | 
                                                        |
| 2235 | +  | 
                                                        |
| 2236 | + /**  | 
                                                        |
| 2237 | + * Used to set an error if there are no events available for generating a preview/test send.  | 
                                                        |
| 2238 | + *  | 
                                                        |
| 2239 | + * @param bool $test_send Whether the error should be generated for the context of a test send.  | 
                                                        |
| 2240 | + */  | 
                                                        |
| 2241 | + protected function noEventsErrorMessage($test_send = false)  | 
                                                        |
| 2242 | +	{ | 
                                                        |
| 2243 | + $events_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 2244 | + [  | 
                                                        |
| 2245 | + 'action' => 'default',  | 
                                                        |
| 2246 | + 'page' => 'espresso_events',  | 
                                                        |
| 2247 | + ],  | 
                                                        |
| 2248 | +			admin_url('admin.php') | 
                                                        |
| 2249 | + );  | 
                                                        |
| 2250 | + $message = $test_send  | 
                                                        |
| 2251 | + ? esc_html__(  | 
                                                        |
| 2252 | + 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',  | 
                                                        |
| 2253 | + 'event_espresso'  | 
                                                        |
| 2254 | + )  | 
                                                        |
| 2255 | + : esc_html__(  | 
                                                        |
| 2256 | + 'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',  | 
                                                        |
| 2257 | + 'event_espresso'  | 
                                                        |
| 2258 | + );  | 
                                                        |
| 2259 | +  | 
                                                        |
| 2260 | + EE_Error::add_attention(  | 
                                                        |
| 2261 | + sprintf(  | 
                                                        |
| 2262 | + $message,  | 
                                                        |
| 2263 | +				"<a href='{$events_url}'>", | 
                                                        |
| 2264 | + '</a>'  | 
                                                        |
| 2265 | + )  | 
                                                        |
| 2266 | + );  | 
                                                        |
| 2267 | + }  | 
                                                        |
| 2268 | +  | 
                                                        |
| 2269 | +  | 
                                                        |
| 2270 | + /**  | 
                                                        |
| 2271 | + * The initial _preview_message is on a no headers route. It will optionally call this if necessary otherwise it  | 
                                                        |
| 2272 | + * gets called automatically.  | 
                                                        |
| 2273 | + *  | 
                                                        |
| 2274 | + * @return void  | 
                                                        |
| 2275 | + * @throws EE_Error  | 
                                                        |
| 2276 | + * @since 4.5.0  | 
                                                        |
| 2277 | + *  | 
                                                        |
| 2278 | + */  | 
                                                        |
| 2279 | + protected function _display_preview_message()  | 
                                                        |
| 2280 | +	{ | 
                                                        |
| 2281 | + $this->display_admin_page_with_no_sidebar();  | 
                                                        |
| 2282 | + }  | 
                                                        |
| 2283 | +  | 
                                                        |
| 2284 | +  | 
                                                        |
| 2285 | + /**  | 
                                                        |
| 2286 | + * registers metaboxes that should show up on the "edit_message_template" page  | 
                                                        |
| 2287 | + *  | 
                                                        |
| 2288 | + * @access protected  | 
                                                        |
| 2289 | + * @return void  | 
                                                        |
| 2290 | + */  | 
                                                        |
| 2291 | + protected function _register_edit_meta_boxes()  | 
                                                        |
| 2292 | +	{ | 
                                                        |
| 2293 | + $this->addMetaBox(  | 
                                                        |
| 2294 | + 'mtp_valid_shortcodes',  | 
                                                        |
| 2295 | +			esc_html__('Valid Shortcodes', 'event_espresso'), | 
                                                        |
| 2296 | + [$this, 'shortcode_meta_box'],  | 
                                                        |
| 2297 | + $this->_current_screen->id,  | 
                                                        |
| 2298 | + 'side'  | 
                                                        |
| 2299 | + );  | 
                                                        |
| 2300 | + $this->addMetaBox(  | 
                                                        |
| 2301 | + 'mtp_extra_actions',  | 
                                                        |
| 2302 | +			esc_html__('Extra Actions', 'event_espresso'), | 
                                                        |
| 2303 | + [$this, 'extra_actions_meta_box'],  | 
                                                        |
| 2304 | + $this->_current_screen->id,  | 
                                                        |
| 2305 | + 'side',  | 
                                                        |
| 2306 | + 'high'  | 
                                                        |
| 2307 | + );  | 
                                                        |
| 2308 | + $this->addMetaBox(  | 
                                                        |
| 2309 | + 'mtp_templates',  | 
                                                        |
| 2310 | +			esc_html__('Template Styles', 'event_espresso'), | 
                                                        |
| 2311 | + [$this, 'template_pack_meta_box'],  | 
                                                        |
| 2312 | + $this->_current_screen->id,  | 
                                                        |
| 2313 | + 'side',  | 
                                                        |
| 2314 | + 'high'  | 
                                                        |
| 2315 | + );  | 
                                                        |
| 2316 | + }  | 
                                                        |
| 2317 | +  | 
                                                        |
| 2318 | +  | 
                                                        |
| 2319 | + /**  | 
                                                        |
| 2320 | + * metabox content for all template pack and variation selection.  | 
                                                        |
| 2321 | + *  | 
                                                        |
| 2322 | + * @return void  | 
                                                        |
| 2323 | + * @throws DomainException  | 
                                                        |
| 2324 | + * @throws EE_Error  | 
                                                        |
| 2325 | + * @throws InvalidArgumentException  | 
                                                        |
| 2326 | + * @throws ReflectionException  | 
                                                        |
| 2327 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2328 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2329 | + * @since 4.5.0  | 
                                                        |
| 2330 | + */  | 
                                                        |
| 2331 | + public function template_pack_meta_box()  | 
                                                        |
| 2332 | +	{ | 
                                                        |
| 2333 | + $this->_set_message_template_group();  | 
                                                        |
| 2334 | +  | 
                                                        |
| 2335 | + $tp_collection = EEH_MSG_Template::get_template_pack_collection();  | 
                                                        |
| 2336 | +  | 
                                                        |
| 2337 | + $tp_select_values = [];  | 
                                                        |
| 2338 | +  | 
                                                        |
| 2339 | +		foreach ($tp_collection as $tp) { | 
                                                        |
| 2340 | + // only include template packs that support this messenger and message type!  | 
                                                        |
| 2341 | + $supports = $tp->get_supports();  | 
                                                        |
| 2342 | + if (  | 
                                                        |
| 2343 | + ! isset($supports[ $this->_message_template_group->messenger() ])  | 
                                                        |
| 2344 | + || ! in_array(  | 
                                                        |
| 2345 | + $this->_message_template_group->message_type(),  | 
                                                        |
| 2346 | + $supports[ $this->_message_template_group->messenger() ],  | 
                                                        |
| 2347 | + true  | 
                                                        |
| 2348 | + )  | 
                                                        |
| 2349 | +			) { | 
                                                        |
| 2350 | + // not supported  | 
                                                        |
| 2351 | + continue;  | 
                                                        |
| 2352 | + }  | 
                                                        |
| 2353 | +  | 
                                                        |
| 2354 | + $tp_select_values[] = [  | 
                                                        |
| 2355 | + 'text' => $tp->label,  | 
                                                        |
| 2356 | + 'id' => $tp->dbref,  | 
                                                        |
| 2357 | + ];  | 
                                                        |
| 2358 | + }  | 
                                                        |
| 2359 | +  | 
                                                        |
| 2360 | + // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by  | 
                                                        |
| 2361 | + // the default template pack. This still allows for the odd template pack to override.  | 
                                                        |
| 2362 | +		if (empty($tp_select_values)) { | 
                                                        |
| 2363 | + $tp_select_values[] = [  | 
                                                        |
| 2364 | +				'text' => esc_html__('Default', 'event_espresso'), | 
                                                        |
| 2365 | + 'id' => 'default',  | 
                                                        |
| 2366 | + ];  | 
                                                        |
| 2367 | + }  | 
                                                        |
| 2368 | +  | 
                                                        |
| 2369 | + // setup variation select values for the currently selected template.  | 
                                                        |
| 2370 | + $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 2371 | + $this->_message_template_group->messenger(),  | 
                                                        |
| 2372 | + $this->_message_template_group->message_type()  | 
                                                        |
| 2373 | + );  | 
                                                        |
| 2374 | + $variations_select_values = [];  | 
                                                        |
| 2375 | +		foreach ($variations as $variation => $label) { | 
                                                        |
| 2376 | + $variations_select_values[] = [  | 
                                                        |
| 2377 | + 'text' => $label,  | 
                                                        |
| 2378 | + 'id' => $variation,  | 
                                                        |
| 2379 | + ];  | 
                                                        |
| 2380 | + }  | 
                                                        |
| 2381 | +  | 
                                                        |
| 2382 | + $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        |
| 2383 | +  | 
                                                        |
| 2384 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2385 | + 'MTP_template_pack',  | 
                                                        |
| 2386 | + $tp_select_values,  | 
                                                        |
| 2387 | + $this->_message_template_group->get_template_pack_name()  | 
                                                        |
| 2388 | + );  | 
                                                        |
| 2389 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2390 | + 'MTP_template_variation',  | 
                                                        |
| 2391 | + $variations_select_values,  | 
                                                        |
| 2392 | + $this->_message_template_group->get_template_pack_variation()  | 
                                                        |
| 2393 | + );  | 
                                                        |
| 2394 | + $template_args['template_pack_label'] = $template_pack_labels->template_pack;  | 
                                                        |
| 2395 | + $template_args['template_variation_label'] = $template_pack_labels->template_variation;  | 
                                                        |
| 2396 | + $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        |
| 2397 | + $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        |
| 2398 | +  | 
                                                        |
| 2399 | + $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 2400 | +  | 
                                                        |
| 2401 | + EEH_Template::display_template($template, $template_args);  | 
                                                        |
| 2402 | + }  | 
                                                        |
| 2403 | +  | 
                                                        |
| 2404 | +  | 
                                                        |
| 2405 | + /**  | 
                                                        |
| 2406 | + * This meta box holds any extra actions related to Message Templates  | 
                                                        |
| 2407 | + * For now, this includes Resetting templates to defaults and sending a test email.  | 
                                                        |
| 2408 | + *  | 
                                                        |
| 2409 | + * @access public  | 
                                                        |
| 2410 | + * @return void  | 
                                                        |
| 2411 | + * @throws EE_Error  | 
                                                        |
| 2412 | + */  | 
                                                        |
| 2413 | + public function extra_actions_meta_box()  | 
                                                        |
| 2414 | +	{ | 
                                                        |
| 2415 | + $template_form_fields = [];  | 
                                                        |
| 2416 | +  | 
                                                        |
| 2417 | + $extra_args = [  | 
                                                        |
| 2418 | + 'msgr' => $this->_message_template_group->messenger(),  | 
                                                        |
| 2419 | + 'mt' => $this->_message_template_group->message_type(),  | 
                                                        |
| 2420 | + 'GRP_ID' => $this->_message_template_group->GRP_ID(),  | 
                                                        |
| 2421 | + ];  | 
                                                        |
| 2422 | + // first we need to see if there are any fields  | 
                                                        |
| 2423 | + $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();  | 
                                                        |
| 2424 | +  | 
                                                        |
| 2425 | +		if (! empty($fields)) { | 
                                                        |
| 2426 | + // yup there be fields  | 
                                                        |
| 2427 | +			foreach ($fields as $field => $config) { | 
                                                        |
| 2428 | + $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2429 | + $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        |
| 2430 | + $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        |
| 2431 | + $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        |
| 2432 | +  | 
                                                        |
| 2433 | + // if type is hidden and the value is empty  | 
                                                        |
| 2434 | + // something may have gone wrong so let's correct with the defaults  | 
                                                        |
| 2435 | + $fix = $config['input'] === 'hidden'  | 
                                                        |
| 2436 | + && isset($existing[ $field ])  | 
                                                        |
| 2437 | + && empty($existing[ $field ])  | 
                                                        |
| 2438 | + ? $default  | 
                                                        |
| 2439 | + : '';  | 
                                                        |
| 2440 | + $existing[ $field ] = isset($existing[ $field ]) && empty($fix)  | 
                                                        |
| 2441 | + ? $existing[ $field ]  | 
                                                        |
| 2442 | + : $fix;  | 
                                                        |
| 2443 | +  | 
                                                        |
| 2444 | + $template_form_fields[ $field_id ] = [  | 
                                                        |
| 2445 | + 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2446 | + 'label' => $config['label'],  | 
                                                        |
| 2447 | + 'input' => $config['input'],  | 
                                                        |
| 2448 | + 'type' => $config['type'],  | 
                                                        |
| 2449 | + 'required' => $config['required'],  | 
                                                        |
| 2450 | + 'validation' => $config['validation'],  | 
                                                        |
| 2451 | + 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default,  | 
                                                        |
| 2452 | + 'css_class' => $config['css_class'],  | 
                                                        |
| 2453 | + 'options' => isset($config['options']) ? $config['options'] : [],  | 
                                                        |
| 2454 | + 'default' => $default,  | 
                                                        |
| 2455 | + 'format' => $config['format'],  | 
                                                        |
| 2456 | + ];  | 
                                                        |
| 2457 | + }  | 
                                                        |
| 2458 | + }  | 
                                                        |
| 2459 | +  | 
                                                        |
| 2460 | + $test_settings_html = ! empty($template_form_fields)  | 
                                                        |
| 2461 | + ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')  | 
                                                        |
| 2462 | + : '';  | 
                                                        |
| 2463 | +  | 
                                                        |
| 2464 | + // print out $test_settings_fields  | 
                                                        |
| 2465 | +		if (! empty($test_settings_html)) { | 
                                                        |
| 2466 | + $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';  | 
                                                        |
| 2467 | + $test_settings_html .= 'name="test_button" value="';  | 
                                                        |
| 2468 | +			$test_settings_html .= esc_html__('Test Send', 'event_espresso'); | 
                                                        |
| 2469 | + $test_settings_html .= '" /><div style="clear:both"></div>';  | 
                                                        |
| 2470 | + }  | 
                                                        |
| 2471 | +  | 
                                                        |
| 2472 | + // and button  | 
                                                        |
| 2473 | + $test_settings_html .= '<div class="publishing-action alignright resetbutton">';  | 
                                                        |
| 2474 | + $test_settings_html .= '<p>';  | 
                                                        |
| 2475 | +		$test_settings_html .= esc_html__('Need to reset this message type and start over?', 'event_espresso'); | 
                                                        |
| 2476 | + $test_settings_html .= '</p>';  | 
                                                        |
| 2477 | + $test_settings_html .= $this->get_action_link_or_button(  | 
                                                        |
| 2478 | + 'reset_to_default',  | 
                                                        |
| 2479 | + 'reset',  | 
                                                        |
| 2480 | + $extra_args,  | 
                                                        |
| 2481 | + 'button--primary reset-default-button'  | 
                                                        |
| 2482 | + );  | 
                                                        |
| 2483 | + $test_settings_html .= '</div><div style="clear:both"></div>';  | 
                                                        |
| 2484 | + echo wp_kses($test_settings_html, AllowedTags::getWithFormTags());  | 
                                                        |
| 2485 | + }  | 
                                                        |
| 2486 | +  | 
                                                        |
| 2487 | +  | 
                                                        |
| 2488 | + /**  | 
                                                        |
| 2489 | + * This returns the shortcode selector skeleton for a given context and field.  | 
                                                        |
| 2490 | + *  | 
                                                        |
| 2491 | + * @param string $field The name of the field retrieving shortcodes for.  | 
                                                        |
| 2492 | + * @param string $linked_input_id The css id of the input that the shortcodes get added to.  | 
                                                        |
| 2493 | + * @return string  | 
                                                        |
| 2494 | + * @throws DomainException  | 
                                                        |
| 2495 | + * @throws EE_Error  | 
                                                        |
| 2496 | + * @throws InvalidArgumentException  | 
                                                        |
| 2497 | + * @throws ReflectionException  | 
                                                        |
| 2498 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2499 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2500 | + * @since 4.9.rc.000  | 
                                                        |
| 2501 | + */  | 
                                                        |
| 2502 | + protected function _get_shortcode_selector($field, $linked_input_id)  | 
                                                        |
| 2503 | +	{ | 
                                                        |
| 2504 | + $template_args = [  | 
                                                        |
| 2505 | + 'shortcodes' => $this->_get_shortcodes([$field]),  | 
                                                        |
| 2506 | + 'fieldname' => $field,  | 
                                                        |
| 2507 | + 'linked_input_id' => $linked_input_id,  | 
                                                        |
| 2508 | + ];  | 
                                                        |
| 2509 | +  | 
                                                        |
| 2510 | + return EEH_Template::display_template(  | 
                                                        |
| 2511 | + EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2512 | + $template_args,  | 
                                                        |
| 2513 | + true  | 
                                                        |
| 2514 | + );  | 
                                                        |
| 2515 | + }  | 
                                                        |
| 2516 | +  | 
                                                        |
| 2517 | +  | 
                                                        |
| 2518 | + /**  | 
                                                        |
| 2519 | + * This just takes care of returning the meta box content for shortcodes (only used on the edit message template  | 
                                                        |
| 2520 | + * page)  | 
                                                        |
| 2521 | + *  | 
                                                        |
| 2522 | + * @access public  | 
                                                        |
| 2523 | + * @return void  | 
                                                        |
| 2524 | + * @throws EE_Error  | 
                                                        |
| 2525 | + * @throws InvalidArgumentException  | 
                                                        |
| 2526 | + * @throws ReflectionException  | 
                                                        |
| 2527 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2528 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2529 | + */  | 
                                                        |
| 2530 | + public function shortcode_meta_box()  | 
                                                        |
| 2531 | +	{ | 
                                                        |
| 2532 | + $shortcodes = $this->_get_shortcodes([], false);  | 
                                                        |
| 2533 | + // just make sure the shortcodes property is set  | 
                                                        |
| 2534 | + // $messenger = $this->_message_template_group->messenger_obj();  | 
                                                        |
| 2535 | + // now let's set the content depending on the status of the shortcodes array  | 
                                                        |
| 2536 | +		if (empty($shortcodes)) { | 
                                                        |
| 2537 | +			echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2538 | + return;  | 
                                                        |
| 2539 | + }  | 
                                                        |
| 2540 | + ?>  | 
                                                        |
| 2541 | 2541 | <div style="float:right; margin-top:10px">  | 
                                                        
| 2542 | 2542 |              <?php echo wp_kses($this->_get_help_tab_link('message_template_shortcodes'), AllowedTags::getAllowedTags()); | 
                                                        
| 2543 | - ?>  | 
                                                        |
| 2543 | + ?>  | 
                                                        |
| 2544 | 2544 | </div>  | 
                                                        
| 2545 | 2545 | <p class="small-text">  | 
                                                        
| 2546 | 2546 | <?php printf(  | 
                                                        
| 2547 | - esc_html__(  | 
                                                        |
| 2548 | - 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',  | 
                                                        |
| 2549 | - 'event_espresso'  | 
                                                        |
| 2550 | - ),  | 
                                                        |
| 2551 | - '<span class="dashicons dashicons-shortcode"></span>'  | 
                                                        |
| 2552 | - ); ?>  | 
                                                        |
| 2547 | + esc_html__(  | 
                                                        |
| 2548 | + 'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',  | 
                                                        |
| 2549 | + 'event_espresso'  | 
                                                        |
| 2550 | + ),  | 
                                                        |
| 2551 | + '<span class="dashicons dashicons-shortcode"></span>'  | 
                                                        |
| 2552 | + ); ?>  | 
                                                        |
| 2553 | 2553 | </p>  | 
                                                        
| 2554 | 2554 | <?php  | 
                                                        
| 2555 | - }  | 
                                                        |
| 2556 | -  | 
                                                        |
| 2557 | -  | 
                                                        |
| 2558 | - /**  | 
                                                        |
| 2559 | - * used to set the $_shortcodes property for when its needed elsewhere.  | 
                                                        |
| 2560 | - *  | 
                                                        |
| 2561 | - * @access protected  | 
                                                        |
| 2562 | - * @return void  | 
                                                        |
| 2563 | - * @throws EE_Error  | 
                                                        |
| 2564 | - * @throws InvalidArgumentException  | 
                                                        |
| 2565 | - * @throws ReflectionException  | 
                                                        |
| 2566 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2567 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2568 | - */  | 
                                                        |
| 2569 | - protected function _set_shortcodes()  | 
                                                        |
| 2570 | -    { | 
                                                        |
| 2571 | -  | 
                                                        |
| 2572 | - // no need to run this if the property is already set  | 
                                                        |
| 2573 | -        if (! empty($this->_shortcodes)) { | 
                                                        |
| 2574 | - return;  | 
                                                        |
| 2575 | - }  | 
                                                        |
| 2576 | -  | 
                                                        |
| 2577 | - $this->_shortcodes = $this->_get_shortcodes();  | 
                                                        |
| 2578 | - }  | 
                                                        |
| 2579 | -  | 
                                                        |
| 2580 | -  | 
                                                        |
| 2581 | - /**  | 
                                                        |
| 2582 | - * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes  | 
                                                        |
| 2583 | - * property)  | 
                                                        |
| 2584 | - *  | 
                                                        |
| 2585 | - * @access protected  | 
                                                        |
| 2586 | - * @param array $fields include an array of specific field names that you want to be used to get the shortcodes  | 
                                                        |
| 2587 | - * for. Defaults to all (for the given context)  | 
                                                        |
| 2588 | - * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes  | 
                                                        |
| 2589 | - * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is  | 
                                                        |
| 2590 | - * true just an array of shortcode/label pairs.  | 
                                                        |
| 2591 | - * @throws EE_Error  | 
                                                        |
| 2592 | - * @throws InvalidArgumentException  | 
                                                        |
| 2593 | - * @throws ReflectionException  | 
                                                        |
| 2594 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2595 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2596 | - */  | 
                                                        |
| 2597 | - protected function _get_shortcodes($fields = [], $merged = true)  | 
                                                        |
| 2598 | -    { | 
                                                        |
| 2599 | - $this->_set_message_template_group();  | 
                                                        |
| 2600 | -  | 
                                                        |
| 2601 | - // we need the messenger and message template to retrieve the valid shortcodes array.  | 
                                                        |
| 2602 | -        $GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 2603 | -        if (empty($GRP_ID)) { | 
                                                        |
| 2604 | - return [];  | 
                                                        |
| 2605 | - }  | 
                                                        |
| 2606 | - $context = $this->request->getRequestParam(  | 
                                                        |
| 2607 | - 'messenger',  | 
                                                        |
| 2608 | - key($this->_message_template_group->contexts_config())  | 
                                                        |
| 2609 | - );  | 
                                                        |
| 2610 | - return $this->_message_template_group->get_shortcodes($context, $fields, $merged);  | 
                                                        |
| 2611 | - }  | 
                                                        |
| 2612 | -  | 
                                                        |
| 2613 | -  | 
                                                        |
| 2614 | - /**  | 
                                                        |
| 2615 | - * This sets the _message_template property (containing the called message_template object)  | 
                                                        |
| 2616 | - *  | 
                                                        |
| 2617 | - * @access protected  | 
                                                        |
| 2618 | - * @return void  | 
                                                        |
| 2619 | - * @throws EE_Error  | 
                                                        |
| 2620 | - * @throws InvalidArgumentException  | 
                                                        |
| 2621 | - * @throws ReflectionException  | 
                                                        |
| 2622 | - * @throws InvalidDataTypeException  | 
                                                        |
| 2623 | - * @throws InvalidInterfaceException  | 
                                                        |
| 2624 | - */  | 
                                                        |
| 2625 | - protected function _set_message_template_group()  | 
                                                        |
| 2626 | -    { | 
                                                        |
| 2627 | - // get out if this is already set.  | 
                                                        |
| 2628 | -        if (! empty($this->_message_template_group)) { | 
                                                        |
| 2629 | - return;  | 
                                                        |
| 2630 | - }  | 
                                                        |
| 2631 | -  | 
                                                        |
| 2632 | -        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2633 | -        $GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int'); | 
                                                        |
| 2634 | -  | 
                                                        |
| 2635 | - // let's get the message templates  | 
                                                        |
| 2636 | - $this->_message_template_group = ! empty($GRP_ID)  | 
                                                        |
| 2637 | - ? $this->getMtgModel()->get_one_by_ID($GRP_ID)  | 
                                                        |
| 2638 | - : $this->getMtgModel()->create_default_object();  | 
                                                        |
| 2639 | -  | 
                                                        |
| 2640 | - $this->_template_pack = $this->_message_template_group->get_template_pack();  | 
                                                        |
| 2641 | - $this->_variation = $this->_message_template_group->get_template_pack_variation();  | 
                                                        |
| 2642 | - }  | 
                                                        |
| 2643 | -  | 
                                                        |
| 2644 | -  | 
                                                        |
| 2645 | - /**  | 
                                                        |
| 2646 | - * sets up a context switcher for edit forms  | 
                                                        |
| 2647 | - *  | 
                                                        |
| 2648 | - * @access protected  | 
                                                        |
| 2649 | - * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form  | 
                                                        |
| 2650 | - * @param array $args various things the context switcher needs.  | 
                                                        |
| 2651 | - * @throws EE_Error  | 
                                                        |
| 2652 | - */  | 
                                                        |
| 2653 | - protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)  | 
                                                        |
| 2654 | -    { | 
                                                        |
| 2655 | - $context_details = $template_group_object->contexts_config();  | 
                                                        |
| 2656 | - $context_label = $template_group_object->context_label();  | 
                                                        |
| 2657 | - ob_start();  | 
                                                        |
| 2658 | - ?>  | 
                                                        |
| 2555 | + }  | 
                                                        |
| 2556 | +  | 
                                                        |
| 2557 | +  | 
                                                        |
| 2558 | + /**  | 
                                                        |
| 2559 | + * used to set the $_shortcodes property for when its needed elsewhere.  | 
                                                        |
| 2560 | + *  | 
                                                        |
| 2561 | + * @access protected  | 
                                                        |
| 2562 | + * @return void  | 
                                                        |
| 2563 | + * @throws EE_Error  | 
                                                        |
| 2564 | + * @throws InvalidArgumentException  | 
                                                        |
| 2565 | + * @throws ReflectionException  | 
                                                        |
| 2566 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2567 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2568 | + */  | 
                                                        |
| 2569 | + protected function _set_shortcodes()  | 
                                                        |
| 2570 | +	{ | 
                                                        |
| 2571 | +  | 
                                                        |
| 2572 | + // no need to run this if the property is already set  | 
                                                        |
| 2573 | +		if (! empty($this->_shortcodes)) { | 
                                                        |
| 2574 | + return;  | 
                                                        |
| 2575 | + }  | 
                                                        |
| 2576 | +  | 
                                                        |
| 2577 | + $this->_shortcodes = $this->_get_shortcodes();  | 
                                                        |
| 2578 | + }  | 
                                                        |
| 2579 | +  | 
                                                        |
| 2580 | +  | 
                                                        |
| 2581 | + /**  | 
                                                        |
| 2582 | + * gets all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes  | 
                                                        |
| 2583 | + * property)  | 
                                                        |
| 2584 | + *  | 
                                                        |
| 2585 | + * @access protected  | 
                                                        |
| 2586 | + * @param array $fields include an array of specific field names that you want to be used to get the shortcodes  | 
                                                        |
| 2587 | + * for. Defaults to all (for the given context)  | 
                                                        |
| 2588 | + * @param boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes  | 
                                                        |
| 2589 | + * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is  | 
                                                        |
| 2590 | + * true just an array of shortcode/label pairs.  | 
                                                        |
| 2591 | + * @throws EE_Error  | 
                                                        |
| 2592 | + * @throws InvalidArgumentException  | 
                                                        |
| 2593 | + * @throws ReflectionException  | 
                                                        |
| 2594 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2595 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2596 | + */  | 
                                                        |
| 2597 | + protected function _get_shortcodes($fields = [], $merged = true)  | 
                                                        |
| 2598 | +	{ | 
                                                        |
| 2599 | + $this->_set_message_template_group();  | 
                                                        |
| 2600 | +  | 
                                                        |
| 2601 | + // we need the messenger and message template to retrieve the valid shortcodes array.  | 
                                                        |
| 2602 | +		$GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 2603 | +		if (empty($GRP_ID)) { | 
                                                        |
| 2604 | + return [];  | 
                                                        |
| 2605 | + }  | 
                                                        |
| 2606 | + $context = $this->request->getRequestParam(  | 
                                                        |
| 2607 | + 'messenger',  | 
                                                        |
| 2608 | + key($this->_message_template_group->contexts_config())  | 
                                                        |
| 2609 | + );  | 
                                                        |
| 2610 | + return $this->_message_template_group->get_shortcodes($context, $fields, $merged);  | 
                                                        |
| 2611 | + }  | 
                                                        |
| 2612 | +  | 
                                                        |
| 2613 | +  | 
                                                        |
| 2614 | + /**  | 
                                                        |
| 2615 | + * This sets the _message_template property (containing the called message_template object)  | 
                                                        |
| 2616 | + *  | 
                                                        |
| 2617 | + * @access protected  | 
                                                        |
| 2618 | + * @return void  | 
                                                        |
| 2619 | + * @throws EE_Error  | 
                                                        |
| 2620 | + * @throws InvalidArgumentException  | 
                                                        |
| 2621 | + * @throws ReflectionException  | 
                                                        |
| 2622 | + * @throws InvalidDataTypeException  | 
                                                        |
| 2623 | + * @throws InvalidInterfaceException  | 
                                                        |
| 2624 | + */  | 
                                                        |
| 2625 | + protected function _set_message_template_group()  | 
                                                        |
| 2626 | +	{ | 
                                                        |
| 2627 | + // get out if this is already set.  | 
                                                        |
| 2628 | +		if (! empty($this->_message_template_group)) { | 
                                                        |
| 2629 | + return;  | 
                                                        |
| 2630 | + }  | 
                                                        |
| 2631 | +  | 
                                                        |
| 2632 | +		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 2633 | +		$GRP_ID = $this->request->getRequestParam('id', $GRP_ID, 'int'); | 
                                                        |
| 2634 | +  | 
                                                        |
| 2635 | + // let's get the message templates  | 
                                                        |
| 2636 | + $this->_message_template_group = ! empty($GRP_ID)  | 
                                                        |
| 2637 | + ? $this->getMtgModel()->get_one_by_ID($GRP_ID)  | 
                                                        |
| 2638 | + : $this->getMtgModel()->create_default_object();  | 
                                                        |
| 2639 | +  | 
                                                        |
| 2640 | + $this->_template_pack = $this->_message_template_group->get_template_pack();  | 
                                                        |
| 2641 | + $this->_variation = $this->_message_template_group->get_template_pack_variation();  | 
                                                        |
| 2642 | + }  | 
                                                        |
| 2643 | +  | 
                                                        |
| 2644 | +  | 
                                                        |
| 2645 | + /**  | 
                                                        |
| 2646 | + * sets up a context switcher for edit forms  | 
                                                        |
| 2647 | + *  | 
                                                        |
| 2648 | + * @access protected  | 
                                                        |
| 2649 | + * @param EE_Message_Template_Group $template_group_object the template group object being displayed on the form  | 
                                                        |
| 2650 | + * @param array $args various things the context switcher needs.  | 
                                                        |
| 2651 | + * @throws EE_Error  | 
                                                        |
| 2652 | + */  | 
                                                        |
| 2653 | + protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)  | 
                                                        |
| 2654 | +	{ | 
                                                        |
| 2655 | + $context_details = $template_group_object->contexts_config();  | 
                                                        |
| 2656 | + $context_label = $template_group_object->context_label();  | 
                                                        |
| 2657 | + ob_start();  | 
                                                        |
| 2658 | + ?>  | 
                                                        |
| 2659 | 2659 | <div class="ee-msg-switcher-container">  | 
                                                        
| 2660 | 2660 | <form method="get" action="<?php echo esc_url_raw(EE_MSG_ADMIN_URL); ?>" id="ee-msg-context-switcher-frm">  | 
                                                        
| 2661 | 2661 | <?php  | 
                                                        
| 2662 | -                foreach ($args as $name => $value) { | 
                                                        |
| 2663 | -                    if ($name === 'context' || empty($value) || $name === 'extra') { | 
                                                        |
| 2664 | - continue;  | 
                                                        |
| 2665 | - }  | 
                                                        |
| 2666 | - ?>  | 
                                                        |
| 2662 | +				foreach ($args as $name => $value) { | 
                                                        |
| 2663 | +					if ($name === 'context' || empty($value) || $name === 'extra') { | 
                                                        |
| 2664 | + continue;  | 
                                                        |
| 2665 | + }  | 
                                                        |
| 2666 | + ?>  | 
                                                        |
| 2667 | 2667 | <input type="hidden"  | 
                                                        
| 2668 | 2668 | name="<?php echo esc_attr($name); ?>"  | 
                                                        
| 2669 | 2669 | value="<?php echo esc_attr($value); ?>"  | 
                                                        
| 2670 | 2670 | />  | 
                                                        
| 2671 | 2671 | <?php  | 
                                                        
| 2672 | - }  | 
                                                        |
| 2673 | - // setup nonce_url  | 
                                                        |
| 2674 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2675 | - $id = 'ee-' . sanitize_key($context_label['label']) . '-select';  | 
                                                        |
| 2676 | - ?>  | 
                                                        |
| 2672 | + }  | 
                                                        |
| 2673 | + // setup nonce_url  | 
                                                        |
| 2674 | + wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2675 | + $id = 'ee-' . sanitize_key($context_label['label']) . '-select';  | 
                                                        |
| 2676 | + ?>  | 
                                                        |
| 2677 | 2677 | <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>  | 
                                                        
| 2678 | 2678 |                      <?php esc_html_e('message context options', 'event_espresso'); ?> | 
                                                        
| 2679 | 2679 | </label>  | 
                                                        
| 2680 | 2680 | <select id="<?php echo esc_attr($id); ?>" name="context">  | 
                                                        
| 2681 | 2681 | <?php  | 
                                                        
| 2682 | - $context_templates = $template_group_object->context_templates();  | 
                                                        |
| 2683 | - if (is_array($context_templates)) :  | 
                                                        |
| 2684 | - foreach ($context_templates as $context => $template_fields) :  | 
                                                        |
| 2685 | - $checked = ($context === $args['context']) ? 'selected' : '';  | 
                                                        |
| 2686 | - ?>  | 
                                                        |
| 2682 | + $context_templates = $template_group_object->context_templates();  | 
                                                        |
| 2683 | + if (is_array($context_templates)) :  | 
                                                        |
| 2684 | + foreach ($context_templates as $context => $template_fields) :  | 
                                                        |
| 2685 | + $checked = ($context === $args['context']) ? 'selected' : '';  | 
                                                        |
| 2686 | + ?>  | 
                                                        |
| 2687 | 2687 | <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>  | 
                                                        
| 2688 | 2688 | <?php echo esc_html($context_details[ $context ]['label']); ?>  | 
                                                        
| 2689 | 2689 | </option>  | 
                                                        
| 2690 | 2690 | <?php endforeach;  | 
                                                        
| 2691 | - endif; ?>  | 
                                                        |
| 2691 | + endif; ?>  | 
                                                        |
| 2692 | 2692 | </select>  | 
                                                        
| 2693 | 2693 | <?php $button_text = sprintf(  | 
                                                        
| 2694 | -                    esc_html__('Switch %s', 'event_espresso'), | 
                                                        |
| 2695 | - ucwords($context_label['label'])  | 
                                                        |
| 2696 | - ); ?>  | 
                                                        |
| 2694 | +					esc_html__('Switch %s', 'event_espresso'), | 
                                                        |
| 2695 | + ucwords($context_label['label'])  | 
                                                        |
| 2696 | + ); ?>  | 
                                                        |
| 2697 | 2697 | <input class='button--secondary'  | 
                                                        
| 2698 | 2698 | id="submit-msg-context-switcher-sbmt"  | 
                                                        
| 2699 | 2699 | type="submit"  | 
                                                        
@@ -2703,1993 +2703,1993 @@ discard block  | 
                                                    ||
| 2703 | 2703 | <?php echo wp_kses($args['extra'], AllowedTags::getWithFormTags()); ?>  | 
                                                        
| 2704 | 2704 | </div> <!-- end .ee-msg-switcher-container -->  | 
                                                        
| 2705 | 2705 | <?php $this->_context_switcher = ob_get_clean();  | 
                                                        
| 2706 | - }  | 
                                                        |
| 2707 | -  | 
                                                        |
| 2708 | -  | 
                                                        |
| 2709 | - /**  | 
                                                        |
| 2710 | - * @param bool $new  | 
                                                        |
| 2711 | - * @throws EE_Error  | 
                                                        |
| 2712 | - * @throws ReflectionException  | 
                                                        |
| 2713 | - */  | 
                                                        |
| 2714 | - protected function _insert_or_update_message_template($new = false)  | 
                                                        |
| 2715 | -    { | 
                                                        |
| 2716 | - $form_data = $this->getMessageTemplateFormData();  | 
                                                        |
| 2717 | - $GRP_ID = $form_data['GRP_ID'];  | 
                                                        |
| 2718 | - $messenger = $form_data['MTP_messenger'];  | 
                                                        |
| 2719 | - $message_type = $form_data['MTP_message_type'];  | 
                                                        |
| 2720 | - $context = $form_data['MTP_context'];  | 
                                                        |
| 2721 | -  | 
                                                        |
| 2722 | - // if this is "new" then we need to generate the default contexts  | 
                                                        |
| 2723 | - // for the selected messenger/message_type for user to edit.  | 
                                                        |
| 2724 | - [$success, $query_args] = $new  | 
                                                        |
| 2725 | - ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)  | 
                                                        |
| 2726 | - : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);  | 
                                                        |
| 2727 | -  | 
                                                        |
| 2728 | - $success = $success ? 1 : 0;  | 
                                                        |
| 2729 | - $action_desc = $new ? 'created' : 'updated';  | 
                                                        |
| 2730 | - $item_desc = $this->generateUpdateDescription($messenger, $message_type, $context);  | 
                                                        |
| 2731 | - $override = $this->performTestSendAfterUpdate($messenger, $message_type, $context);  | 
                                                        |
| 2732 | -  | 
                                                        |
| 2733 | - $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);  | 
                                                        |
| 2734 | - }  | 
                                                        |
| 2735 | -  | 
                                                        |
| 2736 | -  | 
                                                        |
| 2737 | - /**  | 
                                                        |
| 2738 | - * retrieve and sanitize form data  | 
                                                        |
| 2739 | - *  | 
                                                        |
| 2740 | - * @return array  | 
                                                        |
| 2741 | - * @since 4.10.29.p  | 
                                                        |
| 2742 | - */  | 
                                                        |
| 2743 | - protected function getMessageTemplateFormData()  | 
                                                        |
| 2744 | -    { | 
                                                        |
| 2745 | - return [  | 
                                                        |
| 2746 | -            'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'), | 
                                                        |
| 2747 | -            'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')), | 
                                                        |
| 2748 | -            'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')), | 
                                                        |
| 2749 | -            'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')), | 
                                                        |
| 2750 | -            'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'), | 
                                                        |
| 2751 | -            'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'), | 
                                                        |
| 2752 | -            'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'), | 
                                                        |
| 2753 | -            'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'), | 
                                                        |
| 2754 | -            'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'), | 
                                                        |
| 2755 | - ];  | 
                                                        |
| 2756 | - }  | 
                                                        |
| 2757 | -  | 
                                                        |
| 2758 | -  | 
                                                        |
| 2759 | - /**  | 
                                                        |
| 2760 | - * @param int $GRP_ID  | 
                                                        |
| 2761 | - * @param string $messenger  | 
                                                        |
| 2762 | - * @param string $message_type  | 
                                                        |
| 2763 | - * @return array no return on AJAX requests  | 
                                                        |
| 2764 | - * @throws EE_Error  | 
                                                        |
| 2765 | - * @throws ReflectionException  | 
                                                        |
| 2766 | - * @since 4.10.29.p  | 
                                                        |
| 2767 | - */  | 
                                                        |
| 2768 | - private function generateNewTemplates($GRP_ID, $messenger, $message_type)  | 
                                                        |
| 2769 | -    { | 
                                                        |
| 2770 | - $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);  | 
                                                        |
| 2771 | - $success = ! empty($new_templates);  | 
                                                        |
| 2772 | -  | 
                                                        |
| 2773 | - // we return things differently if doing ajax  | 
                                                        |
| 2774 | -        if ($this->request->isAjax()) { | 
                                                        |
| 2775 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 2776 | - $this->_template_args['error'] = ! $success;  | 
                                                        |
| 2777 | - $this->_template_args['content'] = '';  | 
                                                        |
| 2778 | - $this->_template_args['data'] = [  | 
                                                        |
| 2779 | - 'grpID' => $new_templates['GRP_ID'],  | 
                                                        |
| 2780 | - 'templateName' => $new_templates['template_name'],  | 
                                                        |
| 2781 | - ];  | 
                                                        |
| 2782 | -            if ($success) { | 
                                                        |
| 2783 | - EE_Error::overwrite_success();  | 
                                                        |
| 2784 | - EE_Error::add_success(  | 
                                                        |
| 2785 | - esc_html__(  | 
                                                        |
| 2786 | - 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.',  | 
                                                        |
| 2787 | - 'event_espresso'  | 
                                                        |
| 2788 | - )  | 
                                                        |
| 2789 | - );  | 
                                                        |
| 2790 | - }  | 
                                                        |
| 2791 | - $this->_return_json();  | 
                                                        |
| 2792 | - }  | 
                                                        |
| 2793 | - return [  | 
                                                        |
| 2794 | - $success,  | 
                                                        |
| 2795 | - // 'query_args'  | 
                                                        |
| 2796 | - [  | 
                                                        |
| 2797 | - 'id' => $new_templates['GRP_ID'],  | 
                                                        |
| 2798 | - 'context' => $new_templates['MTP_context'],  | 
                                                        |
| 2799 | - 'action' => 'edit_message_template',  | 
                                                        |
| 2800 | - ],  | 
                                                        |
| 2801 | - ];  | 
                                                        |
| 2802 | - }  | 
                                                        |
| 2803 | -  | 
                                                        |
| 2804 | -  | 
                                                        |
| 2805 | - /**  | 
                                                        |
| 2806 | - * @param int $GRP_ID  | 
                                                        |
| 2807 | - * @param string $messenger  | 
                                                        |
| 2808 | - * @param string $message_type  | 
                                                        |
| 2809 | - * @param string $context  | 
                                                        |
| 2810 | - * @param array $form_data  | 
                                                        |
| 2811 | - * @return array  | 
                                                        |
| 2812 | - * @throws EE_Error  | 
                                                        |
| 2813 | - * @since 4.10.29.p  | 
                                                        |
| 2814 | - */  | 
                                                        |
| 2815 | - private function updateExistingTemplates(  | 
                                                        |
| 2816 | - $GRP_ID,  | 
                                                        |
| 2817 | - $messenger,  | 
                                                        |
| 2818 | - $message_type,  | 
                                                        |
| 2819 | - $context,  | 
                                                        |
| 2820 | - array $form_data  | 
                                                        |
| 2821 | -    ) { | 
                                                        |
| 2822 | - $success = false;  | 
                                                        |
| 2823 | - $template_fields = $this->getTemplateFields();  | 
                                                        |
| 2824 | -        if ($template_fields) { | 
                                                        |
| 2825 | - // if field data is valid, then success will be true  | 
                                                        |
| 2826 | - $success = $this->validateTemplateFields(  | 
                                                        |
| 2827 | - $messenger,  | 
                                                        |
| 2828 | - $message_type,  | 
                                                        |
| 2829 | - $context,  | 
                                                        |
| 2830 | - $template_fields  | 
                                                        |
| 2831 | - );  | 
                                                        |
| 2832 | -            if ($success) { | 
                                                        |
| 2833 | - $field_data = [];  | 
                                                        |
| 2834 | -                foreach ($template_fields as $template_field => $content) { | 
                                                        |
| 2835 | - // combine top-level form data with content for this field  | 
                                                        |
| 2836 | - $field_data = $this->getTemplateFieldFormData($content, $form_data);  | 
                                                        |
| 2837 | - $success = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;  | 
                                                        |
| 2838 | - }  | 
                                                        |
| 2839 | - // we can use the last set_column_values for the MTPG update  | 
                                                        |
| 2840 | - // (because its the same for all of these specific MTPs)  | 
                                                        |
| 2841 | - $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;  | 
                                                        |
| 2842 | - }  | 
                                                        |
| 2843 | - }  | 
                                                        |
| 2844 | -  | 
                                                        |
| 2845 | - return [  | 
                                                        |
| 2846 | - $success,  | 
                                                        |
| 2847 | - // 'query_args'  | 
                                                        |
| 2848 | - [  | 
                                                        |
| 2849 | - 'id' => $GRP_ID,  | 
                                                        |
| 2850 | - 'context' => $context,  | 
                                                        |
| 2851 | - 'action' => 'edit_message_template',  | 
                                                        |
| 2852 | - ],  | 
                                                        |
| 2853 | - ];  | 
                                                        |
| 2854 | - }  | 
                                                        |
| 2855 | -  | 
                                                        |
| 2856 | -  | 
                                                        |
| 2857 | - /**  | 
                                                        |
| 2858 | - * @return array  | 
                                                        |
| 2859 | - * @since 4.10.29.p  | 
                                                        |
| 2860 | - */  | 
                                                        |
| 2861 | - private function getTemplateFields()  | 
                                                        |
| 2862 | -    { | 
                                                        |
| 2863 | -        $template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true); | 
                                                        |
| 2864 | -        if (empty($template_fields)) { | 
                                                        |
| 2865 | - EE_Error::add_error(  | 
                                                        |
| 2866 | - esc_html__(  | 
                                                        |
| 2867 | - 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',  | 
                                                        |
| 2868 | - 'event_espresso'  | 
                                                        |
| 2869 | - ),  | 
                                                        |
| 2870 | - __FILE__,  | 
                                                        |
| 2871 | - __FUNCTION__,  | 
                                                        |
| 2872 | - __LINE__  | 
                                                        |
| 2873 | - );  | 
                                                        |
| 2874 | - return null;  | 
                                                        |
| 2875 | - }  | 
                                                        |
| 2876 | - // messages content is expected to be escaped  | 
                                                        |
| 2877 | - return EEH_Array::addSlashesRecursively($template_fields);  | 
                                                        |
| 2878 | - }  | 
                                                        |
| 2879 | -  | 
                                                        |
| 2880 | -  | 
                                                        |
| 2881 | - /**  | 
                                                        |
| 2882 | - * @param string $messenger  | 
                                                        |
| 2883 | - * @param string $message_type  | 
                                                        |
| 2884 | - * @param string $context  | 
                                                        |
| 2885 | - * @param array $template_fields  | 
                                                        |
| 2886 | - * @return bool  | 
                                                        |
| 2887 | - * @throws EE_Error  | 
                                                        |
| 2888 | - * @since 4.10.29.p  | 
                                                        |
| 2889 | - */  | 
                                                        |
| 2890 | - private function validateTemplateFields(  | 
                                                        |
| 2891 | - $messenger,  | 
                                                        |
| 2892 | - $message_type,  | 
                                                        |
| 2893 | - $context,  | 
                                                        |
| 2894 | - array $template_fields  | 
                                                        |
| 2895 | -    ) { | 
                                                        |
| 2896 | - // first validate all fields!  | 
                                                        |
| 2897 | - // this filter allows client code to add its own validation to the template fields as well.  | 
                                                        |
| 2898 | - // returning an empty array means everything passed validation.  | 
                                                        |
| 2899 | - // errors in validation should be represented in an array with the following shape:  | 
                                                        |
| 2900 | - // array(  | 
                                                        |
| 2901 | - // 'fieldname' => array(  | 
                                                        |
| 2902 | - // 'msg' => 'error message'  | 
                                                        |
| 2903 | - // 'value' => 'value for field producing error'  | 
                                                        |
| 2904 | - // )  | 
                                                        |
| 2905 | - $custom_validation = (array) apply_filters(  | 
                                                        |
| 2906 | - 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',  | 
                                                        |
| 2907 | - [],  | 
                                                        |
| 2908 | - $template_fields,  | 
                                                        |
| 2909 | - $context,  | 
                                                        |
| 2910 | - $messenger,  | 
                                                        |
| 2911 | - $message_type  | 
                                                        |
| 2912 | - );  | 
                                                        |
| 2913 | -  | 
                                                        |
| 2914 | - $system_validation = $this->getMtgModel()->validate(  | 
                                                        |
| 2915 | - $template_fields,  | 
                                                        |
| 2916 | - $context,  | 
                                                        |
| 2917 | - $messenger,  | 
                                                        |
| 2918 | - $message_type  | 
                                                        |
| 2919 | - );  | 
                                                        |
| 2920 | -  | 
                                                        |
| 2921 | - $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;  | 
                                                        |
| 2922 | - $validates = array_merge($custom_validation, $system_validation);  | 
                                                        |
| 2923 | -  | 
                                                        |
| 2924 | - // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an  | 
                                                        |
| 2925 | - // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  | 
                                                        |
| 2926 | - // WE need to make sure there is no actual error messages in validates.  | 
                                                        |
| 2927 | -        if (empty($validates)) { | 
                                                        |
| 2928 | - return true;  | 
                                                        |
| 2929 | - }  | 
                                                        |
| 2930 | -  | 
                                                        |
| 2931 | - // add the transient so when the form loads we know which fields to highlight  | 
                                                        |
| 2932 | -        $this->_add_transient('edit_message_template', $validates); | 
                                                        |
| 2933 | - // setup notices  | 
                                                        |
| 2934 | -        foreach ($validates as $error) { | 
                                                        |
| 2935 | -            if (isset($error['msg'])) { | 
                                                        |
| 2936 | - EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2937 | - }  | 
                                                        |
| 2938 | - }  | 
                                                        |
| 2939 | - return false;  | 
                                                        |
| 2940 | - }  | 
                                                        |
| 2941 | -  | 
                                                        |
| 2942 | -  | 
                                                        |
| 2943 | - /**  | 
                                                        |
| 2944 | - * @param array $field_data  | 
                                                        |
| 2945 | - * @param array $form_data  | 
                                                        |
| 2946 | - * @return array  | 
                                                        |
| 2947 | - * @since 4.10.29.p  | 
                                                        |
| 2948 | - */  | 
                                                        |
| 2949 | - private function getTemplateFieldFormData(array $field_data, array $form_data)  | 
                                                        |
| 2950 | -    { | 
                                                        |
| 2951 | - return $form_data + [  | 
                                                        |
| 2952 | - 'MTP_ID' => $field_data['MTP_ID'],  | 
                                                        |
| 2953 | - 'MTP_template_field' => $field_data['name'],  | 
                                                        |
| 2954 | - // if they aren't allowed to use all JS, restrict them to standard allowed post tags  | 
                                                        |
| 2955 | -                'MTP_content'        => ! current_user_can('unfiltered_html') | 
                                                        |
| 2956 | - ? $this->sanitizeMessageTemplateContent($field_data['content'])  | 
                                                        |
| 2957 | - : $field_data['content'],  | 
                                                        |
| 2958 | - ];  | 
                                                        |
| 2959 | - }  | 
                                                        |
| 2960 | -  | 
                                                        |
| 2961 | -  | 
                                                        |
| 2962 | - /**  | 
                                                        |
| 2963 | - * @param string $template_field  | 
                                                        |
| 2964 | - * @param array $form_data  | 
                                                        |
| 2965 | - * @return bool  | 
                                                        |
| 2966 | - * @throws EE_Error  | 
                                                        |
| 2967 | - * @since 4.10.29.p  | 
                                                        |
| 2968 | - */  | 
                                                        |
| 2969 | - private function updateMessageTemplates($template_field, array $form_data)  | 
                                                        |
| 2970 | -    { | 
                                                        |
| 2971 | - $MTP_ID = $form_data['MTP_ID'];  | 
                                                        |
| 2972 | - $message_template_fields = [  | 
                                                        |
| 2973 | - 'GRP_ID' => $form_data['GRP_ID'],  | 
                                                        |
| 2974 | - 'MTP_template_field' => $form_data['MTP_template_field'],  | 
                                                        |
| 2975 | - 'MTP_context' => $form_data['MTP_context'],  | 
                                                        |
| 2976 | - 'MTP_content' => $form_data['MTP_content'],  | 
                                                        |
| 2977 | - ];  | 
                                                        |
| 2978 | -  | 
                                                        |
| 2979 | - $hasMtpID = ! empty($MTP_ID);  | 
                                                        |
| 2980 | - // if we have a MTP_ID for this field then update it, otherwise insert.  | 
                                                        |
| 2981 | - // this has already been through the template field validator and sanitized, so it will be  | 
                                                        |
| 2982 | - // safe to insert this field. Why insert? This typically happens when we introduce a new  | 
                                                        |
| 2983 | - // message template field in a messenger/message type and existing users don't have the  | 
                                                        |
| 2984 | - // default setup for it.  | 
                                                        |
| 2985 | - // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465  | 
                                                        |
| 2986 | - $updated = $hasMtpID  | 
                                                        |
| 2987 | - ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])  | 
                                                        |
| 2988 | - : $this->getMtpModel()->insert($message_template_fields);  | 
                                                        |
| 2989 | -  | 
                                                        |
| 2990 | - $insert_failed = ! $hasMtpID && ! $updated;  | 
                                                        |
| 2991 | - // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)  | 
                                                        |
| 2992 | - // but we won't consider that a problem, but if it returns false, then something went BOOM!  | 
                                                        |
| 2993 | - $update_failed = $hasMtpID && $updated === false;  | 
                                                        |
| 2994 | -  | 
                                                        |
| 2995 | -        if ($insert_failed || $update_failed) { | 
                                                        |
| 2996 | - EE_Error::add_error(  | 
                                                        |
| 2997 | - sprintf(  | 
                                                        |
| 2998 | -                    esc_html__('%s field was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2999 | - $template_field  | 
                                                        |
| 3000 | - ),  | 
                                                        |
| 3001 | - __FILE__,  | 
                                                        |
| 3002 | - __FUNCTION__,  | 
                                                        |
| 3003 | - __LINE__  | 
                                                        |
| 3004 | - );  | 
                                                        |
| 3005 | - return false;  | 
                                                        |
| 3006 | - }  | 
                                                        |
| 3007 | - return true;  | 
                                                        |
| 3008 | - }  | 
                                                        |
| 3009 | -  | 
                                                        |
| 3010 | -  | 
                                                        |
| 3011 | - /**  | 
                                                        |
| 3012 | - * @param array $form_data  | 
                                                        |
| 3013 | - * @return bool  | 
                                                        |
| 3014 | - * @throws EE_Error  | 
                                                        |
| 3015 | - * @since 4.10.29.p  | 
                                                        |
| 3016 | - */  | 
                                                        |
| 3017 | - private function updateMessageTemplateGroup(array $form_data)  | 
                                                        |
| 3018 | -    { | 
                                                        |
| 3019 | - $GRP_ID = $form_data['GRP_ID'];  | 
                                                        |
| 3020 | - $updated = $this->getMtgModel()->update(  | 
                                                        |
| 3021 | - // fields and values  | 
                                                        |
| 3022 | - [  | 
                                                        |
| 3023 | - 'MTP_user_id' => $form_data['MTP_user_id'],  | 
                                                        |
| 3024 | - 'MTP_messenger' => $form_data['MTP_messenger'],  | 
                                                        |
| 3025 | - 'MTP_message_type' => $form_data['MTP_message_type'],  | 
                                                        |
| 3026 | - 'MTP_is_global' => $form_data['MTP_is_global'],  | 
                                                        |
| 3027 | - 'MTP_is_override' => $form_data['MTP_is_override'],  | 
                                                        |
| 3028 | - 'MTP_deleted' => $form_data['MTP_deleted'],  | 
                                                        |
| 3029 | - 'MTP_is_active' => $form_data['MTP_is_active'],  | 
                                                        |
| 3030 | -                'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''), | 
                                                        |
| 3031 | - 'MTP_description' => $this->request->getRequestParam(  | 
                                                        |
| 3032 | - 'ee_msg_non_global_fields[MTP_description]',  | 
                                                        |
| 3033 | - ''  | 
                                                        |
| 3034 | - ),  | 
                                                        |
| 3035 | - ],  | 
                                                        |
| 3036 | - // where  | 
                                                        |
| 3037 | - [['GRP_ID' => $GRP_ID]]  | 
                                                        |
| 3038 | - );  | 
                                                        |
| 3039 | -  | 
                                                        |
| 3040 | -        if ($updated === false) { | 
                                                        |
| 3041 | - EE_Error::add_error(  | 
                                                        |
| 3042 | - sprintf(  | 
                                                        |
| 3043 | - esc_html__(  | 
                                                        |
| 3044 | - 'The Message Template Group (%d) was NOT updated for some reason',  | 
                                                        |
| 3045 | - 'event_espresso'  | 
                                                        |
| 3046 | - ),  | 
                                                        |
| 3047 | - $form_data['GRP_ID']  | 
                                                        |
| 3048 | - ),  | 
                                                        |
| 3049 | - __FILE__,  | 
                                                        |
| 3050 | - __FUNCTION__,  | 
                                                        |
| 3051 | - __LINE__  | 
                                                        |
| 3052 | - );  | 
                                                        |
| 3053 | - return false;  | 
                                                        |
| 3054 | - }  | 
                                                        |
| 3055 | - // k now we need to ensure the template_pack and template_variation fields are set.  | 
                                                        |
| 3056 | -        $template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default'); | 
                                                        |
| 3057 | -        $template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); | 
                                                        |
| 3058 | -  | 
                                                        |
| 3059 | - $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 3060 | -        if ($message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 3061 | - $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 3062 | - $message_template_group->set_template_pack_variation($template_variation);  | 
                                                        |
| 3063 | - }  | 
                                                        |
| 3064 | - return true;  | 
                                                        |
| 3065 | - }  | 
                                                        |
| 3066 | -  | 
                                                        |
| 3067 | -  | 
                                                        |
| 3068 | - /**  | 
                                                        |
| 3069 | - * recursively runs wp_kses() on message template content in a model safe manner  | 
                                                        |
| 3070 | - *  | 
                                                        |
| 3071 | - * @param array|string $content  | 
                                                        |
| 3072 | - * @return array|string  | 
                                                        |
| 3073 | - * @since 4.10.29.p  | 
                                                        |
| 3074 | - */  | 
                                                        |
| 3075 | - private function sanitizeMessageTemplateContent($content)  | 
                                                        |
| 3076 | -    { | 
                                                        |
| 3077 | -        if (is_array($content)) { | 
                                                        |
| 3078 | -            foreach ($content as $key => $value) { | 
                                                        |
| 3079 | - $content[ $key ] = $this->sanitizeMessageTemplateContent($value);  | 
                                                        |
| 3080 | - }  | 
                                                        |
| 3081 | - return $content;  | 
                                                        |
| 3082 | - }  | 
                                                        |
| 3083 | - // remove slashes so wp_kses() works properly  | 
                                                        |
| 3084 | - // wp_kses_stripslashes() only removes slashes from double-quotes,  | 
                                                        |
| 3085 | - // so attributes using single quotes always appear invalid.  | 
                                                        |
| 3086 | - $content = stripslashes($content);  | 
                                                        |
| 3087 | -        $content = wp_kses($content, wp_kses_allowed_html('post')); | 
                                                        |
| 3088 | - // But currently the models expect slashed data, so after wp_kses()  | 
                                                        |
| 3089 | - // runs we need to re-slash the data. Sheesh.  | 
                                                        |
| 3090 | - // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587  | 
                                                        |
| 3091 | - return addslashes($content);  | 
                                                        |
| 3092 | - }  | 
                                                        |
| 3093 | -  | 
                                                        |
| 3094 | -  | 
                                                        |
| 3095 | - /**  | 
                                                        |
| 3096 | - * @param string $messenger  | 
                                                        |
| 3097 | - * @param string $message_type  | 
                                                        |
| 3098 | - * @param string $context  | 
                                                        |
| 3099 | - * @return string  | 
                                                        |
| 3100 | - * @since 4.10.29.p  | 
                                                        |
| 3101 | - */  | 
                                                        |
| 3102 | - private function generateUpdateDescription($messenger, $message_type, $context)  | 
                                                        |
| 3103 | -    { | 
                                                        |
| 3104 | - // need the message type and messenger objects to be able to use the labels for the notices  | 
                                                        |
| 3105 | - $messenger_object = $this->_message_resource_manager->get_messenger($messenger);  | 
                                                        |
| 3106 | - $messenger_label = $messenger_object instanceof EE_messenger  | 
                                                        |
| 3107 | - ? ucwords($messenger_object->label['singular'])  | 
                                                        |
| 3108 | - : '';  | 
                                                        |
| 3109 | -  | 
                                                        |
| 3110 | - $message_type_object = $this->_message_resource_manager->get_message_type($message_type);  | 
                                                        |
| 3111 | - $message_type_label = $message_type_object instanceof EE_message_type  | 
                                                        |
| 3112 | - ? ucwords($message_type_object->label['singular'])  | 
                                                        |
| 3113 | - : '';  | 
                                                        |
| 3114 | -  | 
                                                        |
| 3115 | -        $context   = ucwords(str_replace('_', ' ', $context)); | 
                                                        |
| 3116 | - $item_desc = $messenger_label && $message_type_label  | 
                                                        |
| 3117 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '  | 
                                                        |
| 3118 | - : '';  | 
                                                        |
| 3119 | - $item_desc .= 'Message Template';  | 
                                                        |
| 3120 | - return $item_desc;  | 
                                                        |
| 3121 | - }  | 
                                                        |
| 3122 | -  | 
                                                        |
| 3123 | -  | 
                                                        |
| 3124 | - /**  | 
                                                        |
| 3125 | - * @param string $messenger  | 
                                                        |
| 3126 | - * @param string $message_type  | 
                                                        |
| 3127 | - * @param string $context  | 
                                                        |
| 3128 | - * @return bool  | 
                                                        |
| 3129 | - * @throws EE_Error  | 
                                                        |
| 3130 | - * @throws ReflectionException  | 
                                                        |
| 3131 | - * @since 4.10.29.p  | 
                                                        |
| 3132 | - */  | 
                                                        |
| 3133 | - private function performTestSendAfterUpdate($messenger, $message_type, $context)  | 
                                                        |
| 3134 | -    { | 
                                                        |
| 3135 | - // was a test send triggered?  | 
                                                        |
| 3136 | -        if ($this->request->requestParamIsSet('test_button')) { | 
                                                        |
| 3137 | - EE_Error::overwrite_success();  | 
                                                        |
| 3138 | - $this->_do_test_send($context, $messenger, $message_type);  | 
                                                        |
| 3139 | - return true;  | 
                                                        |
| 3140 | - }  | 
                                                        |
| 3141 | - return false;  | 
                                                        |
| 3142 | - }  | 
                                                        |
| 3143 | -  | 
                                                        |
| 3144 | -  | 
                                                        |
| 3145 | - /**  | 
                                                        |
| 3146 | - * processes a test send request to do an actual messenger delivery test for the given message template being tested  | 
                                                        |
| 3147 | - *  | 
                                                        |
| 3148 | - * @param string $context what context being tested  | 
                                                        |
| 3149 | - * @param string $messenger messenger being tested  | 
                                                        |
| 3150 | - * @param string $message_type message type being tested  | 
                                                        |
| 3151 | - * @throws EE_Error  | 
                                                        |
| 3152 | - * @throws InvalidArgumentException  | 
                                                        |
| 3153 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3154 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3155 | - * @throws ReflectionException  | 
                                                        |
| 3156 | - */  | 
                                                        |
| 3157 | - protected function _do_test_send($context, $messenger, $message_type)  | 
                                                        |
| 3158 | -    { | 
                                                        |
| 3159 | - // set things up for preview  | 
                                                        |
| 3160 | -        $this->request->setRequestParam('messenger', $messenger); | 
                                                        |
| 3161 | -        $this->request->setRequestParam('message_type', $message_type); | 
                                                        |
| 3162 | -        $this->request->setRequestParam('context', $context); | 
                                                        |
| 3163 | -        $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 3164 | -        $this->request->setRequestParam('GRP_ID', $GRP_ID); | 
                                                        |
| 3165 | -  | 
                                                        |
| 3166 | - $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);  | 
                                                        |
| 3167 | -        $test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true); | 
                                                        |
| 3168 | -  | 
                                                        |
| 3169 | - // let's save any existing fields that might be required by the messenger  | 
                                                        |
| 3170 | - if (  | 
                                                        |
| 3171 | - ! empty($test_settings_fld)  | 
                                                        |
| 3172 | - && $active_messenger instanceof EE_messenger  | 
                                                        |
| 3173 | - && apply_filters(  | 
                                                        |
| 3174 | - 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',  | 
                                                        |
| 3175 | - true,  | 
                                                        |
| 3176 | - $test_settings_fld,  | 
                                                        |
| 3177 | - $active_messenger  | 
                                                        |
| 3178 | - )  | 
                                                        |
| 3179 | -        ) { | 
                                                        |
| 3180 | - $active_messenger->set_existing_test_settings($test_settings_fld);  | 
                                                        |
| 3181 | - }  | 
                                                        |
| 3182 | -  | 
                                                        |
| 3183 | - /**  | 
                                                        |
| 3184 | - * Use filter to add additional controls on whether message can send or not  | 
                                                        |
| 3185 | - */  | 
                                                        |
| 3186 | - if (  | 
                                                        |
| 3187 | - apply_filters(  | 
                                                        |
| 3188 | - 'FHEE__Messages_Admin_Page__do_test_send__can_send',  | 
                                                        |
| 3189 | - true,  | 
                                                        |
| 3190 | - $context,  | 
                                                        |
| 3191 | - $this->request->requestParams(),  | 
                                                        |
| 3192 | - $messenger,  | 
                                                        |
| 3193 | - $message_type  | 
                                                        |
| 3194 | - )  | 
                                                        |
| 3195 | -        ) { | 
                                                        |
| 3196 | -            if (EEM_Event::instance()->count() > 0) { | 
                                                        |
| 3197 | - $success = $this->_preview_message(true);  | 
                                                        |
| 3198 | -                if ($success) { | 
                                                        |
| 3199 | -                    EE_Error::add_success(esc_html__('Test message sent', 'event_espresso')); | 
                                                        |
| 3200 | -                } else { | 
                                                        |
| 3201 | - EE_Error::add_error(  | 
                                                        |
| 3202 | -                        esc_html__('The test message was not sent', 'event_espresso'), | 
                                                        |
| 3203 | - __FILE__,  | 
                                                        |
| 3204 | - __FUNCTION__,  | 
                                                        |
| 3205 | - __LINE__  | 
                                                        |
| 3206 | - );  | 
                                                        |
| 3207 | - }  | 
                                                        |
| 3208 | -            } else { | 
                                                        |
| 3209 | - $this->noEventsErrorMessage(true);  | 
                                                        |
| 3210 | - }  | 
                                                        |
| 3211 | - }  | 
                                                        |
| 3212 | - }  | 
                                                        |
| 3213 | -  | 
                                                        |
| 3214 | -  | 
                                                        |
| 3215 | - /**  | 
                                                        |
| 3216 | - * _generate_new_templates  | 
                                                        |
| 3217 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 3218 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 3219 | - * for the event.  | 
                                                        |
| 3220 | - *  | 
                                                        |
| 3221 | - *  | 
                                                        |
| 3222 | - * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 3223 | - * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 3224 | - * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to  | 
                                                        |
| 3225 | - * indicate the message_template_group being used as the base.  | 
                                                        |
| 3226 | - *  | 
                                                        |
| 3227 | - * @param bool $global  | 
                                                        |
| 3228 | - *  | 
                                                        |
| 3229 | - * @return array|bool array of data required for the redirect to the correct edit page or bool if  | 
                                                        |
| 3230 | - * encountering problems.  | 
                                                        |
| 3231 | - * @throws EE_Error  | 
                                                        |
| 3232 | - * @throws ReflectionException  | 
                                                        |
| 3233 | - */  | 
                                                        |
| 3234 | - protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 3235 | -    { | 
                                                        |
| 3236 | - // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we  | 
                                                        |
| 3237 | - // just don't generate any templates.  | 
                                                        |
| 3238 | -        if (empty($message_types)) { | 
                                                        |
| 3239 | - return [];  | 
                                                        |
| 3240 | - }  | 
                                                        |
| 3241 | -  | 
                                                        |
| 3242 | - $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);  | 
                                                        |
| 3243 | - return $templates[0];  | 
                                                        |
| 3244 | - }  | 
                                                        |
| 3245 | -  | 
                                                        |
| 3246 | -  | 
                                                        |
| 3247 | - /**  | 
                                                        |
| 3248 | - * [_trash_or_restore_message_template]  | 
                                                        |
| 3249 | - *  | 
                                                        |
| 3250 | - * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)  | 
                                                        |
| 3251 | - * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just  | 
                                                        |
| 3252 | - * an individual context (FALSE).  | 
                                                        |
| 3253 | - * @return void  | 
                                                        |
| 3254 | - * @throws EE_Error  | 
                                                        |
| 3255 | - * @throws InvalidArgumentException  | 
                                                        |
| 3256 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3257 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3258 | - */  | 
                                                        |
| 3259 | - protected function _trash_or_restore_message_template($trash = true, $all = false)  | 
                                                        |
| 3260 | -    { | 
                                                        |
| 3261 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 3262 | -  | 
                                                        |
| 3263 | - $success = 1;  | 
                                                        |
| 3264 | -  | 
                                                        |
| 3265 | - // incoming GRP_IDs  | 
                                                        |
| 3266 | -        if ($all) { | 
                                                        |
| 3267 | - // Checkboxes  | 
                                                        |
| 3268 | -            $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        |
| 3269 | -            if (! empty($checkboxes)) { | 
                                                        |
| 3270 | - // if array has more than one element then success message should be plural.  | 
                                                        |
| 3271 | - // todo: what about nonce?  | 
                                                        |
| 3272 | - $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        |
| 3273 | -  | 
                                                        |
| 3274 | - // cycle through checkboxes  | 
                                                        |
| 3275 | -                while (list($GRP_ID, $value) = each($checkboxes)) { | 
                                                        |
| 3276 | - $trashed_or_restored = $trash  | 
                                                        |
| 3277 | - ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        |
| 3278 | - : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        |
| 3279 | -                    if (! $trashed_or_restored) { | 
                                                        |
| 3280 | - $success = 0;  | 
                                                        |
| 3281 | - }  | 
                                                        |
| 3282 | - }  | 
                                                        |
| 3283 | -            } else { | 
                                                        |
| 3284 | - // grab single GRP_ID and handle  | 
                                                        |
| 3285 | -                $GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 3286 | -                if (! empty($GRP_ID)) { | 
                                                        |
| 3287 | - $trashed_or_restored = $trash  | 
                                                        |
| 3288 | - ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        |
| 3289 | - : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        |
| 3290 | -                    if (! $trashed_or_restored) { | 
                                                        |
| 3291 | - $success = 0;  | 
                                                        |
| 3292 | - }  | 
                                                        |
| 3293 | -                } else { | 
                                                        |
| 3294 | - $success = 0;  | 
                                                        |
| 3295 | - }  | 
                                                        |
| 3296 | - }  | 
                                                        |
| 3297 | - }  | 
                                                        |
| 3298 | -  | 
                                                        |
| 3299 | - $action_desc = $trash  | 
                                                        |
| 3300 | -            ? esc_html__('moved to the trash', 'event_espresso') | 
                                                        |
| 3301 | -            : esc_html__('restored', 'event_espresso'); | 
                                                        |
| 3302 | -  | 
                                                        |
| 3303 | -        $template_switch = $this->request->getRequestParam('template_switch', false, 'bool'); | 
                                                        |
| 3304 | -        $action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc; | 
                                                        |
| 3305 | -  | 
                                                        |
| 3306 | - $item_desc = $all ? _n(  | 
                                                        |
| 3307 | - 'Message Template Group',  | 
                                                        |
| 3308 | - 'Message Template Groups',  | 
                                                        |
| 3309 | - $success,  | 
                                                        |
| 3310 | - 'event_espresso'  | 
                                                        |
| 3311 | -        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | 
                                                        |
| 3312 | -  | 
                                                        |
| 3313 | - $item_desc = $template_switch  | 
                                                        |
| 3314 | -            ? _n('template', 'templates', $success, 'event_espresso') | 
                                                        |
| 3315 | - : $item_desc;  | 
                                                        |
| 3316 | -  | 
                                                        |
| 3317 | - $this->_redirect_after_action($success, $item_desc, $action_desc, []);  | 
                                                        |
| 3318 | - }  | 
                                                        |
| 3319 | -  | 
                                                        |
| 3320 | -  | 
                                                        |
| 3321 | - /**  | 
                                                        |
| 3322 | - * [_delete_message_template]  | 
                                                        |
| 3323 | - * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.  | 
                                                        |
| 3324 | - *  | 
                                                        |
| 3325 | - * @return void  | 
                                                        |
| 3326 | - * @throws EE_Error  | 
                                                        |
| 3327 | - * @throws InvalidArgumentException  | 
                                                        |
| 3328 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3329 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3330 | - * @throws ReflectionException  | 
                                                        |
| 3331 | - */  | 
                                                        |
| 3332 | - protected function _delete_message_template()  | 
                                                        |
| 3333 | -    { | 
                                                        |
| 3334 | -        do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 3335 | -  | 
                                                        |
| 3336 | - // checkboxes  | 
                                                        |
| 3337 | -        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        |
| 3338 | -        if (! empty($checkboxes)) { | 
                                                        |
| 3339 | - // if array has more than one element then success message should be plural  | 
                                                        |
| 3340 | - $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        |
| 3341 | -  | 
                                                        |
| 3342 | - // cycle through bulk action checkboxes  | 
                                                        |
| 3343 | -            while (list($GRP_ID, $value) = each($checkboxes)) { | 
                                                        |
| 3344 | - $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;  | 
                                                        |
| 3345 | - }  | 
                                                        |
| 3346 | -        } else { | 
                                                        |
| 3347 | - // grab single grp_id and delete  | 
                                                        |
| 3348 | -            $GRP_ID  = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 3349 | - $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 3350 | - }  | 
                                                        |
| 3351 | -  | 
                                                        |
| 3352 | - $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);  | 
                                                        |
| 3353 | - }  | 
                                                        |
| 3354 | -  | 
                                                        |
| 3355 | -  | 
                                                        |
| 3356 | - /**  | 
                                                        |
| 3357 | - * helper for permanently deleting a mtP group and all related message_templates  | 
                                                        |
| 3358 | - *  | 
                                                        |
| 3359 | - * @param int $GRP_ID The group being deleted  | 
                                                        |
| 3360 | - * @param bool $include_group whether to delete the Message Template Group as well.  | 
                                                        |
| 3361 | - * @return bool boolean to indicate the success of the deletes or not.  | 
                                                        |
| 3362 | - * @throws EE_Error  | 
                                                        |
| 3363 | - * @throws InvalidArgumentException  | 
                                                        |
| 3364 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3365 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3366 | - * @throws ReflectionException  | 
                                                        |
| 3367 | - * @throws ReflectionException  | 
                                                        |
| 3368 | - */  | 
                                                        |
| 3369 | - private function _delete_mtp_permanently($GRP_ID, $include_group = true)  | 
                                                        |
| 3370 | -    { | 
                                                        |
| 3371 | - $success = true;  | 
                                                        |
| 3372 | - // first let's GET this group  | 
                                                        |
| 3373 | - $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 3374 | - // then delete permanently all the related Message Templates  | 
                                                        |
| 3375 | -        $deleted = $MTG->delete_related_permanently('Message_Template'); | 
                                                        |
| 3376 | -  | 
                                                        |
| 3377 | -        if ($deleted === 0) { | 
                                                        |
| 3378 | - $success = false;  | 
                                                        |
| 3379 | - }  | 
                                                        |
| 3380 | -  | 
                                                        |
| 3381 | - // now delete permanently this particular group  | 
                                                        |
| 3382 | -  | 
                                                        |
| 3383 | -        if ($include_group && ! $MTG->delete_permanently()) { | 
                                                        |
| 3384 | - $success = false;  | 
                                                        |
| 3385 | - }  | 
                                                        |
| 3386 | -  | 
                                                        |
| 3387 | - return $success;  | 
                                                        |
| 3388 | - }  | 
                                                        |
| 3389 | -  | 
                                                        |
| 3390 | -  | 
                                                        |
| 3391 | - /**  | 
                                                        |
| 3392 | - * _learn_more_about_message_templates_link  | 
                                                        |
| 3393 | - *  | 
                                                        |
| 3394 | - * @access protected  | 
                                                        |
| 3395 | - * @return string  | 
                                                        |
| 3396 | - */  | 
                                                        |
| 3397 | - protected function _learn_more_about_message_templates_link()  | 
                                                        |
| 3398 | -    { | 
                                                        |
| 3399 | - return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'  | 
                                                        |
| 3400 | -               . esc_html__('learn more about how message templates works', 'event_espresso') | 
                                                        |
| 3401 | - . '</a>';  | 
                                                        |
| 3402 | - }  | 
                                                        |
| 3403 | -  | 
                                                        |
| 3404 | -  | 
                                                        |
| 3405 | - /**  | 
                                                        |
| 3406 | - * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by  | 
                                                        |
| 3407 | - * ajax and other routes.  | 
                                                        |
| 3408 | - *  | 
                                                        |
| 3409 | - * @return void  | 
                                                        |
| 3410 | - * @throws DomainException  | 
                                                        |
| 3411 | - * @throws EE_Error  | 
                                                        |
| 3412 | - */  | 
                                                        |
| 3413 | - protected function _settings()  | 
                                                        |
| 3414 | -    { | 
                                                        |
| 3415 | - $this->_set_m_mt_settings();  | 
                                                        |
| 3416 | -  | 
                                                        |
| 3417 | - // let's setup the messenger tabs  | 
                                                        |
| 3418 | - $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(  | 
                                                        |
| 3419 | - $this->_m_mt_settings['messenger_tabs'],  | 
                                                        |
| 3420 | - 'messenger_links',  | 
                                                        |
| 3421 | - '|',  | 
                                                        |
| 3422 | -            $this->request->getRequestParam('selected_messenger', 'email') | 
                                                        |
| 3423 | - );  | 
                                                        |
| 3424 | -  | 
                                                        |
| 3425 | - $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';  | 
                                                        |
| 3426 | - $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';  | 
                                                        |
| 3427 | -  | 
                                                        |
| 3428 | - $this->display_admin_page_with_sidebar();  | 
                                                        |
| 3429 | - }  | 
                                                        |
| 3430 | -  | 
                                                        |
| 3431 | -  | 
                                                        |
| 3432 | - /**  | 
                                                        |
| 3433 | - * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)  | 
                                                        |
| 3434 | - *  | 
                                                        |
| 3435 | - * @access protected  | 
                                                        |
| 3436 | - * @return void  | 
                                                        |
| 3437 | - * @throws DomainException  | 
                                                        |
| 3438 | - */  | 
                                                        |
| 3439 | - protected function _set_m_mt_settings()  | 
                                                        |
| 3440 | -    { | 
                                                        |
| 3441 | - // first if this is already set then lets get out no need to regenerate data.  | 
                                                        |
| 3442 | -        if (! empty($this->_m_mt_settings)) { | 
                                                        |
| 3443 | - return;  | 
                                                        |
| 3444 | - }  | 
                                                        |
| 3445 | -  | 
                                                        |
| 3446 | - // get all installed messengers and message_types  | 
                                                        |
| 3447 | - $messengers = $this->_message_resource_manager->installed_messengers();  | 
                                                        |
| 3448 | - $message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 3449 | -  | 
                                                        |
| 3450 | -  | 
                                                        |
| 3451 | - // assemble the array for the _tab_text_links helper  | 
                                                        |
| 3452 | -  | 
                                                        |
| 3453 | -        foreach ($messengers as $messenger) { | 
                                                        |
| 3454 | - $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3455 | - $class = 'ee-messenger-' . sanitize_key($messenger->label['singular']);  | 
                                                        |
| 3456 | - $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [  | 
                                                        |
| 3457 | - 'label' => ucwords($messenger->label['singular']),  | 
                                                        |
| 3458 | -                'class' => $active ? "{$class} messenger-active" : $class, | 
                                                        |
| 3459 | - 'href' => $messenger->name,  | 
                                                        |
| 3460 | -                'title' => esc_html__('Modify this Messenger', 'event_espresso'), | 
                                                        |
| 3461 | - 'slug' => $messenger->name,  | 
                                                        |
| 3462 | - 'obj' => $messenger,  | 
                                                        |
| 3463 | - 'icon' => $active  | 
                                                        |
| 3464 | - ? '<span class="dashicons dashicons-yes-alt"></span>'  | 
                                                        |
| 3465 | - : '<span class="dashicons dashicons-remove"></span>',  | 
                                                        |
| 3466 | - ];  | 
                                                        |
| 3467 | -  | 
                                                        |
| 3468 | -  | 
                                                        |
| 3469 | - $message_types_for_messenger = $messenger->get_valid_message_types();  | 
                                                        |
| 3470 | -  | 
                                                        |
| 3471 | -            foreach ($message_types as $message_type) { | 
                                                        |
| 3472 | - // first we need to verify that this message type is valid with this messenger. Cause if it isn't then  | 
                                                        |
| 3473 | - // it shouldn't show in either the inactive OR active metabox.  | 
                                                        |
| 3474 | -                if (! in_array($message_type->name, $message_types_for_messenger, true)) { | 
                                                        |
| 3475 | - continue;  | 
                                                        |
| 3476 | - }  | 
                                                        |
| 3477 | -  | 
                                                        |
| 3478 | - $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 3479 | - $messenger->name,  | 
                                                        |
| 3480 | - $message_type->name  | 
                                                        |
| 3481 | - )  | 
                                                        |
| 3482 | - ? 'active'  | 
                                                        |
| 3483 | - : 'inactive';  | 
                                                        |
| 3484 | -  | 
                                                        |
| 3485 | - $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [  | 
                                                        |
| 3486 | - 'label' => ucwords($message_type->label['singular']),  | 
                                                        |
| 3487 | - 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 3488 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 3489 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 3490 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 3491 | - 'title' => $a_or_i === 'active'  | 
                                                        |
| 3492 | -                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        |
| 3493 | -                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        |
| 3494 | - 'content' => $a_or_i === 'active'  | 
                                                        |
| 3495 | - ? $this->_message_type_settings_content($message_type, $messenger, true)  | 
                                                        |
| 3496 | - : $this->_message_type_settings_content($message_type, $messenger),  | 
                                                        |
| 3497 | - 'slug' => $message_type->name,  | 
                                                        |
| 3498 | - 'active' => $a_or_i === 'active',  | 
                                                        |
| 3499 | - 'obj' => $message_type,  | 
                                                        |
| 3500 | - ];  | 
                                                        |
| 3501 | - }  | 
                                                        |
| 3502 | - }  | 
                                                        |
| 3503 | - }  | 
                                                        |
| 3504 | -  | 
                                                        |
| 3505 | -  | 
                                                        |
| 3506 | - /**  | 
                                                        |
| 3507 | - * This just prepares the content for the message type settings  | 
                                                        |
| 3508 | - *  | 
                                                        |
| 3509 | - * @param EE_message_type $message_type The message type object  | 
                                                        |
| 3510 | - * @param EE_messenger $messenger The messenger object  | 
                                                        |
| 3511 | - * @param boolean $active Whether the message type is active or not  | 
                                                        |
| 3512 | - * @return string html output for the content  | 
                                                        |
| 3513 | - * @throws DomainException  | 
                                                        |
| 3514 | - */  | 
                                                        |
| 3515 | - protected function _message_type_settings_content($message_type, $messenger, $active = false)  | 
                                                        |
| 3516 | -    { | 
                                                        |
| 3517 | - // get message type fields  | 
                                                        |
| 3518 | - $fields = $message_type->get_admin_settings_fields();  | 
                                                        |
| 3519 | - $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3520 | -  | 
                                                        |
| 3521 | -        if (! empty($fields) && $active) { | 
                                                        |
| 3522 | - $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        |
| 3523 | -            foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 3524 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 3525 | - $template_form_field[ $field_id ] = [  | 
                                                        |
| 3526 | - 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 3527 | - 'label' => $fldprops['label'],  | 
                                                        |
| 3528 | - 'input' => $fldprops['field_type'],  | 
                                                        |
| 3529 | - 'type' => $fldprops['value_type'],  | 
                                                        |
| 3530 | - 'required' => $fldprops['required'],  | 
                                                        |
| 3531 | - 'validation' => $fldprops['validation'],  | 
                                                        |
| 3532 | - 'value' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3533 | - ? $existing_settings[ $fldname ]  | 
                                                        |
| 3534 | - : $fldprops['default'],  | 
                                                        |
| 3535 | - 'options' => isset($fldprops['options'])  | 
                                                        |
| 3536 | - ? $fldprops['options']  | 
                                                        |
| 3537 | - : [],  | 
                                                        |
| 3538 | - 'default' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3539 | - ? $existing_settings[ $fldname ]  | 
                                                        |
| 3540 | - : $fldprops['default'],  | 
                                                        |
| 3541 | - 'css_class' => 'no-drag',  | 
                                                        |
| 3542 | - 'format' => $fldprops['format'],  | 
                                                        |
| 3543 | - ];  | 
                                                        |
| 3544 | - }  | 
                                                        |
| 3545 | -  | 
                                                        |
| 3546 | -  | 
                                                        |
| 3547 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3548 | - ? $this->_generate_admin_form_fields(  | 
                                                        |
| 3549 | - $template_form_field,  | 
                                                        |
| 3550 | - 'string',  | 
                                                        |
| 3551 | - 'ee_mt_activate_form'  | 
                                                        |
| 3552 | - )  | 
                                                        |
| 3553 | - : '';  | 
                                                        |
| 3554 | - }  | 
                                                        |
| 3555 | -  | 
                                                        |
| 3556 | - $settings_template_args['description'] = $message_type->description;  | 
                                                        |
| 3557 | - // we also need some hidden fields  | 
                                                        |
| 3558 | - $hidden_fields = [  | 
                                                        |
| 3559 | - 'message_type_settings[messenger]' . $message_type->name => [  | 
                                                        |
| 3560 | - 'type' => 'hidden',  | 
                                                        |
| 3561 | - 'value' => $messenger->name,  | 
                                                        |
| 3562 | - ],  | 
                                                        |
| 3563 | - 'message_type_settings[message_type]' . $message_type->name => [  | 
                                                        |
| 3564 | - 'type' => 'hidden',  | 
                                                        |
| 3565 | - 'value' => $message_type->name,  | 
                                                        |
| 3566 | - ],  | 
                                                        |
| 3567 | - 'type' . $message_type->name => [  | 
                                                        |
| 3568 | - 'type' => 'hidden',  | 
                                                        |
| 3569 | - 'value' => 'message_type',  | 
                                                        |
| 3570 | - ],  | 
                                                        |
| 3571 | - ];  | 
                                                        |
| 3572 | -  | 
                                                        |
| 3573 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3574 | - $hidden_fields,  | 
                                                        |
| 3575 | - 'array'  | 
                                                        |
| 3576 | - );  | 
                                                        |
| 3577 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3578 | - ? ' hidden'  | 
                                                        |
| 3579 | - : '';  | 
                                                        |
| 3580 | -  | 
                                                        |
| 3581 | -  | 
                                                        |
| 3582 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 3583 | - return EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        |
| 3584 | - }  | 
                                                        |
| 3585 | -  | 
                                                        |
| 3586 | -  | 
                                                        |
| 3587 | - /**  | 
                                                        |
| 3588 | - * Generate all the metaboxes for the message types and register them for the messages settings page.  | 
                                                        |
| 3589 | - *  | 
                                                        |
| 3590 | - * @access protected  | 
                                                        |
| 3591 | - * @return void  | 
                                                        |
| 3592 | - * @throws DomainException  | 
                                                        |
| 3593 | - */  | 
                                                        |
| 3594 | - protected function _messages_settings_metaboxes()  | 
                                                        |
| 3595 | -    { | 
                                                        |
| 3596 | - $this->_set_m_mt_settings();  | 
                                                        |
| 3597 | - $m_boxes = $mt_boxes = [];  | 
                                                        |
| 3598 | - $m_template_args = $mt_template_args = [];  | 
                                                        |
| 3599 | -  | 
                                                        |
| 3600 | -        $selected_messenger = $this->request->getRequestParam('selected_messenger', 'email'); | 
                                                        |
| 3601 | -  | 
                                                        |
| 3602 | -        if (isset($this->_m_mt_settings['messenger_tabs'])) { | 
                                                        |
| 3603 | -            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | 
                                                        |
| 3604 | - $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);  | 
                                                        |
| 3605 | - $hide_on_message = $is_messenger_active ? '' : 'hidden';  | 
                                                        |
| 3606 | - $hide_off_message = $is_messenger_active ? 'hidden' : '';  | 
                                                        |
| 3607 | -  | 
                                                        |
| 3608 | - // messenger meta boxes  | 
                                                        |
| 3609 | - $active = $selected_messenger === $messenger;  | 
                                                        |
| 3610 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])  | 
                                                        |
| 3611 | - ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']  | 
                                                        |
| 3612 | - : '';  | 
                                                        |
| 3613 | -  | 
                                                        |
| 3614 | - $m_boxes[ $messenger . '_a_box' ] = sprintf(  | 
                                                        |
| 3615 | -                    esc_html__('%s Settings', 'event_espresso'), | 
                                                        |
| 3616 | - $tab_array['label']  | 
                                                        |
| 3617 | - );  | 
                                                        |
| 3618 | -  | 
                                                        |
| 3619 | - $m_template_args[ $messenger . '_a_box' ] = [  | 
                                                        |
| 3620 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 3621 | - 'inactive_message_types' => isset(  | 
                                                        |
| 3622 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3623 | - )  | 
                                                        |
| 3624 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3625 | - : '',  | 
                                                        |
| 3626 | - 'content' => $this->_get_messenger_box_content($tab_array['obj']),  | 
                                                        |
| 3627 | - 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 3628 | - 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 3629 | - 'messenger' => $messenger,  | 
                                                        |
| 3630 | - 'active' => $active,  | 
                                                        |
| 3631 | - ];  | 
                                                        |
| 3632 | -  | 
                                                        |
| 3633 | - // message type meta boxes  | 
                                                        |
| 3634 | - // (which is really just the inactive container for each messenger  | 
                                                        |
| 3635 | - // showing inactive message types for that messenger)  | 
                                                        |
| 3636 | -                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 3637 | - $mt_template_args[ $messenger . '_i_box' ] = [  | 
                                                        |
| 3638 | - 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 3639 | - 'inactive_message_types' => isset(  | 
                                                        |
| 3640 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3641 | - )  | 
                                                        |
| 3642 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3643 | - : '',  | 
                                                        |
| 3644 | - 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 3645 | - 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 3646 | - 'hide_off_message' => $hide_off_message,  | 
                                                        |
| 3647 | - 'messenger' => $messenger,  | 
                                                        |
| 3648 | - 'active' => $active,  | 
                                                        |
| 3649 | - ];  | 
                                                        |
| 3650 | - }  | 
                                                        |
| 3651 | - }  | 
                                                        |
| 3652 | -  | 
                                                        |
| 3653 | -  | 
                                                        |
| 3654 | - // register messenger metaboxes  | 
                                                        |
| 3655 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 3656 | -        foreach ($m_boxes as $box => $label) { | 
                                                        |
| 3657 | - $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];  | 
                                                        |
| 3658 | -            $msgr          = str_replace('_a_box', '', $box); | 
                                                        |
| 3659 | - $this->addMetaBox(  | 
                                                        |
| 3660 | - 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 3661 | - $label,  | 
                                                        |
| 3662 | -                function ($post, $metabox) { | 
                                                        |
| 3663 | - EEH_Template::display_template(  | 
                                                        |
| 3664 | - $metabox['args']['template_path'],  | 
                                                        |
| 3665 | - $metabox['args']['template_args']  | 
                                                        |
| 3666 | - );  | 
                                                        |
| 3667 | - },  | 
                                                        |
| 3668 | - $this->_current_screen->id,  | 
                                                        |
| 3669 | - 'normal',  | 
                                                        |
| 3670 | - 'high',  | 
                                                        |
| 3671 | - $callback_args  | 
                                                        |
| 3672 | - );  | 
                                                        |
| 3673 | - }  | 
                                                        |
| 3674 | -  | 
                                                        |
| 3675 | - // register message type metaboxes  | 
                                                        |
| 3676 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 3677 | -        foreach ($mt_boxes as $box => $label) { | 
                                                        |
| 3678 | - $callback_args = [  | 
                                                        |
| 3679 | - 'template_path' => $mt_template_path,  | 
                                                        |
| 3680 | - 'template_args' => $mt_template_args[ $box ],  | 
                                                        |
| 3681 | - ];  | 
                                                        |
| 3682 | -            $mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 3683 | - $this->addMetaBox(  | 
                                                        |
| 3684 | - 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 3685 | - $label,  | 
                                                        |
| 3686 | -                function ($post, $metabox) { | 
                                                        |
| 3687 | - EEH_Template::display_template(  | 
                                                        |
| 3688 | - $metabox['args']['template_path'],  | 
                                                        |
| 3689 | - $metabox['args']['template_args']  | 
                                                        |
| 3690 | - );  | 
                                                        |
| 3691 | - },  | 
                                                        |
| 3692 | - $this->_current_screen->id,  | 
                                                        |
| 3693 | - 'side',  | 
                                                        |
| 3694 | - 'high',  | 
                                                        |
| 3695 | - $callback_args  | 
                                                        |
| 3696 | - );  | 
                                                        |
| 3697 | - }  | 
                                                        |
| 3698 | -  | 
                                                        |
| 3699 | - // register metabox for global messages settings but only when on the main site. On single site installs this  | 
                                                        |
| 3700 | - // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.  | 
                                                        |
| 3701 | -        if (is_main_site()) { | 
                                                        |
| 3702 | - $this->addMetaBox(  | 
                                                        |
| 3703 | - 'espresso_global_message_settings',  | 
                                                        |
| 3704 | -                esc_html__('Global Message Settings', 'event_espresso'), | 
                                                        |
| 3705 | - [$this, 'global_messages_settings_metabox_content'],  | 
                                                        |
| 3706 | - $this->_current_screen->id,  | 
                                                        |
| 3707 | - 'normal',  | 
                                                        |
| 3708 | - 'low',  | 
                                                        |
| 3709 | - []  | 
                                                        |
| 3710 | - );  | 
                                                        |
| 3711 | - }  | 
                                                        |
| 3712 | - }  | 
                                                        |
| 3713 | -  | 
                                                        |
| 3714 | -  | 
                                                        |
| 3715 | - /**  | 
                                                        |
| 3716 | - * This generates the content for the global messages settings metabox.  | 
                                                        |
| 3717 | - *  | 
                                                        |
| 3718 | - * @return void  | 
                                                        |
| 3719 | - * @throws EE_Error  | 
                                                        |
| 3720 | - * @throws InvalidArgumentException  | 
                                                        |
| 3721 | - * @throws ReflectionException  | 
                                                        |
| 3722 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3723 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3724 | - */  | 
                                                        |
| 3725 | - public function global_messages_settings_metabox_content()  | 
                                                        |
| 3726 | -    { | 
                                                        |
| 3727 | - $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3728 | - echo wp_kses(  | 
                                                        |
| 3729 | - $form->form_open(  | 
                                                        |
| 3730 | - $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),  | 
                                                        |
| 3731 | - 'POST'  | 
                                                        |
| 3732 | - ),  | 
                                                        |
| 3733 | - AllowedTags::getWithFormTags()  | 
                                                        |
| 3734 | - );  | 
                                                        |
| 3735 | - echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());  | 
                                                        |
| 3736 | - echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());  | 
                                                        |
| 3737 | - }  | 
                                                        |
| 3738 | -  | 
                                                        |
| 3739 | -  | 
                                                        |
| 3740 | - /**  | 
                                                        |
| 3741 | - * This generates and returns the form object for the global messages settings.  | 
                                                        |
| 3742 | - *  | 
                                                        |
| 3743 | - * @return EE_Form_Section_Proper  | 
                                                        |
| 3744 | - * @throws EE_Error  | 
                                                        |
| 3745 | - * @throws InvalidArgumentException  | 
                                                        |
| 3746 | - * @throws ReflectionException  | 
                                                        |
| 3747 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3748 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3749 | - */  | 
                                                        |
| 3750 | - protected function _generate_global_settings_form()  | 
                                                        |
| 3751 | -    { | 
                                                        |
| 3752 | - /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3753 | - $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3754 | -  | 
                                                        |
| 3755 | - return new EE_Form_Section_Proper(  | 
                                                        |
| 3756 | - [  | 
                                                        |
| 3757 | - 'name' => 'global_messages_settings',  | 
                                                        |
| 3758 | - 'html_id' => 'global_messages_settings',  | 
                                                        |
| 3759 | - 'html_class' => 'form-table',  | 
                                                        |
| 3760 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 3761 | - 'subsections' => apply_filters(  | 
                                                        |
| 3762 | - 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',  | 
                                                        |
| 3763 | - [  | 
                                                        |
| 3764 | - 'do_messages_on_same_request' => new EE_Select_Input(  | 
                                                        |
| 3765 | - [  | 
                                                        |
| 3766 | -                                true  => esc_html__('On the same request', 'event_espresso'), | 
                                                        |
| 3767 | -                                false => esc_html__('On a separate request', 'event_espresso'), | 
                                                        |
| 3768 | - ],  | 
                                                        |
| 3769 | - [  | 
                                                        |
| 3770 | - 'default' => $network_config->do_messages_on_same_request,  | 
                                                        |
| 3771 | - 'html_label_text' => esc_html__(  | 
                                                        |
| 3772 | - 'Generate and send all messages:',  | 
                                                        |
| 3773 | - 'event_espresso'  | 
                                                        |
| 3774 | - ),  | 
                                                        |
| 3775 | - 'html_help_text' => esc_html__(  | 
                                                        |
| 3776 | - 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',  | 
                                                        |
| 3777 | - 'event_espresso'  | 
                                                        |
| 3778 | - ),  | 
                                                        |
| 3779 | - ]  | 
                                                        |
| 3780 | - ),  | 
                                                        |
| 3781 | - 'delete_threshold' => new EE_Select_Input(  | 
                                                        |
| 3782 | - [  | 
                                                        |
| 3783 | -                                0  => esc_html__('Forever', 'event_espresso'), | 
                                                        |
| 3784 | -                                3  => esc_html__('3 Months', 'event_espresso'), | 
                                                        |
| 3785 | -                                6  => esc_html__('6 Months', 'event_espresso'), | 
                                                        |
| 3786 | -                                9  => esc_html__('9 Months', 'event_espresso'), | 
                                                        |
| 3787 | -                                12 => esc_html__('12 Months', 'event_espresso'), | 
                                                        |
| 3788 | -                                24 => esc_html__('24 Months', 'event_espresso'), | 
                                                        |
| 3789 | -                                36 => esc_html__('36 Months', 'event_espresso'), | 
                                                        |
| 3790 | - ],  | 
                                                        |
| 3791 | - [  | 
                                                        |
| 3792 | - 'default' => EE_Registry::instance()->CFG->messages->delete_threshold,  | 
                                                        |
| 3793 | -                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | 
                                                        |
| 3794 | - 'html_help_text' => esc_html__(  | 
                                                        |
| 3795 | - 'You can control how long a record of processed messages is kept via this option.',  | 
                                                        |
| 3796 | - 'event_espresso'  | 
                                                        |
| 3797 | - ),  | 
                                                        |
| 3798 | - ]  | 
                                                        |
| 3799 | - ),  | 
                                                        |
| 3800 | - 'update_settings' => new EE_Submit_Input(  | 
                                                        |
| 3801 | - [  | 
                                                        |
| 3802 | -                                'default'         => esc_html__('Update', 'event_espresso'), | 
                                                        |
| 3803 | - 'html_label_text' => '',  | 
                                                        |
| 3804 | - ]  | 
                                                        |
| 3805 | - ),  | 
                                                        |
| 3806 | - ]  | 
                                                        |
| 3807 | - ),  | 
                                                        |
| 3808 | - ]  | 
                                                        |
| 3809 | - );  | 
                                                        |
| 3810 | - }  | 
                                                        |
| 3811 | -  | 
                                                        |
| 3812 | -  | 
                                                        |
| 3813 | - /**  | 
                                                        |
| 3814 | - * This handles updating the global settings set on the admin page.  | 
                                                        |
| 3815 | - *  | 
                                                        |
| 3816 | - * @throws EE_Error  | 
                                                        |
| 3817 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3818 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3819 | - * @throws InvalidArgumentException  | 
                                                        |
| 3820 | - * @throws ReflectionException  | 
                                                        |
| 3821 | - */  | 
                                                        |
| 3822 | - protected function _update_global_settings()  | 
                                                        |
| 3823 | -    { | 
                                                        |
| 3824 | - /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3825 | - $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3826 | - $messages_config = EE_Registry::instance()->CFG->messages;  | 
                                                        |
| 3827 | - $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3828 | -        if ($form->was_submitted()) { | 
                                                        |
| 3829 | - $form->receive_form_submission();  | 
                                                        |
| 3830 | -            if ($form->is_valid()) { | 
                                                        |
| 3831 | - $valid_data = $form->valid_data();  | 
                                                        |
| 3832 | -                foreach ($valid_data as $property => $value) { | 
                                                        |
| 3833 | - $setter = 'set_' . $property;  | 
                                                        |
| 3834 | -                    if (method_exists($network_config, $setter)) { | 
                                                        |
| 3835 | -                        $network_config->{$setter}($value); | 
                                                        |
| 3836 | - } elseif (  | 
                                                        |
| 3837 | - property_exists($network_config, $property)  | 
                                                        |
| 3838 | -                        && $network_config->{$property} !== $value | 
                                                        |
| 3839 | -                    ) { | 
                                                        |
| 3840 | -                        $network_config->{$property} = $value; | 
                                                        |
| 3841 | - } elseif (  | 
                                                        |
| 3842 | - property_exists($messages_config, $property)  | 
                                                        |
| 3843 | -                        && $messages_config->{$property} !== $value | 
                                                        |
| 3844 | -                    ) { | 
                                                        |
| 3845 | -                        $messages_config->{$property} = $value; | 
                                                        |
| 3846 | - }  | 
                                                        |
| 3847 | - }  | 
                                                        |
| 3848 | - // only update if the form submission was valid!  | 
                                                        |
| 3849 | - EE_Registry::instance()->NET_CFG->update_config(true, false);  | 
                                                        |
| 3850 | - EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 3851 | - EE_Error::overwrite_success();  | 
                                                        |
| 3852 | -                EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso')); | 
                                                        |
| 3853 | - }  | 
                                                        |
| 3854 | - }  | 
                                                        |
| 3855 | - $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);  | 
                                                        |
| 3856 | - }  | 
                                                        |
| 3857 | -  | 
                                                        |
| 3858 | -  | 
                                                        |
| 3859 | - /**  | 
                                                        |
| 3860 | - * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate  | 
                                                        |
| 3861 | - *  | 
                                                        |
| 3862 | - * @param array $tab_array This is an array of message type tab details used to generate the tabs  | 
                                                        |
| 3863 | - * @return string html formatted tabs  | 
                                                        |
| 3864 | - * @throws DomainException  | 
                                                        |
| 3865 | - */  | 
                                                        |
| 3866 | - protected function _get_mt_tabs($tab_array)  | 
                                                        |
| 3867 | -    { | 
                                                        |
| 3868 | - $tab_array = (array) $tab_array;  | 
                                                        |
| 3869 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3870 | - $tabs = '';  | 
                                                        |
| 3871 | -  | 
                                                        |
| 3872 | -        foreach ($tab_array as $tab) { | 
                                                        |
| 3873 | - $tabs .= EEH_Template::display_template($template, $tab, true);  | 
                                                        |
| 3874 | - }  | 
                                                        |
| 3875 | -  | 
                                                        |
| 3876 | - return $tabs;  | 
                                                        |
| 3877 | - }  | 
                                                        |
| 3878 | -  | 
                                                        |
| 3879 | -  | 
                                                        |
| 3880 | - /**  | 
                                                        |
| 3881 | - * This prepares the content of the messenger meta box admin settings  | 
                                                        |
| 3882 | - *  | 
                                                        |
| 3883 | - * @param EE_messenger $messenger The messenger we're setting up content for  | 
                                                        |
| 3884 | - * @return string html formatted content  | 
                                                        |
| 3885 | - * @throws DomainException  | 
                                                        |
| 3886 | - */  | 
                                                        |
| 3887 | - protected function _get_messenger_box_content(EE_messenger $messenger)  | 
                                                        |
| 3888 | -    { | 
                                                        |
| 3889 | -  | 
                                                        |
| 3890 | - $fields = $messenger->get_admin_settings_fields();  | 
                                                        |
| 3891 | -  | 
                                                        |
| 3892 | - $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3893 | - // is $messenger active?  | 
                                                        |
| 3894 | - $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3895 | -  | 
                                                        |
| 3896 | -  | 
                                                        |
| 3897 | -        if (! empty($fields)) { | 
                                                        |
| 3898 | - $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        |
| 3899 | -  | 
                                                        |
| 3900 | -            foreach ($fields as $field_name => $field_props) { | 
                                                        |
| 3901 | - $field_id = $messenger->name . '-' . $field_name;  | 
                                                        |
| 3902 | - $template_form_field[ $field_id ] = [  | 
                                                        |
| 3903 | - 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3904 | - 'label' => $field_props['label'],  | 
                                                        |
| 3905 | - 'input' => $field_props['field_type'],  | 
                                                        |
| 3906 | - 'type' => $field_props['value_type'],  | 
                                                        |
| 3907 | - 'required' => $field_props['required'],  | 
                                                        |
| 3908 | - 'validation' => $field_props['validation'],  | 
                                                        |
| 3909 | - 'value' => $existing_settings[ $field_id ] ?? $field_props['default'],  | 
                                                        |
| 3910 | - 'css_class' => '',  | 
                                                        |
| 3911 | - 'format' => $field_props['format'],  | 
                                                        |
| 3912 | - ];  | 
                                                        |
| 3913 | - }  | 
                                                        |
| 3914 | -  | 
                                                        |
| 3915 | - $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3916 | - ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')  | 
                                                        |
| 3917 | - : '';  | 
                                                        |
| 3918 | - }  | 
                                                        |
| 3919 | -  | 
                                                        |
| 3920 | - // we also need some hidden fields  | 
                                                        |
| 3921 | - $settings_template_args['hidden_fields'] = [  | 
                                                        |
| 3922 | - 'messenger_settings[messenger]' . $messenger->name => [  | 
                                                        |
| 3923 | - 'type' => 'hidden',  | 
                                                        |
| 3924 | - 'value' => $messenger->name,  | 
                                                        |
| 3925 | - ],  | 
                                                        |
| 3926 | - 'type' . $messenger->name => [  | 
                                                        |
| 3927 | - 'type' => 'hidden',  | 
                                                        |
| 3928 | - 'value' => 'messenger',  | 
                                                        |
| 3929 | - ],  | 
                                                        |
| 3930 | - ];  | 
                                                        |
| 3931 | -  | 
                                                        |
| 3932 | - // make sure any active message types that are existing are included in the hidden fields  | 
                                                        |
| 3933 | -        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { | 
                                                        |
| 3934 | -            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { | 
                                                        |
| 3935 | - $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [  | 
                                                        |
| 3936 | - 'type' => 'hidden',  | 
                                                        |
| 3937 | - 'value' => $mt,  | 
                                                        |
| 3938 | - ];  | 
                                                        |
| 3939 | - }  | 
                                                        |
| 3940 | - }  | 
                                                        |
| 3941 | - $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3942 | - $settings_template_args['hidden_fields'],  | 
                                                        |
| 3943 | - 'array'  | 
                                                        |
| 3944 | - );  | 
                                                        |
| 3945 | - $active =  | 
                                                        |
| 3946 | - $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3947 | -  | 
                                                        |
| 3948 | - $settings_template_args['messenger'] = $messenger->name;  | 
                                                        |
| 3949 | - $settings_template_args['description'] = $messenger->description;  | 
                                                        |
| 3950 | - $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';  | 
                                                        |
| 3951 | -  | 
                                                        |
| 3952 | -  | 
                                                        |
| 3953 | - $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(  | 
                                                        |
| 3954 | - $messenger->name  | 
                                                        |
| 3955 | - )  | 
                                                        |
| 3956 | - ? $settings_template_args['show_hide_edit_form']  | 
                                                        |
| 3957 | - : ' hidden';  | 
                                                        |
| 3958 | -  | 
                                                        |
| 3959 | - $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3960 | - ? ' hidden'  | 
                                                        |
| 3961 | - : $settings_template_args['show_hide_edit_form'];  | 
                                                        |
| 3962 | -  | 
                                                        |
| 3963 | -  | 
                                                        |
| 3964 | - $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        |
| 3965 | -        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3966 | - $settings_template_args['on_off_status'] = $active;  | 
                                                        |
| 3967 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3968 | - return EEH_Template::display_template(  | 
                                                        |
| 3969 | - $template,  | 
                                                        |
| 3970 | - $settings_template_args,  | 
                                                        |
| 3971 | - true  | 
                                                        |
| 3972 | - );  | 
                                                        |
| 3973 | - }  | 
                                                        |
| 3974 | -  | 
                                                        |
| 3975 | -  | 
                                                        |
| 3976 | - /**  | 
                                                        |
| 3977 | - * used by ajax on the messages settings page to activate|deactivate the messenger  | 
                                                        |
| 3978 | - *  | 
                                                        |
| 3979 | - * @throws DomainException  | 
                                                        |
| 3980 | - * @throws EE_Error  | 
                                                        |
| 3981 | - * @throws InvalidDataTypeException  | 
                                                        |
| 3982 | - * @throws InvalidInterfaceException  | 
                                                        |
| 3983 | - * @throws InvalidArgumentException  | 
                                                        |
| 3984 | - * @throws ReflectionException  | 
                                                        |
| 3985 | - */  | 
                                                        |
| 3986 | - public function activate_messenger_toggle()  | 
                                                        |
| 3987 | -    { | 
                                                        |
| 3988 | - $success = true;  | 
                                                        |
| 3989 | - $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3990 | - // let's check that we have required data  | 
                                                        |
| 3991 | -  | 
                                                        |
| 3992 | -        if (! $this->_active_messenger_name) { | 
                                                        |
| 3993 | - EE_Error::add_error(  | 
                                                        |
| 3994 | -                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3995 | - __FILE__,  | 
                                                        |
| 3996 | - __FUNCTION__,  | 
                                                        |
| 3997 | - __LINE__  | 
                                                        |
| 3998 | - );  | 
                                                        |
| 3999 | - $success = false;  | 
                                                        |
| 4000 | - }  | 
                                                        |
| 4001 | -  | 
                                                        |
| 4002 | - // do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 4003 | -        $nonce     = $this->request->getRequestParam('activate_nonce', ''); | 
                                                        |
| 4004 | -        $nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce"; | 
                                                        |
| 4005 | -  | 
                                                        |
| 4006 | - $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 4007 | -  | 
                                                        |
| 4008 | -  | 
                                                        |
| 4009 | -        $status = $this->request->getRequestParam('status'); | 
                                                        |
| 4010 | -        if (! $status) { | 
                                                        |
| 4011 | - EE_Error::add_error(  | 
                                                        |
| 4012 | - esc_html__(  | 
                                                        |
| 4013 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 4014 | - 'event_espresso'  | 
                                                        |
| 4015 | - ),  | 
                                                        |
| 4016 | - __FILE__,  | 
                                                        |
| 4017 | - __FUNCTION__,  | 
                                                        |
| 4018 | - __LINE__  | 
                                                        |
| 4019 | - );  | 
                                                        |
| 4020 | - $success = false;  | 
                                                        |
| 4021 | - }  | 
                                                        |
| 4022 | -  | 
                                                        |
| 4023 | - // do check to verify we have a valid status.  | 
                                                        |
| 4024 | -        if ($status !== 'off' && $status !== 'on') { | 
                                                        |
| 4025 | - EE_Error::add_error(  | 
                                                        |
| 4026 | - sprintf(  | 
                                                        |
| 4027 | -                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 4028 | - $status  | 
                                                        |
| 4029 | - ),  | 
                                                        |
| 4030 | - __FILE__,  | 
                                                        |
| 4031 | - __FUNCTION__,  | 
                                                        |
| 4032 | - __LINE__  | 
                                                        |
| 4033 | - );  | 
                                                        |
| 4034 | - $success = false;  | 
                                                        |
| 4035 | - }  | 
                                                        |
| 4036 | -  | 
                                                        |
| 4037 | -        if ($success) { | 
                                                        |
| 4038 | - // made it here? Stop dawdling then!!  | 
                                                        |
| 4039 | - $success = $status === 'off'  | 
                                                        |
| 4040 | - ? $this->_deactivate_messenger($this->_active_messenger_name)  | 
                                                        |
| 4041 | - : $this->_activate_messenger($this->_active_messenger_name);  | 
                                                        |
| 4042 | - }  | 
                                                        |
| 4043 | -  | 
                                                        |
| 4044 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 4045 | -  | 
                                                        |
| 4046 | - // no special instructions so let's just do the json return (which should automatically do all the special stuff).  | 
                                                        |
| 4047 | - $this->_return_json();  | 
                                                        |
| 4048 | - }  | 
                                                        |
| 4049 | -  | 
                                                        |
| 4050 | -  | 
                                                        |
| 4051 | - /**  | 
                                                        |
| 4052 | - * used by ajax from the messages settings page to activate|deactivate a message type  | 
                                                        |
| 4053 | - *  | 
                                                        |
| 4054 | - * @throws DomainException  | 
                                                        |
| 4055 | - * @throws EE_Error  | 
                                                        |
| 4056 | - * @throws ReflectionException  | 
                                                        |
| 4057 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4058 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4059 | - * @throws InvalidArgumentException  | 
                                                        |
| 4060 | - */  | 
                                                        |
| 4061 | - public function activate_mt_toggle()  | 
                                                        |
| 4062 | -    { | 
                                                        |
| 4063 | - $success = true;  | 
                                                        |
| 4064 | - $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 4065 | -  | 
                                                        |
| 4066 | - // let's make sure we have the necessary data  | 
                                                        |
| 4067 | -        if (! $this->_active_message_type_name) { | 
                                                        |
| 4068 | - EE_Error::add_error(  | 
                                                        |
| 4069 | -                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 4070 | - __FILE__,  | 
                                                        |
| 4071 | - __FUNCTION__,  | 
                                                        |
| 4072 | - __LINE__  | 
                                                        |
| 4073 | - );  | 
                                                        |
| 4074 | - $success = false;  | 
                                                        |
| 4075 | - }  | 
                                                        |
| 4076 | -  | 
                                                        |
| 4077 | -        if (! $this->_active_messenger_name) { | 
                                                        |
| 4078 | - EE_Error::add_error(  | 
                                                        |
| 4079 | -                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 4080 | - __FILE__,  | 
                                                        |
| 4081 | - __FUNCTION__,  | 
                                                        |
| 4082 | - __LINE__  | 
                                                        |
| 4083 | - );  | 
                                                        |
| 4084 | - $success = false;  | 
                                                        |
| 4085 | - }  | 
                                                        |
| 4086 | -  | 
                                                        |
| 4087 | -        $status = $this->request->getRequestParam('status'); | 
                                                        |
| 4088 | -        if (! $status) { | 
                                                        |
| 4089 | - EE_Error::add_error(  | 
                                                        |
| 4090 | - esc_html__(  | 
                                                        |
| 4091 | - 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 4092 | - 'event_espresso'  | 
                                                        |
| 4093 | - ),  | 
                                                        |
| 4094 | - __FILE__,  | 
                                                        |
| 4095 | - __FUNCTION__,  | 
                                                        |
| 4096 | - __LINE__  | 
                                                        |
| 4097 | - );  | 
                                                        |
| 4098 | - $success = false;  | 
                                                        |
| 4099 | - }  | 
                                                        |
| 4100 | -  | 
                                                        |
| 4101 | -  | 
                                                        |
| 4102 | - // do check to verify we have a valid status.  | 
                                                        |
| 4103 | -        if ($status !== 'activate' && $status !== 'deactivate') { | 
                                                        |
| 4104 | - EE_Error::add_error(  | 
                                                        |
| 4105 | - sprintf(  | 
                                                        |
| 4106 | -                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | 
                                                        |
| 4107 | - $status  | 
                                                        |
| 4108 | - ),  | 
                                                        |
| 4109 | - __FILE__,  | 
                                                        |
| 4110 | - __FUNCTION__,  | 
                                                        |
| 4111 | - __LINE__  | 
                                                        |
| 4112 | - );  | 
                                                        |
| 4113 | - $success = false;  | 
                                                        |
| 4114 | - }  | 
                                                        |
| 4115 | -  | 
                                                        |
| 4116 | -  | 
                                                        |
| 4117 | - // do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 4118 | -        $nonce = $this->request->getRequestParam('mt_nonce', ''); | 
                                                        |
| 4119 | -        $this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce"); | 
                                                        |
| 4120 | -  | 
                                                        |
| 4121 | -        if ($success) { | 
                                                        |
| 4122 | - // made it here? um, what are you waiting for then?  | 
                                                        |
| 4123 | - $success = $status === 'deactivate'  | 
                                                        |
| 4124 | - ? $this->_deactivate_message_type_for_messenger(  | 
                                                        |
| 4125 | - $this->_active_messenger_name,  | 
                                                        |
| 4126 | - $this->_active_message_type_name  | 
                                                        |
| 4127 | - )  | 
                                                        |
| 4128 | - : $this->_activate_message_type_for_messenger(  | 
                                                        |
| 4129 | - $this->_active_messenger_name,  | 
                                                        |
| 4130 | - $this->_active_message_type_name  | 
                                                        |
| 4131 | - );  | 
                                                        |
| 4132 | - }  | 
                                                        |
| 4133 | -  | 
                                                        |
| 4134 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 4135 | - $this->_return_json();  | 
                                                        |
| 4136 | - }  | 
                                                        |
| 4137 | -  | 
                                                        |
| 4138 | -  | 
                                                        |
| 4139 | - /**  | 
                                                        |
| 4140 | - * Takes care of processing activating a messenger and preparing the appropriate response.  | 
                                                        |
| 4141 | - *  | 
                                                        |
| 4142 | - * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 4143 | - * @return bool  | 
                                                        |
| 4144 | - * @throws DomainException  | 
                                                        |
| 4145 | - * @throws EE_Error  | 
                                                        |
| 4146 | - * @throws InvalidArgumentException  | 
                                                        |
| 4147 | - * @throws ReflectionException  | 
                                                        |
| 4148 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4149 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4150 | - */  | 
                                                        |
| 4151 | - protected function _activate_messenger($messenger_name)  | 
                                                        |
| 4152 | -    { | 
                                                        |
| 4153 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4154 | - $message_types_to_activate = $active_messenger instanceof EE_Messenger  | 
                                                        |
| 4155 | - ? $active_messenger->get_default_message_types()  | 
                                                        |
| 4156 | - : [];  | 
                                                        |
| 4157 | -  | 
                                                        |
| 4158 | - // ensure is active  | 
                                                        |
| 4159 | - $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);  | 
                                                        |
| 4160 | -  | 
                                                        |
| 4161 | - // set response_data for reload  | 
                                                        |
| 4162 | -        foreach ($message_types_to_activate as $message_type_name) { | 
                                                        |
| 4163 | - $message_type = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4164 | - if (  | 
                                                        |
| 4165 | - $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 4166 | - $messenger_name,  | 
                                                        |
| 4167 | - $message_type_name  | 
                                                        |
| 4168 | - )  | 
                                                        |
| 4169 | - && $message_type instanceof EE_message_type  | 
                                                        |
| 4170 | -            ) { | 
                                                        |
| 4171 | - $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 4172 | -                if ($message_type->get_admin_settings_fields()) { | 
                                                        |
| 4173 | - $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 4174 | - }  | 
                                                        |
| 4175 | - }  | 
                                                        |
| 4176 | - }  | 
                                                        |
| 4177 | -  | 
                                                        |
| 4178 | - // add success message for activating messenger  | 
                                                        |
| 4179 | - return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 4180 | - }  | 
                                                        |
| 4181 | -  | 
                                                        |
| 4182 | -  | 
                                                        |
| 4183 | - /**  | 
                                                        |
| 4184 | - * Takes care of processing deactivating a messenger and preparing the appropriate response.  | 
                                                        |
| 4185 | - *  | 
                                                        |
| 4186 | - * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 4187 | - * @return bool  | 
                                                        |
| 4188 | - * @throws DomainException  | 
                                                        |
| 4189 | - * @throws EE_Error  | 
                                                        |
| 4190 | - * @throws InvalidArgumentException  | 
                                                        |
| 4191 | - * @throws ReflectionException  | 
                                                        |
| 4192 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4193 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4194 | - */  | 
                                                        |
| 4195 | - protected function _deactivate_messenger($messenger_name)  | 
                                                        |
| 4196 | -    { | 
                                                        |
| 4197 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4198 | - $this->_message_resource_manager->deactivate_messenger($messenger_name);  | 
                                                        |
| 4199 | -  | 
                                                        |
| 4200 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 4201 | - }  | 
                                                        |
| 4202 | -  | 
                                                        |
| 4203 | -  | 
                                                        |
| 4204 | - /**  | 
                                                        |
| 4205 | - * Takes care of processing activating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 4206 | - *  | 
                                                        |
| 4207 | - * @param string $messenger_name The name of the messenger the message type is being activated for.  | 
                                                        |
| 4208 | - * @param string $message_type_name The name of the message type being activated for the messenger  | 
                                                        |
| 4209 | - * @return bool  | 
                                                        |
| 4210 | - * @throws DomainException  | 
                                                        |
| 4211 | - * @throws EE_Error  | 
                                                        |
| 4212 | - * @throws InvalidArgumentException  | 
                                                        |
| 4213 | - * @throws ReflectionException  | 
                                                        |
| 4214 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4215 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4216 | - */  | 
                                                        |
| 4217 | - protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 4218 | -    { | 
                                                        |
| 4219 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4220 | - $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4221 | -  | 
                                                        |
| 4222 | - // ensure is active  | 
                                                        |
| 4223 | - $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);  | 
                                                        |
| 4224 | -  | 
                                                        |
| 4225 | - // set response for load  | 
                                                        |
| 4226 | - if (  | 
                                                        |
| 4227 | - $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 4228 | - $messenger_name,  | 
                                                        |
| 4229 | - $message_type_name  | 
                                                        |
| 4230 | - )  | 
                                                        |
| 4231 | -        ) { | 
                                                        |
| 4232 | - $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 4233 | -            if ($message_type_to_activate->get_admin_settings_fields()) { | 
                                                        |
| 4234 | - $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 4235 | - }  | 
                                                        |
| 4236 | - }  | 
                                                        |
| 4237 | -  | 
                                                        |
| 4238 | - return $this->_setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 4239 | - $active_messenger,  | 
                                                        |
| 4240 | - $message_type_to_activate  | 
                                                        |
| 4241 | - );  | 
                                                        |
| 4242 | - }  | 
                                                        |
| 4243 | -  | 
                                                        |
| 4244 | -  | 
                                                        |
| 4245 | - /**  | 
                                                        |
| 4246 | - * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 4247 | - *  | 
                                                        |
| 4248 | - * @param string $messenger_name The name of the messenger the message type is being deactivated for.  | 
                                                        |
| 4249 | - * @param string $message_type_name The name of the message type being deactivated for the messenger  | 
                                                        |
| 4250 | - * @return bool  | 
                                                        |
| 4251 | - * @throws DomainException  | 
                                                        |
| 4252 | - * @throws EE_Error  | 
                                                        |
| 4253 | - * @throws InvalidArgumentException  | 
                                                        |
| 4254 | - * @throws ReflectionException  | 
                                                        |
| 4255 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4256 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4257 | - */  | 
                                                        |
| 4258 | - protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 4259 | -    { | 
                                                        |
| 4260 | - $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4261 | - /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 4262 | - $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4263 | - $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);  | 
                                                        |
| 4264 | -  | 
                                                        |
| 4265 | - return $this->_setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 4266 | - $active_messenger,  | 
                                                        |
| 4267 | - $message_type_to_deactivate  | 
                                                        |
| 4268 | - );  | 
                                                        |
| 4269 | - }  | 
                                                        |
| 4270 | -  | 
                                                        |
| 4271 | -  | 
                                                        |
| 4272 | - /**  | 
                                                        |
| 4273 | - * This just initializes the defaults for activating messenger and message type responses.  | 
                                                        |
| 4274 | - */  | 
                                                        |
| 4275 | - protected function _prep_default_response_for_messenger_or_message_type_toggle()  | 
                                                        |
| 4276 | -    { | 
                                                        |
| 4277 | - $this->_template_args['data']['active_mts'] = [];  | 
                                                        |
| 4278 | - $this->_template_args['data']['mt_reload'] = [];  | 
                                                        |
| 4279 | - }  | 
                                                        |
| 4280 | -  | 
                                                        |
| 4281 | -  | 
                                                        |
| 4282 | - /**  | 
                                                        |
| 4283 | - * Setup appropriate response for activating a messenger and/or message types  | 
                                                        |
| 4284 | - *  | 
                                                        |
| 4285 | - * @param EE_messenger $messenger  | 
                                                        |
| 4286 | - * @param EE_message_type|null $message_type  | 
                                                        |
| 4287 | - * @return bool  | 
                                                        |
| 4288 | - * @throws DomainException  | 
                                                        |
| 4289 | - * @throws EE_Error  | 
                                                        |
| 4290 | - * @throws InvalidArgumentException  | 
                                                        |
| 4291 | - * @throws ReflectionException  | 
                                                        |
| 4292 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4293 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4294 | - */  | 
                                                        |
| 4295 | - protected function _setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 4296 | - $messenger,  | 
                                                        |
| 4297 | - EE_Message_Type $message_type = null  | 
                                                        |
| 4298 | -    ) { | 
                                                        |
| 4299 | - // if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 4300 | -        if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4301 | - EE_Error::add_error(  | 
                                                        |
| 4302 | -                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 4303 | - __FILE__,  | 
                                                        |
| 4304 | - __FUNCTION__,  | 
                                                        |
| 4305 | - __LINE__  | 
                                                        |
| 4306 | - );  | 
                                                        |
| 4307 | - return false;  | 
                                                        |
| 4308 | - }  | 
                                                        |
| 4309 | - // activated  | 
                                                        |
| 4310 | -        if ($this->_template_args['data']['active_mts']) { | 
                                                        |
| 4311 | - EE_Error::overwrite_success();  | 
                                                        |
| 4312 | - // activated a message type with the messenger  | 
                                                        |
| 4313 | -            if ($message_type instanceof EE_message_type) { | 
                                                        |
| 4314 | - EE_Error::add_success(  | 
                                                        |
| 4315 | - sprintf(  | 
                                                        |
| 4316 | - esc_html__(  | 
                                                        |
| 4317 | - '%s message type has been successfully activated with the %s messenger',  | 
                                                        |
| 4318 | - 'event_espresso'  | 
                                                        |
| 4319 | - ),  | 
                                                        |
| 4320 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 4321 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4322 | - )  | 
                                                        |
| 4323 | - );  | 
                                                        |
| 4324 | -  | 
                                                        |
| 4325 | - // if message type was invoice then let's make sure we activate the invoice payment method.  | 
                                                        |
| 4326 | -                if ($message_type->name === 'invoice') { | 
                                                        |
| 4327 | -                    EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 4328 | -                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | 
                                                        |
| 4329 | -                    if ($pm instanceof EE_Payment_Method) { | 
                                                        |
| 4330 | - EE_Error::add_attention(  | 
                                                        |
| 4331 | - esc_html__(  | 
                                                        |
| 4332 | - '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.',  | 
                                                        |
| 4333 | - 'event_espresso'  | 
                                                        |
| 4334 | - )  | 
                                                        |
| 4335 | - );  | 
                                                        |
| 4336 | - }  | 
                                                        |
| 4337 | - }  | 
                                                        |
| 4338 | - // just toggles the entire messenger  | 
                                                        |
| 4339 | -            } else { | 
                                                        |
| 4340 | - EE_Error::add_success(  | 
                                                        |
| 4341 | - sprintf(  | 
                                                        |
| 4342 | -                        esc_html__('%s messenger has been successfully activated', 'event_espresso'), | 
                                                        |
| 4343 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4344 | - )  | 
                                                        |
| 4345 | - );  | 
                                                        |
| 4346 | - }  | 
                                                        |
| 4347 | -  | 
                                                        |
| 4348 | - return true;  | 
                                                        |
| 4349 | -  | 
                                                        |
| 4350 | - // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active  | 
                                                        |
| 4351 | - // message types after the activation process. However its possible some messengers don't HAVE any default_message_types  | 
                                                        |
| 4352 | - // in which case we just give a success message for the messenger being successfully activated.  | 
                                                        |
| 4353 | -        } else { | 
                                                        |
| 4354 | -            if (! $messenger->get_default_message_types()) { | 
                                                        |
| 4355 | - // messenger doesn't have any default message types so still a success.  | 
                                                        |
| 4356 | - EE_Error::add_success(  | 
                                                        |
| 4357 | - sprintf(  | 
                                                        |
| 4358 | -                        esc_html__('%s messenger was successfully activated.', 'event_espresso'), | 
                                                        |
| 4359 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4360 | - )  | 
                                                        |
| 4361 | - );  | 
                                                        |
| 4362 | -  | 
                                                        |
| 4363 | - return true;  | 
                                                        |
| 4364 | -            } else { | 
                                                        |
| 4365 | - EE_Error::add_error(  | 
                                                        |
| 4366 | - $message_type instanceof EE_message_type  | 
                                                        |
| 4367 | - ? sprintf(  | 
                                                        |
| 4368 | - esc_html__(  | 
                                                        |
| 4369 | - '%s message type was not successfully activated with the %s messenger',  | 
                                                        |
| 4370 | - 'event_espresso'  | 
                                                        |
| 4371 | - ),  | 
                                                        |
| 4372 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 4373 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4374 | - )  | 
                                                        |
| 4375 | - : sprintf(  | 
                                                        |
| 4376 | -                        esc_html__('%s messenger was not successfully activated', 'event_espresso'), | 
                                                        |
| 4377 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4378 | - ),  | 
                                                        |
| 4379 | - __FILE__,  | 
                                                        |
| 4380 | - __FUNCTION__,  | 
                                                        |
| 4381 | - __LINE__  | 
                                                        |
| 4382 | - );  | 
                                                        |
| 4383 | -  | 
                                                        |
| 4384 | - return false;  | 
                                                        |
| 4385 | - }  | 
                                                        |
| 4386 | - }  | 
                                                        |
| 4387 | - }  | 
                                                        |
| 4388 | -  | 
                                                        |
| 4389 | -  | 
                                                        |
| 4390 | - /**  | 
                                                        |
| 4391 | - * This sets up the appropriate response for deactivating a messenger and/or message type.  | 
                                                        |
| 4392 | - *  | 
                                                        |
| 4393 | - * @param EE_messenger $messenger  | 
                                                        |
| 4394 | - * @param EE_message_type|null $message_type  | 
                                                        |
| 4395 | - * @return bool  | 
                                                        |
| 4396 | - * @throws DomainException  | 
                                                        |
| 4397 | - * @throws EE_Error  | 
                                                        |
| 4398 | - * @throws InvalidArgumentException  | 
                                                        |
| 4399 | - * @throws ReflectionException  | 
                                                        |
| 4400 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4401 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4402 | - */  | 
                                                        |
| 4403 | - protected function _setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 4404 | - $messenger,  | 
                                                        |
| 4405 | - EE_message_type $message_type = null  | 
                                                        |
| 4406 | -    ) { | 
                                                        |
| 4407 | - EE_Error::overwrite_success();  | 
                                                        |
| 4408 | -  | 
                                                        |
| 4409 | - // if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 4410 | -        if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4411 | - EE_Error::add_error(  | 
                                                        |
| 4412 | -                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 4413 | - __FILE__,  | 
                                                        |
| 4414 | - __FUNCTION__,  | 
                                                        |
| 4415 | - __LINE__  | 
                                                        |
| 4416 | - );  | 
                                                        |
| 4417 | -  | 
                                                        |
| 4418 | - return false;  | 
                                                        |
| 4419 | - }  | 
                                                        |
| 4420 | -  | 
                                                        |
| 4421 | -        if ($message_type instanceof EE_message_type) { | 
                                                        |
| 4422 | - $message_type_name = $message_type->name;  | 
                                                        |
| 4423 | - EE_Error::add_success(  | 
                                                        |
| 4424 | - sprintf(  | 
                                                        |
| 4425 | - esc_html__(  | 
                                                        |
| 4426 | - '%s message type has been successfully deactivated for the %s messenger.',  | 
                                                        |
| 4427 | - 'event_espresso'  | 
                                                        |
| 4428 | - ),  | 
                                                        |
| 4429 | - ucwords($message_type->label['singular']),  | 
                                                        |
| 4430 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4431 | - )  | 
                                                        |
| 4432 | - );  | 
                                                        |
| 4433 | -        } else { | 
                                                        |
| 4434 | - $message_type_name = '';  | 
                                                        |
| 4435 | - EE_Error::add_success(  | 
                                                        |
| 4436 | - sprintf(  | 
                                                        |
| 4437 | -                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), | 
                                                        |
| 4438 | - ucwords($messenger->label['singular'])  | 
                                                        |
| 4439 | - )  | 
                                                        |
| 4440 | - );  | 
                                                        |
| 4441 | - }  | 
                                                        |
| 4442 | -  | 
                                                        |
| 4443 | - // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.  | 
                                                        |
| 4444 | - if (  | 
                                                        |
| 4445 | - $messenger->name === 'html'  | 
                                                        |
| 4446 | - && (  | 
                                                        |
| 4447 | - is_null($message_type)  | 
                                                        |
| 4448 | - || $message_type_name === 'invoice'  | 
                                                        |
| 4449 | - )  | 
                                                        |
| 4450 | -        ) { | 
                                                        |
| 4451 | -            EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 4452 | -            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | 
                                                        |
| 4453 | -            if ($count_updated > 0) { | 
                                                        |
| 4454 | - $msg = $message_type_name === 'invoice'  | 
                                                        |
| 4455 | - ? esc_html__(  | 
                                                        |
| 4456 | - '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.',  | 
                                                        |
| 4457 | - 'event_espresso'  | 
                                                        |
| 4458 | - )  | 
                                                        |
| 4459 | - : esc_html__(  | 
                                                        |
| 4460 | - '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.',  | 
                                                        |
| 4461 | - 'event_espresso'  | 
                                                        |
| 4462 | - );  | 
                                                        |
| 4463 | - EE_Error::add_attention($msg);  | 
                                                        |
| 4464 | - }  | 
                                                        |
| 4465 | - }  | 
                                                        |
| 4466 | -  | 
                                                        |
| 4467 | - return true;  | 
                                                        |
| 4468 | - }  | 
                                                        |
| 4469 | -  | 
                                                        |
| 4470 | -  | 
                                                        |
| 4471 | - /**  | 
                                                        |
| 4472 | - * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)  | 
                                                        |
| 4473 | - *  | 
                                                        |
| 4474 | - * @throws DomainException  | 
                                                        |
| 4475 | - * @throws EE_Error  | 
                                                        |
| 4476 | - * @throws EE_Error  | 
                                                        |
| 4477 | - */  | 
                                                        |
| 4478 | - public function update_mt_form()  | 
                                                        |
| 4479 | -    { | 
                                                        |
| 4480 | -        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) { | 
                                                        |
| 4481 | - EE_Error::add_error(  | 
                                                        |
| 4482 | -                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), | 
                                                        |
| 4483 | - __FILE__,  | 
                                                        |
| 4484 | - __FUNCTION__,  | 
                                                        |
| 4485 | - __LINE__  | 
                                                        |
| 4486 | - );  | 
                                                        |
| 4487 | - $this->_return_json();  | 
                                                        |
| 4488 | - }  | 
                                                        |
| 4489 | -  | 
                                                        |
| 4490 | - $message_types = $this->get_installed_message_types();  | 
                                                        |
| 4491 | - $message_type = $message_types[ $this->_active_message_type_name ];  | 
                                                        |
| 4492 | - $messenger = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);  | 
                                                        |
| 4493 | - $content = $this->_message_type_settings_content($message_type, $messenger, true);  | 
                                                        |
| 4494 | -  | 
                                                        |
| 4495 | - $this->_template_args['success'] = true;  | 
                                                        |
| 4496 | - $this->_template_args['content'] = $content;  | 
                                                        |
| 4497 | - $this->_return_json();  | 
                                                        |
| 4498 | - }  | 
                                                        |
| 4499 | -  | 
                                                        |
| 4500 | -  | 
                                                        |
| 4501 | - /**  | 
                                                        |
| 4502 | - * this handles saving the settings for a messenger or message type  | 
                                                        |
| 4503 | - *  | 
                                                        |
| 4504 | - * @throws EE_Error  | 
                                                        |
| 4505 | - * @throws EE_Error  | 
                                                        |
| 4506 | - */  | 
                                                        |
| 4507 | - public function save_settings()  | 
                                                        |
| 4508 | -    { | 
                                                        |
| 4509 | -        $type = $this->request->getRequestParam('type'); | 
                                                        |
| 4510 | -        if (! $type) { | 
                                                        |
| 4511 | - EE_Error::add_error(  | 
                                                        |
| 4512 | - esc_html__(  | 
                                                        |
| 4513 | - 'Cannot save settings because type is unknown (messenger settings or message type settings?)',  | 
                                                        |
| 4514 | - 'event_espresso'  | 
                                                        |
| 4515 | - ),  | 
                                                        |
| 4516 | - __FILE__,  | 
                                                        |
| 4517 | - __FUNCTION__,  | 
                                                        |
| 4518 | - __LINE__  | 
                                                        |
| 4519 | - );  | 
                                                        |
| 4520 | - $this->_template_args['error'] = true;  | 
                                                        |
| 4521 | - $this->_return_json();  | 
                                                        |
| 4522 | - }  | 
                                                        |
| 4523 | -  | 
                                                        |
| 4524 | -  | 
                                                        |
| 4525 | -        if ($type === 'messenger') { | 
                                                        |
| 4526 | - // this should be an array.  | 
                                                        |
| 4527 | -            $settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true); | 
                                                        |
| 4528 | - $messenger = $settings['messenger'];  | 
                                                        |
| 4529 | - // remove messenger and message_types from settings array  | 
                                                        |
| 4530 | - unset($settings['messenger'], $settings['message_types']);  | 
                                                        |
| 4531 | - $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);  | 
                                                        |
| 4532 | -        } elseif ($type === 'message_type') { | 
                                                        |
| 4533 | -            $settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true); | 
                                                        |
| 4534 | - $messenger = $settings['messenger'];  | 
                                                        |
| 4535 | - $message_type = $settings['message_type'];  | 
                                                        |
| 4536 | - // remove messenger and message_types from settings array  | 
                                                        |
| 4537 | - unset($settings['messenger'], $settings['message_types']);  | 
                                                        |
| 4538 | - $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);  | 
                                                        |
| 4539 | - }  | 
                                                        |
| 4540 | -  | 
                                                        |
| 4541 | - // okay we should have the data all setup. Now we just update!  | 
                                                        |
| 4542 | - $success = $this->_message_resource_manager->update_active_messengers_option();  | 
                                                        |
| 4543 | -  | 
                                                        |
| 4544 | -        if ($success) { | 
                                                        |
| 4545 | -            EE_Error::add_success(esc_html__('Settings updated', 'event_espresso')); | 
                                                        |
| 4546 | -        } else { | 
                                                        |
| 4547 | - EE_Error::add_error(  | 
                                                        |
| 4548 | -                esc_html__('Settings did not get updated', 'event_espresso'), | 
                                                        |
| 4549 | - __FILE__,  | 
                                                        |
| 4550 | - __FUNCTION__,  | 
                                                        |
| 4551 | - __LINE__  | 
                                                        |
| 4552 | - );  | 
                                                        |
| 4553 | - }  | 
                                                        |
| 4554 | -  | 
                                                        |
| 4555 | - $this->_template_args['success'] = $success;  | 
                                                        |
| 4556 | - $this->_return_json();  | 
                                                        |
| 4557 | - }  | 
                                                        |
| 4558 | -  | 
                                                        |
| 4559 | -  | 
                                                        |
| 4560 | -  | 
                                                        |
| 4561 | -  | 
                                                        |
| 4562 | - /** EE MESSAGE PROCESSING ACTIONS **/  | 
                                                        |
| 4563 | -  | 
                                                        |
| 4564 | -  | 
                                                        |
| 4565 | - /**  | 
                                                        |
| 4566 | - * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete  | 
                                                        |
| 4567 | - * However, this does not send immediately, it just queues for sending.  | 
                                                        |
| 4568 | - *  | 
                                                        |
| 4569 | - * @throws EE_Error  | 
                                                        |
| 4570 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4571 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4572 | - * @throws InvalidArgumentException  | 
                                                        |
| 4573 | - * @throws ReflectionException  | 
                                                        |
| 4574 | - * @since 4.9.0  | 
                                                        |
| 4575 | - */  | 
                                                        |
| 4576 | - protected function _generate_now()  | 
                                                        |
| 4577 | -    { | 
                                                        |
| 4578 | - EED_Messages::generate_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4579 | - $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4580 | - }  | 
                                                        |
| 4581 | -  | 
                                                        |
| 4582 | -  | 
                                                        |
| 4583 | - /**  | 
                                                        |
| 4584 | - * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that  | 
                                                        |
| 4585 | - * are EEM_Message::status_resend or EEM_Message::status_idle  | 
                                                        |
| 4586 | - *  | 
                                                        |
| 4587 | - * @throws EE_Error  | 
                                                        |
| 4588 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4589 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4590 | - * @throws InvalidArgumentException  | 
                                                        |
| 4591 | - * @throws ReflectionException  | 
                                                        |
| 4592 | - * @since 4.9.0  | 
                                                        |
| 4593 | - */  | 
                                                        |
| 4594 | - protected function _generate_and_send_now()  | 
                                                        |
| 4595 | -    { | 
                                                        |
| 4596 | - EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4597 | - $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4598 | - }  | 
                                                        |
| 4599 | -  | 
                                                        |
| 4600 | -  | 
                                                        |
| 4601 | - /**  | 
                                                        |
| 4602 | - * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.  | 
                                                        |
| 4603 | - *  | 
                                                        |
| 4604 | - * @throws EE_Error  | 
                                                        |
| 4605 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4606 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4607 | - * @throws InvalidArgumentException  | 
                                                        |
| 4608 | - * @throws ReflectionException  | 
                                                        |
| 4609 | - * @since 4.9.0  | 
                                                        |
| 4610 | - */  | 
                                                        |
| 4611 | - protected function _queue_for_resending()  | 
                                                        |
| 4612 | -    { | 
                                                        |
| 4613 | - EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());  | 
                                                        |
| 4614 | - $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4615 | - }  | 
                                                        |
| 4616 | -  | 
                                                        |
| 4617 | -  | 
                                                        |
| 4618 | - /**  | 
                                                        |
| 4619 | - * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue  | 
                                                        |
| 4620 | - *  | 
                                                        |
| 4621 | - * @throws EE_Error  | 
                                                        |
| 4622 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4623 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4624 | - * @throws InvalidArgumentException  | 
                                                        |
| 4625 | - * @throws ReflectionException  | 
                                                        |
| 4626 | - * @since 4.9.0  | 
                                                        |
| 4627 | - */  | 
                                                        |
| 4628 | - protected function _send_now()  | 
                                                        |
| 4629 | -    { | 
                                                        |
| 4630 | - EED_Messages::send_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4631 | - $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4632 | - }  | 
                                                        |
| 4633 | -  | 
                                                        |
| 4634 | -  | 
                                                        |
| 4635 | - /**  | 
                                                        |
| 4636 | - * Deletes EE_messages for IDs in the request.  | 
                                                        |
| 4637 | - *  | 
                                                        |
| 4638 | - * @throws EE_Error  | 
                                                        |
| 4639 | - * @throws InvalidDataTypeException  | 
                                                        |
| 4640 | - * @throws InvalidInterfaceException  | 
                                                        |
| 4641 | - * @throws InvalidArgumentException  | 
                                                        |
| 4642 | - * @since 4.9.0  | 
                                                        |
| 4643 | - */  | 
                                                        |
| 4644 | - protected function _delete_ee_messages()  | 
                                                        |
| 4645 | -    { | 
                                                        |
| 4646 | - $MSG_IDs = $this->_get_msg_ids_from_request();  | 
                                                        |
| 4647 | - $deleted_count = 0;  | 
                                                        |
| 4648 | -        foreach ($MSG_IDs as $MSG_ID) { | 
                                                        |
| 4649 | -            if ($this->getMsgModel()->delete_by_ID($MSG_ID)) { | 
                                                        |
| 4650 | - $deleted_count++;  | 
                                                        |
| 4651 | - }  | 
                                                        |
| 4652 | - }  | 
                                                        |
| 4653 | -        if ($deleted_count) { | 
                                                        |
| 4654 | - EE_Error::add_success(  | 
                                                        |
| 4655 | - esc_html(  | 
                                                        |
| 4656 | - _n(  | 
                                                        |
| 4657 | - 'Message successfully deleted',  | 
                                                        |
| 4658 | - 'Messages successfully deleted',  | 
                                                        |
| 4659 | - $deleted_count,  | 
                                                        |
| 4660 | - 'event_espresso'  | 
                                                        |
| 4661 | - )  | 
                                                        |
| 4662 | - )  | 
                                                        |
| 4663 | - );  | 
                                                        |
| 4664 | -        } else { | 
                                                        |
| 4665 | - EE_Error::add_error(  | 
                                                        |
| 4666 | -                _n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'), | 
                                                        |
| 4667 | - __FILE__,  | 
                                                        |
| 4668 | - __FUNCTION__,  | 
                                                        |
| 4669 | - __LINE__  | 
                                                        |
| 4670 | - );  | 
                                                        |
| 4671 | - }  | 
                                                        |
| 4672 | - $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4673 | - }  | 
                                                        |
| 4674 | -  | 
                                                        |
| 4675 | -  | 
                                                        |
| 4676 | - /**  | 
                                                        |
| 4677 | - * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.  | 
                                                        |
| 4678 | - *  | 
                                                        |
| 4679 | - * @return array  | 
                                                        |
| 4680 | - * @since 4.9.0  | 
                                                        |
| 4681 | - */  | 
                                                        |
| 4682 | - protected function _get_msg_ids_from_request()  | 
                                                        |
| 4683 | -    { | 
                                                        |
| 4684 | -        $MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true); | 
                                                        |
| 4685 | -        if (empty($MSG_IDs)) { | 
                                                        |
| 4686 | - return [];  | 
                                                        |
| 4687 | - }  | 
                                                        |
| 4688 | - // if 'MSG_ID' was just a single ID (not an array)  | 
                                                        |
| 4689 | - // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123  | 
                                                        |
| 4690 | - // otherwise, $MSG_IDs was already an array where message IDs were used as the keys  | 
                                                        |
| 4691 | - return count($MSG_IDs) === 1 && isset($MSG_IDs[0])  | 
                                                        |
| 4692 | - ? $MSG_IDs  | 
                                                        |
| 4693 | - : array_keys($MSG_IDs);  | 
                                                        |
| 4694 | - }  | 
                                                        |
| 2706 | + }  | 
                                                        |
| 2707 | +  | 
                                                        |
| 2708 | +  | 
                                                        |
| 2709 | + /**  | 
                                                        |
| 2710 | + * @param bool $new  | 
                                                        |
| 2711 | + * @throws EE_Error  | 
                                                        |
| 2712 | + * @throws ReflectionException  | 
                                                        |
| 2713 | + */  | 
                                                        |
| 2714 | + protected function _insert_or_update_message_template($new = false)  | 
                                                        |
| 2715 | +	{ | 
                                                        |
| 2716 | + $form_data = $this->getMessageTemplateFormData();  | 
                                                        |
| 2717 | + $GRP_ID = $form_data['GRP_ID'];  | 
                                                        |
| 2718 | + $messenger = $form_data['MTP_messenger'];  | 
                                                        |
| 2719 | + $message_type = $form_data['MTP_message_type'];  | 
                                                        |
| 2720 | + $context = $form_data['MTP_context'];  | 
                                                        |
| 2721 | +  | 
                                                        |
| 2722 | + // if this is "new" then we need to generate the default contexts  | 
                                                        |
| 2723 | + // for the selected messenger/message_type for user to edit.  | 
                                                        |
| 2724 | + [$success, $query_args] = $new  | 
                                                        |
| 2725 | + ? $this->generateNewTemplates($GRP_ID, $messenger, $message_type)  | 
                                                        |
| 2726 | + : $this->updateExistingTemplates($GRP_ID, $messenger, $message_type, $context, $form_data);  | 
                                                        |
| 2727 | +  | 
                                                        |
| 2728 | + $success = $success ? 1 : 0;  | 
                                                        |
| 2729 | + $action_desc = $new ? 'created' : 'updated';  | 
                                                        |
| 2730 | + $item_desc = $this->generateUpdateDescription($messenger, $message_type, $context);  | 
                                                        |
| 2731 | + $override = $this->performTestSendAfterUpdate($messenger, $message_type, $context);  | 
                                                        |
| 2732 | +  | 
                                                        |
| 2733 | + $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);  | 
                                                        |
| 2734 | + }  | 
                                                        |
| 2735 | +  | 
                                                        |
| 2736 | +  | 
                                                        |
| 2737 | + /**  | 
                                                        |
| 2738 | + * retrieve and sanitize form data  | 
                                                        |
| 2739 | + *  | 
                                                        |
| 2740 | + * @return array  | 
                                                        |
| 2741 | + * @since 4.10.29.p  | 
                                                        |
| 2742 | + */  | 
                                                        |
| 2743 | + protected function getMessageTemplateFormData()  | 
                                                        |
| 2744 | +	{ | 
                                                        |
| 2745 | + return [  | 
                                                        |
| 2746 | +			'GRP_ID'           => $this->request->getRequestParam('GRP_ID', 0, 'int'), | 
                                                        |
| 2747 | +			'MTP_context'      => strtolower($this->request->getRequestParam('MTP_context', '')), | 
                                                        |
| 2748 | +			'MTP_messenger'    => strtolower($this->request->getRequestParam('MTP_messenger', '')), | 
                                                        |
| 2749 | +			'MTP_message_type' => strtolower($this->request->getRequestParam('MTP_message_type', '')), | 
                                                        |
| 2750 | +			'MTP_user_id'      => $this->request->getRequestParam('MTP_user_id', 0, 'int'), | 
                                                        |
| 2751 | +			'MTP_is_global'    => $this->request->getRequestParam('MTP_is_global', 0, 'int'), | 
                                                        |
| 2752 | +			'MTP_is_override'  => $this->request->getRequestParam('MTP_is_override', 0, 'int'), | 
                                                        |
| 2753 | +			'MTP_deleted'      => $this->request->getRequestParam('MTP_deleted', 0, 'int'), | 
                                                        |
| 2754 | +			'MTP_is_active'    => $this->request->getRequestParam('MTP_is_active', 0, 'int'), | 
                                                        |
| 2755 | + ];  | 
                                                        |
| 2756 | + }  | 
                                                        |
| 2757 | +  | 
                                                        |
| 2758 | +  | 
                                                        |
| 2759 | + /**  | 
                                                        |
| 2760 | + * @param int $GRP_ID  | 
                                                        |
| 2761 | + * @param string $messenger  | 
                                                        |
| 2762 | + * @param string $message_type  | 
                                                        |
| 2763 | + * @return array no return on AJAX requests  | 
                                                        |
| 2764 | + * @throws EE_Error  | 
                                                        |
| 2765 | + * @throws ReflectionException  | 
                                                        |
| 2766 | + * @since 4.10.29.p  | 
                                                        |
| 2767 | + */  | 
                                                        |
| 2768 | + private function generateNewTemplates($GRP_ID, $messenger, $message_type)  | 
                                                        |
| 2769 | +	{ | 
                                                        |
| 2770 | + $new_templates = $this->_generate_new_templates($messenger, [$message_type], $GRP_ID);  | 
                                                        |
| 2771 | + $success = ! empty($new_templates);  | 
                                                        |
| 2772 | +  | 
                                                        |
| 2773 | + // we return things differently if doing ajax  | 
                                                        |
| 2774 | +		if ($this->request->isAjax()) { | 
                                                        |
| 2775 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 2776 | + $this->_template_args['error'] = ! $success;  | 
                                                        |
| 2777 | + $this->_template_args['content'] = '';  | 
                                                        |
| 2778 | + $this->_template_args['data'] = [  | 
                                                        |
| 2779 | + 'grpID' => $new_templates['GRP_ID'],  | 
                                                        |
| 2780 | + 'templateName' => $new_templates['template_name'],  | 
                                                        |
| 2781 | + ];  | 
                                                        |
| 2782 | +			if ($success) { | 
                                                        |
| 2783 | + EE_Error::overwrite_success();  | 
                                                        |
| 2784 | + EE_Error::add_success(  | 
                                                        |
| 2785 | + esc_html__(  | 
                                                        |
| 2786 | + 'The new template has been created and automatically selected for this event. You can edit the new template by clicking the edit button. Note before this template is assigned to this event, the event must be saved.',  | 
                                                        |
| 2787 | + 'event_espresso'  | 
                                                        |
| 2788 | + )  | 
                                                        |
| 2789 | + );  | 
                                                        |
| 2790 | + }  | 
                                                        |
| 2791 | + $this->_return_json();  | 
                                                        |
| 2792 | + }  | 
                                                        |
| 2793 | + return [  | 
                                                        |
| 2794 | + $success,  | 
                                                        |
| 2795 | + // 'query_args'  | 
                                                        |
| 2796 | + [  | 
                                                        |
| 2797 | + 'id' => $new_templates['GRP_ID'],  | 
                                                        |
| 2798 | + 'context' => $new_templates['MTP_context'],  | 
                                                        |
| 2799 | + 'action' => 'edit_message_template',  | 
                                                        |
| 2800 | + ],  | 
                                                        |
| 2801 | + ];  | 
                                                        |
| 2802 | + }  | 
                                                        |
| 2803 | +  | 
                                                        |
| 2804 | +  | 
                                                        |
| 2805 | + /**  | 
                                                        |
| 2806 | + * @param int $GRP_ID  | 
                                                        |
| 2807 | + * @param string $messenger  | 
                                                        |
| 2808 | + * @param string $message_type  | 
                                                        |
| 2809 | + * @param string $context  | 
                                                        |
| 2810 | + * @param array $form_data  | 
                                                        |
| 2811 | + * @return array  | 
                                                        |
| 2812 | + * @throws EE_Error  | 
                                                        |
| 2813 | + * @since 4.10.29.p  | 
                                                        |
| 2814 | + */  | 
                                                        |
| 2815 | + private function updateExistingTemplates(  | 
                                                        |
| 2816 | + $GRP_ID,  | 
                                                        |
| 2817 | + $messenger,  | 
                                                        |
| 2818 | + $message_type,  | 
                                                        |
| 2819 | + $context,  | 
                                                        |
| 2820 | + array $form_data  | 
                                                        |
| 2821 | +	) { | 
                                                        |
| 2822 | + $success = false;  | 
                                                        |
| 2823 | + $template_fields = $this->getTemplateFields();  | 
                                                        |
| 2824 | +		if ($template_fields) { | 
                                                        |
| 2825 | + // if field data is valid, then success will be true  | 
                                                        |
| 2826 | + $success = $this->validateTemplateFields(  | 
                                                        |
| 2827 | + $messenger,  | 
                                                        |
| 2828 | + $message_type,  | 
                                                        |
| 2829 | + $context,  | 
                                                        |
| 2830 | + $template_fields  | 
                                                        |
| 2831 | + );  | 
                                                        |
| 2832 | +			if ($success) { | 
                                                        |
| 2833 | + $field_data = [];  | 
                                                        |
| 2834 | +				foreach ($template_fields as $template_field => $content) { | 
                                                        |
| 2835 | + // combine top-level form data with content for this field  | 
                                                        |
| 2836 | + $field_data = $this->getTemplateFieldFormData($content, $form_data);  | 
                                                        |
| 2837 | + $success = $this->updateMessageTemplates($template_field, $field_data) ? $success : false;  | 
                                                        |
| 2838 | + }  | 
                                                        |
| 2839 | + // we can use the last set_column_values for the MTPG update  | 
                                                        |
| 2840 | + // (because its the same for all of these specific MTPs)  | 
                                                        |
| 2841 | + $success = $this->updateMessageTemplateGroup($field_data) ? $success : false;  | 
                                                        |
| 2842 | + }  | 
                                                        |
| 2843 | + }  | 
                                                        |
| 2844 | +  | 
                                                        |
| 2845 | + return [  | 
                                                        |
| 2846 | + $success,  | 
                                                        |
| 2847 | + // 'query_args'  | 
                                                        |
| 2848 | + [  | 
                                                        |
| 2849 | + 'id' => $GRP_ID,  | 
                                                        |
| 2850 | + 'context' => $context,  | 
                                                        |
| 2851 | + 'action' => 'edit_message_template',  | 
                                                        |
| 2852 | + ],  | 
                                                        |
| 2853 | + ];  | 
                                                        |
| 2854 | + }  | 
                                                        |
| 2855 | +  | 
                                                        |
| 2856 | +  | 
                                                        |
| 2857 | + /**  | 
                                                        |
| 2858 | + * @return array  | 
                                                        |
| 2859 | + * @since 4.10.29.p  | 
                                                        |
| 2860 | + */  | 
                                                        |
| 2861 | + private function getTemplateFields()  | 
                                                        |
| 2862 | +	{ | 
                                                        |
| 2863 | +		$template_fields = $this->request->getRequestParam('MTP_template_fields', null, 'html', true); | 
                                                        |
| 2864 | +		if (empty($template_fields)) { | 
                                                        |
| 2865 | + EE_Error::add_error(  | 
                                                        |
| 2866 | + esc_html__(  | 
                                                        |
| 2867 | + 'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',  | 
                                                        |
| 2868 | + 'event_espresso'  | 
                                                        |
| 2869 | + ),  | 
                                                        |
| 2870 | + __FILE__,  | 
                                                        |
| 2871 | + __FUNCTION__,  | 
                                                        |
| 2872 | + __LINE__  | 
                                                        |
| 2873 | + );  | 
                                                        |
| 2874 | + return null;  | 
                                                        |
| 2875 | + }  | 
                                                        |
| 2876 | + // messages content is expected to be escaped  | 
                                                        |
| 2877 | + return EEH_Array::addSlashesRecursively($template_fields);  | 
                                                        |
| 2878 | + }  | 
                                                        |
| 2879 | +  | 
                                                        |
| 2880 | +  | 
                                                        |
| 2881 | + /**  | 
                                                        |
| 2882 | + * @param string $messenger  | 
                                                        |
| 2883 | + * @param string $message_type  | 
                                                        |
| 2884 | + * @param string $context  | 
                                                        |
| 2885 | + * @param array $template_fields  | 
                                                        |
| 2886 | + * @return bool  | 
                                                        |
| 2887 | + * @throws EE_Error  | 
                                                        |
| 2888 | + * @since 4.10.29.p  | 
                                                        |
| 2889 | + */  | 
                                                        |
| 2890 | + private function validateTemplateFields(  | 
                                                        |
| 2891 | + $messenger,  | 
                                                        |
| 2892 | + $message_type,  | 
                                                        |
| 2893 | + $context,  | 
                                                        |
| 2894 | + array $template_fields  | 
                                                        |
| 2895 | +	) { | 
                                                        |
| 2896 | + // first validate all fields!  | 
                                                        |
| 2897 | + // this filter allows client code to add its own validation to the template fields as well.  | 
                                                        |
| 2898 | + // returning an empty array means everything passed validation.  | 
                                                        |
| 2899 | + // errors in validation should be represented in an array with the following shape:  | 
                                                        |
| 2900 | + // array(  | 
                                                        |
| 2901 | + // 'fieldname' => array(  | 
                                                        |
| 2902 | + // 'msg' => 'error message'  | 
                                                        |
| 2903 | + // 'value' => 'value for field producing error'  | 
                                                        |
| 2904 | + // )  | 
                                                        |
| 2905 | + $custom_validation = (array) apply_filters(  | 
                                                        |
| 2906 | + 'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',  | 
                                                        |
| 2907 | + [],  | 
                                                        |
| 2908 | + $template_fields,  | 
                                                        |
| 2909 | + $context,  | 
                                                        |
| 2910 | + $messenger,  | 
                                                        |
| 2911 | + $message_type  | 
                                                        |
| 2912 | + );  | 
                                                        |
| 2913 | +  | 
                                                        |
| 2914 | + $system_validation = $this->getMtgModel()->validate(  | 
                                                        |
| 2915 | + $template_fields,  | 
                                                        |
| 2916 | + $context,  | 
                                                        |
| 2917 | + $messenger,  | 
                                                        |
| 2918 | + $message_type  | 
                                                        |
| 2919 | + );  | 
                                                        |
| 2920 | +  | 
                                                        |
| 2921 | + $system_validation = ! is_array($system_validation) && $system_validation ? [] : $system_validation;  | 
                                                        |
| 2922 | + $validates = array_merge($custom_validation, $system_validation);  | 
                                                        |
| 2923 | +  | 
                                                        |
| 2924 | + // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an  | 
                                                        |
| 2925 | + // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  | 
                                                        |
| 2926 | + // WE need to make sure there is no actual error messages in validates.  | 
                                                        |
| 2927 | +		if (empty($validates)) { | 
                                                        |
| 2928 | + return true;  | 
                                                        |
| 2929 | + }  | 
                                                        |
| 2930 | +  | 
                                                        |
| 2931 | + // add the transient so when the form loads we know which fields to highlight  | 
                                                        |
| 2932 | +		$this->_add_transient('edit_message_template', $validates); | 
                                                        |
| 2933 | + // setup notices  | 
                                                        |
| 2934 | +		foreach ($validates as $error) { | 
                                                        |
| 2935 | +			if (isset($error['msg'])) { | 
                                                        |
| 2936 | + EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 2937 | + }  | 
                                                        |
| 2938 | + }  | 
                                                        |
| 2939 | + return false;  | 
                                                        |
| 2940 | + }  | 
                                                        |
| 2941 | +  | 
                                                        |
| 2942 | +  | 
                                                        |
| 2943 | + /**  | 
                                                        |
| 2944 | + * @param array $field_data  | 
                                                        |
| 2945 | + * @param array $form_data  | 
                                                        |
| 2946 | + * @return array  | 
                                                        |
| 2947 | + * @since 4.10.29.p  | 
                                                        |
| 2948 | + */  | 
                                                        |
| 2949 | + private function getTemplateFieldFormData(array $field_data, array $form_data)  | 
                                                        |
| 2950 | +	{ | 
                                                        |
| 2951 | + return $form_data + [  | 
                                                        |
| 2952 | + 'MTP_ID' => $field_data['MTP_ID'],  | 
                                                        |
| 2953 | + 'MTP_template_field' => $field_data['name'],  | 
                                                        |
| 2954 | + // if they aren't allowed to use all JS, restrict them to standard allowed post tags  | 
                                                        |
| 2955 | +				'MTP_content'        => ! current_user_can('unfiltered_html') | 
                                                        |
| 2956 | + ? $this->sanitizeMessageTemplateContent($field_data['content'])  | 
                                                        |
| 2957 | + : $field_data['content'],  | 
                                                        |
| 2958 | + ];  | 
                                                        |
| 2959 | + }  | 
                                                        |
| 2960 | +  | 
                                                        |
| 2961 | +  | 
                                                        |
| 2962 | + /**  | 
                                                        |
| 2963 | + * @param string $template_field  | 
                                                        |
| 2964 | + * @param array $form_data  | 
                                                        |
| 2965 | + * @return bool  | 
                                                        |
| 2966 | + * @throws EE_Error  | 
                                                        |
| 2967 | + * @since 4.10.29.p  | 
                                                        |
| 2968 | + */  | 
                                                        |
| 2969 | + private function updateMessageTemplates($template_field, array $form_data)  | 
                                                        |
| 2970 | +	{ | 
                                                        |
| 2971 | + $MTP_ID = $form_data['MTP_ID'];  | 
                                                        |
| 2972 | + $message_template_fields = [  | 
                                                        |
| 2973 | + 'GRP_ID' => $form_data['GRP_ID'],  | 
                                                        |
| 2974 | + 'MTP_template_field' => $form_data['MTP_template_field'],  | 
                                                        |
| 2975 | + 'MTP_context' => $form_data['MTP_context'],  | 
                                                        |
| 2976 | + 'MTP_content' => $form_data['MTP_content'],  | 
                                                        |
| 2977 | + ];  | 
                                                        |
| 2978 | +  | 
                                                        |
| 2979 | + $hasMtpID = ! empty($MTP_ID);  | 
                                                        |
| 2980 | + // if we have a MTP_ID for this field then update it, otherwise insert.  | 
                                                        |
| 2981 | + // this has already been through the template field validator and sanitized, so it will be  | 
                                                        |
| 2982 | + // safe to insert this field. Why insert? This typically happens when we introduce a new  | 
                                                        |
| 2983 | + // message template field in a messenger/message type and existing users don't have the  | 
                                                        |
| 2984 | + // default setup for it.  | 
                                                        |
| 2985 | + // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465  | 
                                                        |
| 2986 | + $updated = $hasMtpID  | 
                                                        |
| 2987 | + ? $this->getMtpModel()->update($message_template_fields, [['MTP_ID' => $MTP_ID]])  | 
                                                        |
| 2988 | + : $this->getMtpModel()->insert($message_template_fields);  | 
                                                        |
| 2989 | +  | 
                                                        |
| 2990 | + $insert_failed = ! $hasMtpID && ! $updated;  | 
                                                        |
| 2991 | + // updates will return 0 if the field was not changed (ie: no changes = nothing actually updated)  | 
                                                        |
| 2992 | + // but we won't consider that a problem, but if it returns false, then something went BOOM!  | 
                                                        |
| 2993 | + $update_failed = $hasMtpID && $updated === false;  | 
                                                        |
| 2994 | +  | 
                                                        |
| 2995 | +		if ($insert_failed || $update_failed) { | 
                                                        |
| 2996 | + EE_Error::add_error(  | 
                                                        |
| 2997 | + sprintf(  | 
                                                        |
| 2998 | +					esc_html__('%s field was NOT updated for some reason', 'event_espresso'), | 
                                                        |
| 2999 | + $template_field  | 
                                                        |
| 3000 | + ),  | 
                                                        |
| 3001 | + __FILE__,  | 
                                                        |
| 3002 | + __FUNCTION__,  | 
                                                        |
| 3003 | + __LINE__  | 
                                                        |
| 3004 | + );  | 
                                                        |
| 3005 | + return false;  | 
                                                        |
| 3006 | + }  | 
                                                        |
| 3007 | + return true;  | 
                                                        |
| 3008 | + }  | 
                                                        |
| 3009 | +  | 
                                                        |
| 3010 | +  | 
                                                        |
| 3011 | + /**  | 
                                                        |
| 3012 | + * @param array $form_data  | 
                                                        |
| 3013 | + * @return bool  | 
                                                        |
| 3014 | + * @throws EE_Error  | 
                                                        |
| 3015 | + * @since 4.10.29.p  | 
                                                        |
| 3016 | + */  | 
                                                        |
| 3017 | + private function updateMessageTemplateGroup(array $form_data)  | 
                                                        |
| 3018 | +	{ | 
                                                        |
| 3019 | + $GRP_ID = $form_data['GRP_ID'];  | 
                                                        |
| 3020 | + $updated = $this->getMtgModel()->update(  | 
                                                        |
| 3021 | + // fields and values  | 
                                                        |
| 3022 | + [  | 
                                                        |
| 3023 | + 'MTP_user_id' => $form_data['MTP_user_id'],  | 
                                                        |
| 3024 | + 'MTP_messenger' => $form_data['MTP_messenger'],  | 
                                                        |
| 3025 | + 'MTP_message_type' => $form_data['MTP_message_type'],  | 
                                                        |
| 3026 | + 'MTP_is_global' => $form_data['MTP_is_global'],  | 
                                                        |
| 3027 | + 'MTP_is_override' => $form_data['MTP_is_override'],  | 
                                                        |
| 3028 | + 'MTP_deleted' => $form_data['MTP_deleted'],  | 
                                                        |
| 3029 | + 'MTP_is_active' => $form_data['MTP_is_active'],  | 
                                                        |
| 3030 | +				'MTP_name'         => $this->request->getRequestParam('ee_msg_non_global_fields[MTP_name]', ''), | 
                                                        |
| 3031 | + 'MTP_description' => $this->request->getRequestParam(  | 
                                                        |
| 3032 | + 'ee_msg_non_global_fields[MTP_description]',  | 
                                                        |
| 3033 | + ''  | 
                                                        |
| 3034 | + ),  | 
                                                        |
| 3035 | + ],  | 
                                                        |
| 3036 | + // where  | 
                                                        |
| 3037 | + [['GRP_ID' => $GRP_ID]]  | 
                                                        |
| 3038 | + );  | 
                                                        |
| 3039 | +  | 
                                                        |
| 3040 | +		if ($updated === false) { | 
                                                        |
| 3041 | + EE_Error::add_error(  | 
                                                        |
| 3042 | + sprintf(  | 
                                                        |
| 3043 | + esc_html__(  | 
                                                        |
| 3044 | + 'The Message Template Group (%d) was NOT updated for some reason',  | 
                                                        |
| 3045 | + 'event_espresso'  | 
                                                        |
| 3046 | + ),  | 
                                                        |
| 3047 | + $form_data['GRP_ID']  | 
                                                        |
| 3048 | + ),  | 
                                                        |
| 3049 | + __FILE__,  | 
                                                        |
| 3050 | + __FUNCTION__,  | 
                                                        |
| 3051 | + __LINE__  | 
                                                        |
| 3052 | + );  | 
                                                        |
| 3053 | + return false;  | 
                                                        |
| 3054 | + }  | 
                                                        |
| 3055 | + // k now we need to ensure the template_pack and template_variation fields are set.  | 
                                                        |
| 3056 | +		$template_pack      = $this->request->getRequestParam('MTP_template_pack', 'default'); | 
                                                        |
| 3057 | +		$template_variation = $this->request->getRequestParam('MTP_template_variation', 'default'); | 
                                                        |
| 3058 | +  | 
                                                        |
| 3059 | + $message_template_group = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 3060 | +		if ($message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 3061 | + $message_template_group->set_template_pack_name($template_pack);  | 
                                                        |
| 3062 | + $message_template_group->set_template_pack_variation($template_variation);  | 
                                                        |
| 3063 | + }  | 
                                                        |
| 3064 | + return true;  | 
                                                        |
| 3065 | + }  | 
                                                        |
| 3066 | +  | 
                                                        |
| 3067 | +  | 
                                                        |
| 3068 | + /**  | 
                                                        |
| 3069 | + * recursively runs wp_kses() on message template content in a model safe manner  | 
                                                        |
| 3070 | + *  | 
                                                        |
| 3071 | + * @param array|string $content  | 
                                                        |
| 3072 | + * @return array|string  | 
                                                        |
| 3073 | + * @since 4.10.29.p  | 
                                                        |
| 3074 | + */  | 
                                                        |
| 3075 | + private function sanitizeMessageTemplateContent($content)  | 
                                                        |
| 3076 | +	{ | 
                                                        |
| 3077 | +		if (is_array($content)) { | 
                                                        |
| 3078 | +			foreach ($content as $key => $value) { | 
                                                        |
| 3079 | + $content[ $key ] = $this->sanitizeMessageTemplateContent($value);  | 
                                                        |
| 3080 | + }  | 
                                                        |
| 3081 | + return $content;  | 
                                                        |
| 3082 | + }  | 
                                                        |
| 3083 | + // remove slashes so wp_kses() works properly  | 
                                                        |
| 3084 | + // wp_kses_stripslashes() only removes slashes from double-quotes,  | 
                                                        |
| 3085 | + // so attributes using single quotes always appear invalid.  | 
                                                        |
| 3086 | + $content = stripslashes($content);  | 
                                                        |
| 3087 | +		$content = wp_kses($content, wp_kses_allowed_html('post')); | 
                                                        |
| 3088 | + // But currently the models expect slashed data, so after wp_kses()  | 
                                                        |
| 3089 | + // runs we need to re-slash the data. Sheesh.  | 
                                                        |
| 3090 | + // See https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587  | 
                                                        |
| 3091 | + return addslashes($content);  | 
                                                        |
| 3092 | + }  | 
                                                        |
| 3093 | +  | 
                                                        |
| 3094 | +  | 
                                                        |
| 3095 | + /**  | 
                                                        |
| 3096 | + * @param string $messenger  | 
                                                        |
| 3097 | + * @param string $message_type  | 
                                                        |
| 3098 | + * @param string $context  | 
                                                        |
| 3099 | + * @return string  | 
                                                        |
| 3100 | + * @since 4.10.29.p  | 
                                                        |
| 3101 | + */  | 
                                                        |
| 3102 | + private function generateUpdateDescription($messenger, $message_type, $context)  | 
                                                        |
| 3103 | +	{ | 
                                                        |
| 3104 | + // need the message type and messenger objects to be able to use the labels for the notices  | 
                                                        |
| 3105 | + $messenger_object = $this->_message_resource_manager->get_messenger($messenger);  | 
                                                        |
| 3106 | + $messenger_label = $messenger_object instanceof EE_messenger  | 
                                                        |
| 3107 | + ? ucwords($messenger_object->label['singular'])  | 
                                                        |
| 3108 | + : '';  | 
                                                        |
| 3109 | +  | 
                                                        |
| 3110 | + $message_type_object = $this->_message_resource_manager->get_message_type($message_type);  | 
                                                        |
| 3111 | + $message_type_label = $message_type_object instanceof EE_message_type  | 
                                                        |
| 3112 | + ? ucwords($message_type_object->label['singular'])  | 
                                                        |
| 3113 | + : '';  | 
                                                        |
| 3114 | +  | 
                                                        |
| 3115 | +		$context   = ucwords(str_replace('_', ' ', $context)); | 
                                                        |
| 3116 | + $item_desc = $messenger_label && $message_type_label  | 
                                                        |
| 3117 | + ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '  | 
                                                        |
| 3118 | + : '';  | 
                                                        |
| 3119 | + $item_desc .= 'Message Template';  | 
                                                        |
| 3120 | + return $item_desc;  | 
                                                        |
| 3121 | + }  | 
                                                        |
| 3122 | +  | 
                                                        |
| 3123 | +  | 
                                                        |
| 3124 | + /**  | 
                                                        |
| 3125 | + * @param string $messenger  | 
                                                        |
| 3126 | + * @param string $message_type  | 
                                                        |
| 3127 | + * @param string $context  | 
                                                        |
| 3128 | + * @return bool  | 
                                                        |
| 3129 | + * @throws EE_Error  | 
                                                        |
| 3130 | + * @throws ReflectionException  | 
                                                        |
| 3131 | + * @since 4.10.29.p  | 
                                                        |
| 3132 | + */  | 
                                                        |
| 3133 | + private function performTestSendAfterUpdate($messenger, $message_type, $context)  | 
                                                        |
| 3134 | +	{ | 
                                                        |
| 3135 | + // was a test send triggered?  | 
                                                        |
| 3136 | +		if ($this->request->requestParamIsSet('test_button')) { | 
                                                        |
| 3137 | + EE_Error::overwrite_success();  | 
                                                        |
| 3138 | + $this->_do_test_send($context, $messenger, $message_type);  | 
                                                        |
| 3139 | + return true;  | 
                                                        |
| 3140 | + }  | 
                                                        |
| 3141 | + return false;  | 
                                                        |
| 3142 | + }  | 
                                                        |
| 3143 | +  | 
                                                        |
| 3144 | +  | 
                                                        |
| 3145 | + /**  | 
                                                        |
| 3146 | + * processes a test send request to do an actual messenger delivery test for the given message template being tested  | 
                                                        |
| 3147 | + *  | 
                                                        |
| 3148 | + * @param string $context what context being tested  | 
                                                        |
| 3149 | + * @param string $messenger messenger being tested  | 
                                                        |
| 3150 | + * @param string $message_type message type being tested  | 
                                                        |
| 3151 | + * @throws EE_Error  | 
                                                        |
| 3152 | + * @throws InvalidArgumentException  | 
                                                        |
| 3153 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3154 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3155 | + * @throws ReflectionException  | 
                                                        |
| 3156 | + */  | 
                                                        |
| 3157 | + protected function _do_test_send($context, $messenger, $message_type)  | 
                                                        |
| 3158 | +	{ | 
                                                        |
| 3159 | + // set things up for preview  | 
                                                        |
| 3160 | +		$this->request->setRequestParam('messenger', $messenger); | 
                                                        |
| 3161 | +		$this->request->setRequestParam('message_type', $message_type); | 
                                                        |
| 3162 | +		$this->request->setRequestParam('context', $context); | 
                                                        |
| 3163 | +		$GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        |
| 3164 | +		$this->request->setRequestParam('GRP_ID', $GRP_ID); | 
                                                        |
| 3165 | +  | 
                                                        |
| 3166 | + $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);  | 
                                                        |
| 3167 | +		$test_settings_fld = $this->request->getRequestParam('test_settings_fld', [], 'string', true); | 
                                                        |
| 3168 | +  | 
                                                        |
| 3169 | + // let's save any existing fields that might be required by the messenger  | 
                                                        |
| 3170 | + if (  | 
                                                        |
| 3171 | + ! empty($test_settings_fld)  | 
                                                        |
| 3172 | + && $active_messenger instanceof EE_messenger  | 
                                                        |
| 3173 | + && apply_filters(  | 
                                                        |
| 3174 | + 'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',  | 
                                                        |
| 3175 | + true,  | 
                                                        |
| 3176 | + $test_settings_fld,  | 
                                                        |
| 3177 | + $active_messenger  | 
                                                        |
| 3178 | + )  | 
                                                        |
| 3179 | +		) { | 
                                                        |
| 3180 | + $active_messenger->set_existing_test_settings($test_settings_fld);  | 
                                                        |
| 3181 | + }  | 
                                                        |
| 3182 | +  | 
                                                        |
| 3183 | + /**  | 
                                                        |
| 3184 | + * Use filter to add additional controls on whether message can send or not  | 
                                                        |
| 3185 | + */  | 
                                                        |
| 3186 | + if (  | 
                                                        |
| 3187 | + apply_filters(  | 
                                                        |
| 3188 | + 'FHEE__Messages_Admin_Page__do_test_send__can_send',  | 
                                                        |
| 3189 | + true,  | 
                                                        |
| 3190 | + $context,  | 
                                                        |
| 3191 | + $this->request->requestParams(),  | 
                                                        |
| 3192 | + $messenger,  | 
                                                        |
| 3193 | + $message_type  | 
                                                        |
| 3194 | + )  | 
                                                        |
| 3195 | +		) { | 
                                                        |
| 3196 | +			if (EEM_Event::instance()->count() > 0) { | 
                                                        |
| 3197 | + $success = $this->_preview_message(true);  | 
                                                        |
| 3198 | +				if ($success) { | 
                                                        |
| 3199 | +					EE_Error::add_success(esc_html__('Test message sent', 'event_espresso')); | 
                                                        |
| 3200 | +				} else { | 
                                                        |
| 3201 | + EE_Error::add_error(  | 
                                                        |
| 3202 | +						esc_html__('The test message was not sent', 'event_espresso'), | 
                                                        |
| 3203 | + __FILE__,  | 
                                                        |
| 3204 | + __FUNCTION__,  | 
                                                        |
| 3205 | + __LINE__  | 
                                                        |
| 3206 | + );  | 
                                                        |
| 3207 | + }  | 
                                                        |
| 3208 | +			} else { | 
                                                        |
| 3209 | + $this->noEventsErrorMessage(true);  | 
                                                        |
| 3210 | + }  | 
                                                        |
| 3211 | + }  | 
                                                        |
| 3212 | + }  | 
                                                        |
| 3213 | +  | 
                                                        |
| 3214 | +  | 
                                                        |
| 3215 | + /**  | 
                                                        |
| 3216 | + * _generate_new_templates  | 
                                                        |
| 3217 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 3218 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 3219 | + * for the event.  | 
                                                        |
| 3220 | + *  | 
                                                        |
| 3221 | + *  | 
                                                        |
| 3222 | + * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 3223 | + * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 3224 | + * @param int $GRP_ID If this is a custom template being generated then a GRP_ID needs to be included to  | 
                                                        |
| 3225 | + * indicate the message_template_group being used as the base.  | 
                                                        |
| 3226 | + *  | 
                                                        |
| 3227 | + * @param bool $global  | 
                                                        |
| 3228 | + *  | 
                                                        |
| 3229 | + * @return array|bool array of data required for the redirect to the correct edit page or bool if  | 
                                                        |
| 3230 | + * encountering problems.  | 
                                                        |
| 3231 | + * @throws EE_Error  | 
                                                        |
| 3232 | + * @throws ReflectionException  | 
                                                        |
| 3233 | + */  | 
                                                        |
| 3234 | + protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 3235 | +	{ | 
                                                        |
| 3236 | + // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we  | 
                                                        |
| 3237 | + // just don't generate any templates.  | 
                                                        |
| 3238 | +		if (empty($message_types)) { | 
                                                        |
| 3239 | + return [];  | 
                                                        |
| 3240 | + }  | 
                                                        |
| 3241 | +  | 
                                                        |
| 3242 | + $templates = EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);  | 
                                                        |
| 3243 | + return $templates[0];  | 
                                                        |
| 3244 | + }  | 
                                                        |
| 3245 | +  | 
                                                        |
| 3246 | +  | 
                                                        |
| 3247 | + /**  | 
                                                        |
| 3248 | + * [_trash_or_restore_message_template]  | 
                                                        |
| 3249 | + *  | 
                                                        |
| 3250 | + * @param boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)  | 
                                                        |
| 3251 | + * @param boolean $all whether this is going to trash/restore all contexts within a template group (TRUE) OR just  | 
                                                        |
| 3252 | + * an individual context (FALSE).  | 
                                                        |
| 3253 | + * @return void  | 
                                                        |
| 3254 | + * @throws EE_Error  | 
                                                        |
| 3255 | + * @throws InvalidArgumentException  | 
                                                        |
| 3256 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3257 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3258 | + */  | 
                                                        |
| 3259 | + protected function _trash_or_restore_message_template($trash = true, $all = false)  | 
                                                        |
| 3260 | +	{ | 
                                                        |
| 3261 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 3262 | +  | 
                                                        |
| 3263 | + $success = 1;  | 
                                                        |
| 3264 | +  | 
                                                        |
| 3265 | + // incoming GRP_IDs  | 
                                                        |
| 3266 | +		if ($all) { | 
                                                        |
| 3267 | + // Checkboxes  | 
                                                        |
| 3268 | +			$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        |
| 3269 | +			if (! empty($checkboxes)) { | 
                                                        |
| 3270 | + // if array has more than one element then success message should be plural.  | 
                                                        |
| 3271 | + // todo: what about nonce?  | 
                                                        |
| 3272 | + $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        |
| 3273 | +  | 
                                                        |
| 3274 | + // cycle through checkboxes  | 
                                                        |
| 3275 | +				while (list($GRP_ID, $value) = each($checkboxes)) { | 
                                                        |
| 3276 | + $trashed_or_restored = $trash  | 
                                                        |
| 3277 | + ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        |
| 3278 | + : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        |
| 3279 | +					if (! $trashed_or_restored) { | 
                                                        |
| 3280 | + $success = 0;  | 
                                                        |
| 3281 | + }  | 
                                                        |
| 3282 | + }  | 
                                                        |
| 3283 | +			} else { | 
                                                        |
| 3284 | + // grab single GRP_ID and handle  | 
                                                        |
| 3285 | +				$GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 3286 | +				if (! empty($GRP_ID)) { | 
                                                        |
| 3287 | + $trashed_or_restored = $trash  | 
                                                        |
| 3288 | + ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        |
| 3289 | + : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        |
| 3290 | +					if (! $trashed_or_restored) { | 
                                                        |
| 3291 | + $success = 0;  | 
                                                        |
| 3292 | + }  | 
                                                        |
| 3293 | +				} else { | 
                                                        |
| 3294 | + $success = 0;  | 
                                                        |
| 3295 | + }  | 
                                                        |
| 3296 | + }  | 
                                                        |
| 3297 | + }  | 
                                                        |
| 3298 | +  | 
                                                        |
| 3299 | + $action_desc = $trash  | 
                                                        |
| 3300 | +			? esc_html__('moved to the trash', 'event_espresso') | 
                                                        |
| 3301 | +			: esc_html__('restored', 'event_espresso'); | 
                                                        |
| 3302 | +  | 
                                                        |
| 3303 | +		$template_switch = $this->request->getRequestParam('template_switch', false, 'bool'); | 
                                                        |
| 3304 | +		$action_desc     = $template_switch ? esc_html__('switched', 'event_espresso') : $action_desc; | 
                                                        |
| 3305 | +  | 
                                                        |
| 3306 | + $item_desc = $all ? _n(  | 
                                                        |
| 3307 | + 'Message Template Group',  | 
                                                        |
| 3308 | + 'Message Template Groups',  | 
                                                        |
| 3309 | + $success,  | 
                                                        |
| 3310 | + 'event_espresso'  | 
                                                        |
| 3311 | +		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso'); | 
                                                        |
| 3312 | +  | 
                                                        |
| 3313 | + $item_desc = $template_switch  | 
                                                        |
| 3314 | +			? _n('template', 'templates', $success, 'event_espresso') | 
                                                        |
| 3315 | + : $item_desc;  | 
                                                        |
| 3316 | +  | 
                                                        |
| 3317 | + $this->_redirect_after_action($success, $item_desc, $action_desc, []);  | 
                                                        |
| 3318 | + }  | 
                                                        |
| 3319 | +  | 
                                                        |
| 3320 | +  | 
                                                        |
| 3321 | + /**  | 
                                                        |
| 3322 | + * [_delete_message_template]  | 
                                                        |
| 3323 | + * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.  | 
                                                        |
| 3324 | + *  | 
                                                        |
| 3325 | + * @return void  | 
                                                        |
| 3326 | + * @throws EE_Error  | 
                                                        |
| 3327 | + * @throws InvalidArgumentException  | 
                                                        |
| 3328 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3329 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3330 | + * @throws ReflectionException  | 
                                                        |
| 3331 | + */  | 
                                                        |
| 3332 | + protected function _delete_message_template()  | 
                                                        |
| 3333 | +	{ | 
                                                        |
| 3334 | +		do_action('AHEE_log', __FILE__, __FUNCTION__, ''); | 
                                                        |
| 3335 | +  | 
                                                        |
| 3336 | + // checkboxes  | 
                                                        |
| 3337 | +		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        |
| 3338 | +		if (! empty($checkboxes)) { | 
                                                        |
| 3339 | + // if array has more than one element then success message should be plural  | 
                                                        |
| 3340 | + $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        |
| 3341 | +  | 
                                                        |
| 3342 | + // cycle through bulk action checkboxes  | 
                                                        |
| 3343 | +			while (list($GRP_ID, $value) = each($checkboxes)) { | 
                                                        |
| 3344 | + $success = $this->_delete_mtp_permanently($GRP_ID) ? $success : false;  | 
                                                        |
| 3345 | + }  | 
                                                        |
| 3346 | +		} else { | 
                                                        |
| 3347 | + // grab single grp_id and delete  | 
                                                        |
| 3348 | +			$GRP_ID  = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        |
| 3349 | + $success = $this->_delete_mtp_permanently($GRP_ID);  | 
                                                        |
| 3350 | + }  | 
                                                        |
| 3351 | +  | 
                                                        |
| 3352 | + $this->_redirect_after_action($success, 'Message Templates', 'deleted', []);  | 
                                                        |
| 3353 | + }  | 
                                                        |
| 3354 | +  | 
                                                        |
| 3355 | +  | 
                                                        |
| 3356 | + /**  | 
                                                        |
| 3357 | + * helper for permanently deleting a mtP group and all related message_templates  | 
                                                        |
| 3358 | + *  | 
                                                        |
| 3359 | + * @param int $GRP_ID The group being deleted  | 
                                                        |
| 3360 | + * @param bool $include_group whether to delete the Message Template Group as well.  | 
                                                        |
| 3361 | + * @return bool boolean to indicate the success of the deletes or not.  | 
                                                        |
| 3362 | + * @throws EE_Error  | 
                                                        |
| 3363 | + * @throws InvalidArgumentException  | 
                                                        |
| 3364 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3365 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3366 | + * @throws ReflectionException  | 
                                                        |
| 3367 | + * @throws ReflectionException  | 
                                                        |
| 3368 | + */  | 
                                                        |
| 3369 | + private function _delete_mtp_permanently($GRP_ID, $include_group = true)  | 
                                                        |
| 3370 | +	{ | 
                                                        |
| 3371 | + $success = true;  | 
                                                        |
| 3372 | + // first let's GET this group  | 
                                                        |
| 3373 | + $MTG = $this->getMtgModel()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 3374 | + // then delete permanently all the related Message Templates  | 
                                                        |
| 3375 | +		$deleted = $MTG->delete_related_permanently('Message_Template'); | 
                                                        |
| 3376 | +  | 
                                                        |
| 3377 | +		if ($deleted === 0) { | 
                                                        |
| 3378 | + $success = false;  | 
                                                        |
| 3379 | + }  | 
                                                        |
| 3380 | +  | 
                                                        |
| 3381 | + // now delete permanently this particular group  | 
                                                        |
| 3382 | +  | 
                                                        |
| 3383 | +		if ($include_group && ! $MTG->delete_permanently()) { | 
                                                        |
| 3384 | + $success = false;  | 
                                                        |
| 3385 | + }  | 
                                                        |
| 3386 | +  | 
                                                        |
| 3387 | + return $success;  | 
                                                        |
| 3388 | + }  | 
                                                        |
| 3389 | +  | 
                                                        |
| 3390 | +  | 
                                                        |
| 3391 | + /**  | 
                                                        |
| 3392 | + * _learn_more_about_message_templates_link  | 
                                                        |
| 3393 | + *  | 
                                                        |
| 3394 | + * @access protected  | 
                                                        |
| 3395 | + * @return string  | 
                                                        |
| 3396 | + */  | 
                                                        |
| 3397 | + protected function _learn_more_about_message_templates_link()  | 
                                                        |
| 3398 | +	{ | 
                                                        |
| 3399 | + return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'  | 
                                                        |
| 3400 | +			   . esc_html__('learn more about how message templates works', 'event_espresso') | 
                                                        |
| 3401 | + . '</a>';  | 
                                                        |
| 3402 | + }  | 
                                                        |
| 3403 | +  | 
                                                        |
| 3404 | +  | 
                                                        |
| 3405 | + /**  | 
                                                        |
| 3406 | + * Used for setting up messenger/message type activation. This loads up the initial view. The rest is handled by  | 
                                                        |
| 3407 | + * ajax and other routes.  | 
                                                        |
| 3408 | + *  | 
                                                        |
| 3409 | + * @return void  | 
                                                        |
| 3410 | + * @throws DomainException  | 
                                                        |
| 3411 | + * @throws EE_Error  | 
                                                        |
| 3412 | + */  | 
                                                        |
| 3413 | + protected function _settings()  | 
                                                        |
| 3414 | +	{ | 
                                                        |
| 3415 | + $this->_set_m_mt_settings();  | 
                                                        |
| 3416 | +  | 
                                                        |
| 3417 | + // let's setup the messenger tabs  | 
                                                        |
| 3418 | + $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(  | 
                                                        |
| 3419 | + $this->_m_mt_settings['messenger_tabs'],  | 
                                                        |
| 3420 | + 'messenger_links',  | 
                                                        |
| 3421 | + '|',  | 
                                                        |
| 3422 | +			$this->request->getRequestParam('selected_messenger', 'email') | 
                                                        |
| 3423 | + );  | 
                                                        |
| 3424 | +  | 
                                                        |
| 3425 | + $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';  | 
                                                        |
| 3426 | + $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';  | 
                                                        |
| 3427 | +  | 
                                                        |
| 3428 | + $this->display_admin_page_with_sidebar();  | 
                                                        |
| 3429 | + }  | 
                                                        |
| 3430 | +  | 
                                                        |
| 3431 | +  | 
                                                        |
| 3432 | + /**  | 
                                                        |
| 3433 | + * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)  | 
                                                        |
| 3434 | + *  | 
                                                        |
| 3435 | + * @access protected  | 
                                                        |
| 3436 | + * @return void  | 
                                                        |
| 3437 | + * @throws DomainException  | 
                                                        |
| 3438 | + */  | 
                                                        |
| 3439 | + protected function _set_m_mt_settings()  | 
                                                        |
| 3440 | +	{ | 
                                                        |
| 3441 | + // first if this is already set then lets get out no need to regenerate data.  | 
                                                        |
| 3442 | +		if (! empty($this->_m_mt_settings)) { | 
                                                        |
| 3443 | + return;  | 
                                                        |
| 3444 | + }  | 
                                                        |
| 3445 | +  | 
                                                        |
| 3446 | + // get all installed messengers and message_types  | 
                                                        |
| 3447 | + $messengers = $this->_message_resource_manager->installed_messengers();  | 
                                                        |
| 3448 | + $message_types = $this->_message_resource_manager->installed_message_types();  | 
                                                        |
| 3449 | +  | 
                                                        |
| 3450 | +  | 
                                                        |
| 3451 | + // assemble the array for the _tab_text_links helper  | 
                                                        |
| 3452 | +  | 
                                                        |
| 3453 | +		foreach ($messengers as $messenger) { | 
                                                        |
| 3454 | + $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3455 | + $class = 'ee-messenger-' . sanitize_key($messenger->label['singular']);  | 
                                                        |
| 3456 | + $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [  | 
                                                        |
| 3457 | + 'label' => ucwords($messenger->label['singular']),  | 
                                                        |
| 3458 | +				'class' => $active ? "{$class} messenger-active" : $class, | 
                                                        |
| 3459 | + 'href' => $messenger->name,  | 
                                                        |
| 3460 | +				'title' => esc_html__('Modify this Messenger', 'event_espresso'), | 
                                                        |
| 3461 | + 'slug' => $messenger->name,  | 
                                                        |
| 3462 | + 'obj' => $messenger,  | 
                                                        |
| 3463 | + 'icon' => $active  | 
                                                        |
| 3464 | + ? '<span class="dashicons dashicons-yes-alt"></span>'  | 
                                                        |
| 3465 | + : '<span class="dashicons dashicons-remove"></span>',  | 
                                                        |
| 3466 | + ];  | 
                                                        |
| 3467 | +  | 
                                                        |
| 3468 | +  | 
                                                        |
| 3469 | + $message_types_for_messenger = $messenger->get_valid_message_types();  | 
                                                        |
| 3470 | +  | 
                                                        |
| 3471 | +			foreach ($message_types as $message_type) { | 
                                                        |
| 3472 | + // first we need to verify that this message type is valid with this messenger. Cause if it isn't then  | 
                                                        |
| 3473 | + // it shouldn't show in either the inactive OR active metabox.  | 
                                                        |
| 3474 | +				if (! in_array($message_type->name, $message_types_for_messenger, true)) { | 
                                                        |
| 3475 | + continue;  | 
                                                        |
| 3476 | + }  | 
                                                        |
| 3477 | +  | 
                                                        |
| 3478 | + $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 3479 | + $messenger->name,  | 
                                                        |
| 3480 | + $message_type->name  | 
                                                        |
| 3481 | + )  | 
                                                        |
| 3482 | + ? 'active'  | 
                                                        |
| 3483 | + : 'inactive';  | 
                                                        |
| 3484 | +  | 
                                                        |
| 3485 | + $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [  | 
                                                        |
| 3486 | + 'label' => ucwords($message_type->label['singular']),  | 
                                                        |
| 3487 | + 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 3488 | + 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 3489 | + 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 3490 | + 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 3491 | + 'title' => $a_or_i === 'active'  | 
                                                        |
| 3492 | +						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        |
| 3493 | +						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        |
| 3494 | + 'content' => $a_or_i === 'active'  | 
                                                        |
| 3495 | + ? $this->_message_type_settings_content($message_type, $messenger, true)  | 
                                                        |
| 3496 | + : $this->_message_type_settings_content($message_type, $messenger),  | 
                                                        |
| 3497 | + 'slug' => $message_type->name,  | 
                                                        |
| 3498 | + 'active' => $a_or_i === 'active',  | 
                                                        |
| 3499 | + 'obj' => $message_type,  | 
                                                        |
| 3500 | + ];  | 
                                                        |
| 3501 | + }  | 
                                                        |
| 3502 | + }  | 
                                                        |
| 3503 | + }  | 
                                                        |
| 3504 | +  | 
                                                        |
| 3505 | +  | 
                                                        |
| 3506 | + /**  | 
                                                        |
| 3507 | + * This just prepares the content for the message type settings  | 
                                                        |
| 3508 | + *  | 
                                                        |
| 3509 | + * @param EE_message_type $message_type The message type object  | 
                                                        |
| 3510 | + * @param EE_messenger $messenger The messenger object  | 
                                                        |
| 3511 | + * @param boolean $active Whether the message type is active or not  | 
                                                        |
| 3512 | + * @return string html output for the content  | 
                                                        |
| 3513 | + * @throws DomainException  | 
                                                        |
| 3514 | + */  | 
                                                        |
| 3515 | + protected function _message_type_settings_content($message_type, $messenger, $active = false)  | 
                                                        |
| 3516 | +	{ | 
                                                        |
| 3517 | + // get message type fields  | 
                                                        |
| 3518 | + $fields = $message_type->get_admin_settings_fields();  | 
                                                        |
| 3519 | + $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3520 | +  | 
                                                        |
| 3521 | +		if (! empty($fields) && $active) { | 
                                                        |
| 3522 | + $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        |
| 3523 | +			foreach ($fields as $fldname => $fldprops) { | 
                                                        |
| 3524 | + $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 3525 | + $template_form_field[ $field_id ] = [  | 
                                                        |
| 3526 | + 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 3527 | + 'label' => $fldprops['label'],  | 
                                                        |
| 3528 | + 'input' => $fldprops['field_type'],  | 
                                                        |
| 3529 | + 'type' => $fldprops['value_type'],  | 
                                                        |
| 3530 | + 'required' => $fldprops['required'],  | 
                                                        |
| 3531 | + 'validation' => $fldprops['validation'],  | 
                                                        |
| 3532 | + 'value' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3533 | + ? $existing_settings[ $fldname ]  | 
                                                        |
| 3534 | + : $fldprops['default'],  | 
                                                        |
| 3535 | + 'options' => isset($fldprops['options'])  | 
                                                        |
| 3536 | + ? $fldprops['options']  | 
                                                        |
| 3537 | + : [],  | 
                                                        |
| 3538 | + 'default' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3539 | + ? $existing_settings[ $fldname ]  | 
                                                        |
| 3540 | + : $fldprops['default'],  | 
                                                        |
| 3541 | + 'css_class' => 'no-drag',  | 
                                                        |
| 3542 | + 'format' => $fldprops['format'],  | 
                                                        |
| 3543 | + ];  | 
                                                        |
| 3544 | + }  | 
                                                        |
| 3545 | +  | 
                                                        |
| 3546 | +  | 
                                                        |
| 3547 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3548 | + ? $this->_generate_admin_form_fields(  | 
                                                        |
| 3549 | + $template_form_field,  | 
                                                        |
| 3550 | + 'string',  | 
                                                        |
| 3551 | + 'ee_mt_activate_form'  | 
                                                        |
| 3552 | + )  | 
                                                        |
| 3553 | + : '';  | 
                                                        |
| 3554 | + }  | 
                                                        |
| 3555 | +  | 
                                                        |
| 3556 | + $settings_template_args['description'] = $message_type->description;  | 
                                                        |
| 3557 | + // we also need some hidden fields  | 
                                                        |
| 3558 | + $hidden_fields = [  | 
                                                        |
| 3559 | + 'message_type_settings[messenger]' . $message_type->name => [  | 
                                                        |
| 3560 | + 'type' => 'hidden',  | 
                                                        |
| 3561 | + 'value' => $messenger->name,  | 
                                                        |
| 3562 | + ],  | 
                                                        |
| 3563 | + 'message_type_settings[message_type]' . $message_type->name => [  | 
                                                        |
| 3564 | + 'type' => 'hidden',  | 
                                                        |
| 3565 | + 'value' => $message_type->name,  | 
                                                        |
| 3566 | + ],  | 
                                                        |
| 3567 | + 'type' . $message_type->name => [  | 
                                                        |
| 3568 | + 'type' => 'hidden',  | 
                                                        |
| 3569 | + 'value' => 'message_type',  | 
                                                        |
| 3570 | + ],  | 
                                                        |
| 3571 | + ];  | 
                                                        |
| 3572 | +  | 
                                                        |
| 3573 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3574 | + $hidden_fields,  | 
                                                        |
| 3575 | + 'array'  | 
                                                        |
| 3576 | + );  | 
                                                        |
| 3577 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3578 | + ? ' hidden'  | 
                                                        |
| 3579 | + : '';  | 
                                                        |
| 3580 | +  | 
                                                        |
| 3581 | +  | 
                                                        |
| 3582 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 3583 | + return EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        |
| 3584 | + }  | 
                                                        |
| 3585 | +  | 
                                                        |
| 3586 | +  | 
                                                        |
| 3587 | + /**  | 
                                                        |
| 3588 | + * Generate all the metaboxes for the message types and register them for the messages settings page.  | 
                                                        |
| 3589 | + *  | 
                                                        |
| 3590 | + * @access protected  | 
                                                        |
| 3591 | + * @return void  | 
                                                        |
| 3592 | + * @throws DomainException  | 
                                                        |
| 3593 | + */  | 
                                                        |
| 3594 | + protected function _messages_settings_metaboxes()  | 
                                                        |
| 3595 | +	{ | 
                                                        |
| 3596 | + $this->_set_m_mt_settings();  | 
                                                        |
| 3597 | + $m_boxes = $mt_boxes = [];  | 
                                                        |
| 3598 | + $m_template_args = $mt_template_args = [];  | 
                                                        |
| 3599 | +  | 
                                                        |
| 3600 | +		$selected_messenger = $this->request->getRequestParam('selected_messenger', 'email'); | 
                                                        |
| 3601 | +  | 
                                                        |
| 3602 | +		if (isset($this->_m_mt_settings['messenger_tabs'])) { | 
                                                        |
| 3603 | +			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) { | 
                                                        |
| 3604 | + $is_messenger_active = $this->_message_resource_manager->is_messenger_active($messenger);  | 
                                                        |
| 3605 | + $hide_on_message = $is_messenger_active ? '' : 'hidden';  | 
                                                        |
| 3606 | + $hide_off_message = $is_messenger_active ? 'hidden' : '';  | 
                                                        |
| 3607 | +  | 
                                                        |
| 3608 | + // messenger meta boxes  | 
                                                        |
| 3609 | + $active = $selected_messenger === $messenger;  | 
                                                        |
| 3610 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])  | 
                                                        |
| 3611 | + ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']  | 
                                                        |
| 3612 | + : '';  | 
                                                        |
| 3613 | +  | 
                                                        |
| 3614 | + $m_boxes[ $messenger . '_a_box' ] = sprintf(  | 
                                                        |
| 3615 | +					esc_html__('%s Settings', 'event_espresso'), | 
                                                        |
| 3616 | + $tab_array['label']  | 
                                                        |
| 3617 | + );  | 
                                                        |
| 3618 | +  | 
                                                        |
| 3619 | + $m_template_args[ $messenger . '_a_box' ] = [  | 
                                                        |
| 3620 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 3621 | + 'inactive_message_types' => isset(  | 
                                                        |
| 3622 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3623 | + )  | 
                                                        |
| 3624 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3625 | + : '',  | 
                                                        |
| 3626 | + 'content' => $this->_get_messenger_box_content($tab_array['obj']),  | 
                                                        |
| 3627 | + 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 3628 | + 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 3629 | + 'messenger' => $messenger,  | 
                                                        |
| 3630 | + 'active' => $active,  | 
                                                        |
| 3631 | + ];  | 
                                                        |
| 3632 | +  | 
                                                        |
| 3633 | + // message type meta boxes  | 
                                                        |
| 3634 | + // (which is really just the inactive container for each messenger  | 
                                                        |
| 3635 | + // showing inactive message types for that messenger)  | 
                                                        |
| 3636 | +				$mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 3637 | + $mt_template_args[ $messenger . '_i_box' ] = [  | 
                                                        |
| 3638 | + 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        |
| 3639 | + 'inactive_message_types' => isset(  | 
                                                        |
| 3640 | + $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3641 | + )  | 
                                                        |
| 3642 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3643 | + : '',  | 
                                                        |
| 3644 | + 'hidden' => $active ? '' : ' hidden',  | 
                                                        |
| 3645 | + 'hide_on_message' => $hide_on_message,  | 
                                                        |
| 3646 | + 'hide_off_message' => $hide_off_message,  | 
                                                        |
| 3647 | + 'messenger' => $messenger,  | 
                                                        |
| 3648 | + 'active' => $active,  | 
                                                        |
| 3649 | + ];  | 
                                                        |
| 3650 | + }  | 
                                                        |
| 3651 | + }  | 
                                                        |
| 3652 | +  | 
                                                        |
| 3653 | +  | 
                                                        |
| 3654 | + // register messenger metaboxes  | 
                                                        |
| 3655 | + $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 3656 | +		foreach ($m_boxes as $box => $label) { | 
                                                        |
| 3657 | + $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];  | 
                                                        |
| 3658 | +			$msgr          = str_replace('_a_box', '', $box); | 
                                                        |
| 3659 | + $this->addMetaBox(  | 
                                                        |
| 3660 | + 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 3661 | + $label,  | 
                                                        |
| 3662 | +				function ($post, $metabox) { | 
                                                        |
| 3663 | + EEH_Template::display_template(  | 
                                                        |
| 3664 | + $metabox['args']['template_path'],  | 
                                                        |
| 3665 | + $metabox['args']['template_args']  | 
                                                        |
| 3666 | + );  | 
                                                        |
| 3667 | + },  | 
                                                        |
| 3668 | + $this->_current_screen->id,  | 
                                                        |
| 3669 | + 'normal',  | 
                                                        |
| 3670 | + 'high',  | 
                                                        |
| 3671 | + $callback_args  | 
                                                        |
| 3672 | + );  | 
                                                        |
| 3673 | + }  | 
                                                        |
| 3674 | +  | 
                                                        |
| 3675 | + // register message type metaboxes  | 
                                                        |
| 3676 | + $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 3677 | +		foreach ($mt_boxes as $box => $label) { | 
                                                        |
| 3678 | + $callback_args = [  | 
                                                        |
| 3679 | + 'template_path' => $mt_template_path,  | 
                                                        |
| 3680 | + 'template_args' => $mt_template_args[ $box ],  | 
                                                        |
| 3681 | + ];  | 
                                                        |
| 3682 | +			$mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 3683 | + $this->addMetaBox(  | 
                                                        |
| 3684 | + 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 3685 | + $label,  | 
                                                        |
| 3686 | +				function ($post, $metabox) { | 
                                                        |
| 3687 | + EEH_Template::display_template(  | 
                                                        |
| 3688 | + $metabox['args']['template_path'],  | 
                                                        |
| 3689 | + $metabox['args']['template_args']  | 
                                                        |
| 3690 | + );  | 
                                                        |
| 3691 | + },  | 
                                                        |
| 3692 | + $this->_current_screen->id,  | 
                                                        |
| 3693 | + 'side',  | 
                                                        |
| 3694 | + 'high',  | 
                                                        |
| 3695 | + $callback_args  | 
                                                        |
| 3696 | + );  | 
                                                        |
| 3697 | + }  | 
                                                        |
| 3698 | +  | 
                                                        |
| 3699 | + // register metabox for global messages settings but only when on the main site. On single site installs this  | 
                                                        |
| 3700 | + // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.  | 
                                                        |
| 3701 | +		if (is_main_site()) { | 
                                                        |
| 3702 | + $this->addMetaBox(  | 
                                                        |
| 3703 | + 'espresso_global_message_settings',  | 
                                                        |
| 3704 | +				esc_html__('Global Message Settings', 'event_espresso'), | 
                                                        |
| 3705 | + [$this, 'global_messages_settings_metabox_content'],  | 
                                                        |
| 3706 | + $this->_current_screen->id,  | 
                                                        |
| 3707 | + 'normal',  | 
                                                        |
| 3708 | + 'low',  | 
                                                        |
| 3709 | + []  | 
                                                        |
| 3710 | + );  | 
                                                        |
| 3711 | + }  | 
                                                        |
| 3712 | + }  | 
                                                        |
| 3713 | +  | 
                                                        |
| 3714 | +  | 
                                                        |
| 3715 | + /**  | 
                                                        |
| 3716 | + * This generates the content for the global messages settings metabox.  | 
                                                        |
| 3717 | + *  | 
                                                        |
| 3718 | + * @return void  | 
                                                        |
| 3719 | + * @throws EE_Error  | 
                                                        |
| 3720 | + * @throws InvalidArgumentException  | 
                                                        |
| 3721 | + * @throws ReflectionException  | 
                                                        |
| 3722 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3723 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3724 | + */  | 
                                                        |
| 3725 | + public function global_messages_settings_metabox_content()  | 
                                                        |
| 3726 | +	{ | 
                                                        |
| 3727 | + $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3728 | + echo wp_kses(  | 
                                                        |
| 3729 | + $form->form_open(  | 
                                                        |
| 3730 | + $this->add_query_args_and_nonce(['action' => 'update_global_settings'], EE_MSG_ADMIN_URL),  | 
                                                        |
| 3731 | + 'POST'  | 
                                                        |
| 3732 | + ),  | 
                                                        |
| 3733 | + AllowedTags::getWithFormTags()  | 
                                                        |
| 3734 | + );  | 
                                                        |
| 3735 | + echo wp_kses($form->get_html(), AllowedTags::getWithFormTags());  | 
                                                        |
| 3736 | + echo wp_kses($form->form_close(), AllowedTags::getWithFormTags());  | 
                                                        |
| 3737 | + }  | 
                                                        |
| 3738 | +  | 
                                                        |
| 3739 | +  | 
                                                        |
| 3740 | + /**  | 
                                                        |
| 3741 | + * This generates and returns the form object for the global messages settings.  | 
                                                        |
| 3742 | + *  | 
                                                        |
| 3743 | + * @return EE_Form_Section_Proper  | 
                                                        |
| 3744 | + * @throws EE_Error  | 
                                                        |
| 3745 | + * @throws InvalidArgumentException  | 
                                                        |
| 3746 | + * @throws ReflectionException  | 
                                                        |
| 3747 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3748 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3749 | + */  | 
                                                        |
| 3750 | + protected function _generate_global_settings_form()  | 
                                                        |
| 3751 | +	{ | 
                                                        |
| 3752 | + /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3753 | + $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3754 | +  | 
                                                        |
| 3755 | + return new EE_Form_Section_Proper(  | 
                                                        |
| 3756 | + [  | 
                                                        |
| 3757 | + 'name' => 'global_messages_settings',  | 
                                                        |
| 3758 | + 'html_id' => 'global_messages_settings',  | 
                                                        |
| 3759 | + 'html_class' => 'form-table',  | 
                                                        |
| 3760 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(),  | 
                                                        |
| 3761 | + 'subsections' => apply_filters(  | 
                                                        |
| 3762 | + 'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',  | 
                                                        |
| 3763 | + [  | 
                                                        |
| 3764 | + 'do_messages_on_same_request' => new EE_Select_Input(  | 
                                                        |
| 3765 | + [  | 
                                                        |
| 3766 | +								true  => esc_html__('On the same request', 'event_espresso'), | 
                                                        |
| 3767 | +								false => esc_html__('On a separate request', 'event_espresso'), | 
                                                        |
| 3768 | + ],  | 
                                                        |
| 3769 | + [  | 
                                                        |
| 3770 | + 'default' => $network_config->do_messages_on_same_request,  | 
                                                        |
| 3771 | + 'html_label_text' => esc_html__(  | 
                                                        |
| 3772 | + 'Generate and send all messages:',  | 
                                                        |
| 3773 | + 'event_espresso'  | 
                                                        |
| 3774 | + ),  | 
                                                        |
| 3775 | + 'html_help_text' => esc_html__(  | 
                                                        |
| 3776 | + 'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system. This makes things execute faster for people registering for your events. However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',  | 
                                                        |
| 3777 | + 'event_espresso'  | 
                                                        |
| 3778 | + ),  | 
                                                        |
| 3779 | + ]  | 
                                                        |
| 3780 | + ),  | 
                                                        |
| 3781 | + 'delete_threshold' => new EE_Select_Input(  | 
                                                        |
| 3782 | + [  | 
                                                        |
| 3783 | +								0  => esc_html__('Forever', 'event_espresso'), | 
                                                        |
| 3784 | +								3  => esc_html__('3 Months', 'event_espresso'), | 
                                                        |
| 3785 | +								6  => esc_html__('6 Months', 'event_espresso'), | 
                                                        |
| 3786 | +								9  => esc_html__('9 Months', 'event_espresso'), | 
                                                        |
| 3787 | +								12 => esc_html__('12 Months', 'event_espresso'), | 
                                                        |
| 3788 | +								24 => esc_html__('24 Months', 'event_espresso'), | 
                                                        |
| 3789 | +								36 => esc_html__('36 Months', 'event_espresso'), | 
                                                        |
| 3790 | + ],  | 
                                                        |
| 3791 | + [  | 
                                                        |
| 3792 | + 'default' => EE_Registry::instance()->CFG->messages->delete_threshold,  | 
                                                        |
| 3793 | +								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'), | 
                                                        |
| 3794 | + 'html_help_text' => esc_html__(  | 
                                                        |
| 3795 | + 'You can control how long a record of processed messages is kept via this option.',  | 
                                                        |
| 3796 | + 'event_espresso'  | 
                                                        |
| 3797 | + ),  | 
                                                        |
| 3798 | + ]  | 
                                                        |
| 3799 | + ),  | 
                                                        |
| 3800 | + 'update_settings' => new EE_Submit_Input(  | 
                                                        |
| 3801 | + [  | 
                                                        |
| 3802 | +								'default'         => esc_html__('Update', 'event_espresso'), | 
                                                        |
| 3803 | + 'html_label_text' => '',  | 
                                                        |
| 3804 | + ]  | 
                                                        |
| 3805 | + ),  | 
                                                        |
| 3806 | + ]  | 
                                                        |
| 3807 | + ),  | 
                                                        |
| 3808 | + ]  | 
                                                        |
| 3809 | + );  | 
                                                        |
| 3810 | + }  | 
                                                        |
| 3811 | +  | 
                                                        |
| 3812 | +  | 
                                                        |
| 3813 | + /**  | 
                                                        |
| 3814 | + * This handles updating the global settings set on the admin page.  | 
                                                        |
| 3815 | + *  | 
                                                        |
| 3816 | + * @throws EE_Error  | 
                                                        |
| 3817 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3818 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3819 | + * @throws InvalidArgumentException  | 
                                                        |
| 3820 | + * @throws ReflectionException  | 
                                                        |
| 3821 | + */  | 
                                                        |
| 3822 | + protected function _update_global_settings()  | 
                                                        |
| 3823 | +	{ | 
                                                        |
| 3824 | + /** @var EE_Network_Core_Config $network_config */  | 
                                                        |
| 3825 | + $network_config = EE_Registry::instance()->NET_CFG->core;  | 
                                                        |
| 3826 | + $messages_config = EE_Registry::instance()->CFG->messages;  | 
                                                        |
| 3827 | + $form = $this->_generate_global_settings_form();  | 
                                                        |
| 3828 | +		if ($form->was_submitted()) { | 
                                                        |
| 3829 | + $form->receive_form_submission();  | 
                                                        |
| 3830 | +			if ($form->is_valid()) { | 
                                                        |
| 3831 | + $valid_data = $form->valid_data();  | 
                                                        |
| 3832 | +				foreach ($valid_data as $property => $value) { | 
                                                        |
| 3833 | + $setter = 'set_' . $property;  | 
                                                        |
| 3834 | +					if (method_exists($network_config, $setter)) { | 
                                                        |
| 3835 | +						$network_config->{$setter}($value); | 
                                                        |
| 3836 | + } elseif (  | 
                                                        |
| 3837 | + property_exists($network_config, $property)  | 
                                                        |
| 3838 | +						&& $network_config->{$property} !== $value | 
                                                        |
| 3839 | +					) { | 
                                                        |
| 3840 | +						$network_config->{$property} = $value; | 
                                                        |
| 3841 | + } elseif (  | 
                                                        |
| 3842 | + property_exists($messages_config, $property)  | 
                                                        |
| 3843 | +						&& $messages_config->{$property} !== $value | 
                                                        |
| 3844 | +					) { | 
                                                        |
| 3845 | +						$messages_config->{$property} = $value; | 
                                                        |
| 3846 | + }  | 
                                                        |
| 3847 | + }  | 
                                                        |
| 3848 | + // only update if the form submission was valid!  | 
                                                        |
| 3849 | + EE_Registry::instance()->NET_CFG->update_config(true, false);  | 
                                                        |
| 3850 | + EE_Registry::instance()->CFG->update_espresso_config();  | 
                                                        |
| 3851 | + EE_Error::overwrite_success();  | 
                                                        |
| 3852 | +				EE_Error::add_success(esc_html__('Global message settings were updated', 'event_espresso')); | 
                                                        |
| 3853 | + }  | 
                                                        |
| 3854 | + }  | 
                                                        |
| 3855 | + $this->_redirect_after_action(0, '', '', ['action' => 'settings'], true);  | 
                                                        |
| 3856 | + }  | 
                                                        |
| 3857 | +  | 
                                                        |
| 3858 | +  | 
                                                        |
| 3859 | + /**  | 
                                                        |
| 3860 | + * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate  | 
                                                        |
| 3861 | + *  | 
                                                        |
| 3862 | + * @param array $tab_array This is an array of message type tab details used to generate the tabs  | 
                                                        |
| 3863 | + * @return string html formatted tabs  | 
                                                        |
| 3864 | + * @throws DomainException  | 
                                                        |
| 3865 | + */  | 
                                                        |
| 3866 | + protected function _get_mt_tabs($tab_array)  | 
                                                        |
| 3867 | +	{ | 
                                                        |
| 3868 | + $tab_array = (array) $tab_array;  | 
                                                        |
| 3869 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3870 | + $tabs = '';  | 
                                                        |
| 3871 | +  | 
                                                        |
| 3872 | +		foreach ($tab_array as $tab) { | 
                                                        |
| 3873 | + $tabs .= EEH_Template::display_template($template, $tab, true);  | 
                                                        |
| 3874 | + }  | 
                                                        |
| 3875 | +  | 
                                                        |
| 3876 | + return $tabs;  | 
                                                        |
| 3877 | + }  | 
                                                        |
| 3878 | +  | 
                                                        |
| 3879 | +  | 
                                                        |
| 3880 | + /**  | 
                                                        |
| 3881 | + * This prepares the content of the messenger meta box admin settings  | 
                                                        |
| 3882 | + *  | 
                                                        |
| 3883 | + * @param EE_messenger $messenger The messenger we're setting up content for  | 
                                                        |
| 3884 | + * @return string html formatted content  | 
                                                        |
| 3885 | + * @throws DomainException  | 
                                                        |
| 3886 | + */  | 
                                                        |
| 3887 | + protected function _get_messenger_box_content(EE_messenger $messenger)  | 
                                                        |
| 3888 | +	{ | 
                                                        |
| 3889 | +  | 
                                                        |
| 3890 | + $fields = $messenger->get_admin_settings_fields();  | 
                                                        |
| 3891 | +  | 
                                                        |
| 3892 | + $settings_template_args['template_form_fields'] = '';  | 
                                                        |
| 3893 | + // is $messenger active?  | 
                                                        |
| 3894 | + $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3895 | +  | 
                                                        |
| 3896 | +  | 
                                                        |
| 3897 | +		if (! empty($fields)) { | 
                                                        |
| 3898 | + $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        |
| 3899 | +  | 
                                                        |
| 3900 | +			foreach ($fields as $field_name => $field_props) { | 
                                                        |
| 3901 | + $field_id = $messenger->name . '-' . $field_name;  | 
                                                        |
| 3902 | + $template_form_field[ $field_id ] = [  | 
                                                        |
| 3903 | + 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3904 | + 'label' => $field_props['label'],  | 
                                                        |
| 3905 | + 'input' => $field_props['field_type'],  | 
                                                        |
| 3906 | + 'type' => $field_props['value_type'],  | 
                                                        |
| 3907 | + 'required' => $field_props['required'],  | 
                                                        |
| 3908 | + 'validation' => $field_props['validation'],  | 
                                                        |
| 3909 | + 'value' => $existing_settings[ $field_id ] ?? $field_props['default'],  | 
                                                        |
| 3910 | + 'css_class' => '',  | 
                                                        |
| 3911 | + 'format' => $field_props['format'],  | 
                                                        |
| 3912 | + ];  | 
                                                        |
| 3913 | + }  | 
                                                        |
| 3914 | +  | 
                                                        |
| 3915 | + $settings_template_args['template_form_fields'] = ! empty($template_form_field)  | 
                                                        |
| 3916 | + ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')  | 
                                                        |
| 3917 | + : '';  | 
                                                        |
| 3918 | + }  | 
                                                        |
| 3919 | +  | 
                                                        |
| 3920 | + // we also need some hidden fields  | 
                                                        |
| 3921 | + $settings_template_args['hidden_fields'] = [  | 
                                                        |
| 3922 | + 'messenger_settings[messenger]' . $messenger->name => [  | 
                                                        |
| 3923 | + 'type' => 'hidden',  | 
                                                        |
| 3924 | + 'value' => $messenger->name,  | 
                                                        |
| 3925 | + ],  | 
                                                        |
| 3926 | + 'type' . $messenger->name => [  | 
                                                        |
| 3927 | + 'type' => 'hidden',  | 
                                                        |
| 3928 | + 'value' => 'messenger',  | 
                                                        |
| 3929 | + ],  | 
                                                        |
| 3930 | + ];  | 
                                                        |
| 3931 | +  | 
                                                        |
| 3932 | + // make sure any active message types that are existing are included in the hidden fields  | 
                                                        |
| 3933 | +		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { | 
                                                        |
| 3934 | +			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { | 
                                                        |
| 3935 | + $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [  | 
                                                        |
| 3936 | + 'type' => 'hidden',  | 
                                                        |
| 3937 | + 'value' => $mt,  | 
                                                        |
| 3938 | + ];  | 
                                                        |
| 3939 | + }  | 
                                                        |
| 3940 | + }  | 
                                                        |
| 3941 | + $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(  | 
                                                        |
| 3942 | + $settings_template_args['hidden_fields'],  | 
                                                        |
| 3943 | + 'array'  | 
                                                        |
| 3944 | + );  | 
                                                        |
| 3945 | + $active =  | 
                                                        |
| 3946 | + $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        |
| 3947 | +  | 
                                                        |
| 3948 | + $settings_template_args['messenger'] = $messenger->name;  | 
                                                        |
| 3949 | + $settings_template_args['description'] = $messenger->description;  | 
                                                        |
| 3950 | + $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';  | 
                                                        |
| 3951 | +  | 
                                                        |
| 3952 | +  | 
                                                        |
| 3953 | + $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(  | 
                                                        |
| 3954 | + $messenger->name  | 
                                                        |
| 3955 | + )  | 
                                                        |
| 3956 | + ? $settings_template_args['show_hide_edit_form']  | 
                                                        |
| 3957 | + : ' hidden';  | 
                                                        |
| 3958 | +  | 
                                                        |
| 3959 | + $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3960 | + ? ' hidden'  | 
                                                        |
| 3961 | + : $settings_template_args['show_hide_edit_form'];  | 
                                                        |
| 3962 | +  | 
                                                        |
| 3963 | +  | 
                                                        |
| 3964 | + $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        |
| 3965 | +		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3966 | + $settings_template_args['on_off_status'] = $active;  | 
                                                        |
| 3967 | + $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3968 | + return EEH_Template::display_template(  | 
                                                        |
| 3969 | + $template,  | 
                                                        |
| 3970 | + $settings_template_args,  | 
                                                        |
| 3971 | + true  | 
                                                        |
| 3972 | + );  | 
                                                        |
| 3973 | + }  | 
                                                        |
| 3974 | +  | 
                                                        |
| 3975 | +  | 
                                                        |
| 3976 | + /**  | 
                                                        |
| 3977 | + * used by ajax on the messages settings page to activate|deactivate the messenger  | 
                                                        |
| 3978 | + *  | 
                                                        |
| 3979 | + * @throws DomainException  | 
                                                        |
| 3980 | + * @throws EE_Error  | 
                                                        |
| 3981 | + * @throws InvalidDataTypeException  | 
                                                        |
| 3982 | + * @throws InvalidInterfaceException  | 
                                                        |
| 3983 | + * @throws InvalidArgumentException  | 
                                                        |
| 3984 | + * @throws ReflectionException  | 
                                                        |
| 3985 | + */  | 
                                                        |
| 3986 | + public function activate_messenger_toggle()  | 
                                                        |
| 3987 | +	{ | 
                                                        |
| 3988 | + $success = true;  | 
                                                        |
| 3989 | + $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 3990 | + // let's check that we have required data  | 
                                                        |
| 3991 | +  | 
                                                        |
| 3992 | +		if (! $this->_active_messenger_name) { | 
                                                        |
| 3993 | + EE_Error::add_error(  | 
                                                        |
| 3994 | +				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 3995 | + __FILE__,  | 
                                                        |
| 3996 | + __FUNCTION__,  | 
                                                        |
| 3997 | + __LINE__  | 
                                                        |
| 3998 | + );  | 
                                                        |
| 3999 | + $success = false;  | 
                                                        |
| 4000 | + }  | 
                                                        |
| 4001 | +  | 
                                                        |
| 4002 | + // do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 4003 | +		$nonce     = $this->request->getRequestParam('activate_nonce', ''); | 
                                                        |
| 4004 | +		$nonce_ref = "activate_{$this->_active_messenger_name}_toggle_nonce"; | 
                                                        |
| 4005 | +  | 
                                                        |
| 4006 | + $this->_verify_nonce($nonce, $nonce_ref);  | 
                                                        |
| 4007 | +  | 
                                                        |
| 4008 | +  | 
                                                        |
| 4009 | +		$status = $this->request->getRequestParam('status'); | 
                                                        |
| 4010 | +		if (! $status) { | 
                                                        |
| 4011 | + EE_Error::add_error(  | 
                                                        |
| 4012 | + esc_html__(  | 
                                                        |
| 4013 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 4014 | + 'event_espresso'  | 
                                                        |
| 4015 | + ),  | 
                                                        |
| 4016 | + __FILE__,  | 
                                                        |
| 4017 | + __FUNCTION__,  | 
                                                        |
| 4018 | + __LINE__  | 
                                                        |
| 4019 | + );  | 
                                                        |
| 4020 | + $success = false;  | 
                                                        |
| 4021 | + }  | 
                                                        |
| 4022 | +  | 
                                                        |
| 4023 | + // do check to verify we have a valid status.  | 
                                                        |
| 4024 | +		if ($status !== 'off' && $status !== 'on') { | 
                                                        |
| 4025 | + EE_Error::add_error(  | 
                                                        |
| 4026 | + sprintf(  | 
                                                        |
| 4027 | +					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'), | 
                                                        |
| 4028 | + $status  | 
                                                        |
| 4029 | + ),  | 
                                                        |
| 4030 | + __FILE__,  | 
                                                        |
| 4031 | + __FUNCTION__,  | 
                                                        |
| 4032 | + __LINE__  | 
                                                        |
| 4033 | + );  | 
                                                        |
| 4034 | + $success = false;  | 
                                                        |
| 4035 | + }  | 
                                                        |
| 4036 | +  | 
                                                        |
| 4037 | +		if ($success) { | 
                                                        |
| 4038 | + // made it here? Stop dawdling then!!  | 
                                                        |
| 4039 | + $success = $status === 'off'  | 
                                                        |
| 4040 | + ? $this->_deactivate_messenger($this->_active_messenger_name)  | 
                                                        |
| 4041 | + : $this->_activate_messenger($this->_active_messenger_name);  | 
                                                        |
| 4042 | + }  | 
                                                        |
| 4043 | +  | 
                                                        |
| 4044 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 4045 | +  | 
                                                        |
| 4046 | + // no special instructions so let's just do the json return (which should automatically do all the special stuff).  | 
                                                        |
| 4047 | + $this->_return_json();  | 
                                                        |
| 4048 | + }  | 
                                                        |
| 4049 | +  | 
                                                        |
| 4050 | +  | 
                                                        |
| 4051 | + /**  | 
                                                        |
| 4052 | + * used by ajax from the messages settings page to activate|deactivate a message type  | 
                                                        |
| 4053 | + *  | 
                                                        |
| 4054 | + * @throws DomainException  | 
                                                        |
| 4055 | + * @throws EE_Error  | 
                                                        |
| 4056 | + * @throws ReflectionException  | 
                                                        |
| 4057 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4058 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4059 | + * @throws InvalidArgumentException  | 
                                                        |
| 4060 | + */  | 
                                                        |
| 4061 | + public function activate_mt_toggle()  | 
                                                        |
| 4062 | +	{ | 
                                                        |
| 4063 | + $success = true;  | 
                                                        |
| 4064 | + $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        |
| 4065 | +  | 
                                                        |
| 4066 | + // let's make sure we have the necessary data  | 
                                                        |
| 4067 | +		if (! $this->_active_message_type_name) { | 
                                                        |
| 4068 | + EE_Error::add_error(  | 
                                                        |
| 4069 | +				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 4070 | + __FILE__,  | 
                                                        |
| 4071 | + __FUNCTION__,  | 
                                                        |
| 4072 | + __LINE__  | 
                                                        |
| 4073 | + );  | 
                                                        |
| 4074 | + $success = false;  | 
                                                        |
| 4075 | + }  | 
                                                        |
| 4076 | +  | 
                                                        |
| 4077 | +		if (! $this->_active_messenger_name) { | 
                                                        |
| 4078 | + EE_Error::add_error(  | 
                                                        |
| 4079 | +				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        |
| 4080 | + __FILE__,  | 
                                                        |
| 4081 | + __FUNCTION__,  | 
                                                        |
| 4082 | + __LINE__  | 
                                                        |
| 4083 | + );  | 
                                                        |
| 4084 | + $success = false;  | 
                                                        |
| 4085 | + }  | 
                                                        |
| 4086 | +  | 
                                                        |
| 4087 | +		$status = $this->request->getRequestParam('status'); | 
                                                        |
| 4088 | +		if (! $status) { | 
                                                        |
| 4089 | + EE_Error::add_error(  | 
                                                        |
| 4090 | + esc_html__(  | 
                                                        |
| 4091 | + 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        |
| 4092 | + 'event_espresso'  | 
                                                        |
| 4093 | + ),  | 
                                                        |
| 4094 | + __FILE__,  | 
                                                        |
| 4095 | + __FUNCTION__,  | 
                                                        |
| 4096 | + __LINE__  | 
                                                        |
| 4097 | + );  | 
                                                        |
| 4098 | + $success = false;  | 
                                                        |
| 4099 | + }  | 
                                                        |
| 4100 | +  | 
                                                        |
| 4101 | +  | 
                                                        |
| 4102 | + // do check to verify we have a valid status.  | 
                                                        |
| 4103 | +		if ($status !== 'activate' && $status !== 'deactivate') { | 
                                                        |
| 4104 | + EE_Error::add_error(  | 
                                                        |
| 4105 | + sprintf(  | 
                                                        |
| 4106 | +					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'), | 
                                                        |
| 4107 | + $status  | 
                                                        |
| 4108 | + ),  | 
                                                        |
| 4109 | + __FILE__,  | 
                                                        |
| 4110 | + __FUNCTION__,  | 
                                                        |
| 4111 | + __LINE__  | 
                                                        |
| 4112 | + );  | 
                                                        |
| 4113 | + $success = false;  | 
                                                        |
| 4114 | + }  | 
                                                        |
| 4115 | +  | 
                                                        |
| 4116 | +  | 
                                                        |
| 4117 | + // do a nonce check here since we're not arriving via a normal route  | 
                                                        |
| 4118 | +		$nonce = $this->request->getRequestParam('mt_nonce', ''); | 
                                                        |
| 4119 | +		$this->_verify_nonce($nonce, "{$this->_active_message_type_name}_nonce"); | 
                                                        |
| 4120 | +  | 
                                                        |
| 4121 | +		if ($success) { | 
                                                        |
| 4122 | + // made it here? um, what are you waiting for then?  | 
                                                        |
| 4123 | + $success = $status === 'deactivate'  | 
                                                        |
| 4124 | + ? $this->_deactivate_message_type_for_messenger(  | 
                                                        |
| 4125 | + $this->_active_messenger_name,  | 
                                                        |
| 4126 | + $this->_active_message_type_name  | 
                                                        |
| 4127 | + )  | 
                                                        |
| 4128 | + : $this->_activate_message_type_for_messenger(  | 
                                                        |
| 4129 | + $this->_active_messenger_name,  | 
                                                        |
| 4130 | + $this->_active_message_type_name  | 
                                                        |
| 4131 | + );  | 
                                                        |
| 4132 | + }  | 
                                                        |
| 4133 | +  | 
                                                        |
| 4134 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 4135 | + $this->_return_json();  | 
                                                        |
| 4136 | + }  | 
                                                        |
| 4137 | +  | 
                                                        |
| 4138 | +  | 
                                                        |
| 4139 | + /**  | 
                                                        |
| 4140 | + * Takes care of processing activating a messenger and preparing the appropriate response.  | 
                                                        |
| 4141 | + *  | 
                                                        |
| 4142 | + * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 4143 | + * @return bool  | 
                                                        |
| 4144 | + * @throws DomainException  | 
                                                        |
| 4145 | + * @throws EE_Error  | 
                                                        |
| 4146 | + * @throws InvalidArgumentException  | 
                                                        |
| 4147 | + * @throws ReflectionException  | 
                                                        |
| 4148 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4149 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4150 | + */  | 
                                                        |
| 4151 | + protected function _activate_messenger($messenger_name)  | 
                                                        |
| 4152 | +	{ | 
                                                        |
| 4153 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4154 | + $message_types_to_activate = $active_messenger instanceof EE_Messenger  | 
                                                        |
| 4155 | + ? $active_messenger->get_default_message_types()  | 
                                                        |
| 4156 | + : [];  | 
                                                        |
| 4157 | +  | 
                                                        |
| 4158 | + // ensure is active  | 
                                                        |
| 4159 | + $this->_message_resource_manager->activate_messenger($active_messenger, $message_types_to_activate);  | 
                                                        |
| 4160 | +  | 
                                                        |
| 4161 | + // set response_data for reload  | 
                                                        |
| 4162 | +		foreach ($message_types_to_activate as $message_type_name) { | 
                                                        |
| 4163 | + $message_type = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4164 | + if (  | 
                                                        |
| 4165 | + $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 4166 | + $messenger_name,  | 
                                                        |
| 4167 | + $message_type_name  | 
                                                        |
| 4168 | + )  | 
                                                        |
| 4169 | + && $message_type instanceof EE_message_type  | 
                                                        |
| 4170 | +			) { | 
                                                        |
| 4171 | + $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 4172 | +				if ($message_type->get_admin_settings_fields()) { | 
                                                        |
| 4173 | + $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 4174 | + }  | 
                                                        |
| 4175 | + }  | 
                                                        |
| 4176 | + }  | 
                                                        |
| 4177 | +  | 
                                                        |
| 4178 | + // add success message for activating messenger  | 
                                                        |
| 4179 | + return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 4180 | + }  | 
                                                        |
| 4181 | +  | 
                                                        |
| 4182 | +  | 
                                                        |
| 4183 | + /**  | 
                                                        |
| 4184 | + * Takes care of processing deactivating a messenger and preparing the appropriate response.  | 
                                                        |
| 4185 | + *  | 
                                                        |
| 4186 | + * @param string $messenger_name The name of the messenger being activated  | 
                                                        |
| 4187 | + * @return bool  | 
                                                        |
| 4188 | + * @throws DomainException  | 
                                                        |
| 4189 | + * @throws EE_Error  | 
                                                        |
| 4190 | + * @throws InvalidArgumentException  | 
                                                        |
| 4191 | + * @throws ReflectionException  | 
                                                        |
| 4192 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4193 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4194 | + */  | 
                                                        |
| 4195 | + protected function _deactivate_messenger($messenger_name)  | 
                                                        |
| 4196 | +	{ | 
                                                        |
| 4197 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4198 | + $this->_message_resource_manager->deactivate_messenger($messenger_name);  | 
                                                        |
| 4199 | +  | 
                                                        |
| 4200 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);  | 
                                                        |
| 4201 | + }  | 
                                                        |
| 4202 | +  | 
                                                        |
| 4203 | +  | 
                                                        |
| 4204 | + /**  | 
                                                        |
| 4205 | + * Takes care of processing activating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 4206 | + *  | 
                                                        |
| 4207 | + * @param string $messenger_name The name of the messenger the message type is being activated for.  | 
                                                        |
| 4208 | + * @param string $message_type_name The name of the message type being activated for the messenger  | 
                                                        |
| 4209 | + * @return bool  | 
                                                        |
| 4210 | + * @throws DomainException  | 
                                                        |
| 4211 | + * @throws EE_Error  | 
                                                        |
| 4212 | + * @throws InvalidArgumentException  | 
                                                        |
| 4213 | + * @throws ReflectionException  | 
                                                        |
| 4214 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4215 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4216 | + */  | 
                                                        |
| 4217 | + protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 4218 | +	{ | 
                                                        |
| 4219 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4220 | + $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4221 | +  | 
                                                        |
| 4222 | + // ensure is active  | 
                                                        |
| 4223 | + $this->_message_resource_manager->activate_messenger($active_messenger, $message_type_name);  | 
                                                        |
| 4224 | +  | 
                                                        |
| 4225 | + // set response for load  | 
                                                        |
| 4226 | + if (  | 
                                                        |
| 4227 | + $this->_message_resource_manager->is_message_type_active_for_messenger(  | 
                                                        |
| 4228 | + $messenger_name,  | 
                                                        |
| 4229 | + $message_type_name  | 
                                                        |
| 4230 | + )  | 
                                                        |
| 4231 | +		) { | 
                                                        |
| 4232 | + $this->_template_args['data']['active_mts'][] = $message_type_name;  | 
                                                        |
| 4233 | +			if ($message_type_to_activate->get_admin_settings_fields()) { | 
                                                        |
| 4234 | + $this->_template_args['data']['mt_reload'][] = $message_type_name;  | 
                                                        |
| 4235 | + }  | 
                                                        |
| 4236 | + }  | 
                                                        |
| 4237 | +  | 
                                                        |
| 4238 | + return $this->_setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 4239 | + $active_messenger,  | 
                                                        |
| 4240 | + $message_type_to_activate  | 
                                                        |
| 4241 | + );  | 
                                                        |
| 4242 | + }  | 
                                                        |
| 4243 | +  | 
                                                        |
| 4244 | +  | 
                                                        |
| 4245 | + /**  | 
                                                        |
| 4246 | + * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.  | 
                                                        |
| 4247 | + *  | 
                                                        |
| 4248 | + * @param string $messenger_name The name of the messenger the message type is being deactivated for.  | 
                                                        |
| 4249 | + * @param string $message_type_name The name of the message type being deactivated for the messenger  | 
                                                        |
| 4250 | + * @return bool  | 
                                                        |
| 4251 | + * @throws DomainException  | 
                                                        |
| 4252 | + * @throws EE_Error  | 
                                                        |
| 4253 | + * @throws InvalidArgumentException  | 
                                                        |
| 4254 | + * @throws ReflectionException  | 
                                                        |
| 4255 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4256 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4257 | + */  | 
                                                        |
| 4258 | + protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)  | 
                                                        |
| 4259 | +	{ | 
                                                        |
| 4260 | + $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);  | 
                                                        |
| 4261 | + /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */  | 
                                                        |
| 4262 | + $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);  | 
                                                        |
| 4263 | + $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);  | 
                                                        |
| 4264 | +  | 
                                                        |
| 4265 | + return $this->_setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 4266 | + $active_messenger,  | 
                                                        |
| 4267 | + $message_type_to_deactivate  | 
                                                        |
| 4268 | + );  | 
                                                        |
| 4269 | + }  | 
                                                        |
| 4270 | +  | 
                                                        |
| 4271 | +  | 
                                                        |
| 4272 | + /**  | 
                                                        |
| 4273 | + * This just initializes the defaults for activating messenger and message type responses.  | 
                                                        |
| 4274 | + */  | 
                                                        |
| 4275 | + protected function _prep_default_response_for_messenger_or_message_type_toggle()  | 
                                                        |
| 4276 | +	{ | 
                                                        |
| 4277 | + $this->_template_args['data']['active_mts'] = [];  | 
                                                        |
| 4278 | + $this->_template_args['data']['mt_reload'] = [];  | 
                                                        |
| 4279 | + }  | 
                                                        |
| 4280 | +  | 
                                                        |
| 4281 | +  | 
                                                        |
| 4282 | + /**  | 
                                                        |
| 4283 | + * Setup appropriate response for activating a messenger and/or message types  | 
                                                        |
| 4284 | + *  | 
                                                        |
| 4285 | + * @param EE_messenger $messenger  | 
                                                        |
| 4286 | + * @param EE_message_type|null $message_type  | 
                                                        |
| 4287 | + * @return bool  | 
                                                        |
| 4288 | + * @throws DomainException  | 
                                                        |
| 4289 | + * @throws EE_Error  | 
                                                        |
| 4290 | + * @throws InvalidArgumentException  | 
                                                        |
| 4291 | + * @throws ReflectionException  | 
                                                        |
| 4292 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4293 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4294 | + */  | 
                                                        |
| 4295 | + protected function _setup_response_message_for_activating_messenger_with_message_types(  | 
                                                        |
| 4296 | + $messenger,  | 
                                                        |
| 4297 | + EE_Message_Type $message_type = null  | 
                                                        |
| 4298 | +	) { | 
                                                        |
| 4299 | + // if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 4300 | +		if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4301 | + EE_Error::add_error(  | 
                                                        |
| 4302 | +				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 4303 | + __FILE__,  | 
                                                        |
| 4304 | + __FUNCTION__,  | 
                                                        |
| 4305 | + __LINE__  | 
                                                        |
| 4306 | + );  | 
                                                        |
| 4307 | + return false;  | 
                                                        |
| 4308 | + }  | 
                                                        |
| 4309 | + // activated  | 
                                                        |
| 4310 | +		if ($this->_template_args['data']['active_mts']) { | 
                                                        |
| 4311 | + EE_Error::overwrite_success();  | 
                                                        |
| 4312 | + // activated a message type with the messenger  | 
                                                        |
| 4313 | +			if ($message_type instanceof EE_message_type) { | 
                                                        |
| 4314 | + EE_Error::add_success(  | 
                                                        |
| 4315 | + sprintf(  | 
                                                        |
| 4316 | + esc_html__(  | 
                                                        |
| 4317 | + '%s message type has been successfully activated with the %s messenger',  | 
                                                        |
| 4318 | + 'event_espresso'  | 
                                                        |
| 4319 | + ),  | 
                                                        |
| 4320 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 4321 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4322 | + )  | 
                                                        |
| 4323 | + );  | 
                                                        |
| 4324 | +  | 
                                                        |
| 4325 | + // if message type was invoice then let's make sure we activate the invoice payment method.  | 
                                                        |
| 4326 | +				if ($message_type->name === 'invoice') { | 
                                                        |
| 4327 | +					EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 4328 | +					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); | 
                                                        |
| 4329 | +					if ($pm instanceof EE_Payment_Method) { | 
                                                        |
| 4330 | + EE_Error::add_attention(  | 
                                                        |
| 4331 | + esc_html__(  | 
                                                        |
| 4332 | + '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.',  | 
                                                        |
| 4333 | + 'event_espresso'  | 
                                                        |
| 4334 | + )  | 
                                                        |
| 4335 | + );  | 
                                                        |
| 4336 | + }  | 
                                                        |
| 4337 | + }  | 
                                                        |
| 4338 | + // just toggles the entire messenger  | 
                                                        |
| 4339 | +			} else { | 
                                                        |
| 4340 | + EE_Error::add_success(  | 
                                                        |
| 4341 | + sprintf(  | 
                                                        |
| 4342 | +						esc_html__('%s messenger has been successfully activated', 'event_espresso'), | 
                                                        |
| 4343 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4344 | + )  | 
                                                        |
| 4345 | + );  | 
                                                        |
| 4346 | + }  | 
                                                        |
| 4347 | +  | 
                                                        |
| 4348 | + return true;  | 
                                                        |
| 4349 | +  | 
                                                        |
| 4350 | + // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active  | 
                                                        |
| 4351 | + // message types after the activation process. However its possible some messengers don't HAVE any default_message_types  | 
                                                        |
| 4352 | + // in which case we just give a success message for the messenger being successfully activated.  | 
                                                        |
| 4353 | +		} else { | 
                                                        |
| 4354 | +			if (! $messenger->get_default_message_types()) { | 
                                                        |
| 4355 | + // messenger doesn't have any default message types so still a success.  | 
                                                        |
| 4356 | + EE_Error::add_success(  | 
                                                        |
| 4357 | + sprintf(  | 
                                                        |
| 4358 | +						esc_html__('%s messenger was successfully activated.', 'event_espresso'), | 
                                                        |
| 4359 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4360 | + )  | 
                                                        |
| 4361 | + );  | 
                                                        |
| 4362 | +  | 
                                                        |
| 4363 | + return true;  | 
                                                        |
| 4364 | +			} else { | 
                                                        |
| 4365 | + EE_Error::add_error(  | 
                                                        |
| 4366 | + $message_type instanceof EE_message_type  | 
                                                        |
| 4367 | + ? sprintf(  | 
                                                        |
| 4368 | + esc_html__(  | 
                                                        |
| 4369 | + '%s message type was not successfully activated with the %s messenger',  | 
                                                        |
| 4370 | + 'event_espresso'  | 
                                                        |
| 4371 | + ),  | 
                                                        |
| 4372 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 4373 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4374 | + )  | 
                                                        |
| 4375 | + : sprintf(  | 
                                                        |
| 4376 | +						esc_html__('%s messenger was not successfully activated', 'event_espresso'), | 
                                                        |
| 4377 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4378 | + ),  | 
                                                        |
| 4379 | + __FILE__,  | 
                                                        |
| 4380 | + __FUNCTION__,  | 
                                                        |
| 4381 | + __LINE__  | 
                                                        |
| 4382 | + );  | 
                                                        |
| 4383 | +  | 
                                                        |
| 4384 | + return false;  | 
                                                        |
| 4385 | + }  | 
                                                        |
| 4386 | + }  | 
                                                        |
| 4387 | + }  | 
                                                        |
| 4388 | +  | 
                                                        |
| 4389 | +  | 
                                                        |
| 4390 | + /**  | 
                                                        |
| 4391 | + * This sets up the appropriate response for deactivating a messenger and/or message type.  | 
                                                        |
| 4392 | + *  | 
                                                        |
| 4393 | + * @param EE_messenger $messenger  | 
                                                        |
| 4394 | + * @param EE_message_type|null $message_type  | 
                                                        |
| 4395 | + * @return bool  | 
                                                        |
| 4396 | + * @throws DomainException  | 
                                                        |
| 4397 | + * @throws EE_Error  | 
                                                        |
| 4398 | + * @throws InvalidArgumentException  | 
                                                        |
| 4399 | + * @throws ReflectionException  | 
                                                        |
| 4400 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4401 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4402 | + */  | 
                                                        |
| 4403 | + protected function _setup_response_message_for_deactivating_messenger_with_message_types(  | 
                                                        |
| 4404 | + $messenger,  | 
                                                        |
| 4405 | + EE_message_type $message_type = null  | 
                                                        |
| 4406 | +	) { | 
                                                        |
| 4407 | + EE_Error::overwrite_success();  | 
                                                        |
| 4408 | +  | 
                                                        |
| 4409 | + // if $messenger isn't a valid messenger object then get out.  | 
                                                        |
| 4410 | +		if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4411 | + EE_Error::add_error(  | 
                                                        |
| 4412 | +				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | 
                                                        |
| 4413 | + __FILE__,  | 
                                                        |
| 4414 | + __FUNCTION__,  | 
                                                        |
| 4415 | + __LINE__  | 
                                                        |
| 4416 | + );  | 
                                                        |
| 4417 | +  | 
                                                        |
| 4418 | + return false;  | 
                                                        |
| 4419 | + }  | 
                                                        |
| 4420 | +  | 
                                                        |
| 4421 | +		if ($message_type instanceof EE_message_type) { | 
                                                        |
| 4422 | + $message_type_name = $message_type->name;  | 
                                                        |
| 4423 | + EE_Error::add_success(  | 
                                                        |
| 4424 | + sprintf(  | 
                                                        |
| 4425 | + esc_html__(  | 
                                                        |
| 4426 | + '%s message type has been successfully deactivated for the %s messenger.',  | 
                                                        |
| 4427 | + 'event_espresso'  | 
                                                        |
| 4428 | + ),  | 
                                                        |
| 4429 | + ucwords($message_type->label['singular']),  | 
                                                        |
| 4430 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4431 | + )  | 
                                                        |
| 4432 | + );  | 
                                                        |
| 4433 | +		} else { | 
                                                        |
| 4434 | + $message_type_name = '';  | 
                                                        |
| 4435 | + EE_Error::add_success(  | 
                                                        |
| 4436 | + sprintf(  | 
                                                        |
| 4437 | +					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'), | 
                                                        |
| 4438 | + ucwords($messenger->label['singular'])  | 
                                                        |
| 4439 | + )  | 
                                                        |
| 4440 | + );  | 
                                                        |
| 4441 | + }  | 
                                                        |
| 4442 | +  | 
                                                        |
| 4443 | + // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.  | 
                                                        |
| 4444 | + if (  | 
                                                        |
| 4445 | + $messenger->name === 'html'  | 
                                                        |
| 4446 | + && (  | 
                                                        |
| 4447 | + is_null($message_type)  | 
                                                        |
| 4448 | + || $message_type_name === 'invoice'  | 
                                                        |
| 4449 | + )  | 
                                                        |
| 4450 | +		) { | 
                                                        |
| 4451 | +			EE_Registry::instance()->load_lib('Payment_Method_Manager'); | 
                                                        |
| 4452 | +			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice'); | 
                                                        |
| 4453 | +			if ($count_updated > 0) { | 
                                                        |
| 4454 | + $msg = $message_type_name === 'invoice'  | 
                                                        |
| 4455 | + ? esc_html__(  | 
                                                        |
| 4456 | + '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.',  | 
                                                        |
| 4457 | + 'event_espresso'  | 
                                                        |
| 4458 | + )  | 
                                                        |
| 4459 | + : esc_html__(  | 
                                                        |
| 4460 | + '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.',  | 
                                                        |
| 4461 | + 'event_espresso'  | 
                                                        |
| 4462 | + );  | 
                                                        |
| 4463 | + EE_Error::add_attention($msg);  | 
                                                        |
| 4464 | + }  | 
                                                        |
| 4465 | + }  | 
                                                        |
| 4466 | +  | 
                                                        |
| 4467 | + return true;  | 
                                                        |
| 4468 | + }  | 
                                                        |
| 4469 | +  | 
                                                        |
| 4470 | +  | 
                                                        |
| 4471 | + /**  | 
                                                        |
| 4472 | + * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)  | 
                                                        |
| 4473 | + *  | 
                                                        |
| 4474 | + * @throws DomainException  | 
                                                        |
| 4475 | + * @throws EE_Error  | 
                                                        |
| 4476 | + * @throws EE_Error  | 
                                                        |
| 4477 | + */  | 
                                                        |
| 4478 | + public function update_mt_form()  | 
                                                        |
| 4479 | +	{ | 
                                                        |
| 4480 | +		if (! $this->_active_messenger_name || ! $this->_active_message_type_name) { | 
                                                        |
| 4481 | + EE_Error::add_error(  | 
                                                        |
| 4482 | +				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), | 
                                                        |
| 4483 | + __FILE__,  | 
                                                        |
| 4484 | + __FUNCTION__,  | 
                                                        |
| 4485 | + __LINE__  | 
                                                        |
| 4486 | + );  | 
                                                        |
| 4487 | + $this->_return_json();  | 
                                                        |
| 4488 | + }  | 
                                                        |
| 4489 | +  | 
                                                        |
| 4490 | + $message_types = $this->get_installed_message_types();  | 
                                                        |
| 4491 | + $message_type = $message_types[ $this->_active_message_type_name ];  | 
                                                        |
| 4492 | + $messenger = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);  | 
                                                        |
| 4493 | + $content = $this->_message_type_settings_content($message_type, $messenger, true);  | 
                                                        |
| 4494 | +  | 
                                                        |
| 4495 | + $this->_template_args['success'] = true;  | 
                                                        |
| 4496 | + $this->_template_args['content'] = $content;  | 
                                                        |
| 4497 | + $this->_return_json();  | 
                                                        |
| 4498 | + }  | 
                                                        |
| 4499 | +  | 
                                                        |
| 4500 | +  | 
                                                        |
| 4501 | + /**  | 
                                                        |
| 4502 | + * this handles saving the settings for a messenger or message type  | 
                                                        |
| 4503 | + *  | 
                                                        |
| 4504 | + * @throws EE_Error  | 
                                                        |
| 4505 | + * @throws EE_Error  | 
                                                        |
| 4506 | + */  | 
                                                        |
| 4507 | + public function save_settings()  | 
                                                        |
| 4508 | +	{ | 
                                                        |
| 4509 | +		$type = $this->request->getRequestParam('type'); | 
                                                        |
| 4510 | +		if (! $type) { | 
                                                        |
| 4511 | + EE_Error::add_error(  | 
                                                        |
| 4512 | + esc_html__(  | 
                                                        |
| 4513 | + 'Cannot save settings because type is unknown (messenger settings or message type settings?)',  | 
                                                        |
| 4514 | + 'event_espresso'  | 
                                                        |
| 4515 | + ),  | 
                                                        |
| 4516 | + __FILE__,  | 
                                                        |
| 4517 | + __FUNCTION__,  | 
                                                        |
| 4518 | + __LINE__  | 
                                                        |
| 4519 | + );  | 
                                                        |
| 4520 | + $this->_template_args['error'] = true;  | 
                                                        |
| 4521 | + $this->_return_json();  | 
                                                        |
| 4522 | + }  | 
                                                        |
| 4523 | +  | 
                                                        |
| 4524 | +  | 
                                                        |
| 4525 | +		if ($type === 'messenger') { | 
                                                        |
| 4526 | + // this should be an array.  | 
                                                        |
| 4527 | +			$settings  = $this->request->getRequestParam('messenger_settings', [], 'string', true); | 
                                                        |
| 4528 | + $messenger = $settings['messenger'];  | 
                                                        |
| 4529 | + // remove messenger and message_types from settings array  | 
                                                        |
| 4530 | + unset($settings['messenger'], $settings['message_types']);  | 
                                                        |
| 4531 | + $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);  | 
                                                        |
| 4532 | +		} elseif ($type === 'message_type') { | 
                                                        |
| 4533 | +			$settings     = $this->request->getRequestParam('message_type_settings', [], 'string', true); | 
                                                        |
| 4534 | + $messenger = $settings['messenger'];  | 
                                                        |
| 4535 | + $message_type = $settings['message_type'];  | 
                                                        |
| 4536 | + // remove messenger and message_types from settings array  | 
                                                        |
| 4537 | + unset($settings['messenger'], $settings['message_types']);  | 
                                                        |
| 4538 | + $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);  | 
                                                        |
| 4539 | + }  | 
                                                        |
| 4540 | +  | 
                                                        |
| 4541 | + // okay we should have the data all setup. Now we just update!  | 
                                                        |
| 4542 | + $success = $this->_message_resource_manager->update_active_messengers_option();  | 
                                                        |
| 4543 | +  | 
                                                        |
| 4544 | +		if ($success) { | 
                                                        |
| 4545 | +			EE_Error::add_success(esc_html__('Settings updated', 'event_espresso')); | 
                                                        |
| 4546 | +		} else { | 
                                                        |
| 4547 | + EE_Error::add_error(  | 
                                                        |
| 4548 | +				esc_html__('Settings did not get updated', 'event_espresso'), | 
                                                        |
| 4549 | + __FILE__,  | 
                                                        |
| 4550 | + __FUNCTION__,  | 
                                                        |
| 4551 | + __LINE__  | 
                                                        |
| 4552 | + );  | 
                                                        |
| 4553 | + }  | 
                                                        |
| 4554 | +  | 
                                                        |
| 4555 | + $this->_template_args['success'] = $success;  | 
                                                        |
| 4556 | + $this->_return_json();  | 
                                                        |
| 4557 | + }  | 
                                                        |
| 4558 | +  | 
                                                        |
| 4559 | +  | 
                                                        |
| 4560 | +  | 
                                                        |
| 4561 | +  | 
                                                        |
| 4562 | + /** EE MESSAGE PROCESSING ACTIONS **/  | 
                                                        |
| 4563 | +  | 
                                                        |
| 4564 | +  | 
                                                        |
| 4565 | + /**  | 
                                                        |
| 4566 | + * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete  | 
                                                        |
| 4567 | + * However, this does not send immediately, it just queues for sending.  | 
                                                        |
| 4568 | + *  | 
                                                        |
| 4569 | + * @throws EE_Error  | 
                                                        |
| 4570 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4571 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4572 | + * @throws InvalidArgumentException  | 
                                                        |
| 4573 | + * @throws ReflectionException  | 
                                                        |
| 4574 | + * @since 4.9.0  | 
                                                        |
| 4575 | + */  | 
                                                        |
| 4576 | + protected function _generate_now()  | 
                                                        |
| 4577 | +	{ | 
                                                        |
| 4578 | + EED_Messages::generate_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4579 | + $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4580 | + }  | 
                                                        |
| 4581 | +  | 
                                                        |
| 4582 | +  | 
                                                        |
| 4583 | + /**  | 
                                                        |
| 4584 | + * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that  | 
                                                        |
| 4585 | + * are EEM_Message::status_resend or EEM_Message::status_idle  | 
                                                        |
| 4586 | + *  | 
                                                        |
| 4587 | + * @throws EE_Error  | 
                                                        |
| 4588 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4589 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4590 | + * @throws InvalidArgumentException  | 
                                                        |
| 4591 | + * @throws ReflectionException  | 
                                                        |
| 4592 | + * @since 4.9.0  | 
                                                        |
| 4593 | + */  | 
                                                        |
| 4594 | + protected function _generate_and_send_now()  | 
                                                        |
| 4595 | +	{ | 
                                                        |
| 4596 | + EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4597 | + $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4598 | + }  | 
                                                        |
| 4599 | +  | 
                                                        |
| 4600 | +  | 
                                                        |
| 4601 | + /**  | 
                                                        |
| 4602 | + * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.  | 
                                                        |
| 4603 | + *  | 
                                                        |
| 4604 | + * @throws EE_Error  | 
                                                        |
| 4605 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4606 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4607 | + * @throws InvalidArgumentException  | 
                                                        |
| 4608 | + * @throws ReflectionException  | 
                                                        |
| 4609 | + * @since 4.9.0  | 
                                                        |
| 4610 | + */  | 
                                                        |
| 4611 | + protected function _queue_for_resending()  | 
                                                        |
| 4612 | +	{ | 
                                                        |
| 4613 | + EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());  | 
                                                        |
| 4614 | + $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4615 | + }  | 
                                                        |
| 4616 | +  | 
                                                        |
| 4617 | +  | 
                                                        |
| 4618 | + /**  | 
                                                        |
| 4619 | + * This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue  | 
                                                        |
| 4620 | + *  | 
                                                        |
| 4621 | + * @throws EE_Error  | 
                                                        |
| 4622 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4623 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4624 | + * @throws InvalidArgumentException  | 
                                                        |
| 4625 | + * @throws ReflectionException  | 
                                                        |
| 4626 | + * @since 4.9.0  | 
                                                        |
| 4627 | + */  | 
                                                        |
| 4628 | + protected function _send_now()  | 
                                                        |
| 4629 | +	{ | 
                                                        |
| 4630 | + EED_Messages::send_now($this->_get_msg_ids_from_request());  | 
                                                        |
| 4631 | + $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4632 | + }  | 
                                                        |
| 4633 | +  | 
                                                        |
| 4634 | +  | 
                                                        |
| 4635 | + /**  | 
                                                        |
| 4636 | + * Deletes EE_messages for IDs in the request.  | 
                                                        |
| 4637 | + *  | 
                                                        |
| 4638 | + * @throws EE_Error  | 
                                                        |
| 4639 | + * @throws InvalidDataTypeException  | 
                                                        |
| 4640 | + * @throws InvalidInterfaceException  | 
                                                        |
| 4641 | + * @throws InvalidArgumentException  | 
                                                        |
| 4642 | + * @since 4.9.0  | 
                                                        |
| 4643 | + */  | 
                                                        |
| 4644 | + protected function _delete_ee_messages()  | 
                                                        |
| 4645 | +	{ | 
                                                        |
| 4646 | + $MSG_IDs = $this->_get_msg_ids_from_request();  | 
                                                        |
| 4647 | + $deleted_count = 0;  | 
                                                        |
| 4648 | +		foreach ($MSG_IDs as $MSG_ID) { | 
                                                        |
| 4649 | +			if ($this->getMsgModel()->delete_by_ID($MSG_ID)) { | 
                                                        |
| 4650 | + $deleted_count++;  | 
                                                        |
| 4651 | + }  | 
                                                        |
| 4652 | + }  | 
                                                        |
| 4653 | +		if ($deleted_count) { | 
                                                        |
| 4654 | + EE_Error::add_success(  | 
                                                        |
| 4655 | + esc_html(  | 
                                                        |
| 4656 | + _n(  | 
                                                        |
| 4657 | + 'Message successfully deleted',  | 
                                                        |
| 4658 | + 'Messages successfully deleted',  | 
                                                        |
| 4659 | + $deleted_count,  | 
                                                        |
| 4660 | + 'event_espresso'  | 
                                                        |
| 4661 | + )  | 
                                                        |
| 4662 | + )  | 
                                                        |
| 4663 | + );  | 
                                                        |
| 4664 | +		} else { | 
                                                        |
| 4665 | + EE_Error::add_error(  | 
                                                        |
| 4666 | +				_n('The message was not deleted.', 'The messages were not deleted', count($MSG_IDs), 'event_espresso'), | 
                                                        |
| 4667 | + __FILE__,  | 
                                                        |
| 4668 | + __FUNCTION__,  | 
                                                        |
| 4669 | + __LINE__  | 
                                                        |
| 4670 | + );  | 
                                                        |
| 4671 | + }  | 
                                                        |
| 4672 | + $this->_redirect_after_action(false, '', '', [], true);  | 
                                                        |
| 4673 | + }  | 
                                                        |
| 4674 | +  | 
                                                        |
| 4675 | +  | 
                                                        |
| 4676 | + /**  | 
                                                        |
| 4677 | + * This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.  | 
                                                        |
| 4678 | + *  | 
                                                        |
| 4679 | + * @return array  | 
                                                        |
| 4680 | + * @since 4.9.0  | 
                                                        |
| 4681 | + */  | 
                                                        |
| 4682 | + protected function _get_msg_ids_from_request()  | 
                                                        |
| 4683 | +	{ | 
                                                        |
| 4684 | +		$MSG_IDs = $this->request->getRequestParam('MSG_ID', [], 'string', true); | 
                                                        |
| 4685 | +		if (empty($MSG_IDs)) { | 
                                                        |
| 4686 | + return [];  | 
                                                        |
| 4687 | + }  | 
                                                        |
| 4688 | + // if 'MSG_ID' was just a single ID (not an array)  | 
                                                        |
| 4689 | + // then $MSG_IDs will be something like [123] so $MSG_IDs[0] should be 123  | 
                                                        |
| 4690 | + // otherwise, $MSG_IDs was already an array where message IDs were used as the keys  | 
                                                        |
| 4691 | + return count($MSG_IDs) === 1 && isset($MSG_IDs[0])  | 
                                                        |
| 4692 | + ? $MSG_IDs  | 
                                                        |
| 4693 | + : array_keys($MSG_IDs);  | 
                                                        |
| 4694 | + }  | 
                                                        |
| 4695 | 4695 | }  | 
                                                        
@@ -115,7 +115,7 @@ discard block  | 
                                                    ||
| 115 | 115 | */  | 
                                                        
| 116 | 116 | public function getMsgModel()  | 
                                                        
| 117 | 117 |      { | 
                                                        
| 118 | -        if (! $this->MSG_MODEL instanceof EEM_Message) { | 
                                                        |
| 118 | +        if ( ! $this->MSG_MODEL instanceof EEM_Message) { | 
                                                        |
| 119 | 119 | $this->MSG_MODEL = EEM_Message::instance();  | 
                                                        
| 120 | 120 | }  | 
                                                        
| 121 | 121 | return $this->MSG_MODEL;  | 
                                                        
@@ -128,7 +128,7 @@ discard block  | 
                                                    ||
| 128 | 128 | */  | 
                                                        
| 129 | 129 | public function getMtpModel()  | 
                                                        
| 130 | 130 |      { | 
                                                        
| 131 | -        if (! $this->MTP_MODEL instanceof EEM_Message_Template) { | 
                                                        |
| 131 | +        if ( ! $this->MTP_MODEL instanceof EEM_Message_Template) { | 
                                                        |
| 132 | 132 | $this->MTP_MODEL = EEM_Message_Template::instance();  | 
                                                        
| 133 | 133 | }  | 
                                                        
| 134 | 134 | return $this->MTP_MODEL;  | 
                                                        
@@ -141,7 +141,7 @@ discard block  | 
                                                    ||
| 141 | 141 | */  | 
                                                        
| 142 | 142 | public function getMtgModel()  | 
                                                        
| 143 | 143 |      { | 
                                                        
| 144 | -        if (! $this->MTG_MODEL instanceof EEM_Message_Template_Group) { | 
                                                        |
| 144 | +        if ( ! $this->MTG_MODEL instanceof EEM_Message_Template_Group) { | 
                                                        |
| 145 | 145 | $this->MTG_MODEL = EEM_Message_Template_Group::instance();  | 
                                                        
| 146 | 146 | }  | 
                                                        
| 147 | 147 | return $this->MTG_MODEL;  | 
                                                        
@@ -211,8 +211,8 @@ discard block  | 
                                                    ||
| 211 | 211 | $i = 1;  | 
                                                        
| 212 | 212 |          foreach ($active_messengers as $active_messenger) { | 
                                                        
| 213 | 213 |              if ($active_messenger instanceof EE_Message) { | 
                                                        
| 214 | - $m_values[ $i ]['id'] = $active_messenger->messenger();  | 
                                                        |
| 215 | - $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 214 | + $m_values[$i]['id'] = $active_messenger->messenger();  | 
                                                        |
| 215 | + $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());  | 
                                                        |
| 216 | 216 | $i++;  | 
                                                        
| 217 | 217 | }  | 
                                                        
| 218 | 218 | }  | 
                                                        
@@ -248,8 +248,8 @@ discard block  | 
                                                    ||
| 248 | 248 | $i = 1;  | 
                                                        
| 249 | 249 |          foreach ($active_messages as $active_message) { | 
                                                        
| 250 | 250 |              if ($active_message instanceof EE_Message) { | 
                                                        
| 251 | - $mt_values[ $i ]['id'] = $active_message->message_type();  | 
                                                        |
| 252 | - $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 251 | + $mt_values[$i]['id'] = $active_message->message_type();  | 
                                                        |
| 252 | + $mt_values[$i]['text'] = ucwords($active_message->message_type_label());  | 
                                                        |
| 253 | 253 | $i++;  | 
                                                        
| 254 | 254 | }  | 
                                                        
| 255 | 255 | }  | 
                                                        
@@ -288,7 +288,7 @@ discard block  | 
                                                    ||
| 288 | 288 |                  if ($message_type instanceof EE_message_type) { | 
                                                        
| 289 | 289 | $message_type_contexts = $message_type->get_contexts();  | 
                                                        
| 290 | 290 |                      foreach ($message_type_contexts as $context => $context_details) { | 
                                                        
| 291 | - $contexts[ $context ] = $context_details['label'];  | 
                                                        |
| 291 | + $contexts[$context] = $context_details['label'];  | 
                                                        |
| 292 | 292 | }  | 
                                                        
| 293 | 293 | }  | 
                                                        
| 294 | 294 | }  | 
                                                        
@@ -321,7 +321,7 @@ discard block  | 
                                                    ||
| 321 | 321 |              ['none_selected' => esc_html__('Show All Messengers', 'event_espresso')], | 
                                                        
| 322 | 322 | $messenger_options  | 
                                                        
| 323 | 323 | );  | 
                                                        
| 324 | - $input = new EE_Select_Input(  | 
                                                        |
| 324 | + $input = new EE_Select_Input(  | 
                                                        |
| 325 | 325 | $messenger_options,  | 
                                                        
| 326 | 326 | [  | 
                                                        
| 327 | 327 | 'html_name' => 'ee_messenger_filter_by',  | 
                                                        
@@ -358,7 +358,7 @@ discard block  | 
                                                    ||
| 358 | 358 |              ['none_selected' => esc_html__('Show All Message Types', 'event_espresso')], | 
                                                        
| 359 | 359 | $message_type_options  | 
                                                        
| 360 | 360 | );  | 
                                                        
| 361 | - $input = new EE_Select_Input(  | 
                                                        |
| 361 | + $input = new EE_Select_Input(  | 
                                                        |
| 362 | 362 | $message_type_options,  | 
                                                        
| 363 | 363 | [  | 
                                                        
| 364 | 364 | 'html_name' => 'ee_message_type_filter_by',  | 
                                                        
@@ -395,7 +395,7 @@ discard block  | 
                                                    ||
| 395 | 395 |              ['none_selected' => esc_html__('Show all Contexts', 'event_espresso')], | 
                                                        
| 396 | 396 | $context_options  | 
                                                        
| 397 | 397 | );  | 
                                                        
| 398 | - $input = new EE_Select_Input(  | 
                                                        |
| 398 | + $input = new EE_Select_Input(  | 
                                                        |
| 399 | 399 | $context_options,  | 
                                                        
| 400 | 400 | [  | 
                                                        
| 401 | 401 | 'html_name' => 'ee_context_filter_by',  | 
                                                        
@@ -776,53 +776,53 @@ discard block  | 
                                                    ||
| 776 | 776 | |
| 777 | 777 | public function messages_help_tab()  | 
                                                        
| 778 | 778 |      { | 
                                                        
| 779 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 779 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');  | 
                                                        |
| 780 | 780 | }  | 
                                                        
| 781 | 781 | |
| 782 | 782 | |
| 783 | 783 | public function messengers_help_tab()  | 
                                                        
| 784 | 784 |      { | 
                                                        
| 785 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 785 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');  | 
                                                        |
| 786 | 786 | }  | 
                                                        
| 787 | 787 | |
| 788 | 788 | |
| 789 | 789 | public function message_types_help_tab()  | 
                                                        
| 790 | 790 |      { | 
                                                        
| 791 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 791 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');  | 
                                                        |
| 792 | 792 | }  | 
                                                        
| 793 | 793 | |
| 794 | 794 | |
| 795 | 795 | public function messages_overview_help_tab()  | 
                                                        
| 796 | 796 |      { | 
                                                        
| 797 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 797 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');  | 
                                                        |
| 798 | 798 | }  | 
                                                        
| 799 | 799 | |
| 800 | 800 | |
| 801 | 801 | public function message_templates_help_tab()  | 
                                                        
| 802 | 802 |      { | 
                                                        
| 803 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 803 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');  | 
                                                        |
| 804 | 804 | }  | 
                                                        
| 805 | 805 | |
| 806 | 806 | |
| 807 | 807 | public function edit_message_template_help_tab()  | 
                                                        
| 808 | 808 |      { | 
                                                        
| 809 | - $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'  | 
                                                        |
| 809 | + $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'  | 
                                                        |
| 810 | 810 |                          . esc_attr__('Editor Title', 'event_espresso') | 
                                                        
| 811 | 811 | . '" />';  | 
                                                        
| 812 | - $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'  | 
                                                        |
| 812 | + $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'  | 
                                                        |
| 813 | 813 |                          . esc_attr__('Context Switcher and Preview', 'event_espresso') | 
                                                        
| 814 | 814 | . '" />';  | 
                                                        
| 815 | - $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'  | 
                                                        |
| 815 | + $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'  | 
                                                        |
| 816 | 816 |                          . esc_attr__('Message Template Form Fields', 'event_espresso') | 
                                                        
| 817 | 817 | . '" />';  | 
                                                        
| 818 | - $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'  | 
                                                        |
| 818 | + $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'  | 
                                                        |
| 819 | 819 |                          . esc_attr__('Shortcodes Metabox', 'event_espresso') | 
                                                        
| 820 | 820 | . '" />';  | 
                                                        
| 821 | - $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'  | 
                                                        |
| 821 | + $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'  | 
                                                        |
| 822 | 822 |                          . esc_attr__('Publish Metabox', 'event_espresso') | 
                                                        
| 823 | 823 | . '" />';  | 
                                                        
| 824 | 824 | EEH_Template::display_template(  | 
                                                        
| 825 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 825 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',  | 
                                                        |
| 826 | 826 | $args  | 
                                                        
| 827 | 827 | );  | 
                                                        
| 828 | 828 | }  | 
                                                        
@@ -837,7 +837,7 @@ discard block  | 
                                                    ||
| 837 | 837 | $this->_set_shortcodes();  | 
                                                        
| 838 | 838 | $args['shortcodes'] = $this->_shortcodes;  | 
                                                        
| 839 | 839 | EEH_Template::display_template(  | 
                                                        
| 840 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 840 | + EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',  | 
                                                        |
| 841 | 841 | $args  | 
                                                        
| 842 | 842 | );  | 
                                                        
| 843 | 843 | }  | 
                                                        
@@ -845,16 +845,16 @@ discard block  | 
                                                    ||
| 845 | 845 | |
| 846 | 846 | public function preview_message_help_tab()  | 
                                                        
| 847 | 847 |      { | 
                                                        
| 848 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 848 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');  | 
                                                        |
| 849 | 849 | }  | 
                                                        
| 850 | 850 | |
| 851 | 851 | |
| 852 | 852 | public function settings_help_tab()  | 
                                                        
| 853 | 853 |      { | 
                                                        
| 854 | - $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'  | 
                                                        |
| 855 | -                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 856 | - $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'  | 
                                                        |
| 857 | -                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'; | 
                                                        |
| 854 | + $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'  | 
                                                        |
| 855 | +                        . '" alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'; | 
                                                        |
| 856 | + $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'  | 
                                                        |
| 857 | +                        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'; | 
                                                        |
| 858 | 858 | $args['img3'] = '<div class="ee-switch">'  | 
                                                        
| 859 | 859 | . '<input class="ee-switch__input" id="ee-on-off-toggle-on" type="checkbox" checked>'  | 
                                                        
| 860 | 860 | . '<label class="ee-switch__toggle" for="ee-on-off-toggle-on"></label>'  | 
                                                        
@@ -863,25 +863,25 @@ discard block  | 
                                                    ||
| 863 | 863 | . '<input class="ee-switch__input" id="ee-on-off-toggle-off" type="checkbox">'  | 
                                                        
| 864 | 864 | . '<label class="ee-switch__toggle" for="ee-on-off-toggle-off"></label>'  | 
                                                        
| 865 | 865 | . '</div>';  | 
                                                        
| 866 | - EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 866 | + EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);  | 
                                                        |
| 867 | 867 | }  | 
                                                        
| 868 | 868 | |
| 869 | 869 | |
| 870 | 870 | public function load_scripts_styles()  | 
                                                        
| 871 | 871 |      { | 
                                                        
| 872 | -        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 872 | +        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION); | 
                                                        |
| 873 | 873 |          wp_enqueue_style('espresso_ee_msg'); | 
                                                        
| 874 | 874 | |
| 875 | 875 | wp_register_script(  | 
                                                        
| 876 | 876 | 'ee-messages-settings',  | 
                                                        
| 877 | - EE_MSG_ASSETS_URL . 'ee-messages-settings.js',  | 
                                                        |
| 877 | + EE_MSG_ASSETS_URL.'ee-messages-settings.js',  | 
                                                        |
| 878 | 878 | ['jquery-ui-droppable', 'ee-serialize-full-array'],  | 
                                                        
| 879 | 879 | EVENT_ESPRESSO_VERSION,  | 
                                                        
| 880 | 880 | true  | 
                                                        
| 881 | 881 | );  | 
                                                        
| 882 | 882 | wp_register_script(  | 
                                                        
| 883 | 883 | 'ee-msg-list-table-js',  | 
                                                        
| 884 | - EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',  | 
                                                        |
| 884 | + EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',  | 
                                                        |
| 885 | 885 | ['ee-dialog'],  | 
                                                        
| 886 | 886 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 887 | 887 | );  | 
                                                        
@@ -924,7 +924,7 @@ discard block  | 
                                                    ||
| 924 | 924 | |
| 925 | 925 | $this->_set_shortcodes();  | 
                                                        
| 926 | 926 | |
| 927 | - EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 927 | + EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(  | 
                                                        |
| 928 | 928 | esc_html__(  | 
                                                        
| 929 | 929 | 'Are you sure you want to reset the %s %s message templates? Remember continuing will reset the templates for all contexts in this messenger and message type group.',  | 
                                                        
| 930 | 930 | 'event_espresso'  | 
                                                        
@@ -936,14 +936,14 @@ discard block  | 
                                                    ||
| 936 | 936 | 'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded. Any custom content in the existing template will be lost. Are you sure you wish to do this?',  | 
                                                        
| 937 | 937 | 'event_espresso'  | 
                                                        
| 938 | 938 | );  | 
                                                        
| 939 | - EE_Registry::$i18n_js_strings['server_error'] = esc_html__(  | 
                                                        |
| 939 | + EE_Registry::$i18n_js_strings['server_error'] = esc_html__(  | 
                                                        |
| 940 | 940 | 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',  | 
                                                        
| 941 | 941 | 'event_espresso'  | 
                                                        
| 942 | 942 | );  | 
                                                        
| 943 | 943 | |
| 944 | 944 | wp_register_script(  | 
                                                        
| 945 | 945 | 'ee_msgs_edit_js',  | 
                                                        
| 946 | - EE_MSG_ASSETS_URL . 'ee_message_editor.js',  | 
                                                        |
| 946 | + EE_MSG_ASSETS_URL.'ee_message_editor.js',  | 
                                                        |
| 947 | 947 | ['jquery'],  | 
                                                        
| 948 | 948 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 949 | 949 | );  | 
                                                        
@@ -986,7 +986,7 @@ discard block  | 
                                                    ||
| 986 | 986 |      { | 
                                                        
| 987 | 987 | wp_register_style(  | 
                                                        
| 988 | 988 | 'ee-message-settings',  | 
                                                        
| 989 | - EE_MSG_ASSETS_URL . 'ee_message_settings.css',  | 
                                                        |
| 989 | + EE_MSG_ASSETS_URL.'ee_message_settings.css',  | 
                                                        |
| 990 | 990 | [],  | 
                                                        
| 991 | 991 | EVENT_ESPRESSO_VERSION  | 
                                                        
| 992 | 992 | );  | 
                                                        
@@ -1072,7 +1072,7 @@ discard block  | 
                                                    ||
| 1072 | 1072 | }  | 
                                                        
| 1073 | 1073 | $status_bulk_actions = $common_bulk_actions;  | 
                                                        
| 1074 | 1074 | // unset bulk actions not applying to status  | 
                                                        
| 1075 | -            if (! empty($status_bulk_actions)) { | 
                                                        |
| 1075 | +            if ( ! empty($status_bulk_actions)) { | 
                                                        |
| 1076 | 1076 |                  switch ($status) { | 
                                                        
| 1077 | 1077 | case EEM_Message::status_idle:  | 
                                                        
| 1078 | 1078 | case EEM_Message::status_resend:  | 
                                                        
@@ -1101,7 +1101,7 @@ discard block  | 
                                                    ||
| 1101 | 1101 | continue;  | 
                                                        
| 1102 | 1102 | }  | 
                                                        
| 1103 | 1103 | |
| 1104 | - $this->_views[ strtolower($status) ] = [  | 
                                                        |
| 1104 | + $this->_views[strtolower($status)] = [  | 
                                                        |
| 1105 | 1105 | 'slug' => strtolower($status),  | 
                                                        
| 1106 | 1106 | 'label' => EEH_Template::pretty_status($status, false, 'sentence'),  | 
                                                        
| 1107 | 1107 | 'count' => 0,  | 
                                                        
@@ -1149,7 +1149,7 @@ discard block  | 
                                                    ||
| 1149 | 1149 |              if ($action_item === 'see_notifications_for') { | 
                                                        
| 1150 | 1150 | continue;  | 
                                                        
| 1151 | 1151 | }  | 
                                                        
| 1152 | - $action_items[ $action_item ] = [  | 
                                                        |
| 1152 | + $action_items[$action_item] = [  | 
                                                        |
| 1153 | 1153 | 'class' => $action_details['css_class'],  | 
                                                        
| 1154 | 1154 | 'desc' => $action_details['label'],  | 
                                                        
| 1155 | 1155 | ];  | 
                                                        
@@ -1158,37 +1158,37 @@ discard block  | 
                                                    ||
| 1158 | 1158 | /** @var array $status_items status legend setup */  | 
                                                        
| 1159 | 1159 | $status_items = [  | 
                                                        
| 1160 | 1160 | 'sent_status' => [  | 
                                                        
| 1161 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_sent,  | 
                                                        |
| 1161 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_sent,  | 
                                                        |
| 1162 | 1162 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),  | 
                                                        
| 1163 | 1163 | ],  | 
                                                        
| 1164 | 1164 | 'idle_status' => [  | 
                                                        
| 1165 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_idle,  | 
                                                        |
| 1165 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_idle,  | 
                                                        |
| 1166 | 1166 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),  | 
                                                        
| 1167 | 1167 | ],  | 
                                                        
| 1168 | 1168 | 'failed_status' => [  | 
                                                        
| 1169 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_failed,  | 
                                                        |
| 1169 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_failed,  | 
                                                        |
| 1170 | 1170 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),  | 
                                                        
| 1171 | 1171 | ],  | 
                                                        
| 1172 | 1172 | 'messenger_executing_status' => [  | 
                                                        
| 1173 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_messenger_executing,  | 
                                                        |
| 1173 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_messenger_executing,  | 
                                                        |
| 1174 | 1174 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),  | 
                                                        
| 1175 | 1175 | ],  | 
                                                        
| 1176 | 1176 | 'resend_status' => [  | 
                                                        
| 1177 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_resend,  | 
                                                        |
| 1177 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_resend,  | 
                                                        |
| 1178 | 1178 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),  | 
                                                        
| 1179 | 1179 | ],  | 
                                                        
| 1180 | 1180 | 'incomplete_status' => [  | 
                                                        
| 1181 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_incomplete,  | 
                                                        |
| 1181 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_incomplete,  | 
                                                        |
| 1182 | 1182 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),  | 
                                                        
| 1183 | 1183 | ],  | 
                                                        
| 1184 | 1184 | 'retry_status' => [  | 
                                                        
| 1185 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_retry,  | 
                                                        |
| 1185 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_retry,  | 
                                                        |
| 1186 | 1186 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),  | 
                                                        
| 1187 | 1187 | ],  | 
                                                        
| 1188 | 1188 | ];  | 
                                                        
| 1189 | 1189 |          if (EEM_Message::debug()) { | 
                                                        
| 1190 | 1190 | $status_items['debug_only_status'] = [  | 
                                                        
| 1191 | - 'class' => 'ee-status-legend ee-status-bg--' . EEM_Message::status_debug_only,  | 
                                                        |
| 1191 | + 'class' => 'ee-status-legend ee-status-bg--'.EEM_Message::status_debug_only,  | 
                                                        |
| 1192 | 1192 | 'desc' => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),  | 
                                                        
| 1193 | 1193 | ];  | 
                                                        
| 1194 | 1194 | }  | 
                                                        
@@ -1203,11 +1203,11 @@ discard block  | 
                                                    ||
| 1203 | 1203 | protected function _custom_mtps_preview()  | 
                                                        
| 1204 | 1204 |      { | 
                                                        
| 1205 | 1205 |          $this->_admin_page_title              = esc_html__('Custom Message Templates (Preview)', 'event_espresso'); | 
                                                        
| 1206 | - $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'  | 
                                                        |
| 1207 | - . ' alt="' . esc_attr__(  | 
                                                        |
| 1206 | + $this->_template_args['preview_img'] = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png"'  | 
                                                        |
| 1207 | + . ' alt="'.esc_attr__(  | 
                                                        |
| 1208 | 1208 | 'Preview Custom Message Templates screenshot',  | 
                                                        
| 1209 | 1209 | 'event_espresso'  | 
                                                        
| 1210 | - ) . '" />';  | 
                                                        |
| 1210 | + ).'" />';  | 
                                                        |
| 1211 | 1211 | $this->_template_args['preview_text'] = '<strong>'  | 
                                                        
| 1212 | 1212 | . esc_html__(  | 
                                                        
| 1213 | 1213 | 'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',  | 
                                                        
@@ -1283,7 +1283,7 @@ discard block  | 
                                                    ||
| 1283 | 1283 | $installed = [];  | 
                                                        
| 1284 | 1284 | |
| 1285 | 1285 |          foreach ($installed_message_types as $message_type) { | 
                                                        
| 1286 | - $installed[ $message_type->name ] = $message_type;  | 
                                                        |
| 1286 | + $installed[$message_type->name] = $message_type;  | 
                                                        |
| 1287 | 1287 | }  | 
                                                        
| 1288 | 1288 | |
| 1289 | 1289 | return $installed;  | 
                                                        
@@ -1409,7 +1409,7 @@ discard block  | 
                                                    ||
| 1409 | 1409 | // we need to assemble the title from Various details  | 
                                                        
| 1410 | 1410 | $context_label = sprintf(  | 
                                                        
| 1411 | 1411 |              esc_html__('(%s %s)', 'event_espresso'), | 
                                                        
| 1412 | - $c_config[ $context ]['label'],  | 
                                                        |
| 1412 | + $c_config[$context]['label'],  | 
                                                        |
| 1413 | 1413 | ucwords($c_label['label'])  | 
                                                        
| 1414 | 1414 | );  | 
                                                        
| 1415 | 1415 | |
@@ -1432,7 +1432,7 @@ discard block  | 
                                                    ||
| 1432 | 1432 | $context  | 
                                                        
| 1433 | 1433 | );  | 
                                                        
| 1434 | 1434 | |
| 1435 | -        if (! $template_field_structure) { | 
                                                        |
| 1435 | +        if ( ! $template_field_structure) { | 
                                                        |
| 1436 | 1436 | $template_field_structure = false;  | 
                                                        
| 1437 | 1437 | $template_fields = esc_html__(  | 
                                                        
| 1438 | 1438 | 'There was an error in assembling the fields for this display (you should see an error message)',  | 
                                                        
@@ -1446,21 +1446,21 @@ discard block  | 
                                                    ||
| 1446 | 1446 | |
| 1447 | 1447 | // if we have the extra key.. then we need to remove the content index from the template_field_structure as it  | 
                                                        
| 1448 | 1448 | // will get handled in the "extra" array.  | 
                                                        
| 1449 | -        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) { | 
                                                        |
| 1450 | -            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1451 | - unset($template_field_structure[ $context ][ $reference_field ]);  | 
                                                        |
| 1449 | +        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) { | 
                                                        |
| 1450 | +            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) { | 
                                                        |
| 1451 | + unset($template_field_structure[$context][$reference_field]);  | 
                                                        |
| 1452 | 1452 | }  | 
                                                        
| 1453 | 1453 | }  | 
                                                        
| 1454 | 1454 | |
| 1455 | 1455 | // let's loop through the template_field_structure and actually assemble the input fields!  | 
                                                        
| 1456 | -        if (! empty($template_field_structure)) { | 
                                                        |
| 1457 | -            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) { | 
                                                        |
| 1456 | +        if ( ! empty($template_field_structure)) { | 
                                                        |
| 1457 | +            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) { | 
                                                        |
| 1458 | 1458 | // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in  | 
                                                        
| 1459 | 1459 | // the extra array and reset them.  | 
                                                        
| 1460 | 1460 |                  if ($template_field === 'extra') { | 
                                                        
| 1461 | 1461 | $this->_template_args['is_extra_fields'] = true;  | 
                                                        
| 1462 | 1462 |                      foreach ($field_setup_array as $reference_field => $new_fields_array) { | 
                                                        
| 1463 | - $message_template = $message_templates[ $context ][ $reference_field ];  | 
                                                        |
| 1463 | + $message_template = $message_templates[$context][$reference_field];  | 
                                                        |
| 1464 | 1464 | $content = $message_template instanceof EE_Message_Template  | 
                                                        
| 1465 | 1465 |                              ? $message_template->get('MTP_content') | 
                                                        
| 1466 | 1466 | : '';  | 
                                                        
@@ -1469,7 +1469,7 @@ discard block  | 
                                                    ||
| 1469 | 1469 | $continue = false;  | 
                                                        
| 1470 | 1470 |                              if (isset($extra_array['shortcodes_required'])) { | 
                                                        
| 1471 | 1471 |                                  foreach ((array) $extra_array['shortcodes_required'] as $shortcode) { | 
                                                        
| 1472 | -                                    if (! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1472 | +                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) { | 
                                                        |
| 1473 | 1473 | $continue = true;  | 
                                                        
| 1474 | 1474 | }  | 
                                                        
| 1475 | 1475 | }  | 
                                                        
@@ -1478,51 +1478,51 @@ discard block  | 
                                                    ||
| 1478 | 1478 | }  | 
                                                        
| 1479 | 1479 | }  | 
                                                        
| 1480 | 1480 | |
| 1481 | - $field_id = $reference_field . '-' . $extra_field . '-content';  | 
                                                        |
| 1481 | + $field_id = $reference_field.'-'.$extra_field.'-content';  | 
                                                        |
| 1482 | 1482 | |
| 1483 | - $template_form_fields[ $field_id ] = $extra_array;  | 
                                                        |
| 1484 | - $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['  | 
                                                        |
| 1483 | + $template_form_fields[$field_id] = $extra_array;  | 
                                                        |
| 1484 | + $template_form_fields[$field_id]['name'] = 'MTP_template_fields['  | 
                                                        |
| 1485 | 1485 | . $reference_field  | 
                                                        
| 1486 | 1486 | . '][content]['  | 
                                                        
| 1487 | - . $extra_field . ']';  | 
                                                        |
| 1488 | - $css_class = $extra_array['css_class'] ?? '';  | 
                                                        |
| 1487 | + . $extra_field.']';  | 
                                                        |
| 1488 | + $css_class = $extra_array['css_class'] ?? '';  | 
                                                        |
| 1489 | 1489 | |
| 1490 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1490 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1491 | 1491 | && in_array($extra_field, $v_fields, true)  | 
                                                        
| 1492 | 1492 | && (  | 
                                                        
| 1493 | - is_array($validators[ $extra_field ])  | 
                                                        |
| 1494 | - && isset($validators[ $extra_field ]['msg'])  | 
                                                        |
| 1493 | + is_array($validators[$extra_field])  | 
                                                        |
| 1494 | + && isset($validators[$extra_field]['msg'])  | 
                                                        |
| 1495 | 1495 | )  | 
                                                        
| 1496 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1496 | + ? 'validate-error '.$css_class  | 
                                                        |
| 1497 | 1497 | : $css_class;  | 
                                                        
| 1498 | 1498 | |
| 1499 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1500 | - && isset($content[ $extra_field ])  | 
                                                        |
| 1501 | - ? $content[ $extra_field ]  | 
                                                        |
| 1499 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates)  | 
                                                        |
| 1500 | + && isset($content[$extra_field])  | 
                                                        |
| 1501 | + ? $content[$extra_field]  | 
                                                        |
| 1502 | 1502 | : '';  | 
                                                        
| 1503 | 1503 | |
| 1504 | 1504 | // do we have a validation error? if we do then let's use that value instead  | 
                                                        
| 1505 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])  | 
                                                        |
| 1506 | - ? $validators[ $extra_field ]['value']  | 
                                                        |
| 1507 | - : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1505 | + $template_form_fields[$field_id]['value'] = isset($validators[$extra_field])  | 
                                                        |
| 1506 | + ? $validators[$extra_field]['value']  | 
                                                        |
| 1507 | + : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1508 | 1508 | |
| 1509 | 1509 | |
| 1510 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1510 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1511 | 1511 | |
| 1512 | 1512 | // shortcode selector  | 
                                                        
| 1513 | 1513 | $field_name_to_use = $extra_field === 'main'  | 
                                                        
| 1514 | 1514 | ? 'content'  | 
                                                        
| 1515 | 1515 | : $extra_field;  | 
                                                        
| 1516 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1516 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1517 | 1517 | $field_name_to_use,  | 
                                                        
| 1518 | 1518 | $field_id  | 
                                                        
| 1519 | 1519 | );  | 
                                                        
| 1520 | 1520 | }  | 
                                                        
| 1521 | - $template_field_MTP_id = $reference_field . '-MTP_ID';  | 
                                                        |
| 1522 | - $template_field_template_name_id = $reference_field . '-name';  | 
                                                        |
| 1521 | + $template_field_MTP_id = $reference_field.'-MTP_ID';  | 
                                                        |
| 1522 | + $template_field_template_name_id = $reference_field.'-name';  | 
                                                        |
| 1523 | 1523 | |
| 1524 | - $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1525 | - 'name' => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',  | 
                                                        |
| 1524 | + $template_form_fields[$template_field_MTP_id] = [  | 
                                                        |
| 1525 | + 'name' => 'MTP_template_fields['.$reference_field.'][MTP_ID]',  | 
                                                        |
| 1526 | 1526 | 'label' => null,  | 
                                                        
| 1527 | 1527 | 'input' => 'hidden',  | 
                                                        
| 1528 | 1528 | 'type' => 'int',  | 
                                                        
@@ -1534,8 +1534,8 @@ discard block  | 
                                                    ||
| 1534 | 1534 | 'db-col' => 'MTP_ID',  | 
                                                        
| 1535 | 1535 | ];  | 
                                                        
| 1536 | 1536 | |
| 1537 | - $template_form_fields[ $template_field_template_name_id ] = [  | 
                                                        |
| 1538 | - 'name' => 'MTP_template_fields[' . $reference_field . '][name]',  | 
                                                        |
| 1537 | + $template_form_fields[$template_field_template_name_id] = [  | 
                                                        |
| 1538 | + 'name' => 'MTP_template_fields['.$reference_field.'][name]',  | 
                                                        |
| 1539 | 1539 | 'label' => null,  | 
                                                        
| 1540 | 1540 | 'input' => 'hidden',  | 
                                                        
| 1541 | 1541 | 'type' => 'string',  | 
                                                        
@@ -1549,34 +1549,34 @@ discard block  | 
                                                    ||
| 1549 | 1549 | }  | 
                                                        
| 1550 | 1550 | continue; // skip the next stuff, we got the necessary fields here for this dataset.  | 
                                                        
| 1551 | 1551 |                  } else { | 
                                                        
| 1552 | - $field_id = $template_field . '-content';  | 
                                                        |
| 1553 | - $template_form_fields[ $field_id ] = $field_setup_array;  | 
                                                        |
| 1554 | - $template_form_fields[ $field_id ]['name'] =  | 
                                                        |
| 1555 | - 'MTP_template_fields[' . $template_field . '][content]';  | 
                                                        |
| 1556 | - $message_template = $message_templates[ $context ][ $template_field ]  | 
                                                        |
| 1552 | + $field_id = $template_field.'-content';  | 
                                                        |
| 1553 | + $template_form_fields[$field_id] = $field_setup_array;  | 
                                                        |
| 1554 | + $template_form_fields[$field_id]['name'] =  | 
                                                        |
| 1555 | + 'MTP_template_fields['.$template_field.'][content]';  | 
                                                        |
| 1556 | + $message_template = $message_templates[$context][$template_field]  | 
                                                        |
| 1557 | 1557 | ?? null;  | 
                                                        
| 1558 | - $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)  | 
                                                        |
| 1559 | - && is_array($message_templates[ $context ])  | 
                                                        |
| 1558 | + $template_form_fields[$field_id]['value'] = ! empty($message_templates)  | 
                                                        |
| 1559 | + && is_array($message_templates[$context])  | 
                                                        |
| 1560 | 1560 | && $message_template instanceof EE_Message_Template  | 
                                                        
| 1561 | 1561 |                          ? $message_template->get('MTP_content') | 
                                                        
| 1562 | 1562 | : '';  | 
                                                        
| 1563 | 1563 | |
| 1564 | 1564 | // do we have a validator error for this field? if we do then we'll use that value instead  | 
                                                        
| 1565 | - $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])  | 
                                                        |
| 1566 | - ? $validators[ $template_field ]['value']  | 
                                                        |
| 1567 | - : $template_form_fields[ $field_id ]['value'];  | 
                                                        |
| 1565 | + $template_form_fields[$field_id]['value'] = isset($validators[$template_field])  | 
                                                        |
| 1566 | + ? $validators[$template_field]['value']  | 
                                                        |
| 1567 | + : $template_form_fields[$field_id]['value'];  | 
                                                        |
| 1568 | 1568 | |
| 1569 | 1569 | |
| 1570 | - $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';  | 
                                                        |
| 1570 | + $template_form_fields[$field_id]['db-col'] = 'MTP_content';  | 
                                                        |
| 1571 | 1571 | $css_class = $field_setup_array['css_class'] ?? '';  | 
                                                        
| 1572 | - $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1572 | + $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)  | 
                                                        |
| 1573 | 1573 | && in_array($template_field, $v_fields, true)  | 
                                                        
| 1574 | - && isset($validators[ $template_field ]['msg'])  | 
                                                        |
| 1575 | - ? 'validate-error ' . $css_class  | 
                                                        |
| 1574 | + && isset($validators[$template_field]['msg'])  | 
                                                        |
| 1575 | + ? 'validate-error '.$css_class  | 
                                                        |
| 1576 | 1576 | : $css_class;  | 
                                                        
| 1577 | 1577 | |
| 1578 | 1578 | // shortcode selector  | 
                                                        
| 1579 | - $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1579 | + $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(  | 
                                                        |
| 1580 | 1580 | $template_field,  | 
                                                        
| 1581 | 1581 | $field_id  | 
                                                        
| 1582 | 1582 | );  | 
                                                        
@@ -1584,12 +1584,12 @@ discard block  | 
                                                    ||
| 1584 | 1584 | |
| 1585 | 1585 | // k took care of content field(s) now let's take care of others.  | 
                                                        
| 1586 | 1586 | |
| 1587 | - $template_field_MTP_id = $template_field . '-MTP_ID';  | 
                                                        |
| 1588 | - $template_field_field_template_name_id = $template_field . '-name';  | 
                                                        |
| 1587 | + $template_field_MTP_id = $template_field.'-MTP_ID';  | 
                                                        |
| 1588 | + $template_field_field_template_name_id = $template_field.'-name';  | 
                                                        |
| 1589 | 1589 | |
| 1590 | 1590 | // foreach template field there are actually two form fields created  | 
                                                        
| 1591 | - $template_form_fields[ $template_field_MTP_id ] = [  | 
                                                        |
| 1592 | - 'name' => 'MTP_template_fields[' . $template_field . '][MTP_ID]',  | 
                                                        |
| 1591 | + $template_form_fields[$template_field_MTP_id] = [  | 
                                                        |
| 1592 | + 'name' => 'MTP_template_fields['.$template_field.'][MTP_ID]',  | 
                                                        |
| 1593 | 1593 | 'label' => null,  | 
                                                        
| 1594 | 1594 | 'input' => 'hidden',  | 
                                                        
| 1595 | 1595 | 'type' => 'int',  | 
                                                        
@@ -1601,8 +1601,8 @@ discard block  | 
                                                    ||
| 1601 | 1601 | 'db-col' => 'MTP_ID',  | 
                                                        
| 1602 | 1602 | ];  | 
                                                        
| 1603 | 1603 | |
| 1604 | - $template_form_fields[ $template_field_field_template_name_id ] = [  | 
                                                        |
| 1605 | - 'name' => 'MTP_template_fields[' . $template_field . '][name]',  | 
                                                        |
| 1604 | + $template_form_fields[$template_field_field_template_name_id] = [  | 
                                                        |
| 1605 | + 'name' => 'MTP_template_fields['.$template_field.'][name]',  | 
                                                        |
| 1606 | 1606 | 'label' => null,  | 
                                                        
| 1607 | 1607 | 'input' => 'hidden',  | 
                                                        
| 1608 | 1608 | 'type' => 'string',  | 
                                                        
@@ -1719,7 +1719,7 @@ discard block  | 
                                                    ||
| 1719 | 1719 | 'format' => '%d',  | 
                                                        
| 1720 | 1720 | 'db-col' => 'MTP_deleted',  | 
                                                        
| 1721 | 1721 | ];  | 
                                                        
| 1722 | - $sidebar_form_fields['ee-msg-author'] = [  | 
                                                        |
| 1722 | + $sidebar_form_fields['ee-msg-author'] = [  | 
                                                        |
| 1723 | 1723 | 'name' => 'MTP_user_id',  | 
                                                        
| 1724 | 1724 |                  'label'      => esc_html__('Author', 'event_espresso'), | 
                                                        
| 1725 | 1725 | 'input' => 'hidden',  | 
                                                        
@@ -1738,17 +1738,17 @@ discard block  | 
                                                    ||
| 1738 | 1738 | 'value' => $action,  | 
                                                        
| 1739 | 1739 | ];  | 
                                                        
| 1740 | 1740 | |
| 1741 | - $sidebar_form_fields['ee-msg-id'] = [  | 
                                                        |
| 1741 | + $sidebar_form_fields['ee-msg-id'] = [  | 
                                                        |
| 1742 | 1742 | 'name' => 'id',  | 
                                                        
| 1743 | 1743 | 'input' => 'hidden',  | 
                                                        
| 1744 | 1744 | 'type' => 'int',  | 
                                                        
| 1745 | 1745 | 'value' => $GRP_ID,  | 
                                                        
| 1746 | 1746 | ];  | 
                                                        
| 1747 | 1747 | $sidebar_form_fields['ee-msg-evt-nonce'] = [  | 
                                                        
| 1748 | - 'name' => $action . '_nonce',  | 
                                                        |
| 1748 | + 'name' => $action.'_nonce',  | 
                                                        |
| 1749 | 1749 | 'input' => 'hidden',  | 
                                                        
| 1750 | 1750 | 'type' => 'string',  | 
                                                        
| 1751 | - 'value' => wp_create_nonce($action . '_nonce'),  | 
                                                        |
| 1751 | + 'value' => wp_create_nonce($action.'_nonce'),  | 
                                                        |
| 1752 | 1752 | ];  | 
                                                        
| 1753 | 1753 | |
| 1754 | 1754 |              $template_switch = $this->request->getRequestParam('template_switch'); | 
                                                        
@@ -1779,7 +1779,7 @@ discard block  | 
                                                    ||
| 1779 | 1779 | );  | 
                                                        
| 1780 | 1780 | |
| 1781 | 1781 | // add preview button  | 
                                                        
| 1782 | - $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1782 | + $preview_url = parent::add_query_args_and_nonce(  | 
                                                        |
| 1783 | 1783 | [  | 
                                                        
| 1784 | 1784 | 'message_type' => $message_template_group->message_type(),  | 
                                                        
| 1785 | 1785 | 'messenger' => $message_template_group->messenger(),  | 
                                                        
@@ -1790,7 +1790,7 @@ discard block  | 
                                                    ||
| 1790 | 1790 | ],  | 
                                                        
| 1791 | 1791 | $this->_admin_base_url  | 
                                                        
| 1792 | 1792 | );  | 
                                                        
| 1793 | - $preview_button = '<a href="' . $preview_url . '" class="button--secondary messages-preview-button">'  | 
                                                        |
| 1793 | + $preview_button = '<a href="'.$preview_url.'" class="button--secondary messages-preview-button">'  | 
                                                        |
| 1794 | 1794 |                            . esc_html__('Preview', 'event_espresso') | 
                                                        
| 1795 | 1795 | . '</a>';  | 
                                                        
| 1796 | 1796 | |
@@ -1828,11 +1828,11 @@ discard block  | 
                                                    ||
| 1828 | 1828 | $this->_template_args['before_admin_page_content'] .= $this->add_context_switcher();  | 
                                                        
| 1829 | 1829 | $this->_template_args['before_admin_page_content'] .= '</div>';  | 
                                                        
| 1830 | 1830 | $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();  | 
                                                        
| 1831 | - $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1831 | + $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();  | 
                                                        |
| 1832 | 1832 | |
| 1833 | 1833 | $this->_template_path = $this->_template_args['GRP_ID']  | 
                                                        
| 1834 | 1834 | ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'  | 
                                                        
| 1835 | - : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1835 | + : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';  | 
                                                        |
| 1836 | 1836 | |
| 1837 | 1837 | // send along EE_Message_Template_Group object for further template use.  | 
                                                        
| 1838 | 1838 | $this->_template_args['MTP'] = $message_template_group;  | 
                                                        
@@ -1888,7 +1888,7 @@ discard block  | 
                                                    ||
| 1888 | 1888 |      ) { | 
                                                        
| 1889 | 1889 | $template_args = [  | 
                                                        
| 1890 | 1890 | 'context' => $context,  | 
                                                        
| 1891 | -            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'), | 
                                                        |
| 1891 | +            'nonce'                     => wp_create_nonce('activate_'.$context.'_toggle_nonce'), | 
                                                        |
| 1892 | 1892 | 'is_active' => $message_template_group->is_context_active($context),  | 
                                                        
| 1893 | 1893 | 'on_off_action' => $message_template_group->is_context_active($context)  | 
                                                        
| 1894 | 1894 | ? 'context-off'  | 
                                                        
@@ -1897,7 +1897,7 @@ discard block  | 
                                                    ||
| 1897 | 1897 | 'message_template_group_id' => $message_template_group->ID(),  | 
                                                        
| 1898 | 1898 | ];  | 
                                                        
| 1899 | 1899 | return EEH_Template::display_template(  | 
                                                        
| 1900 | - EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',  | 
                                                        |
| 1900 | + EE_MSG_TEMPLATE_PATH.'ee_msg_editor_active_context_element.template.php',  | 
                                                        |
| 1901 | 1901 | $template_args,  | 
                                                        
| 1902 | 1902 | true  | 
                                                        
| 1903 | 1903 | );  | 
                                                        
@@ -1954,7 +1954,7 @@ discard block  | 
                                                    ||
| 1954 | 1954 | }  | 
                                                        
| 1955 | 1955 |          $message_template_group_id = $this->request->getRequestParam('message_template_group_id', 0, 'int'); | 
                                                        
| 1956 | 1956 | $message_template_group = $this->getMtgModel()->get_one_by_ID($message_template_group_id);  | 
                                                        
| 1957 | -        if (! $message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1957 | +        if ( ! $message_template_group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1958 | 1958 | EE_Error::add_error(  | 
                                                        
| 1959 | 1959 | sprintf(  | 
                                                        
| 1960 | 1960 | esc_html__(  | 
                                                        
@@ -2085,7 +2085,7 @@ discard block  | 
                                                    ||
| 2085 | 2085 |          $messenger    = $this->request->getRequestParam('msgr'); | 
                                                        
| 2086 | 2086 |          $message_type = $this->request->getRequestParam('mt'); | 
                                                        
| 2087 | 2087 | // we need to make sure we've got the info we need.  | 
                                                        
| 2088 | -        if (! ($GRP_ID && $messenger && $message_type)) { | 
                                                        |
| 2088 | +        if ( ! ($GRP_ID && $messenger && $message_type)) { | 
                                                        |
| 2089 | 2089 | EE_Error::add_error(  | 
                                                        
| 2090 | 2090 | esc_html__(  | 
                                                        
| 2091 | 2091 | 'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset. At least one of these is missing.',  | 
                                                        
@@ -2122,7 +2122,7 @@ discard block  | 
                                                    ||
| 2122 | 2122 | }  | 
                                                        
| 2123 | 2123 | |
| 2124 | 2124 | // any error messages?  | 
                                                        
| 2125 | -        if (! $success) { | 
                                                        |
| 2125 | +        if ( ! $success) { | 
                                                        |
| 2126 | 2126 | EE_Error::add_error(  | 
                                                        
| 2127 | 2127 | esc_html__(  | 
                                                        
| 2128 | 2128 | 'Something went wrong with deleting existing templates. Unable to reset to default',  | 
                                                        
@@ -2171,7 +2171,7 @@ discard block  | 
                                                    ||
| 2171 | 2171 |      { | 
                                                        
| 2172 | 2172 | // first make sure we've got the necessary parameters  | 
                                                        
| 2173 | 2173 |          $GRP_ID = $this->request->getRequestParam('GRP_ID', 0, 'int'); | 
                                                        
| 2174 | -        if (! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) { | 
                                                        |
| 2174 | +        if ( ! ($GRP_ID && $this->_active_messenger_name && $this->_active_message_type_name)) { | 
                                                        |
| 2175 | 2175 | EE_Error::add_error(  | 
                                                        
| 2176 | 2176 |                  esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'), | 
                                                        
| 2177 | 2177 | __FILE__,  | 
                                                        
@@ -2197,7 +2197,7 @@ discard block  | 
                                                    ||
| 2197 | 2197 |          $EVT_ID = $this->request->getRequestParam('evt_id', 0, 'int'); | 
                                                        
| 2198 | 2198 | |
| 2199 | 2199 | // let's add a button to go back to the edit view  | 
                                                        
| 2200 | - $query_args = [  | 
                                                        |
| 2200 | + $query_args = [  | 
                                                        |
| 2201 | 2201 | 'id' => $GRP_ID,  | 
                                                        
| 2202 | 2202 | 'evt_id' => $EVT_ID,  | 
                                                        
| 2203 | 2203 | 'context' => $context,  | 
                                                        
@@ -2218,7 +2218,7 @@ discard block  | 
                                                    ||
| 2218 | 2218 | $preview_title = sprintf(  | 
                                                        
| 2219 | 2219 |              esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'), | 
                                                        
| 2220 | 2220 | $active_messenger_label,  | 
                                                        
| 2221 | - ucwords($message_types[ $this->_active_message_type_name ]->label['singular'])  | 
                                                        |
| 2221 | + ucwords($message_types[$this->_active_message_type_name]->label['singular'])  | 
                                                        |
| 2222 | 2222 | );  | 
                                                        
| 2223 | 2223 |          if (empty($preview)) { | 
                                                        
| 2224 | 2224 | $this->noEventsErrorMessage();  | 
                                                        
@@ -2226,7 +2226,7 @@ discard block  | 
                                                    ||
| 2226 | 2226 | // setup display of preview.  | 
                                                        
| 2227 | 2227 | $this->_admin_page_title = $preview_title;  | 
                                                        
| 2228 | 2228 | $this->_template_args['admin_page_title'] = $preview_title;  | 
                                                        
| 2229 | - $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;  | 
                                                        |
| 2229 | + $this->_template_args['admin_page_content'] = $preview_button.'<br />'.$preview;  | 
                                                        |
| 2230 | 2230 | $this->_template_args['data']['force_json'] = true;  | 
                                                        
| 2231 | 2231 | |
| 2232 | 2232 | return '';  | 
                                                        
@@ -2247,7 +2247,7 @@ discard block  | 
                                                    ||
| 2247 | 2247 | ],  | 
                                                        
| 2248 | 2248 |              admin_url('admin.php') | 
                                                        
| 2249 | 2249 | );  | 
                                                        
| 2250 | - $message = $test_send  | 
                                                        |
| 2250 | + $message = $test_send  | 
                                                        |
| 2251 | 2251 | ? esc_html__(  | 
                                                        
| 2252 | 2252 | 'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',  | 
                                                        
| 2253 | 2253 | 'event_espresso'  | 
                                                        
@@ -2340,10 +2340,10 @@ discard block  | 
                                                    ||
| 2340 | 2340 | // only include template packs that support this messenger and message type!  | 
                                                        
| 2341 | 2341 | $supports = $tp->get_supports();  | 
                                                        
| 2342 | 2342 | if (  | 
                                                        
| 2343 | - ! isset($supports[ $this->_message_template_group->messenger() ])  | 
                                                        |
| 2343 | + ! isset($supports[$this->_message_template_group->messenger()])  | 
                                                        |
| 2344 | 2344 | || ! in_array(  | 
                                                        
| 2345 | 2345 | $this->_message_template_group->message_type(),  | 
                                                        
| 2346 | - $supports[ $this->_message_template_group->messenger() ],  | 
                                                        |
| 2346 | + $supports[$this->_message_template_group->messenger()],  | 
                                                        |
| 2347 | 2347 | true  | 
                                                        
| 2348 | 2348 | )  | 
                                                        
| 2349 | 2349 |              ) { | 
                                                        
@@ -2367,7 +2367,7 @@ discard block  | 
                                                    ||
| 2367 | 2367 | }  | 
                                                        
| 2368 | 2368 | |
| 2369 | 2369 | // setup variation select values for the currently selected template.  | 
                                                        
| 2370 | - $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 2370 | + $variations = $this->_message_template_group->get_template_pack()->get_variations(  | 
                                                        |
| 2371 | 2371 | $this->_message_template_group->messenger(),  | 
                                                        
| 2372 | 2372 | $this->_message_template_group->message_type()  | 
                                                        
| 2373 | 2373 | );  | 
                                                        
@@ -2381,12 +2381,12 @@ discard block  | 
                                                    ||
| 2381 | 2381 | |
| 2382 | 2382 | $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();  | 
                                                        
| 2383 | 2383 | |
| 2384 | - $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2384 | + $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2385 | 2385 | 'MTP_template_pack',  | 
                                                        
| 2386 | 2386 | $tp_select_values,  | 
                                                        
| 2387 | 2387 | $this->_message_template_group->get_template_pack_name()  | 
                                                        
| 2388 | 2388 | );  | 
                                                        
| 2389 | - $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2389 | + $template_args['variations_selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 2390 | 2390 | 'MTP_template_variation',  | 
                                                        
| 2391 | 2391 | $variations_select_values,  | 
                                                        
| 2392 | 2392 | $this->_message_template_group->get_template_pack_variation()  | 
                                                        
@@ -2396,7 +2396,7 @@ discard block  | 
                                                    ||
| 2396 | 2396 | $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;  | 
                                                        
| 2397 | 2397 | $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;  | 
                                                        
| 2398 | 2398 | |
| 2399 | - $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 2399 | + $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';  | 
                                                        |
| 2400 | 2400 | |
| 2401 | 2401 | EEH_Template::display_template($template, $template_args);  | 
                                                        
| 2402 | 2402 | }  | 
                                                        
@@ -2422,33 +2422,33 @@ discard block  | 
                                                    ||
| 2422 | 2422 | // first we need to see if there are any fields  | 
                                                        
| 2423 | 2423 | $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();  | 
                                                        
| 2424 | 2424 | |
| 2425 | -        if (! empty($fields)) { | 
                                                        |
| 2425 | +        if ( ! empty($fields)) { | 
                                                        |
| 2426 | 2426 | // yup there be fields  | 
                                                        
| 2427 | 2427 |              foreach ($fields as $field => $config) { | 
                                                        
| 2428 | - $field_id = $this->_message_template_group->messenger() . '_' . $field;  | 
                                                        |
| 2428 | + $field_id = $this->_message_template_group->messenger().'_'.$field;  | 
                                                        |
| 2429 | 2429 | $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();  | 
                                                        
| 2430 | 2430 | $default = isset($config['default']) ? $config['default'] : '';  | 
                                                        
| 2431 | 2431 | $default = isset($config['value']) ? $config['value'] : $default;  | 
                                                        
| 2432 | 2432 | |
| 2433 | 2433 | // if type is hidden and the value is empty  | 
                                                        
| 2434 | 2434 | // something may have gone wrong so let's correct with the defaults  | 
                                                        
| 2435 | - $fix = $config['input'] === 'hidden'  | 
                                                        |
| 2436 | - && isset($existing[ $field ])  | 
                                                        |
| 2437 | - && empty($existing[ $field ])  | 
                                                        |
| 2435 | + $fix = $config['input'] === 'hidden'  | 
                                                        |
| 2436 | + && isset($existing[$field])  | 
                                                        |
| 2437 | + && empty($existing[$field])  | 
                                                        |
| 2438 | 2438 | ? $default  | 
                                                        
| 2439 | 2439 | : '';  | 
                                                        
| 2440 | - $existing[ $field ] = isset($existing[ $field ]) && empty($fix)  | 
                                                        |
| 2441 | - ? $existing[ $field ]  | 
                                                        |
| 2440 | + $existing[$field] = isset($existing[$field]) && empty($fix)  | 
                                                        |
| 2441 | + ? $existing[$field]  | 
                                                        |
| 2442 | 2442 | : $fix;  | 
                                                        
| 2443 | 2443 | |
| 2444 | - $template_form_fields[ $field_id ] = [  | 
                                                        |
| 2445 | - 'name' => 'test_settings_fld[' . $field . ']',  | 
                                                        |
| 2444 | + $template_form_fields[$field_id] = [  | 
                                                        |
| 2445 | + 'name' => 'test_settings_fld['.$field.']',  | 
                                                        |
| 2446 | 2446 | 'label' => $config['label'],  | 
                                                        
| 2447 | 2447 | 'input' => $config['input'],  | 
                                                        
| 2448 | 2448 | 'type' => $config['type'],  | 
                                                        
| 2449 | 2449 | 'required' => $config['required'],  | 
                                                        
| 2450 | 2450 | 'validation' => $config['validation'],  | 
                                                        
| 2451 | - 'value' => isset($existing[ $field ]) ? $existing[ $field ] : $default,  | 
                                                        |
| 2451 | + 'value' => isset($existing[$field]) ? $existing[$field] : $default,  | 
                                                        |
| 2452 | 2452 | 'css_class' => $config['css_class'],  | 
                                                        
| 2453 | 2453 | 'options' => isset($config['options']) ? $config['options'] : [],  | 
                                                        
| 2454 | 2454 | 'default' => $default,  | 
                                                        
@@ -2462,7 +2462,7 @@ discard block  | 
                                                    ||
| 2462 | 2462 | : '';  | 
                                                        
| 2463 | 2463 | |
| 2464 | 2464 | // print out $test_settings_fields  | 
                                                        
| 2465 | -        if (! empty($test_settings_html)) { | 
                                                        |
| 2465 | +        if ( ! empty($test_settings_html)) { | 
                                                        |
| 2466 | 2466 | $test_settings_html .= '<input type="submit" class="button--primary mtp-test-button alignright" ';  | 
                                                        
| 2467 | 2467 | $test_settings_html .= 'name="test_button" value="';  | 
                                                        
| 2468 | 2468 |              $test_settings_html .= esc_html__('Test Send', 'event_espresso'); | 
                                                        
@@ -2508,7 +2508,7 @@ discard block  | 
                                                    ||
| 2508 | 2508 | ];  | 
                                                        
| 2509 | 2509 | |
| 2510 | 2510 | return EEH_Template::display_template(  | 
                                                        
| 2511 | - EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2511 | + EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',  | 
                                                        |
| 2512 | 2512 | $template_args,  | 
                                                        
| 2513 | 2513 | true  | 
                                                        
| 2514 | 2514 | );  | 
                                                        
@@ -2534,7 +2534,7 @@ discard block  | 
                                                    ||
| 2534 | 2534 | // $messenger = $this->_message_template_group->messenger_obj();  | 
                                                        
| 2535 | 2535 | // now let's set the content depending on the status of the shortcodes array  | 
                                                        
| 2536 | 2536 |          if (empty($shortcodes)) { | 
                                                        
| 2537 | -            echo '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>'; | 
                                                        |
| 2537 | +            echo '<p>'.esc_html__('There are no valid shortcodes available', 'event_espresso').'</p>'; | 
                                                        |
| 2538 | 2538 | return;  | 
                                                        
| 2539 | 2539 | }  | 
                                                        
| 2540 | 2540 | ?>  | 
                                                        
@@ -2570,7 +2570,7 @@ discard block  | 
                                                    ||
| 2570 | 2570 |      { | 
                                                        
| 2571 | 2571 | |
| 2572 | 2572 | // no need to run this if the property is already set  | 
                                                        
| 2573 | -        if (! empty($this->_shortcodes)) { | 
                                                        |
| 2573 | +        if ( ! empty($this->_shortcodes)) { | 
                                                        |
| 2574 | 2574 | return;  | 
                                                        
| 2575 | 2575 | }  | 
                                                        
| 2576 | 2576 | |
@@ -2625,7 +2625,7 @@ discard block  | 
                                                    ||
| 2625 | 2625 | protected function _set_message_template_group()  | 
                                                        
| 2626 | 2626 |      { | 
                                                        
| 2627 | 2627 | // get out if this is already set.  | 
                                                        
| 2628 | -        if (! empty($this->_message_template_group)) { | 
                                                        |
| 2628 | +        if ( ! empty($this->_message_template_group)) { | 
                                                        |
| 2629 | 2629 | return;  | 
                                                        
| 2630 | 2630 | }  | 
                                                        
| 2631 | 2631 | |
@@ -2671,8 +2671,8 @@ discard block  | 
                                                    ||
| 2671 | 2671 | <?php  | 
                                                        
| 2672 | 2672 | }  | 
                                                        
| 2673 | 2673 | // setup nonce_url  | 
                                                        
| 2674 | - wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);  | 
                                                        |
| 2675 | - $id = 'ee-' . sanitize_key($context_label['label']) . '-select';  | 
                                                        |
| 2674 | + wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);  | 
                                                        |
| 2675 | + $id = 'ee-'.sanitize_key($context_label['label']).'-select';  | 
                                                        |
| 2676 | 2676 | ?>  | 
                                                        
| 2677 | 2677 | <label for='<?php echo esc_attr($id); ?>' class='screen-reader-text'>  | 
                                                        
| 2678 | 2678 |                      <?php esc_html_e('message context options', 'event_espresso'); ?> | 
                                                        
@@ -2685,7 +2685,7 @@ discard block  | 
                                                    ||
| 2685 | 2685 | $checked = ($context === $args['context']) ? 'selected' : '';  | 
                                                        
| 2686 | 2686 | ?>  | 
                                                        
| 2687 | 2687 | <option value="<?php echo esc_attr($context); ?>" <?php echo esc_attr($checked); ?>>  | 
                                                        
| 2688 | - <?php echo esc_html($context_details[ $context ]['label']); ?>  | 
                                                        |
| 2688 | + <?php echo esc_html($context_details[$context]['label']); ?>  | 
                                                        |
| 2689 | 2689 | </option>  | 
                                                        
| 2690 | 2690 | <?php endforeach;  | 
                                                        
| 2691 | 2691 | endif; ?>  | 
                                                        
@@ -3076,7 +3076,7 @@ discard block  | 
                                                    ||
| 3076 | 3076 |      { | 
                                                        
| 3077 | 3077 |          if (is_array($content)) { | 
                                                        
| 3078 | 3078 |              foreach ($content as $key => $value) { | 
                                                        
| 3079 | - $content[ $key ] = $this->sanitizeMessageTemplateContent($value);  | 
                                                        |
| 3079 | + $content[$key] = $this->sanitizeMessageTemplateContent($value);  | 
                                                        |
| 3080 | 3080 | }  | 
                                                        
| 3081 | 3081 | return $content;  | 
                                                        
| 3082 | 3082 | }  | 
                                                        
@@ -3114,7 +3114,7 @@ discard block  | 
                                                    ||
| 3114 | 3114 | |
| 3115 | 3115 |          $context   = ucwords(str_replace('_', ' ', $context)); | 
                                                        
| 3116 | 3116 | $item_desc = $messenger_label && $message_type_label  | 
                                                        
| 3117 | - ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '  | 
                                                        |
| 3117 | + ? $messenger_label.' '.$message_type_label.' '.$context.' '  | 
                                                        |
| 3118 | 3118 | : '';  | 
                                                        
| 3119 | 3119 | $item_desc .= 'Message Template';  | 
                                                        
| 3120 | 3120 | return $item_desc;  | 
                                                        
@@ -3266,7 +3266,7 @@ discard block  | 
                                                    ||
| 3266 | 3266 |          if ($all) { | 
                                                        
| 3267 | 3267 | // Checkboxes  | 
                                                        
| 3268 | 3268 |              $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        
| 3269 | -            if (! empty($checkboxes)) { | 
                                                        |
| 3269 | +            if ( ! empty($checkboxes)) { | 
                                                        |
| 3270 | 3270 | // if array has more than one element then success message should be plural.  | 
                                                        
| 3271 | 3271 | // todo: what about nonce?  | 
                                                        
| 3272 | 3272 | $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        
@@ -3276,18 +3276,18 @@ discard block  | 
                                                    ||
| 3276 | 3276 | $trashed_or_restored = $trash  | 
                                                        
| 3277 | 3277 | ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        
| 3278 | 3278 | : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        
| 3279 | -                    if (! $trashed_or_restored) { | 
                                                        |
| 3279 | +                    if ( ! $trashed_or_restored) { | 
                                                        |
| 3280 | 3280 | $success = 0;  | 
                                                        
| 3281 | 3281 | }  | 
                                                        
| 3282 | 3282 | }  | 
                                                        
| 3283 | 3283 |              } else { | 
                                                        
| 3284 | 3284 | // grab single GRP_ID and handle  | 
                                                        
| 3285 | 3285 |                  $GRP_ID = $this->request->getRequestParam('id', 0, 'int'); | 
                                                        
| 3286 | -                if (! empty($GRP_ID)) { | 
                                                        |
| 3286 | +                if ( ! empty($GRP_ID)) { | 
                                                        |
| 3287 | 3287 | $trashed_or_restored = $trash  | 
                                                        
| 3288 | 3288 | ? $this->getMtgModel()->delete_by_ID($GRP_ID)  | 
                                                        
| 3289 | 3289 | : $this->getMtgModel()->restore_by_ID($GRP_ID);  | 
                                                        
| 3290 | -                    if (! $trashed_or_restored) { | 
                                                        |
| 3290 | +                    if ( ! $trashed_or_restored) { | 
                                                        |
| 3291 | 3291 | $success = 0;  | 
                                                        
| 3292 | 3292 | }  | 
                                                        
| 3293 | 3293 |                  } else { | 
                                                        
@@ -3335,7 +3335,7 @@ discard block  | 
                                                    ||
| 3335 | 3335 | |
| 3336 | 3336 | // checkboxes  | 
                                                        
| 3337 | 3337 |          $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true); | 
                                                        
| 3338 | -        if (! empty($checkboxes)) { | 
                                                        |
| 3338 | +        if ( ! empty($checkboxes)) { | 
                                                        |
| 3339 | 3339 | // if array has more than one element then success message should be plural  | 
                                                        
| 3340 | 3340 | $success = count($checkboxes) > 1 ? 2 : 1;  | 
                                                        
| 3341 | 3341 | |
@@ -3439,7 +3439,7 @@ discard block  | 
                                                    ||
| 3439 | 3439 | protected function _set_m_mt_settings()  | 
                                                        
| 3440 | 3440 |      { | 
                                                        
| 3441 | 3441 | // first if this is already set then lets get out no need to regenerate data.  | 
                                                        
| 3442 | -        if (! empty($this->_m_mt_settings)) { | 
                                                        |
| 3442 | +        if ( ! empty($this->_m_mt_settings)) { | 
                                                        |
| 3443 | 3443 | return;  | 
                                                        
| 3444 | 3444 | }  | 
                                                        
| 3445 | 3445 | |
@@ -3452,8 +3452,8 @@ discard block  | 
                                                    ||
| 3452 | 3452 | |
| 3453 | 3453 |          foreach ($messengers as $messenger) { | 
                                                        
| 3454 | 3454 | $active = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        
| 3455 | - $class = 'ee-messenger-' . sanitize_key($messenger->label['singular']);  | 
                                                        |
| 3456 | - $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = [  | 
                                                        |
| 3455 | + $class = 'ee-messenger-'.sanitize_key($messenger->label['singular']);  | 
                                                        |
| 3456 | + $this->_m_mt_settings['messenger_tabs'][$messenger->name] = [  | 
                                                        |
| 3457 | 3457 | 'label' => ucwords($messenger->label['singular']),  | 
                                                        
| 3458 | 3458 |                  'class' => $active ? "{$class} messenger-active" : $class, | 
                                                        
| 3459 | 3459 | 'href' => $messenger->name,  | 
                                                        
@@ -3471,7 +3471,7 @@ discard block  | 
                                                    ||
| 3471 | 3471 |              foreach ($message_types as $message_type) { | 
                                                        
| 3472 | 3472 | // first we need to verify that this message type is valid with this messenger. Cause if it isn't then  | 
                                                        
| 3473 | 3473 | // it shouldn't show in either the inactive OR active metabox.  | 
                                                        
| 3474 | -                if (! in_array($message_type->name, $message_types_for_messenger, true)) { | 
                                                        |
| 3474 | +                if ( ! in_array($message_type->name, $message_types_for_messenger, true)) { | 
                                                        |
| 3475 | 3475 | continue;  | 
                                                        
| 3476 | 3476 | }  | 
                                                        
| 3477 | 3477 | |
@@ -3482,12 +3482,12 @@ discard block  | 
                                                    ||
| 3482 | 3482 | ? 'active'  | 
                                                        
| 3483 | 3483 | : 'inactive';  | 
                                                        
| 3484 | 3484 | |
| 3485 | - $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = [  | 
                                                        |
| 3485 | + $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = [  | 
                                                        |
| 3486 | 3486 | 'label' => ucwords($message_type->label['singular']),  | 
                                                        
| 3487 | - 'class' => 'message-type-' . $a_or_i,  | 
                                                        |
| 3488 | - 'slug_id' => $message_type->name . '-messagetype-' . $messenger->name,  | 
                                                        |
| 3489 | - 'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),  | 
                                                        |
| 3490 | - 'href' => 'espresso_' . $message_type->name . '_message_type_settings',  | 
                                                        |
| 3487 | + 'class' => 'message-type-'.$a_or_i,  | 
                                                        |
| 3488 | + 'slug_id' => $message_type->name.'-messagetype-'.$messenger->name,  | 
                                                        |
| 3489 | + 'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),  | 
                                                        |
| 3490 | + 'href' => 'espresso_'.$message_type->name.'_message_type_settings',  | 
                                                        |
| 3491 | 3491 | 'title' => $a_or_i === 'active'  | 
                                                        
| 3492 | 3492 |                          ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso') | 
                                                        
| 3493 | 3493 |                          : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'), | 
                                                        
@@ -3518,25 +3518,25 @@ discard block  | 
                                                    ||
| 3518 | 3518 | $fields = $message_type->get_admin_settings_fields();  | 
                                                        
| 3519 | 3519 | $settings_template_args['template_form_fields'] = '';  | 
                                                        
| 3520 | 3520 | |
| 3521 | -        if (! empty($fields) && $active) { | 
                                                        |
| 3521 | +        if ( ! empty($fields) && $active) { | 
                                                        |
| 3522 | 3522 | $existing_settings = $message_type->get_existing_admin_settings($messenger->name);  | 
                                                        
| 3523 | 3523 |              foreach ($fields as $fldname => $fldprops) { | 
                                                        
| 3524 | - $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;  | 
                                                        |
| 3525 | - $template_form_field[ $field_id ] = [  | 
                                                        |
| 3526 | - 'name' => 'message_type_settings[' . $fldname . ']',  | 
                                                        |
| 3524 | + $field_id = $messenger->name.'-'.$message_type->name.'-'.$fldname;  | 
                                                        |
| 3525 | + $template_form_field[$field_id] = [  | 
                                                        |
| 3526 | + 'name' => 'message_type_settings['.$fldname.']',  | 
                                                        |
| 3527 | 3527 | 'label' => $fldprops['label'],  | 
                                                        
| 3528 | 3528 | 'input' => $fldprops['field_type'],  | 
                                                        
| 3529 | 3529 | 'type' => $fldprops['value_type'],  | 
                                                        
| 3530 | 3530 | 'required' => $fldprops['required'],  | 
                                                        
| 3531 | 3531 | 'validation' => $fldprops['validation'],  | 
                                                        
| 3532 | - 'value' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3533 | - ? $existing_settings[ $fldname ]  | 
                                                        |
| 3532 | + 'value' => isset($existing_settings[$fldname])  | 
                                                        |
| 3533 | + ? $existing_settings[$fldname]  | 
                                                        |
| 3534 | 3534 | : $fldprops['default'],  | 
                                                        
| 3535 | 3535 | 'options' => isset($fldprops['options'])  | 
                                                        
| 3536 | 3536 | ? $fldprops['options']  | 
                                                        
| 3537 | 3537 | : [],  | 
                                                        
| 3538 | - 'default' => isset($existing_settings[ $fldname ])  | 
                                                        |
| 3539 | - ? $existing_settings[ $fldname ]  | 
                                                        |
| 3538 | + 'default' => isset($existing_settings[$fldname])  | 
                                                        |
| 3539 | + ? $existing_settings[$fldname]  | 
                                                        |
| 3540 | 3540 | : $fldprops['default'],  | 
                                                        
| 3541 | 3541 | 'css_class' => 'no-drag',  | 
                                                        
| 3542 | 3542 | 'format' => $fldprops['format'],  | 
                                                        
@@ -3556,15 +3556,15 @@ discard block  | 
                                                    ||
| 3556 | 3556 | $settings_template_args['description'] = $message_type->description;  | 
                                                        
| 3557 | 3557 | // we also need some hidden fields  | 
                                                        
| 3558 | 3558 | $hidden_fields = [  | 
                                                        
| 3559 | - 'message_type_settings[messenger]' . $message_type->name => [  | 
                                                        |
| 3559 | + 'message_type_settings[messenger]'.$message_type->name => [  | 
                                                        |
| 3560 | 3560 | 'type' => 'hidden',  | 
                                                        
| 3561 | 3561 | 'value' => $messenger->name,  | 
                                                        
| 3562 | 3562 | ],  | 
                                                        
| 3563 | - 'message_type_settings[message_type]' . $message_type->name => [  | 
                                                        |
| 3563 | + 'message_type_settings[message_type]'.$message_type->name => [  | 
                                                        |
| 3564 | 3564 | 'type' => 'hidden',  | 
                                                        
| 3565 | 3565 | 'value' => $message_type->name,  | 
                                                        
| 3566 | 3566 | ],  | 
                                                        
| 3567 | - 'type' . $message_type->name => [  | 
                                                        |
| 3567 | + 'type'.$message_type->name => [  | 
                                                        |
| 3568 | 3568 | 'type' => 'hidden',  | 
                                                        
| 3569 | 3569 | 'value' => 'message_type',  | 
                                                        
| 3570 | 3570 | ],  | 
                                                        
@@ -3574,12 +3574,12 @@ discard block  | 
                                                    ||
| 3574 | 3574 | $hidden_fields,  | 
                                                        
| 3575 | 3575 | 'array'  | 
                                                        
| 3576 | 3576 | );  | 
                                                        
| 3577 | - $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3577 | + $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])  | 
                                                        |
| 3578 | 3578 | ? ' hidden'  | 
                                                        
| 3579 | 3579 | : '';  | 
                                                        
| 3580 | 3580 | |
| 3581 | 3581 | |
| 3582 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 3582 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';  | 
                                                        |
| 3583 | 3583 | return EEH_Template::display_template($template, $settings_template_args, true);  | 
                                                        
| 3584 | 3584 | }  | 
                                                        
| 3585 | 3585 | |
@@ -3607,21 +3607,21 @@ discard block  | 
                                                    ||
| 3607 | 3607 | |
| 3608 | 3608 | // messenger meta boxes  | 
                                                        
| 3609 | 3609 | $active = $selected_messenger === $messenger;  | 
                                                        
| 3610 | - $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][ $messenger ]['active'])  | 
                                                        |
| 3611 | - ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']  | 
                                                        |
| 3610 | + $active_mt_tabs = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])  | 
                                                        |
| 3611 | + ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']  | 
                                                        |
| 3612 | 3612 | : '';  | 
                                                        
| 3613 | 3613 | |
| 3614 | - $m_boxes[ $messenger . '_a_box' ] = sprintf(  | 
                                                        |
| 3614 | + $m_boxes[$messenger.'_a_box'] = sprintf(  | 
                                                        |
| 3615 | 3615 |                      esc_html__('%s Settings', 'event_espresso'), | 
                                                        
| 3616 | 3616 | $tab_array['label']  | 
                                                        
| 3617 | 3617 | );  | 
                                                        
| 3618 | 3618 | |
| 3619 | - $m_template_args[ $messenger . '_a_box' ] = [  | 
                                                        |
| 3619 | + $m_template_args[$messenger.'_a_box'] = [  | 
                                                        |
| 3620 | 3620 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        
| 3621 | 3621 | 'inactive_message_types' => isset(  | 
                                                        
| 3622 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3622 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']  | 
                                                        |
| 3623 | 3623 | )  | 
                                                        
| 3624 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3624 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 3625 | 3625 | : '',  | 
                                                        
| 3626 | 3626 | 'content' => $this->_get_messenger_box_content($tab_array['obj']),  | 
                                                        
| 3627 | 3627 | 'hidden' => $active ? '' : ' hidden',  | 
                                                        
@@ -3633,13 +3633,13 @@ discard block  | 
                                                    ||
| 3633 | 3633 | // message type meta boxes  | 
                                                        
| 3634 | 3634 | // (which is really just the inactive container for each messenger  | 
                                                        
| 3635 | 3635 | // showing inactive message types for that messenger)  | 
                                                        
| 3636 | -                $mt_boxes[ $messenger . '_i_box' ]         = esc_html__('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 3637 | - $mt_template_args[ $messenger . '_i_box' ] = [  | 
                                                        |
| 3636 | +                $mt_boxes[$messenger.'_i_box']         = esc_html__('Inactive Message Types', 'event_espresso'); | 
                                                        |
| 3637 | + $mt_template_args[$messenger.'_i_box'] = [  | 
                                                        |
| 3638 | 3638 | 'active_message_types' => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',  | 
                                                        
| 3639 | 3639 | 'inactive_message_types' => isset(  | 
                                                        
| 3640 | - $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']  | 
                                                        |
| 3640 | + $this->_m_mt_settings['message_type_tabs'][$messenger]['inactive']  | 
                                                        |
| 3641 | 3641 | )  | 
                                                        
| 3642 | - ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])  | 
                                                        |
| 3642 | + ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])  | 
                                                        |
| 3643 | 3643 | : '',  | 
                                                        
| 3644 | 3644 | 'hidden' => $active ? '' : ' hidden',  | 
                                                        
| 3645 | 3645 | 'hide_on_message' => $hide_on_message,  | 
                                                        
@@ -3652,14 +3652,14 @@ discard block  | 
                                                    ||
| 3652 | 3652 | |
| 3653 | 3653 | |
| 3654 | 3654 | // register messenger metaboxes  | 
                                                        
| 3655 | - $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 3655 | + $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';  | 
                                                        |
| 3656 | 3656 |          foreach ($m_boxes as $box => $label) { | 
                                                        
| 3657 | - $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]];  | 
                                                        |
| 3657 | + $callback_args = ['template_path' => $m_template_path, 'template_args' => $m_template_args[$box]];  | 
                                                        |
| 3658 | 3658 |              $msgr          = str_replace('_a_box', '', $box); | 
                                                        
| 3659 | 3659 | $this->addMetaBox(  | 
                                                        
| 3660 | - 'espresso_' . $msgr . '_settings',  | 
                                                        |
| 3660 | + 'espresso_'.$msgr.'_settings',  | 
                                                        |
| 3661 | 3661 | $label,  | 
                                                        
| 3662 | -                function ($post, $metabox) { | 
                                                        |
| 3662 | +                function($post, $metabox) { | 
                                                        |
| 3663 | 3663 | EEH_Template::display_template(  | 
                                                        
| 3664 | 3664 | $metabox['args']['template_path'],  | 
                                                        
| 3665 | 3665 | $metabox['args']['template_args']  | 
                                                        
@@ -3673,17 +3673,17 @@ discard block  | 
                                                    ||
| 3673 | 3673 | }  | 
                                                        
| 3674 | 3674 | |
| 3675 | 3675 | // register message type metaboxes  | 
                                                        
| 3676 | - $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 3676 | + $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';  | 
                                                        |
| 3677 | 3677 |          foreach ($mt_boxes as $box => $label) { | 
                                                        
| 3678 | 3678 | $callback_args = [  | 
                                                        
| 3679 | 3679 | 'template_path' => $mt_template_path,  | 
                                                        
| 3680 | - 'template_args' => $mt_template_args[ $box ],  | 
                                                        |
| 3680 | + 'template_args' => $mt_template_args[$box],  | 
                                                        |
| 3681 | 3681 | ];  | 
                                                        
| 3682 | -            $mt            = str_replace('_i_box', '', $box); | 
                                                        |
| 3682 | +            $mt = str_replace('_i_box', '', $box); | 
                                                        |
| 3683 | 3683 | $this->addMetaBox(  | 
                                                        
| 3684 | - 'espresso_' . $mt . '_inactive_mts',  | 
                                                        |
| 3684 | + 'espresso_'.$mt.'_inactive_mts',  | 
                                                        |
| 3685 | 3685 | $label,  | 
                                                        
| 3686 | -                function ($post, $metabox) { | 
                                                        |
| 3686 | +                function($post, $metabox) { | 
                                                        |
| 3687 | 3687 | EEH_Template::display_template(  | 
                                                        
| 3688 | 3688 | $metabox['args']['template_path'],  | 
                                                        
| 3689 | 3689 | $metabox['args']['template_args']  | 
                                                        
@@ -3830,7 +3830,7 @@ discard block  | 
                                                    ||
| 3830 | 3830 |              if ($form->is_valid()) { | 
                                                        
| 3831 | 3831 | $valid_data = $form->valid_data();  | 
                                                        
| 3832 | 3832 |                  foreach ($valid_data as $property => $value) { | 
                                                        
| 3833 | - $setter = 'set_' . $property;  | 
                                                        |
| 3833 | + $setter = 'set_'.$property;  | 
                                                        |
| 3834 | 3834 |                      if (method_exists($network_config, $setter)) { | 
                                                        
| 3835 | 3835 |                          $network_config->{$setter}($value); | 
                                                        
| 3836 | 3836 | } elseif (  | 
                                                        
@@ -3866,7 +3866,7 @@ discard block  | 
                                                    ||
| 3866 | 3866 | protected function _get_mt_tabs($tab_array)  | 
                                                        
| 3867 | 3867 |      { | 
                                                        
| 3868 | 3868 | $tab_array = (array) $tab_array;  | 
                                                        
| 3869 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3869 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';  | 
                                                        |
| 3870 | 3870 | $tabs = '';  | 
                                                        
| 3871 | 3871 | |
| 3872 | 3872 |          foreach ($tab_array as $tab) { | 
                                                        
@@ -3894,19 +3894,19 @@ discard block  | 
                                                    ||
| 3894 | 3894 | $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        
| 3895 | 3895 | |
| 3896 | 3896 | |
| 3897 | -        if (! empty($fields)) { | 
                                                        |
| 3897 | +        if ( ! empty($fields)) { | 
                                                        |
| 3898 | 3898 | $existing_settings = $messenger->get_existing_admin_settings();  | 
                                                        
| 3899 | 3899 | |
| 3900 | 3900 |              foreach ($fields as $field_name => $field_props) { | 
                                                        
| 3901 | - $field_id = $messenger->name . '-' . $field_name;  | 
                                                        |
| 3902 | - $template_form_field[ $field_id ] = [  | 
                                                        |
| 3903 | - 'name' => 'messenger_settings[' . $field_id . ']',  | 
                                                        |
| 3901 | + $field_id = $messenger->name.'-'.$field_name;  | 
                                                        |
| 3902 | + $template_form_field[$field_id] = [  | 
                                                        |
| 3903 | + 'name' => 'messenger_settings['.$field_id.']',  | 
                                                        |
| 3904 | 3904 | 'label' => $field_props['label'],  | 
                                                        
| 3905 | 3905 | 'input' => $field_props['field_type'],  | 
                                                        
| 3906 | 3906 | 'type' => $field_props['value_type'],  | 
                                                        
| 3907 | 3907 | 'required' => $field_props['required'],  | 
                                                        
| 3908 | 3908 | 'validation' => $field_props['validation'],  | 
                                                        
| 3909 | - 'value' => $existing_settings[ $field_id ] ?? $field_props['default'],  | 
                                                        |
| 3909 | + 'value' => $existing_settings[$field_id] ?? $field_props['default'],  | 
                                                        |
| 3910 | 3910 | 'css_class' => '',  | 
                                                        
| 3911 | 3911 | 'format' => $field_props['format'],  | 
                                                        
| 3912 | 3912 | ];  | 
                                                        
@@ -3919,20 +3919,20 @@ discard block  | 
                                                    ||
| 3919 | 3919 | |
| 3920 | 3920 | // we also need some hidden fields  | 
                                                        
| 3921 | 3921 | $settings_template_args['hidden_fields'] = [  | 
                                                        
| 3922 | - 'messenger_settings[messenger]' . $messenger->name => [  | 
                                                        |
| 3922 | + 'messenger_settings[messenger]'.$messenger->name => [  | 
                                                        |
| 3923 | 3923 | 'type' => 'hidden',  | 
                                                        
| 3924 | 3924 | 'value' => $messenger->name,  | 
                                                        
| 3925 | 3925 | ],  | 
                                                        
| 3926 | - 'type' . $messenger->name => [  | 
                                                        |
| 3926 | + 'type'.$messenger->name => [  | 
                                                        |
| 3927 | 3927 | 'type' => 'hidden',  | 
                                                        
| 3928 | 3928 | 'value' => 'messenger',  | 
                                                        
| 3929 | 3929 | ],  | 
                                                        
| 3930 | 3930 | ];  | 
                                                        
| 3931 | 3931 | |
| 3932 | 3932 | // make sure any active message types that are existing are included in the hidden fields  | 
                                                        
| 3933 | -        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) { | 
                                                        |
| 3934 | -            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) { | 
                                                        |
| 3935 | - $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = [  | 
                                                        |
| 3933 | +        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) { | 
                                                        |
| 3934 | +            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) { | 
                                                        |
| 3935 | + $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = [  | 
                                                        |
| 3936 | 3936 | 'type' => 'hidden',  | 
                                                        
| 3937 | 3937 | 'value' => $mt,  | 
                                                        
| 3938 | 3938 | ];  | 
                                                        
@@ -3942,7 +3942,7 @@ discard block  | 
                                                    ||
| 3942 | 3942 | $settings_template_args['hidden_fields'],  | 
                                                        
| 3943 | 3943 | 'array'  | 
                                                        
| 3944 | 3944 | );  | 
                                                        
| 3945 | - $active =  | 
                                                        |
| 3945 | + $active =  | 
                                                        |
| 3946 | 3946 | $this->_message_resource_manager->is_messenger_active($messenger->name);  | 
                                                        
| 3947 | 3947 | |
| 3948 | 3948 | $settings_template_args['messenger'] = $messenger->name;  | 
                                                        
@@ -3962,9 +3962,9 @@ discard block  | 
                                                    ||
| 3962 | 3962 | |
| 3963 | 3963 | |
| 3964 | 3964 | $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';  | 
                                                        
| 3965 | -        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce'); | 
                                                        |
| 3965 | +        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce'); | 
                                                        |
| 3966 | 3966 | $settings_template_args['on_off_status'] = $active;  | 
                                                        
| 3967 | - $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3967 | + $template = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';  | 
                                                        |
| 3968 | 3968 | return EEH_Template::display_template(  | 
                                                        
| 3969 | 3969 | $template,  | 
                                                        
| 3970 | 3970 | $settings_template_args,  | 
                                                        
@@ -3989,7 +3989,7 @@ discard block  | 
                                                    ||
| 3989 | 3989 | $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        
| 3990 | 3990 | // let's check that we have required data  | 
                                                        
| 3991 | 3991 | |
| 3992 | -        if (! $this->_active_messenger_name) { | 
                                                        |
| 3992 | +        if ( ! $this->_active_messenger_name) { | 
                                                        |
| 3993 | 3993 | EE_Error::add_error(  | 
                                                        
| 3994 | 3994 |                  esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        
| 3995 | 3995 | __FILE__,  | 
                                                        
@@ -4007,7 +4007,7 @@ discard block  | 
                                                    ||
| 4007 | 4007 | |
| 4008 | 4008 | |
| 4009 | 4009 |          $status = $this->request->getRequestParam('status'); | 
                                                        
| 4010 | -        if (! $status) { | 
                                                        |
| 4010 | +        if ( ! $status) { | 
                                                        |
| 4011 | 4011 | EE_Error::add_error(  | 
                                                        
| 4012 | 4012 | esc_html__(  | 
                                                        
| 4013 | 4013 | 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        
@@ -4064,7 +4064,7 @@ discard block  | 
                                                    ||
| 4064 | 4064 | $this->_prep_default_response_for_messenger_or_message_type_toggle();  | 
                                                        
| 4065 | 4065 | |
| 4066 | 4066 | // let's make sure we have the necessary data  | 
                                                        
| 4067 | -        if (! $this->_active_message_type_name) { | 
                                                        |
| 4067 | +        if ( ! $this->_active_message_type_name) { | 
                                                        |
| 4068 | 4068 | EE_Error::add_error(  | 
                                                        
| 4069 | 4069 |                  esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'), | 
                                                        
| 4070 | 4070 | __FILE__,  | 
                                                        
@@ -4074,7 +4074,7 @@ discard block  | 
                                                    ||
| 4074 | 4074 | $success = false;  | 
                                                        
| 4075 | 4075 | }  | 
                                                        
| 4076 | 4076 | |
| 4077 | -        if (! $this->_active_messenger_name) { | 
                                                        |
| 4077 | +        if ( ! $this->_active_messenger_name) { | 
                                                        |
| 4078 | 4078 | EE_Error::add_error(  | 
                                                        
| 4079 | 4079 |                  esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'), | 
                                                        
| 4080 | 4080 | __FILE__,  | 
                                                        
@@ -4085,7 +4085,7 @@ discard block  | 
                                                    ||
| 4085 | 4085 | }  | 
                                                        
| 4086 | 4086 | |
| 4087 | 4087 |          $status = $this->request->getRequestParam('status'); | 
                                                        
| 4088 | -        if (! $status) { | 
                                                        |
| 4088 | +        if ( ! $status) { | 
                                                        |
| 4089 | 4089 | EE_Error::add_error(  | 
                                                        
| 4090 | 4090 | esc_html__(  | 
                                                        
| 4091 | 4091 | 'Messenger status needed to know whether activation or deactivation is happening. No status is given',  | 
                                                        
@@ -4297,7 +4297,7 @@ discard block  | 
                                                    ||
| 4297 | 4297 | EE_Message_Type $message_type = null  | 
                                                        
| 4298 | 4298 |      ) { | 
                                                        
| 4299 | 4299 | // if $messenger isn't a valid messenger object then get out.  | 
                                                        
| 4300 | -        if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4300 | +        if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4301 | 4301 | EE_Error::add_error(  | 
                                                        
| 4302 | 4302 |                  esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'), | 
                                                        
| 4303 | 4303 | __FILE__,  | 
                                                        
@@ -4351,7 +4351,7 @@ discard block  | 
                                                    ||
| 4351 | 4351 | // message types after the activation process. However its possible some messengers don't HAVE any default_message_types  | 
                                                        
| 4352 | 4352 | // in which case we just give a success message for the messenger being successfully activated.  | 
                                                        
| 4353 | 4353 |          } else { | 
                                                        
| 4354 | -            if (! $messenger->get_default_message_types()) { | 
                                                        |
| 4354 | +            if ( ! $messenger->get_default_message_types()) { | 
                                                        |
| 4355 | 4355 | // messenger doesn't have any default message types so still a success.  | 
                                                        
| 4356 | 4356 | EE_Error::add_success(  | 
                                                        
| 4357 | 4357 | sprintf(  | 
                                                        
@@ -4407,7 +4407,7 @@ discard block  | 
                                                    ||
| 4407 | 4407 | EE_Error::overwrite_success();  | 
                                                        
| 4408 | 4408 | |
| 4409 | 4409 | // if $messenger isn't a valid messenger object then get out.  | 
                                                        
| 4410 | -        if (! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4410 | +        if ( ! $messenger instanceof EE_Messenger) { | 
                                                        |
| 4411 | 4411 | EE_Error::add_error(  | 
                                                        
| 4412 | 4412 |                  esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'), | 
                                                        
| 4413 | 4413 | __FILE__,  | 
                                                        
@@ -4477,7 +4477,7 @@ discard block  | 
                                                    ||
| 4477 | 4477 | */  | 
                                                        
| 4478 | 4478 | public function update_mt_form()  | 
                                                        
| 4479 | 4479 |      { | 
                                                        
| 4480 | -        if (! $this->_active_messenger_name || ! $this->_active_message_type_name) { | 
                                                        |
| 4480 | +        if ( ! $this->_active_messenger_name || ! $this->_active_message_type_name) { | 
                                                        |
| 4481 | 4481 | EE_Error::add_error(  | 
                                                        
| 4482 | 4482 |                  esc_html__('Require message type or messenger to send an updated form', 'event_espresso'), | 
                                                        
| 4483 | 4483 | __FILE__,  | 
                                                        
@@ -4488,7 +4488,7 @@ discard block  | 
                                                    ||
| 4488 | 4488 | }  | 
                                                        
| 4489 | 4489 | |
| 4490 | 4490 | $message_types = $this->get_installed_message_types();  | 
                                                        
| 4491 | - $message_type = $message_types[ $this->_active_message_type_name ];  | 
                                                        |
| 4491 | + $message_type = $message_types[$this->_active_message_type_name];  | 
                                                        |
| 4492 | 4492 | $messenger = $this->_message_resource_manager->get_active_messenger($this->_active_messenger_name);  | 
                                                        
| 4493 | 4493 | $content = $this->_message_type_settings_content($message_type, $messenger, true);  | 
                                                        
| 4494 | 4494 | |
@@ -4507,7 +4507,7 @@ discard block  | 
                                                    ||
| 4507 | 4507 | public function save_settings()  | 
                                                        
| 4508 | 4508 |      { | 
                                                        
| 4509 | 4509 |          $type = $this->request->getRequestParam('type'); | 
                                                        
| 4510 | -        if (! $type) { | 
                                                        |
| 4510 | +        if ( ! $type) { | 
                                                        |
| 4511 | 4511 | EE_Error::add_error(  | 
                                                        
| 4512 | 4512 | esc_html__(  | 
                                                        
| 4513 | 4513 | 'Cannot save settings because type is unknown (messenger settings or message type settings?)',  | 
                                                        
@@ -10,806 +10,806 @@  | 
                                                    ||
| 10 | 10 | */  | 
                                                        
| 11 | 11 | class EE_Caf_Messages  | 
                                                        
| 12 | 12 |  { | 
                                                        
| 13 | - /**  | 
                                                        |
| 14 | - * constructor.  | 
                                                        |
| 15 | - */  | 
                                                        |
| 16 | - public function __construct()  | 
                                                        |
| 17 | -    { | 
                                                        |
| 18 | - $this->_caf_hooks();  | 
                                                        |
| 19 | - }  | 
                                                        |
| 20 | -  | 
                                                        |
| 21 | -  | 
                                                        |
| 22 | - /**  | 
                                                        |
| 23 | - * Contains all the hooks filters for setting up caffeinated messages functionality.  | 
                                                        |
| 24 | - *  | 
                                                        |
| 25 | - * @since 4.3.2  | 
                                                        |
| 26 | - *  | 
                                                        |
| 27 | - * @return void  | 
                                                        |
| 28 | - */  | 
                                                        |
| 29 | - private function _caf_hooks()  | 
                                                        |
| 30 | -    { | 
                                                        |
| 31 | -        add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); | 
                                                        |
| 32 | - add_filter(  | 
                                                        |
| 33 | - 'FHEE__EE_Email_messenger__get_validator_config',  | 
                                                        |
| 34 | - array($this, 'email_messenger_validator_config'),  | 
                                                        |
| 35 | - 5,  | 
                                                        |
| 36 | - 2  | 
                                                        |
| 37 | - );  | 
                                                        |
| 38 | - add_filter(  | 
                                                        |
| 39 | - 'FHEE__EE_Email_messenger__get_template_fields',  | 
                                                        |
| 40 | - array($this, 'email_messenger_template_fields'),  | 
                                                        |
| 41 | - 5,  | 
                                                        |
| 42 | - 2  | 
                                                        |
| 43 | - );  | 
                                                        |
| 44 | - add_filter(  | 
                                                        |
| 45 | - 'FHEE__EE_Html_messenger__get_template_fields',  | 
                                                        |
| 46 | - array($this, 'html_messenger_template_fields'),  | 
                                                        |
| 47 | - 5,  | 
                                                        |
| 48 | - 2  | 
                                                        |
| 49 | - );  | 
                                                        |
| 50 | - add_filter(  | 
                                                        |
| 51 | - 'FHEE__EE_Html_messenger__get_validator_config',  | 
                                                        |
| 52 | - array($this, 'html_messenger_validator_config'),  | 
                                                        |
| 53 | - 5,  | 
                                                        |
| 54 | - 2  | 
                                                        |
| 55 | - );  | 
                                                        |
| 56 | -        add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); | 
                                                        |
| 57 | - add_filter(  | 
                                                        |
| 58 | - 'FHEE__EE_Pdf_messenger__get_validator_config',  | 
                                                        |
| 59 | - array($this, 'pdf_messenger_validator_config'),  | 
                                                        |
| 60 | - 5,  | 
                                                        |
| 61 | - 2  | 
                                                        |
| 62 | - );  | 
                                                        |
| 63 | - add_filter(  | 
                                                        |
| 64 | - 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',  | 
                                                        |
| 65 | - array($this, 'new_default_templates'),  | 
                                                        |
| 66 | - 5,  | 
                                                        |
| 67 | - 7  | 
                                                        |
| 68 | - );  | 
                                                        |
| 69 | - add_filter(  | 
                                                        |
| 70 | - 'FHEE__EE_Messages_Base__get_valid_shortcodes',  | 
                                                        |
| 71 | - array($this, 'message_types_valid_shortcodes'),  | 
                                                        |
| 72 | - 5,  | 
                                                        |
| 73 | - 2  | 
                                                        |
| 74 | - );  | 
                                                        |
| 75 | -  | 
                                                        |
| 76 | - // shortcode parsers  | 
                                                        |
| 77 | -        add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); | 
                                                        |
| 78 | -        add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); | 
                                                        |
| 79 | - add_filter(  | 
                                                        |
| 80 | - 'FHEE__EE_Recipient_List_Shortcodes__shortcodes',  | 
                                                        |
| 81 | - array($this, 'additional_recipient_details_shortcodes'),  | 
                                                        |
| 82 | - 5,  | 
                                                        |
| 83 | - 2  | 
                                                        |
| 84 | - );  | 
                                                        |
| 85 | - add_filter(  | 
                                                        |
| 86 | - 'FHEE__EE_Recipient_List_Shortcodes__parser_after',  | 
                                                        |
| 87 | - array($this, 'additional_recipient_details_parser'),  | 
                                                        |
| 88 | - 5,  | 
                                                        |
| 89 | - 5  | 
                                                        |
| 90 | - );  | 
                                                        |
| 91 | - add_filter(  | 
                                                        |
| 92 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',  | 
                                                        |
| 93 | - array($this, 'additional_primary_registration_details_shortcodes'),  | 
                                                        |
| 94 | - 5,  | 
                                                        |
| 95 | - 2  | 
                                                        |
| 96 | - );  | 
                                                        |
| 97 | - add_filter(  | 
                                                        |
| 98 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',  | 
                                                        |
| 99 | - array($this, 'additional_primary_registration_details_parser'),  | 
                                                        |
| 100 | - 5,  | 
                                                        |
| 101 | - 5  | 
                                                        |
| 102 | - );  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - /**  | 
                                                        |
| 105 | - * @since 4.2.0  | 
                                                        |
| 106 | - */  | 
                                                        |
| 107 | -        add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); | 
                                                        |
| 108 | -        add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); | 
                                                        |
| 109 | -  | 
                                                        |
| 110 | - /**  | 
                                                        |
| 111 | - * @since 4.3.0  | 
                                                        |
| 112 | - */  | 
                                                        |
| 113 | - // eat our own dog food!  | 
                                                        |
| 114 | -        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); | 
                                                        |
| 115 | -        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); | 
                                                        |
| 116 | -        do_action('EE_Brewing_Regular___messages_caf'); | 
                                                        |
| 117 | - }  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | -  | 
                                                        |
| 120 | - /**  | 
                                                        |
| 121 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the  | 
                                                        |
| 122 | - * messages system.  | 
                                                        |
| 123 | - *  | 
                                                        |
| 124 | - * @param array $dir_ref original array of paths  | 
                                                        |
| 125 | - *  | 
                                                        |
| 126 | - * @return array appended paths  | 
                                                        |
| 127 | - */  | 
                                                        |
| 128 | - public function messages_autoload_paths($dir_ref)  | 
                                                        |
| 129 | -    { | 
                                                        |
| 130 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';  | 
                                                        |
| 131 | -  | 
                                                        |
| 132 | - return $dir_ref;  | 
                                                        |
| 133 | - }  | 
                                                        |
| 134 | -  | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)  | 
                                                        |
| 137 | -    { | 
                                                        |
| 138 | - $validator_config['attendee_list'] = array(  | 
                                                        |
| 139 | -            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), | 
                                                        |
| 140 | -            'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 141 | - );  | 
                                                        |
| 142 | - $validator_config['question_list'] = array(  | 
                                                        |
| 143 | -            'shortcodes' => array('question'), | 
                                                        |
| 144 | -            'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 145 | - );  | 
                                                        |
| 146 | -  | 
                                                        |
| 147 | - return $validator_config;  | 
                                                        |
| 148 | - }  | 
                                                        |
| 149 | -  | 
                                                        |
| 150 | -  | 
                                                        |
| 151 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)  | 
                                                        |
| 152 | -    { | 
                                                        |
| 153 | - $validator_config['attendee_list'] = array(  | 
                                                        |
| 154 | -            'shortcodes' => array('attendee', 'question_list'), | 
                                                        |
| 155 | -            'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 156 | - );  | 
                                                        |
| 157 | - $validator_config['question_list'] = array(  | 
                                                        |
| 158 | -            'shortcodes' => array('question'), | 
                                                        |
| 159 | -            'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 160 | - );  | 
                                                        |
| 161 | -  | 
                                                        |
| 162 | - return $validator_config;  | 
                                                        |
| 163 | - }  | 
                                                        |
| 164 | -  | 
                                                        |
| 165 | -  | 
                                                        |
| 166 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)  | 
                                                        |
| 167 | -    { | 
                                                        |
| 168 | - $validator_config['attendee_list'] = array(  | 
                                                        |
| 169 | -            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), | 
                                                        |
| 170 | -            'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 171 | - );  | 
                                                        |
| 172 | - $validator_config['question_list'] = array(  | 
                                                        |
| 173 | -            'shortcodes' => array('question'), | 
                                                        |
| 174 | -            'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 175 | - );  | 
                                                        |
| 176 | -  | 
                                                        |
| 177 | - return $validator_config;  | 
                                                        |
| 178 | - }  | 
                                                        |
| 179 | -  | 
                                                        |
| 180 | -  | 
                                                        |
| 181 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)  | 
                                                        |
| 182 | -    { | 
                                                        |
| 183 | - $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 184 | - 'input' => 'textarea',  | 
                                                        |
| 185 | - 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 186 | - 'type' => 'string',  | 
                                                        |
| 187 | - 'required' => false,  | 
                                                        |
| 188 | - 'validation' => true,  | 
                                                        |
| 189 | - 'format' => '%s',  | 
                                                        |
| 190 | - 'css_class' => 'large-text',  | 
                                                        |
| 191 | - 'rows' => '5',  | 
                                                        |
| 192 | -            'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 193 | - );  | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | - return $template_fields;  | 
                                                        |
| 196 | - }  | 
                                                        |
| 197 | -  | 
                                                        |
| 198 | -  | 
                                                        |
| 199 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)  | 
                                                        |
| 200 | -    { | 
                                                        |
| 201 | - $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 202 | - 'input' => 'textarea',  | 
                                                        |
| 203 | - 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 204 | - 'type' => 'string',  | 
                                                        |
| 205 | - 'required' => false,  | 
                                                        |
| 206 | - 'validation' => true,  | 
                                                        |
| 207 | - 'format' => '%s',  | 
                                                        |
| 208 | - 'css_class' => 'large-text',  | 
                                                        |
| 209 | - 'rows' => '5',  | 
                                                        |
| 210 | -            'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 211 | - );  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - return $template_fields;  | 
                                                        |
| 214 | - }  | 
                                                        |
| 215 | -  | 
                                                        |
| 216 | -  | 
                                                        |
| 217 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)  | 
                                                        |
| 218 | -    { | 
                                                        |
| 219 | - $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 220 | - 'input' => 'textarea',  | 
                                                        |
| 221 | - 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 222 | - 'type' => 'string',  | 
                                                        |
| 223 | - 'required' => false,  | 
                                                        |
| 224 | - 'validation' => true,  | 
                                                        |
| 225 | - 'format' => '%s',  | 
                                                        |
| 226 | - 'css_class' => 'large-text',  | 
                                                        |
| 227 | - 'rows' => '5',  | 
                                                        |
| 228 | -            'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 229 | - );  | 
                                                        |
| 230 | -  | 
                                                        |
| 231 | - return $template_fields;  | 
                                                        |
| 232 | - }  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | -  | 
                                                        |
| 235 | - public function new_default_templates(  | 
                                                        |
| 236 | - $contents,  | 
                                                        |
| 237 | - $actual_path,  | 
                                                        |
| 238 | - EE_messenger $messenger,  | 
                                                        |
| 239 | - EE_message_type $message_type,  | 
                                                        |
| 240 | - $field,  | 
                                                        |
| 241 | - $context,  | 
                                                        |
| 242 | - EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 243 | -    ) { | 
                                                        |
| 244 | -  | 
                                                        |
| 245 | - // we're only modifying templates for the default template pack  | 
                                                        |
| 246 | -        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { | 
                                                        |
| 247 | - return $contents;  | 
                                                        |
| 248 | - }  | 
                                                        |
| 249 | -  | 
                                                        |
| 250 | - // the template file name we're replacing contents for.  | 
                                                        |
| 251 | - $template_file_prefix = $field . '_' . $context;  | 
                                                        |
| 252 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_';  | 
                                                        |
| 253 | -  | 
                                                        |
| 254 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';  | 
                                                        |
| 255 | -  | 
                                                        |
| 256 | -        if ($messenger->name == 'email' && $message_type->name == 'registration') { | 
                                                        |
| 257 | -            switch ($template_file_prefix) { | 
                                                        |
| 258 | - case 'question_list_admin':  | 
                                                        |
| 259 | - case 'question_list_attendee':  | 
                                                        |
| 260 | - case 'question_list_primary_attendee':  | 
                                                        |
| 261 | - $path = $base_path . $msg_prefix . 'question_list.template.php';  | 
                                                        |
| 262 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 263 | - break;  | 
                                                        |
| 264 | -  | 
                                                        |
| 265 | - case 'attendee_list_primary_attendee':  | 
                                                        |
| 266 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php';  | 
                                                        |
| 267 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 268 | - break;  | 
                                                        |
| 269 | -  | 
                                                        |
| 270 | - case 'attendee_list_admin':  | 
                                                        |
| 271 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';  | 
                                                        |
| 272 | - $contents = EEH_Template::display_template(  | 
                                                        |
| 273 | - $path,  | 
                                                        |
| 274 | - array(),  | 
                                                        |
| 275 | - true  | 
                                                        |
| 276 | - );  | 
                                                        |
| 277 | - break;  | 
                                                        |
| 278 | -  | 
                                                        |
| 279 | - case 'attendee_list_attendee':  | 
                                                        |
| 280 | - $contents = '';  | 
                                                        |
| 281 | - break;  | 
                                                        |
| 282 | -  | 
                                                        |
| 283 | - case 'event_list_attendee':  | 
                                                        |
| 284 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';  | 
                                                        |
| 285 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 286 | - break;  | 
                                                        |
| 287 | - }  | 
                                                        |
| 288 | -        } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { | 
                                                        |
| 289 | -            switch ($template_file_prefix) { | 
                                                        |
| 290 | - case 'content_attendee':  | 
                                                        |
| 291 | - $path = $base_path . $msg_prefix . 'content.template.php';  | 
                                                        |
| 292 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 293 | - break;  | 
                                                        |
| 294 | -  | 
                                                        |
| 295 | - case 'newsletter_content_attendee':  | 
                                                        |
| 296 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php';  | 
                                                        |
| 297 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 298 | - break;  | 
                                                        |
| 299 | -  | 
                                                        |
| 300 | - case 'newsletter_subject_attendee':  | 
                                                        |
| 301 | - $path = $base_path . $msg_prefix . 'subject.template.php';  | 
                                                        |
| 302 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 303 | - break;  | 
                                                        |
| 304 | - }  | 
                                                        |
| 305 | -        } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { | 
                                                        |
| 306 | -            switch ($template_file_prefix) { | 
                                                        |
| 307 | - case 'attendee_list_purchaser':  | 
                                                        |
| 308 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php';  | 
                                                        |
| 309 | - $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 310 | - break;  | 
                                                        |
| 311 | - }  | 
                                                        |
| 312 | - }  | 
                                                        |
| 313 | -  | 
                                                        |
| 314 | - return $contents;  | 
                                                        |
| 315 | - }  | 
                                                        |
| 316 | -  | 
                                                        |
| 317 | -  | 
                                                        |
| 318 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)  | 
                                                        |
| 319 | -    { | 
                                                        |
| 320 | - // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode.  | 
                                                        |
| 321 | - $include_with = array(  | 
                                                        |
| 322 | - 'registration',  | 
                                                        |
| 323 | - 'cancelled_registration',  | 
                                                        |
| 324 | - 'declined_registration',  | 
                                                        |
| 325 | - 'not_approved_registration',  | 
                                                        |
| 326 | - 'payment_declined',  | 
                                                        |
| 327 | - 'payment_failed',  | 
                                                        |
| 328 | - 'payment_cancelled',  | 
                                                        |
| 329 | - 'payment',  | 
                                                        |
| 330 | - 'payment_reminder',  | 
                                                        |
| 331 | - 'pending_approval',  | 
                                                        |
| 332 | - 'registration_summary',  | 
                                                        |
| 333 | - 'invoice',  | 
                                                        |
| 334 | - 'receipt',  | 
                                                        |
| 335 | - );  | 
                                                        |
| 336 | -        if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { | 
                                                        |
| 337 | - $contexts = array_keys($msg->get_contexts());  | 
                                                        |
| 338 | -            foreach ($contexts as $context) { | 
                                                        |
| 339 | - $valid_shortcodes[ $context ][] = 'question_list';  | 
                                                        |
| 340 | - $valid_shortcodes[ $context ][] = 'question';  | 
                                                        |
| 341 | - }  | 
                                                        |
| 342 | - }  | 
                                                        |
| 343 | -  | 
                                                        |
| 344 | - return $valid_shortcodes;  | 
                                                        |
| 345 | - }  | 
                                                        |
| 346 | -  | 
                                                        |
| 347 | -  | 
                                                        |
| 348 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 349 | -    { | 
                                                        |
| 350 | - $shortcodes['[ANSWER_*]'] = esc_html__(  | 
                                                        |
| 351 | - 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',  | 
                                                        |
| 352 | - 'event_espresso'  | 
                                                        |
| 353 | - );  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | - return $shortcodes;  | 
                                                        |
| 356 | - }  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | -  | 
                                                        |
| 359 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 360 | -    { | 
                                                        |
| 361 | -  | 
                                                        |
| 362 | - if (  | 
                                                        |
| 363 | - strpos($shortcode, '[ANSWER_*') === false  | 
                                                        |
| 364 | - || ! isset($extra_data['data']->questions)  | 
                                                        |
| 365 | - || ! isset($extra_data['data']->registrations)  | 
                                                        |
| 366 | -        ) { | 
                                                        |
| 367 | - return $parsed;  | 
                                                        |
| 368 | - }  | 
                                                        |
| 369 | -  | 
                                                        |
| 370 | - // let's get the question from the code.  | 
                                                        |
| 371 | -        $shortcode = str_replace('[ANSWER_*', '', $shortcode); | 
                                                        |
| 372 | -        $shortcode = trim(str_replace(']', '', $shortcode)); | 
                                                        |
| 373 | -  | 
                                                        |
| 374 | - $registration = $data instanceof EE_Registration ? $data : null;  | 
                                                        |
| 375 | - $registration = ! $registration instanceof EE_Registration && is_array(  | 
                                                        |
| 376 | - $extra_data  | 
                                                        |
| 377 | - ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;  | 
                                                        |
| 378 | -  | 
                                                        |
| 379 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null;  | 
                                                        |
| 380 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array(  | 
                                                        |
| 381 | - $extra_data  | 
                                                        |
| 382 | - ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;  | 
                                                        |
| 383 | -  | 
                                                        |
| 384 | -        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { | 
                                                        |
| 385 | - return $parsed;  | 
                                                        |
| 386 | - }  | 
                                                        |
| 387 | -  | 
                                                        |
| 388 | - // now let's figure out which question has this text.  | 
                                                        |
| 389 | -        foreach ($aee->questions as $ansid => $question) { | 
                                                        |
| 390 | - if (  | 
                                                        |
| 391 | - $question instanceof EE_Question  | 
                                                        |
| 392 | - && trim($question->display_text()) == trim($shortcode)  | 
                                                        |
| 393 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])  | 
                                                        |
| 394 | -            ) { | 
                                                        |
| 395 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(  | 
                                                        |
| 396 | - 'ANS_value',  | 
                                                        |
| 397 | - 'no_wpautop'  | 
                                                        |
| 398 | - );  | 
                                                        |
| 399 | - }  | 
                                                        |
| 400 | - }  | 
                                                        |
| 401 | -  | 
                                                        |
| 402 | - // nothing!  | 
                                                        |
| 403 | - return $parsed;  | 
                                                        |
| 404 | - }  | 
                                                        |
| 405 | -  | 
                                                        |
| 406 | -  | 
                                                        |
| 407 | - /**  | 
                                                        |
| 408 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes.  | 
                                                        |
| 409 | - *  | 
                                                        |
| 410 | - * @since 4.2  | 
                                                        |
| 411 | - *  | 
                                                        |
| 412 | - * @param array $shortcodes array of shortcodes and  | 
                                                        |
| 413 | - * descriptions  | 
                                                        |
| 414 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object  | 
                                                        |
| 415 | - *  | 
                                                        |
| 416 | - * @return array array of shortcodes and  | 
                                                        |
| 417 | - * descriptions  | 
                                                        |
| 418 | - */  | 
                                                        |
| 419 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 420 | -    { | 
                                                        |
| 421 | - $shortcodes['[DTT_NAME]'] = esc_html__(  | 
                                                        |
| 422 | - 'This will be parsed to the Title given for a Datetime',  | 
                                                        |
| 423 | - 'event_espresso'  | 
                                                        |
| 424 | - );  | 
                                                        |
| 425 | - $shortcodes['[DTT_DESCRIPTION]'] = esc_html__(  | 
                                                        |
| 426 | - 'This will be parsed to the description for a Datetime',  | 
                                                        |
| 427 | - 'event_espresso'  | 
                                                        |
| 428 | - );  | 
                                                        |
| 429 | - $shortcodes['[DTT_NAME_OR_DATES]'] = esc_html__(  | 
                                                        |
| 430 | - 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',  | 
                                                        |
| 431 | - 'event_espresso'  | 
                                                        |
| 432 | - );  | 
                                                        |
| 433 | -  | 
                                                        |
| 434 | - return $shortcodes;  | 
                                                        |
| 435 | - }  | 
                                                        |
| 436 | -  | 
                                                        |
| 437 | -  | 
                                                        |
| 438 | - /**  | 
                                                        |
| 439 | - * Callback for additional shortcodes parser filter used for adding parser for new  | 
                                                        |
| 440 | - * Datetime shortcodes  | 
                                                        |
| 441 | - *  | 
                                                        |
| 442 | - * @since 4.2  | 
                                                        |
| 443 | - *  | 
                                                        |
| 444 | - * @param string $parsed The finished parsed string for the given shortcode.  | 
                                                        |
| 445 | - * @param string $shortcode The shortcode being parsed.  | 
                                                        |
| 446 | - * @param object $data The incoming data object for the Shortcode Parser.  | 
                                                        |
| 447 | - * @param object $extra_data The incoming extra date object for the Shortcode  | 
                                                        |
| 448 | - * Parser.  | 
                                                        |
| 449 | - * @param EE_Datetime_Shortcodes $shortcode_parser  | 
                                                        |
| 450 | - *  | 
                                                        |
| 451 | - * @return string The new parsed string.  | 
                                                        |
| 452 | - */  | 
                                                        |
| 453 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 454 | -    { | 
                                                        |
| 455 | -  | 
                                                        |
| 456 | -        if (! $data instanceof EE_Datetime) { | 
                                                        |
| 457 | - return ''; // get out because we can only parse with the datetime object.  | 
                                                        |
| 458 | - }  | 
                                                        |
| 459 | -  | 
                                                        |
| 460 | -        switch ($shortcode) { | 
                                                        |
| 461 | - case '[DTT_NAME]':  | 
                                                        |
| 462 | - return $data->name();  | 
                                                        |
| 463 | - break;  | 
                                                        |
| 464 | - case '[DTT_DESCRIPTION]':  | 
                                                        |
| 465 | - return $data->description();  | 
                                                        |
| 466 | - break;  | 
                                                        |
| 467 | - case '[DTT_NAME_OR_DATES]':  | 
                                                        |
| 468 | - return $data->get_dtt_display_name(true);  | 
                                                        |
| 469 | - break;  | 
                                                        |
| 470 | - default:  | 
                                                        |
| 471 | - return $parsed;  | 
                                                        |
| 472 | - break;  | 
                                                        |
| 473 | - }  | 
                                                        |
| 474 | - }  | 
                                                        |
| 475 | -  | 
                                                        |
| 476 | -  | 
                                                        |
| 477 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 478 | -    { | 
                                                        |
| 479 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = esc_html__(  | 
                                                        |
| 480 | - 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',  | 
                                                        |
| 481 | - 'event_espresso'  | 
                                                        |
| 482 | - );  | 
                                                        |
| 483 | -  | 
                                                        |
| 484 | - return $shortcodes;  | 
                                                        |
| 485 | - }  | 
                                                        |
| 486 | -  | 
                                                        |
| 487 | -  | 
                                                        |
| 488 | - /**  | 
                                                        |
| 489 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).  | 
                                                        |
| 490 | - *  | 
                                                        |
| 491 | - * @param string $parsed The original parsed content for the shortcode  | 
                                                        |
| 492 | - * @param string $shortcode The shortcode being parsed  | 
                                                        |
| 493 | - * @param array $data The shortcode parser data array  | 
                                                        |
| 494 | - * @param array $extra_data The shortcode parser extra data array  | 
                                                        |
| 495 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser.  | 
                                                        |
| 496 | - *  | 
                                                        |
| 497 | - * @return string  | 
                                                        |
| 498 | - */  | 
                                                        |
| 499 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 500 | -    { | 
                                                        |
| 501 | -  | 
                                                        |
| 502 | -        if (array($data) && ! isset($data['data'])) { | 
                                                        |
| 503 | - return $parsed;  | 
                                                        |
| 504 | - }  | 
                                                        |
| 505 | -  | 
                                                        |
| 506 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;  | 
                                                        |
| 507 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;  | 
                                                        |
| 508 | -  | 
                                                        |
| 509 | -        if (! $recipient instanceof EE_Messages_Addressee) { | 
                                                        |
| 510 | - return $parsed;  | 
                                                        |
| 511 | - }  | 
                                                        |
| 512 | -  | 
                                                        |
| 513 | -        switch ($shortcode) { | 
                                                        |
| 514 | - case '[RECIPIENT_QUESTION_LIST]':  | 
                                                        |
| 515 | - $att = $recipient->att_obj;  | 
                                                        |
| 516 | - $registrations_on_attendee = $att instanceof EE_Attendee  | 
                                                        |
| 517 | - ? $recipient->attendees[ $att->ID() ]['reg_objs']  | 
                                                        |
| 518 | - : array();  | 
                                                        |
| 519 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;  | 
                                                        |
| 520 | - $answers = array();  | 
                                                        |
| 521 | -  | 
                                                        |
| 522 | - $template = is_array($data['template']) && isset($data['template']['question_list'])  | 
                                                        |
| 523 | - ? $data['template']['question_list']  | 
                                                        |
| 524 | - : $extra_data['template']['question_list'];  | 
                                                        |
| 525 | -                $valid_shortcodes = array('question'); | 
                                                        |
| 526 | -  | 
                                                        |
| 527 | - // if the context is main_content then get all answers for all registrations on this attendee  | 
                                                        |
| 528 | -                if ($data['data'] instanceof EE_Messages_Addressee) { | 
                                                        |
| 529 | -                    foreach ($registrations_on_attendee as $reg) { | 
                                                        |
| 530 | -                        if ($reg instanceof EE_Registration) { | 
                                                        |
| 531 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])  | 
                                                        |
| 532 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs']  | 
                                                        |
| 533 | - : array();  | 
                                                        |
| 534 | -                            foreach ($anss as $ans) { | 
                                                        |
| 535 | -                                if ($ans instanceof EE_Answer) { | 
                                                        |
| 536 | - $answers[ $ans->ID() ] = $ans;  | 
                                                        |
| 537 | - }  | 
                                                        |
| 538 | - }  | 
                                                        |
| 539 | - }  | 
                                                        |
| 540 | - }  | 
                                                        |
| 541 | - }  | 
                                                        |
| 542 | -  | 
                                                        |
| 543 | - // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.  | 
                                                        |
| 544 | -                if ($data['data'] instanceof EE_Event) { | 
                                                        |
| 545 | - $event = $data['data'];  | 
                                                        |
| 546 | -                    foreach ($registrations_on_attendee as $reg) { | 
                                                        |
| 547 | -                        if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { | 
                                                        |
| 548 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])  | 
                                                        |
| 549 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs']  | 
                                                        |
| 550 | - : array();  | 
                                                        |
| 551 | -                            foreach ($anss as $ans) { | 
                                                        |
| 552 | -                                if ($ans instanceof EE_Answer) { | 
                                                        |
| 553 | - $answers[ $ans->ID() ] = $ans;  | 
                                                        |
| 554 | - }  | 
                                                        |
| 555 | - }  | 
                                                        |
| 556 | - }  | 
                                                        |
| 557 | - }  | 
                                                        |
| 558 | - }  | 
                                                        |
| 559 | -  | 
                                                        |
| 560 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();  | 
                                                        |
| 561 | -  | 
                                                        |
| 562 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee  | 
                                                        |
| 563 | - // object on it.  | 
                                                        |
| 564 | -                if (! isset($extra_data['data'])) { | 
                                                        |
| 565 | - $extra_data['data'] = $recipient;  | 
                                                        |
| 566 | - }  | 
                                                        |
| 567 | -  | 
                                                        |
| 568 | - return $this->_parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 569 | - $shortcode_parser,  | 
                                                        |
| 570 | - $questions,  | 
                                                        |
| 571 | - $answers,  | 
                                                        |
| 572 | - $template,  | 
                                                        |
| 573 | - $valid_shortcodes,  | 
                                                        |
| 574 | - $extra_data  | 
                                                        |
| 575 | - );  | 
                                                        |
| 576 | - break;  | 
                                                        |
| 577 | -  | 
                                                        |
| 578 | - default:  | 
                                                        |
| 579 | - return $parsed;  | 
                                                        |
| 580 | - break;  | 
                                                        |
| 581 | - }  | 
                                                        |
| 582 | - }  | 
                                                        |
| 583 | -  | 
                                                        |
| 584 | -  | 
                                                        |
| 585 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 586 | -    { | 
                                                        |
| 587 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = esc_html__(  | 
                                                        |
| 588 | - 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',  | 
                                                        |
| 589 | - 'event_espresso'  | 
                                                        |
| 590 | - );  | 
                                                        |
| 591 | -  | 
                                                        |
| 592 | - return $shortcodes;  | 
                                                        |
| 593 | - }  | 
                                                        |
| 594 | -  | 
                                                        |
| 595 | -  | 
                                                        |
| 596 | - /**  | 
                                                        |
| 597 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).  | 
                                                        |
| 598 | - *  | 
                                                        |
| 599 | - * @param string $parsed The original parsed content for the shortcode  | 
                                                        |
| 600 | - * @param string $shortcode The shortcode being parsed  | 
                                                        |
| 601 | - * @param array $data The shortcode parser data array  | 
                                                        |
| 602 | - * @param array $extra_data The shortcode parser extra data array  | 
                                                        |
| 603 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser.  | 
                                                        |
| 604 | - *  | 
                                                        |
| 605 | - * @return string  | 
                                                        |
| 606 | - */  | 
                                                        |
| 607 | - public function additional_primary_registration_details_parser(  | 
                                                        |
| 608 | - $parsed,  | 
                                                        |
| 609 | - $shortcode,  | 
                                                        |
| 610 | - $data,  | 
                                                        |
| 611 | - $extra_data,  | 
                                                        |
| 612 | - $shortcode_parser  | 
                                                        |
| 613 | -    ) { | 
                                                        |
| 614 | -        if (array($data) && ! isset($data['data'])) { | 
                                                        |
| 615 | - return $parsed;  | 
                                                        |
| 616 | - }  | 
                                                        |
| 617 | -  | 
                                                        |
| 618 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;  | 
                                                        |
| 619 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;  | 
                                                        |
| 620 | -  | 
                                                        |
| 621 | -        if (! $recipient instanceof EE_Messages_Addressee) { | 
                                                        |
| 622 | - return $parsed;  | 
                                                        |
| 623 | - }  | 
                                                        |
| 624 | -  | 
                                                        |
| 625 | -        switch ($shortcode) { | 
                                                        |
| 626 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]':  | 
                                                        |
| 627 | -                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { | 
                                                        |
| 628 | - return '';  | 
                                                        |
| 629 | - }  | 
                                                        |
| 630 | - $registration = $recipient->primary_reg_obj;  | 
                                                        |
| 631 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])  | 
                                                        |
| 632 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs']  | 
                                                        |
| 633 | - : array();  | 
                                                        |
| 634 | -                if (empty($answers)) { | 
                                                        |
| 635 | - return '';  | 
                                                        |
| 636 | - }  | 
                                                        |
| 637 | - $template = is_array($data['template']) && isset($data['template']['question_list'])  | 
                                                        |
| 638 | - ? $data['template']['question_list']  | 
                                                        |
| 639 | - : $extra_data['template']['question_list'];  | 
                                                        |
| 640 | -                $valid_shortcodes = array('question'); | 
                                                        |
| 641 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];  | 
                                                        |
| 642 | - $questions = isset($recipient->questions) ? $recipient->questions : array();  | 
                                                        |
| 643 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee  | 
                                                        |
| 644 | - // object on it.  | 
                                                        |
| 645 | -                if (! isset($extra_data['data'])) { | 
                                                        |
| 646 | - $extra_data['data'] = $recipient;  | 
                                                        |
| 647 | - }  | 
                                                        |
| 648 | - return $this->_parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 649 | - $shortcode_parser,  | 
                                                        |
| 650 | - $questions,  | 
                                                        |
| 651 | - $answers,  | 
                                                        |
| 652 | - $template,  | 
                                                        |
| 653 | - $valid_shortcodes,  | 
                                                        |
| 654 | - $extra_data  | 
                                                        |
| 655 | - );  | 
                                                        |
| 656 | - break;  | 
                                                        |
| 657 | -  | 
                                                        |
| 658 | - default:  | 
                                                        |
| 659 | - return $parsed;  | 
                                                        |
| 660 | - break;  | 
                                                        |
| 661 | - }  | 
                                                        |
| 662 | - }  | 
                                                        |
| 663 | -  | 
                                                        |
| 664 | -  | 
                                                        |
| 665 | - /**  | 
                                                        |
| 666 | - * Takes care of registering the message types that are only available in caffeinated EE.  | 
                                                        |
| 667 | - *  | 
                                                        |
| 668 | - * @since 4.3.2  | 
                                                        |
| 669 | - *  | 
                                                        |
| 670 | - * @return void  | 
                                                        |
| 671 | - */  | 
                                                        |
| 672 | - public function register_caf_message_types()  | 
                                                        |
| 673 | -    { | 
                                                        |
| 674 | - // register newsletter message type  | 
                                                        |
| 675 | - $setup_args = array(  | 
                                                        |
| 676 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php',  | 
                                                        |
| 677 | - 'autoloadpaths' => array(  | 
                                                        |
| 678 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',  | 
                                                        |
| 679 | - ),  | 
                                                        |
| 680 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 681 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 682 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 683 | - );  | 
                                                        |
| 684 | -        EE_Register_Message_Type::register('newsletter', $setup_args); | 
                                                        |
| 685 | -  | 
                                                        |
| 686 | - // register payment reminder message type  | 
                                                        |
| 687 | - $setup_args = array(  | 
                                                        |
| 688 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php',  | 
                                                        |
| 689 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),  | 
                                                        |
| 690 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 691 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 692 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 693 | - );  | 
                                                        |
| 694 | -        EE_Register_Message_Type::register('payment_reminder', $setup_args); | 
                                                        |
| 695 | -  | 
                                                        |
| 696 | - // register payment declined message type  | 
                                                        |
| 697 | - $setup_args = array(  | 
                                                        |
| 698 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php',  | 
                                                        |
| 699 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),  | 
                                                        |
| 700 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 701 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 702 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 703 | - );  | 
                                                        |
| 704 | -        EE_Register_Message_Type::register('payment_declined', $setup_args); | 
                                                        |
| 705 | -  | 
                                                        |
| 706 | - // register registration declined message type  | 
                                                        |
| 707 | - $setup_args = array(  | 
                                                        |
| 708 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php',  | 
                                                        |
| 709 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),  | 
                                                        |
| 710 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 711 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 712 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 713 | - );  | 
                                                        |
| 714 | -        EE_Register_Message_Type::register('declined_registration', $setup_args); | 
                                                        |
| 715 | -  | 
                                                        |
| 716 | - // register registration cancelled message type  | 
                                                        |
| 717 | - $setup_args = array(  | 
                                                        |
| 718 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php',  | 
                                                        |
| 719 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),  | 
                                                        |
| 720 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 721 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 722 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 723 | - );  | 
                                                        |
| 724 | -        EE_Register_Message_Type::register('cancelled_registration', $setup_args); | 
                                                        |
| 725 | -  | 
                                                        |
| 726 | -  | 
                                                        |
| 727 | - // register payment failed message type  | 
                                                        |
| 728 | - $setup_args = array(  | 
                                                        |
| 729 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php',  | 
                                                        |
| 730 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),  | 
                                                        |
| 731 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 732 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 733 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 734 | - );  | 
                                                        |
| 735 | -        EE_Register_Message_Type::register('payment_failed', $setup_args); | 
                                                        |
| 736 | -  | 
                                                        |
| 737 | - // register payment declined message type  | 
                                                        |
| 738 | - $setup_args = array(  | 
                                                        |
| 739 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php',  | 
                                                        |
| 740 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),  | 
                                                        |
| 741 | -            'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 742 | -            'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 743 | -            'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 744 | - );  | 
                                                        |
| 745 | -        EE_Register_Message_Type::register('payment_cancelled', $setup_args); | 
                                                        |
| 746 | - }  | 
                                                        |
| 747 | -  | 
                                                        |
| 748 | -  | 
                                                        |
| 749 | - /**  | 
                                                        |
| 750 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items.  | 
                                                        |
| 751 | - *  | 
                                                        |
| 752 | - * @since 4.3.2  | 
                                                        |
| 753 | - *  | 
                                                        |
| 754 | - * @return void  | 
                                                        |
| 755 | - */  | 
                                                        |
| 756 | - public function register_caf_shortcodes()  | 
                                                        |
| 757 | -    { | 
                                                        |
| 758 | - $setup_args = array(  | 
                                                        |
| 759 | - 'autoloadpaths' => array(  | 
                                                        |
| 760 | - EE_CAF_LIBRARIES . 'shortcodes/',  | 
                                                        |
| 761 | - ),  | 
                                                        |
| 762 | -            'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), | 
                                                        |
| 763 | -            'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), | 
                                                        |
| 764 | -            'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'), | 
                                                        |
| 765 | - );  | 
                                                        |
| 766 | -        EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); | 
                                                        |
| 767 | - }  | 
                                                        |
| 768 | -  | 
                                                        |
| 769 | -  | 
                                                        |
| 770 | - /**  | 
                                                        |
| 771 | - * Parses a question list shortcode using given data and template  | 
                                                        |
| 772 | - *  | 
                                                        |
| 773 | - * @param \EE_Shortcodes $shortcode_parser  | 
                                                        |
| 774 | - * @param EE_Question[] $questions An array of questions indexed by answer id.  | 
                                                        |
| 775 | - * @param EE_Answer[] $answers An array of answer objects  | 
                                                        |
| 776 | - * @param string $template Template content to be parsed.  | 
                                                        |
| 777 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed.  | 
                                                        |
| 778 | - * @param array $extra_data Extra data that might be used when parsing the template.  | 
                                                        |
| 779 | - */  | 
                                                        |
| 780 | - protected function _parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 781 | - $shortcode_parser,  | 
                                                        |
| 782 | - $questions,  | 
                                                        |
| 783 | - $answers,  | 
                                                        |
| 784 | - $template,  | 
                                                        |
| 785 | - $valid_shortcodes,  | 
                                                        |
| 786 | - $extra_data  | 
                                                        |
| 787 | -    ) { | 
                                                        |
| 788 | - $question_list = '';  | 
                                                        |
| 789 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */  | 
                                                        |
| 790 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper();  | 
                                                        |
| 791 | -        foreach ($answers as $answer) { | 
                                                        |
| 792 | -            if ($answer instanceof EE_Answer) { | 
                                                        |
| 793 | - // first see if the question is in our $questions array. If not then try to get from answer object.  | 
                                                        |
| 794 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;  | 
                                                        |
| 795 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question;  | 
                                                        |
| 796 | - if (  | 
                                                        |
| 797 | - ! $question instanceof EE_Question  | 
                                                        |
| 798 | - || (  | 
                                                        |
| 799 | - $question instanceof EE_Question  | 
                                                        |
| 800 | - && $question->admin_only()  | 
                                                        |
| 801 | - )  | 
                                                        |
| 802 | -                ) { | 
                                                        |
| 803 | - continue;  | 
                                                        |
| 804 | - }  | 
                                                        |
| 805 | - $question_list .= $shortcode_helper->parse_question_list_template(  | 
                                                        |
| 806 | - $template,  | 
                                                        |
| 807 | - $answer,  | 
                                                        |
| 808 | - $valid_shortcodes,  | 
                                                        |
| 809 | - $extra_data  | 
                                                        |
| 810 | - );  | 
                                                        |
| 811 | - }  | 
                                                        |
| 812 | - }  | 
                                                        |
| 813 | - return $question_list;  | 
                                                        |
| 814 | - }  | 
                                                        |
| 13 | + /**  | 
                                                        |
| 14 | + * constructor.  | 
                                                        |
| 15 | + */  | 
                                                        |
| 16 | + public function __construct()  | 
                                                        |
| 17 | +	{ | 
                                                        |
| 18 | + $this->_caf_hooks();  | 
                                                        |
| 19 | + }  | 
                                                        |
| 20 | +  | 
                                                        |
| 21 | +  | 
                                                        |
| 22 | + /**  | 
                                                        |
| 23 | + * Contains all the hooks filters for setting up caffeinated messages functionality.  | 
                                                        |
| 24 | + *  | 
                                                        |
| 25 | + * @since 4.3.2  | 
                                                        |
| 26 | + *  | 
                                                        |
| 27 | + * @return void  | 
                                                        |
| 28 | + */  | 
                                                        |
| 29 | + private function _caf_hooks()  | 
                                                        |
| 30 | +	{ | 
                                                        |
| 31 | +		add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); | 
                                                        |
| 32 | + add_filter(  | 
                                                        |
| 33 | + 'FHEE__EE_Email_messenger__get_validator_config',  | 
                                                        |
| 34 | + array($this, 'email_messenger_validator_config'),  | 
                                                        |
| 35 | + 5,  | 
                                                        |
| 36 | + 2  | 
                                                        |
| 37 | + );  | 
                                                        |
| 38 | + add_filter(  | 
                                                        |
| 39 | + 'FHEE__EE_Email_messenger__get_template_fields',  | 
                                                        |
| 40 | + array($this, 'email_messenger_template_fields'),  | 
                                                        |
| 41 | + 5,  | 
                                                        |
| 42 | + 2  | 
                                                        |
| 43 | + );  | 
                                                        |
| 44 | + add_filter(  | 
                                                        |
| 45 | + 'FHEE__EE_Html_messenger__get_template_fields',  | 
                                                        |
| 46 | + array($this, 'html_messenger_template_fields'),  | 
                                                        |
| 47 | + 5,  | 
                                                        |
| 48 | + 2  | 
                                                        |
| 49 | + );  | 
                                                        |
| 50 | + add_filter(  | 
                                                        |
| 51 | + 'FHEE__EE_Html_messenger__get_validator_config',  | 
                                                        |
| 52 | + array($this, 'html_messenger_validator_config'),  | 
                                                        |
| 53 | + 5,  | 
                                                        |
| 54 | + 2  | 
                                                        |
| 55 | + );  | 
                                                        |
| 56 | +		add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); | 
                                                        |
| 57 | + add_filter(  | 
                                                        |
| 58 | + 'FHEE__EE_Pdf_messenger__get_validator_config',  | 
                                                        |
| 59 | + array($this, 'pdf_messenger_validator_config'),  | 
                                                        |
| 60 | + 5,  | 
                                                        |
| 61 | + 2  | 
                                                        |
| 62 | + );  | 
                                                        |
| 63 | + add_filter(  | 
                                                        |
| 64 | + 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',  | 
                                                        |
| 65 | + array($this, 'new_default_templates'),  | 
                                                        |
| 66 | + 5,  | 
                                                        |
| 67 | + 7  | 
                                                        |
| 68 | + );  | 
                                                        |
| 69 | + add_filter(  | 
                                                        |
| 70 | + 'FHEE__EE_Messages_Base__get_valid_shortcodes',  | 
                                                        |
| 71 | + array($this, 'message_types_valid_shortcodes'),  | 
                                                        |
| 72 | + 5,  | 
                                                        |
| 73 | + 2  | 
                                                        |
| 74 | + );  | 
                                                        |
| 75 | +  | 
                                                        |
| 76 | + // shortcode parsers  | 
                                                        |
| 77 | +		add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); | 
                                                        |
| 78 | +		add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); | 
                                                        |
| 79 | + add_filter(  | 
                                                        |
| 80 | + 'FHEE__EE_Recipient_List_Shortcodes__shortcodes',  | 
                                                        |
| 81 | + array($this, 'additional_recipient_details_shortcodes'),  | 
                                                        |
| 82 | + 5,  | 
                                                        |
| 83 | + 2  | 
                                                        |
| 84 | + );  | 
                                                        |
| 85 | + add_filter(  | 
                                                        |
| 86 | + 'FHEE__EE_Recipient_List_Shortcodes__parser_after',  | 
                                                        |
| 87 | + array($this, 'additional_recipient_details_parser'),  | 
                                                        |
| 88 | + 5,  | 
                                                        |
| 89 | + 5  | 
                                                        |
| 90 | + );  | 
                                                        |
| 91 | + add_filter(  | 
                                                        |
| 92 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',  | 
                                                        |
| 93 | + array($this, 'additional_primary_registration_details_shortcodes'),  | 
                                                        |
| 94 | + 5,  | 
                                                        |
| 95 | + 2  | 
                                                        |
| 96 | + );  | 
                                                        |
| 97 | + add_filter(  | 
                                                        |
| 98 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',  | 
                                                        |
| 99 | + array($this, 'additional_primary_registration_details_parser'),  | 
                                                        |
| 100 | + 5,  | 
                                                        |
| 101 | + 5  | 
                                                        |
| 102 | + );  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + /**  | 
                                                        |
| 105 | + * @since 4.2.0  | 
                                                        |
| 106 | + */  | 
                                                        |
| 107 | +		add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); | 
                                                        |
| 108 | +		add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); | 
                                                        |
| 109 | +  | 
                                                        |
| 110 | + /**  | 
                                                        |
| 111 | + * @since 4.3.0  | 
                                                        |
| 112 | + */  | 
                                                        |
| 113 | + // eat our own dog food!  | 
                                                        |
| 114 | +		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); | 
                                                        |
| 115 | +		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); | 
                                                        |
| 116 | +		do_action('EE_Brewing_Regular___messages_caf'); | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | +  | 
                                                        |
| 120 | + /**  | 
                                                        |
| 121 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the  | 
                                                        |
| 122 | + * messages system.  | 
                                                        |
| 123 | + *  | 
                                                        |
| 124 | + * @param array $dir_ref original array of paths  | 
                                                        |
| 125 | + *  | 
                                                        |
| 126 | + * @return array appended paths  | 
                                                        |
| 127 | + */  | 
                                                        |
| 128 | + public function messages_autoload_paths($dir_ref)  | 
                                                        |
| 129 | +	{ | 
                                                        |
| 130 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';  | 
                                                        |
| 131 | +  | 
                                                        |
| 132 | + return $dir_ref;  | 
                                                        |
| 133 | + }  | 
                                                        |
| 134 | +  | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)  | 
                                                        |
| 137 | +	{ | 
                                                        |
| 138 | + $validator_config['attendee_list'] = array(  | 
                                                        |
| 139 | +			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), | 
                                                        |
| 140 | +			'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 141 | + );  | 
                                                        |
| 142 | + $validator_config['question_list'] = array(  | 
                                                        |
| 143 | +			'shortcodes' => array('question'), | 
                                                        |
| 144 | +			'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 145 | + );  | 
                                                        |
| 146 | +  | 
                                                        |
| 147 | + return $validator_config;  | 
                                                        |
| 148 | + }  | 
                                                        |
| 149 | +  | 
                                                        |
| 150 | +  | 
                                                        |
| 151 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)  | 
                                                        |
| 152 | +	{ | 
                                                        |
| 153 | + $validator_config['attendee_list'] = array(  | 
                                                        |
| 154 | +			'shortcodes' => array('attendee', 'question_list'), | 
                                                        |
| 155 | +			'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 156 | + );  | 
                                                        |
| 157 | + $validator_config['question_list'] = array(  | 
                                                        |
| 158 | +			'shortcodes' => array('question'), | 
                                                        |
| 159 | +			'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 160 | + );  | 
                                                        |
| 161 | +  | 
                                                        |
| 162 | + return $validator_config;  | 
                                                        |
| 163 | + }  | 
                                                        |
| 164 | +  | 
                                                        |
| 165 | +  | 
                                                        |
| 166 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)  | 
                                                        |
| 167 | +	{ | 
                                                        |
| 168 | + $validator_config['attendee_list'] = array(  | 
                                                        |
| 169 | +			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), | 
                                                        |
| 170 | +			'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 171 | + );  | 
                                                        |
| 172 | + $validator_config['question_list'] = array(  | 
                                                        |
| 173 | +			'shortcodes' => array('question'), | 
                                                        |
| 174 | +			'required'   => array('[QUESTION_LIST]'), | 
                                                        |
| 175 | + );  | 
                                                        |
| 176 | +  | 
                                                        |
| 177 | + return $validator_config;  | 
                                                        |
| 178 | + }  | 
                                                        |
| 179 | +  | 
                                                        |
| 180 | +  | 
                                                        |
| 181 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)  | 
                                                        |
| 182 | +	{ | 
                                                        |
| 183 | + $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 184 | + 'input' => 'textarea',  | 
                                                        |
| 185 | + 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 186 | + 'type' => 'string',  | 
                                                        |
| 187 | + 'required' => false,  | 
                                                        |
| 188 | + 'validation' => true,  | 
                                                        |
| 189 | + 'format' => '%s',  | 
                                                        |
| 190 | + 'css_class' => 'large-text',  | 
                                                        |
| 191 | + 'rows' => '5',  | 
                                                        |
| 192 | +			'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 193 | + );  | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | + return $template_fields;  | 
                                                        |
| 196 | + }  | 
                                                        |
| 197 | +  | 
                                                        |
| 198 | +  | 
                                                        |
| 199 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)  | 
                                                        |
| 200 | +	{ | 
                                                        |
| 201 | + $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 202 | + 'input' => 'textarea',  | 
                                                        |
| 203 | + 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 204 | + 'type' => 'string',  | 
                                                        |
| 205 | + 'required' => false,  | 
                                                        |
| 206 | + 'validation' => true,  | 
                                                        |
| 207 | + 'format' => '%s',  | 
                                                        |
| 208 | + 'css_class' => 'large-text',  | 
                                                        |
| 209 | + 'rows' => '5',  | 
                                                        |
| 210 | +			'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 211 | + );  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + return $template_fields;  | 
                                                        |
| 214 | + }  | 
                                                        |
| 215 | +  | 
                                                        |
| 216 | +  | 
                                                        |
| 217 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)  | 
                                                        |
| 218 | +	{ | 
                                                        |
| 219 | + $template_fields['extra']['content']['question_list'] = array(  | 
                                                        |
| 220 | + 'input' => 'textarea',  | 
                                                        |
| 221 | + 'label' => '[QUESTION_LIST]',  | 
                                                        |
| 222 | + 'type' => 'string',  | 
                                                        |
| 223 | + 'required' => false,  | 
                                                        |
| 224 | + 'validation' => true,  | 
                                                        |
| 225 | + 'format' => '%s',  | 
                                                        |
| 226 | + 'css_class' => 'large-text',  | 
                                                        |
| 227 | + 'rows' => '5',  | 
                                                        |
| 228 | +			'shortcodes_required' => array('[QUESTION_LIST]'), | 
                                                        |
| 229 | + );  | 
                                                        |
| 230 | +  | 
                                                        |
| 231 | + return $template_fields;  | 
                                                        |
| 232 | + }  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | +  | 
                                                        |
| 235 | + public function new_default_templates(  | 
                                                        |
| 236 | + $contents,  | 
                                                        |
| 237 | + $actual_path,  | 
                                                        |
| 238 | + EE_messenger $messenger,  | 
                                                        |
| 239 | + EE_message_type $message_type,  | 
                                                        |
| 240 | + $field,  | 
                                                        |
| 241 | + $context,  | 
                                                        |
| 242 | + EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 243 | +	) { | 
                                                        |
| 244 | +  | 
                                                        |
| 245 | + // we're only modifying templates for the default template pack  | 
                                                        |
| 246 | +		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { | 
                                                        |
| 247 | + return $contents;  | 
                                                        |
| 248 | + }  | 
                                                        |
| 249 | +  | 
                                                        |
| 250 | + // the template file name we're replacing contents for.  | 
                                                        |
| 251 | + $template_file_prefix = $field . '_' . $context;  | 
                                                        |
| 252 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_';  | 
                                                        |
| 253 | +  | 
                                                        |
| 254 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';  | 
                                                        |
| 255 | +  | 
                                                        |
| 256 | +		if ($messenger->name == 'email' && $message_type->name == 'registration') { | 
                                                        |
| 257 | +			switch ($template_file_prefix) { | 
                                                        |
| 258 | + case 'question_list_admin':  | 
                                                        |
| 259 | + case 'question_list_attendee':  | 
                                                        |
| 260 | + case 'question_list_primary_attendee':  | 
                                                        |
| 261 | + $path = $base_path . $msg_prefix . 'question_list.template.php';  | 
                                                        |
| 262 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 263 | + break;  | 
                                                        |
| 264 | +  | 
                                                        |
| 265 | + case 'attendee_list_primary_attendee':  | 
                                                        |
| 266 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php';  | 
                                                        |
| 267 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 268 | + break;  | 
                                                        |
| 269 | +  | 
                                                        |
| 270 | + case 'attendee_list_admin':  | 
                                                        |
| 271 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';  | 
                                                        |
| 272 | + $contents = EEH_Template::display_template(  | 
                                                        |
| 273 | + $path,  | 
                                                        |
| 274 | + array(),  | 
                                                        |
| 275 | + true  | 
                                                        |
| 276 | + );  | 
                                                        |
| 277 | + break;  | 
                                                        |
| 278 | +  | 
                                                        |
| 279 | + case 'attendee_list_attendee':  | 
                                                        |
| 280 | + $contents = '';  | 
                                                        |
| 281 | + break;  | 
                                                        |
| 282 | +  | 
                                                        |
| 283 | + case 'event_list_attendee':  | 
                                                        |
| 284 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';  | 
                                                        |
| 285 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 286 | + break;  | 
                                                        |
| 287 | + }  | 
                                                        |
| 288 | +		} elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { | 
                                                        |
| 289 | +			switch ($template_file_prefix) { | 
                                                        |
| 290 | + case 'content_attendee':  | 
                                                        |
| 291 | + $path = $base_path . $msg_prefix . 'content.template.php';  | 
                                                        |
| 292 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 293 | + break;  | 
                                                        |
| 294 | +  | 
                                                        |
| 295 | + case 'newsletter_content_attendee':  | 
                                                        |
| 296 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php';  | 
                                                        |
| 297 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 298 | + break;  | 
                                                        |
| 299 | +  | 
                                                        |
| 300 | + case 'newsletter_subject_attendee':  | 
                                                        |
| 301 | + $path = $base_path . $msg_prefix . 'subject.template.php';  | 
                                                        |
| 302 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 303 | + break;  | 
                                                        |
| 304 | + }  | 
                                                        |
| 305 | +		} elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { | 
                                                        |
| 306 | +			switch ($template_file_prefix) { | 
                                                        |
| 307 | + case 'attendee_list_purchaser':  | 
                                                        |
| 308 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php';  | 
                                                        |
| 309 | + $contents = EEH_Template::display_template($path, array(), true);  | 
                                                        |
| 310 | + break;  | 
                                                        |
| 311 | + }  | 
                                                        |
| 312 | + }  | 
                                                        |
| 313 | +  | 
                                                        |
| 314 | + return $contents;  | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | +  | 
                                                        |
| 317 | +  | 
                                                        |
| 318 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)  | 
                                                        |
| 319 | +	{ | 
                                                        |
| 320 | + // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode.  | 
                                                        |
| 321 | + $include_with = array(  | 
                                                        |
| 322 | + 'registration',  | 
                                                        |
| 323 | + 'cancelled_registration',  | 
                                                        |
| 324 | + 'declined_registration',  | 
                                                        |
| 325 | + 'not_approved_registration',  | 
                                                        |
| 326 | + 'payment_declined',  | 
                                                        |
| 327 | + 'payment_failed',  | 
                                                        |
| 328 | + 'payment_cancelled',  | 
                                                        |
| 329 | + 'payment',  | 
                                                        |
| 330 | + 'payment_reminder',  | 
                                                        |
| 331 | + 'pending_approval',  | 
                                                        |
| 332 | + 'registration_summary',  | 
                                                        |
| 333 | + 'invoice',  | 
                                                        |
| 334 | + 'receipt',  | 
                                                        |
| 335 | + );  | 
                                                        |
| 336 | +		if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { | 
                                                        |
| 337 | + $contexts = array_keys($msg->get_contexts());  | 
                                                        |
| 338 | +			foreach ($contexts as $context) { | 
                                                        |
| 339 | + $valid_shortcodes[ $context ][] = 'question_list';  | 
                                                        |
| 340 | + $valid_shortcodes[ $context ][] = 'question';  | 
                                                        |
| 341 | + }  | 
                                                        |
| 342 | + }  | 
                                                        |
| 343 | +  | 
                                                        |
| 344 | + return $valid_shortcodes;  | 
                                                        |
| 345 | + }  | 
                                                        |
| 346 | +  | 
                                                        |
| 347 | +  | 
                                                        |
| 348 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 349 | +	{ | 
                                                        |
| 350 | + $shortcodes['[ANSWER_*]'] = esc_html__(  | 
                                                        |
| 351 | + 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',  | 
                                                        |
| 352 | + 'event_espresso'  | 
                                                        |
| 353 | + );  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | + return $shortcodes;  | 
                                                        |
| 356 | + }  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | +  | 
                                                        |
| 359 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 360 | +	{ | 
                                                        |
| 361 | +  | 
                                                        |
| 362 | + if (  | 
                                                        |
| 363 | + strpos($shortcode, '[ANSWER_*') === false  | 
                                                        |
| 364 | + || ! isset($extra_data['data']->questions)  | 
                                                        |
| 365 | + || ! isset($extra_data['data']->registrations)  | 
                                                        |
| 366 | +		) { | 
                                                        |
| 367 | + return $parsed;  | 
                                                        |
| 368 | + }  | 
                                                        |
| 369 | +  | 
                                                        |
| 370 | + // let's get the question from the code.  | 
                                                        |
| 371 | +		$shortcode = str_replace('[ANSWER_*', '', $shortcode); | 
                                                        |
| 372 | +		$shortcode = trim(str_replace(']', '', $shortcode)); | 
                                                        |
| 373 | +  | 
                                                        |
| 374 | + $registration = $data instanceof EE_Registration ? $data : null;  | 
                                                        |
| 375 | + $registration = ! $registration instanceof EE_Registration && is_array(  | 
                                                        |
| 376 | + $extra_data  | 
                                                        |
| 377 | + ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;  | 
                                                        |
| 378 | +  | 
                                                        |
| 379 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null;  | 
                                                        |
| 380 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array(  | 
                                                        |
| 381 | + $extra_data  | 
                                                        |
| 382 | + ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;  | 
                                                        |
| 383 | +  | 
                                                        |
| 384 | +		if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { | 
                                                        |
| 385 | + return $parsed;  | 
                                                        |
| 386 | + }  | 
                                                        |
| 387 | +  | 
                                                        |
| 388 | + // now let's figure out which question has this text.  | 
                                                        |
| 389 | +		foreach ($aee->questions as $ansid => $question) { | 
                                                        |
| 390 | + if (  | 
                                                        |
| 391 | + $question instanceof EE_Question  | 
                                                        |
| 392 | + && trim($question->display_text()) == trim($shortcode)  | 
                                                        |
| 393 | + && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])  | 
                                                        |
| 394 | +			) { | 
                                                        |
| 395 | + return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(  | 
                                                        |
| 396 | + 'ANS_value',  | 
                                                        |
| 397 | + 'no_wpautop'  | 
                                                        |
| 398 | + );  | 
                                                        |
| 399 | + }  | 
                                                        |
| 400 | + }  | 
                                                        |
| 401 | +  | 
                                                        |
| 402 | + // nothing!  | 
                                                        |
| 403 | + return $parsed;  | 
                                                        |
| 404 | + }  | 
                                                        |
| 405 | +  | 
                                                        |
| 406 | +  | 
                                                        |
| 407 | + /**  | 
                                                        |
| 408 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes.  | 
                                                        |
| 409 | + *  | 
                                                        |
| 410 | + * @since 4.2  | 
                                                        |
| 411 | + *  | 
                                                        |
| 412 | + * @param array $shortcodes array of shortcodes and  | 
                                                        |
| 413 | + * descriptions  | 
                                                        |
| 414 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object  | 
                                                        |
| 415 | + *  | 
                                                        |
| 416 | + * @return array array of shortcodes and  | 
                                                        |
| 417 | + * descriptions  | 
                                                        |
| 418 | + */  | 
                                                        |
| 419 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 420 | +	{ | 
                                                        |
| 421 | + $shortcodes['[DTT_NAME]'] = esc_html__(  | 
                                                        |
| 422 | + 'This will be parsed to the Title given for a Datetime',  | 
                                                        |
| 423 | + 'event_espresso'  | 
                                                        |
| 424 | + );  | 
                                                        |
| 425 | + $shortcodes['[DTT_DESCRIPTION]'] = esc_html__(  | 
                                                        |
| 426 | + 'This will be parsed to the description for a Datetime',  | 
                                                        |
| 427 | + 'event_espresso'  | 
                                                        |
| 428 | + );  | 
                                                        |
| 429 | + $shortcodes['[DTT_NAME_OR_DATES]'] = esc_html__(  | 
                                                        |
| 430 | + 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',  | 
                                                        |
| 431 | + 'event_espresso'  | 
                                                        |
| 432 | + );  | 
                                                        |
| 433 | +  | 
                                                        |
| 434 | + return $shortcodes;  | 
                                                        |
| 435 | + }  | 
                                                        |
| 436 | +  | 
                                                        |
| 437 | +  | 
                                                        |
| 438 | + /**  | 
                                                        |
| 439 | + * Callback for additional shortcodes parser filter used for adding parser for new  | 
                                                        |
| 440 | + * Datetime shortcodes  | 
                                                        |
| 441 | + *  | 
                                                        |
| 442 | + * @since 4.2  | 
                                                        |
| 443 | + *  | 
                                                        |
| 444 | + * @param string $parsed The finished parsed string for the given shortcode.  | 
                                                        |
| 445 | + * @param string $shortcode The shortcode being parsed.  | 
                                                        |
| 446 | + * @param object $data The incoming data object for the Shortcode Parser.  | 
                                                        |
| 447 | + * @param object $extra_data The incoming extra date object for the Shortcode  | 
                                                        |
| 448 | + * Parser.  | 
                                                        |
| 449 | + * @param EE_Datetime_Shortcodes $shortcode_parser  | 
                                                        |
| 450 | + *  | 
                                                        |
| 451 | + * @return string The new parsed string.  | 
                                                        |
| 452 | + */  | 
                                                        |
| 453 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 454 | +	{ | 
                                                        |
| 455 | +  | 
                                                        |
| 456 | +		if (! $data instanceof EE_Datetime) { | 
                                                        |
| 457 | + return ''; // get out because we can only parse with the datetime object.  | 
                                                        |
| 458 | + }  | 
                                                        |
| 459 | +  | 
                                                        |
| 460 | +		switch ($shortcode) { | 
                                                        |
| 461 | + case '[DTT_NAME]':  | 
                                                        |
| 462 | + return $data->name();  | 
                                                        |
| 463 | + break;  | 
                                                        |
| 464 | + case '[DTT_DESCRIPTION]':  | 
                                                        |
| 465 | + return $data->description();  | 
                                                        |
| 466 | + break;  | 
                                                        |
| 467 | + case '[DTT_NAME_OR_DATES]':  | 
                                                        |
| 468 | + return $data->get_dtt_display_name(true);  | 
                                                        |
| 469 | + break;  | 
                                                        |
| 470 | + default:  | 
                                                        |
| 471 | + return $parsed;  | 
                                                        |
| 472 | + break;  | 
                                                        |
| 473 | + }  | 
                                                        |
| 474 | + }  | 
                                                        |
| 475 | +  | 
                                                        |
| 476 | +  | 
                                                        |
| 477 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 478 | +	{ | 
                                                        |
| 479 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = esc_html__(  | 
                                                        |
| 480 | + 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',  | 
                                                        |
| 481 | + 'event_espresso'  | 
                                                        |
| 482 | + );  | 
                                                        |
| 483 | +  | 
                                                        |
| 484 | + return $shortcodes;  | 
                                                        |
| 485 | + }  | 
                                                        |
| 486 | +  | 
                                                        |
| 487 | +  | 
                                                        |
| 488 | + /**  | 
                                                        |
| 489 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).  | 
                                                        |
| 490 | + *  | 
                                                        |
| 491 | + * @param string $parsed The original parsed content for the shortcode  | 
                                                        |
| 492 | + * @param string $shortcode The shortcode being parsed  | 
                                                        |
| 493 | + * @param array $data The shortcode parser data array  | 
                                                        |
| 494 | + * @param array $extra_data The shortcode parser extra data array  | 
                                                        |
| 495 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser.  | 
                                                        |
| 496 | + *  | 
                                                        |
| 497 | + * @return string  | 
                                                        |
| 498 | + */  | 
                                                        |
| 499 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)  | 
                                                        |
| 500 | +	{ | 
                                                        |
| 501 | +  | 
                                                        |
| 502 | +		if (array($data) && ! isset($data['data'])) { | 
                                                        |
| 503 | + return $parsed;  | 
                                                        |
| 504 | + }  | 
                                                        |
| 505 | +  | 
                                                        |
| 506 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;  | 
                                                        |
| 507 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;  | 
                                                        |
| 508 | +  | 
                                                        |
| 509 | +		if (! $recipient instanceof EE_Messages_Addressee) { | 
                                                        |
| 510 | + return $parsed;  | 
                                                        |
| 511 | + }  | 
                                                        |
| 512 | +  | 
                                                        |
| 513 | +		switch ($shortcode) { | 
                                                        |
| 514 | + case '[RECIPIENT_QUESTION_LIST]':  | 
                                                        |
| 515 | + $att = $recipient->att_obj;  | 
                                                        |
| 516 | + $registrations_on_attendee = $att instanceof EE_Attendee  | 
                                                        |
| 517 | + ? $recipient->attendees[ $att->ID() ]['reg_objs']  | 
                                                        |
| 518 | + : array();  | 
                                                        |
| 519 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;  | 
                                                        |
| 520 | + $answers = array();  | 
                                                        |
| 521 | +  | 
                                                        |
| 522 | + $template = is_array($data['template']) && isset($data['template']['question_list'])  | 
                                                        |
| 523 | + ? $data['template']['question_list']  | 
                                                        |
| 524 | + : $extra_data['template']['question_list'];  | 
                                                        |
| 525 | +				$valid_shortcodes = array('question'); | 
                                                        |
| 526 | +  | 
                                                        |
| 527 | + // if the context is main_content then get all answers for all registrations on this attendee  | 
                                                        |
| 528 | +				if ($data['data'] instanceof EE_Messages_Addressee) { | 
                                                        |
| 529 | +					foreach ($registrations_on_attendee as $reg) { | 
                                                        |
| 530 | +						if ($reg instanceof EE_Registration) { | 
                                                        |
| 531 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])  | 
                                                        |
| 532 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs']  | 
                                                        |
| 533 | + : array();  | 
                                                        |
| 534 | +							foreach ($anss as $ans) { | 
                                                        |
| 535 | +								if ($ans instanceof EE_Answer) { | 
                                                        |
| 536 | + $answers[ $ans->ID() ] = $ans;  | 
                                                        |
| 537 | + }  | 
                                                        |
| 538 | + }  | 
                                                        |
| 539 | + }  | 
                                                        |
| 540 | + }  | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | +  | 
                                                        |
| 543 | + // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.  | 
                                                        |
| 544 | +				if ($data['data'] instanceof EE_Event) { | 
                                                        |
| 545 | + $event = $data['data'];  | 
                                                        |
| 546 | +					foreach ($registrations_on_attendee as $reg) { | 
                                                        |
| 547 | +						if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { | 
                                                        |
| 548 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])  | 
                                                        |
| 549 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs']  | 
                                                        |
| 550 | + : array();  | 
                                                        |
| 551 | +							foreach ($anss as $ans) { | 
                                                        |
| 552 | +								if ($ans instanceof EE_Answer) { | 
                                                        |
| 553 | + $answers[ $ans->ID() ] = $ans;  | 
                                                        |
| 554 | + }  | 
                                                        |
| 555 | + }  | 
                                                        |
| 556 | + }  | 
                                                        |
| 557 | + }  | 
                                                        |
| 558 | + }  | 
                                                        |
| 559 | +  | 
                                                        |
| 560 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();  | 
                                                        |
| 561 | +  | 
                                                        |
| 562 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee  | 
                                                        |
| 563 | + // object on it.  | 
                                                        |
| 564 | +				if (! isset($extra_data['data'])) { | 
                                                        |
| 565 | + $extra_data['data'] = $recipient;  | 
                                                        |
| 566 | + }  | 
                                                        |
| 567 | +  | 
                                                        |
| 568 | + return $this->_parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 569 | + $shortcode_parser,  | 
                                                        |
| 570 | + $questions,  | 
                                                        |
| 571 | + $answers,  | 
                                                        |
| 572 | + $template,  | 
                                                        |
| 573 | + $valid_shortcodes,  | 
                                                        |
| 574 | + $extra_data  | 
                                                        |
| 575 | + );  | 
                                                        |
| 576 | + break;  | 
                                                        |
| 577 | +  | 
                                                        |
| 578 | + default:  | 
                                                        |
| 579 | + return $parsed;  | 
                                                        |
| 580 | + break;  | 
                                                        |
| 581 | + }  | 
                                                        |
| 582 | + }  | 
                                                        |
| 583 | +  | 
                                                        |
| 584 | +  | 
                                                        |
| 585 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)  | 
                                                        |
| 586 | +	{ | 
                                                        |
| 587 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = esc_html__(  | 
                                                        |
| 588 | + 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',  | 
                                                        |
| 589 | + 'event_espresso'  | 
                                                        |
| 590 | + );  | 
                                                        |
| 591 | +  | 
                                                        |
| 592 | + return $shortcodes;  | 
                                                        |
| 593 | + }  | 
                                                        |
| 594 | +  | 
                                                        |
| 595 | +  | 
                                                        |
| 596 | + /**  | 
                                                        |
| 597 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).  | 
                                                        |
| 598 | + *  | 
                                                        |
| 599 | + * @param string $parsed The original parsed content for the shortcode  | 
                                                        |
| 600 | + * @param string $shortcode The shortcode being parsed  | 
                                                        |
| 601 | + * @param array $data The shortcode parser data array  | 
                                                        |
| 602 | + * @param array $extra_data The shortcode parser extra data array  | 
                                                        |
| 603 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser.  | 
                                                        |
| 604 | + *  | 
                                                        |
| 605 | + * @return string  | 
                                                        |
| 606 | + */  | 
                                                        |
| 607 | + public function additional_primary_registration_details_parser(  | 
                                                        |
| 608 | + $parsed,  | 
                                                        |
| 609 | + $shortcode,  | 
                                                        |
| 610 | + $data,  | 
                                                        |
| 611 | + $extra_data,  | 
                                                        |
| 612 | + $shortcode_parser  | 
                                                        |
| 613 | +	) { | 
                                                        |
| 614 | +		if (array($data) && ! isset($data['data'])) { | 
                                                        |
| 615 | + return $parsed;  | 
                                                        |
| 616 | + }  | 
                                                        |
| 617 | +  | 
                                                        |
| 618 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;  | 
                                                        |
| 619 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;  | 
                                                        |
| 620 | +  | 
                                                        |
| 621 | +		if (! $recipient instanceof EE_Messages_Addressee) { | 
                                                        |
| 622 | + return $parsed;  | 
                                                        |
| 623 | + }  | 
                                                        |
| 624 | +  | 
                                                        |
| 625 | +		switch ($shortcode) { | 
                                                        |
| 626 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]':  | 
                                                        |
| 627 | +				if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { | 
                                                        |
| 628 | + return '';  | 
                                                        |
| 629 | + }  | 
                                                        |
| 630 | + $registration = $recipient->primary_reg_obj;  | 
                                                        |
| 631 | + $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])  | 
                                                        |
| 632 | + ? $recipient->registrations[ $registration->ID() ]['ans_objs']  | 
                                                        |
| 633 | + : array();  | 
                                                        |
| 634 | +				if (empty($answers)) { | 
                                                        |
| 635 | + return '';  | 
                                                        |
| 636 | + }  | 
                                                        |
| 637 | + $template = is_array($data['template']) && isset($data['template']['question_list'])  | 
                                                        |
| 638 | + ? $data['template']['question_list']  | 
                                                        |
| 639 | + : $extra_data['template']['question_list'];  | 
                                                        |
| 640 | +				$valid_shortcodes = array('question'); | 
                                                        |
| 641 | + $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];  | 
                                                        |
| 642 | + $questions = isset($recipient->questions) ? $recipient->questions : array();  | 
                                                        |
| 643 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee  | 
                                                        |
| 644 | + // object on it.  | 
                                                        |
| 645 | +				if (! isset($extra_data['data'])) { | 
                                                        |
| 646 | + $extra_data['data'] = $recipient;  | 
                                                        |
| 647 | + }  | 
                                                        |
| 648 | + return $this->_parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 649 | + $shortcode_parser,  | 
                                                        |
| 650 | + $questions,  | 
                                                        |
| 651 | + $answers,  | 
                                                        |
| 652 | + $template,  | 
                                                        |
| 653 | + $valid_shortcodes,  | 
                                                        |
| 654 | + $extra_data  | 
                                                        |
| 655 | + );  | 
                                                        |
| 656 | + break;  | 
                                                        |
| 657 | +  | 
                                                        |
| 658 | + default:  | 
                                                        |
| 659 | + return $parsed;  | 
                                                        |
| 660 | + break;  | 
                                                        |
| 661 | + }  | 
                                                        |
| 662 | + }  | 
                                                        |
| 663 | +  | 
                                                        |
| 664 | +  | 
                                                        |
| 665 | + /**  | 
                                                        |
| 666 | + * Takes care of registering the message types that are only available in caffeinated EE.  | 
                                                        |
| 667 | + *  | 
                                                        |
| 668 | + * @since 4.3.2  | 
                                                        |
| 669 | + *  | 
                                                        |
| 670 | + * @return void  | 
                                                        |
| 671 | + */  | 
                                                        |
| 672 | + public function register_caf_message_types()  | 
                                                        |
| 673 | +	{ | 
                                                        |
| 674 | + // register newsletter message type  | 
                                                        |
| 675 | + $setup_args = array(  | 
                                                        |
| 676 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php',  | 
                                                        |
| 677 | + 'autoloadpaths' => array(  | 
                                                        |
| 678 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',  | 
                                                        |
| 679 | + ),  | 
                                                        |
| 680 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 681 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 682 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 683 | + );  | 
                                                        |
| 684 | +		EE_Register_Message_Type::register('newsletter', $setup_args); | 
                                                        |
| 685 | +  | 
                                                        |
| 686 | + // register payment reminder message type  | 
                                                        |
| 687 | + $setup_args = array(  | 
                                                        |
| 688 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php',  | 
                                                        |
| 689 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),  | 
                                                        |
| 690 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 691 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 692 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 693 | + );  | 
                                                        |
| 694 | +		EE_Register_Message_Type::register('payment_reminder', $setup_args); | 
                                                        |
| 695 | +  | 
                                                        |
| 696 | + // register payment declined message type  | 
                                                        |
| 697 | + $setup_args = array(  | 
                                                        |
| 698 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php',  | 
                                                        |
| 699 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),  | 
                                                        |
| 700 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 701 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 702 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 703 | + );  | 
                                                        |
| 704 | +		EE_Register_Message_Type::register('payment_declined', $setup_args); | 
                                                        |
| 705 | +  | 
                                                        |
| 706 | + // register registration declined message type  | 
                                                        |
| 707 | + $setup_args = array(  | 
                                                        |
| 708 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php',  | 
                                                        |
| 709 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),  | 
                                                        |
| 710 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 711 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 712 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 713 | + );  | 
                                                        |
| 714 | +		EE_Register_Message_Type::register('declined_registration', $setup_args); | 
                                                        |
| 715 | +  | 
                                                        |
| 716 | + // register registration cancelled message type  | 
                                                        |
| 717 | + $setup_args = array(  | 
                                                        |
| 718 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php',  | 
                                                        |
| 719 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),  | 
                                                        |
| 720 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 721 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 722 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 723 | + );  | 
                                                        |
| 724 | +		EE_Register_Message_Type::register('cancelled_registration', $setup_args); | 
                                                        |
| 725 | +  | 
                                                        |
| 726 | +  | 
                                                        |
| 727 | + // register payment failed message type  | 
                                                        |
| 728 | + $setup_args = array(  | 
                                                        |
| 729 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php',  | 
                                                        |
| 730 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),  | 
                                                        |
| 731 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 732 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 733 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 734 | + );  | 
                                                        |
| 735 | +		EE_Register_Message_Type::register('payment_failed', $setup_args); | 
                                                        |
| 736 | +  | 
                                                        |
| 737 | + // register payment declined message type  | 
                                                        |
| 738 | + $setup_args = array(  | 
                                                        |
| 739 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php',  | 
                                                        |
| 740 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),  | 
                                                        |
| 741 | +			'messengers_to_activate_with'                      => array('email'), | 
                                                        |
| 742 | +			'messengers_to_validate_with'                      => array('email'), | 
                                                        |
| 743 | +			'messengers_supporting_default_template_pack_with' => array('email'), | 
                                                        |
| 744 | + );  | 
                                                        |
| 745 | +		EE_Register_Message_Type::register('payment_cancelled', $setup_args); | 
                                                        |
| 746 | + }  | 
                                                        |
| 747 | +  | 
                                                        |
| 748 | +  | 
                                                        |
| 749 | + /**  | 
                                                        |
| 750 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items.  | 
                                                        |
| 751 | + *  | 
                                                        |
| 752 | + * @since 4.3.2  | 
                                                        |
| 753 | + *  | 
                                                        |
| 754 | + * @return void  | 
                                                        |
| 755 | + */  | 
                                                        |
| 756 | + public function register_caf_shortcodes()  | 
                                                        |
| 757 | +	{ | 
                                                        |
| 758 | + $setup_args = array(  | 
                                                        |
| 759 | + 'autoloadpaths' => array(  | 
                                                        |
| 760 | + EE_CAF_LIBRARIES . 'shortcodes/',  | 
                                                        |
| 761 | + ),  | 
                                                        |
| 762 | +			'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), | 
                                                        |
| 763 | +			'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), | 
                                                        |
| 764 | +			'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'), | 
                                                        |
| 765 | + );  | 
                                                        |
| 766 | +		EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); | 
                                                        |
| 767 | + }  | 
                                                        |
| 768 | +  | 
                                                        |
| 769 | +  | 
                                                        |
| 770 | + /**  | 
                                                        |
| 771 | + * Parses a question list shortcode using given data and template  | 
                                                        |
| 772 | + *  | 
                                                        |
| 773 | + * @param \EE_Shortcodes $shortcode_parser  | 
                                                        |
| 774 | + * @param EE_Question[] $questions An array of questions indexed by answer id.  | 
                                                        |
| 775 | + * @param EE_Answer[] $answers An array of answer objects  | 
                                                        |
| 776 | + * @param string $template Template content to be parsed.  | 
                                                        |
| 777 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed.  | 
                                                        |
| 778 | + * @param array $extra_data Extra data that might be used when parsing the template.  | 
                                                        |
| 779 | + */  | 
                                                        |
| 780 | + protected function _parse_question_list_for_primary_or_recipient_registration(  | 
                                                        |
| 781 | + $shortcode_parser,  | 
                                                        |
| 782 | + $questions,  | 
                                                        |
| 783 | + $answers,  | 
                                                        |
| 784 | + $template,  | 
                                                        |
| 785 | + $valid_shortcodes,  | 
                                                        |
| 786 | + $extra_data  | 
                                                        |
| 787 | +	) { | 
                                                        |
| 788 | + $question_list = '';  | 
                                                        |
| 789 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */  | 
                                                        |
| 790 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper();  | 
                                                        |
| 791 | +		foreach ($answers as $answer) { | 
                                                        |
| 792 | +			if ($answer instanceof EE_Answer) { | 
                                                        |
| 793 | + // first see if the question is in our $questions array. If not then try to get from answer object.  | 
                                                        |
| 794 | + $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;  | 
                                                        |
| 795 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question;  | 
                                                        |
| 796 | + if (  | 
                                                        |
| 797 | + ! $question instanceof EE_Question  | 
                                                        |
| 798 | + || (  | 
                                                        |
| 799 | + $question instanceof EE_Question  | 
                                                        |
| 800 | + && $question->admin_only()  | 
                                                        |
| 801 | + )  | 
                                                        |
| 802 | +				) { | 
                                                        |
| 803 | + continue;  | 
                                                        |
| 804 | + }  | 
                                                        |
| 805 | + $question_list .= $shortcode_helper->parse_question_list_template(  | 
                                                        |
| 806 | + $template,  | 
                                                        |
| 807 | + $answer,  | 
                                                        |
| 808 | + $valid_shortcodes,  | 
                                                        |
| 809 | + $extra_data  | 
                                                        |
| 810 | + );  | 
                                                        |
| 811 | + }  | 
                                                        |
| 812 | + }  | 
                                                        |
| 813 | + return $question_list;  | 
                                                        |
| 814 | + }  | 
                                                        |
| 815 | 815 | }  | 
                                                        
@@ -12,549 +12,549 @@  | 
                                                    ||
| 12 | 12 | */  | 
                                                        
| 13 | 13 | class EE_Html_messenger extends EE_messenger  | 
                                                        
| 14 | 14 |  { | 
                                                        
| 15 | - /**  | 
                                                        |
| 16 | - * The following are the properties that this messenger requires for displaying the html  | 
                                                        |
| 17 | - */  | 
                                                        |
| 18 | - /**  | 
                                                        |
| 19 | - * This is the html body generated by the template via the message type.  | 
                                                        |
| 20 | - *  | 
                                                        |
| 21 | - * @var string  | 
                                                        |
| 22 | - */  | 
                                                        |
| 23 | - protected $_content = '';  | 
                                                        |
| 24 | -  | 
                                                        |
| 25 | - /**  | 
                                                        |
| 26 | - * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is  | 
                                                        |
| 27 | - * equivalent to the "subject" of the page.  | 
                                                        |
| 28 | - *  | 
                                                        |
| 29 | - * @var string  | 
                                                        |
| 30 | - */  | 
                                                        |
| 31 | - protected $_subject = '';  | 
                                                        |
| 32 | -  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | - /**  | 
                                                        |
| 35 | - * EE_Html_messenger constructor.  | 
                                                        |
| 36 | - */  | 
                                                        |
| 37 | - public function __construct()  | 
                                                        |
| 38 | -    { | 
                                                        |
| 39 | - // set properties  | 
                                                        |
| 40 | - $this->name = 'html';  | 
                                                        |
| 41 | - $this->description = esc_html__(  | 
                                                        |
| 42 | - 'This messenger outputs a message to a browser for display.',  | 
                                                        |
| 43 | - 'event_espresso'  | 
                                                        |
| 44 | - );  | 
                                                        |
| 45 | - $this->label = [  | 
                                                        |
| 46 | -            'singular' => esc_html__('html', 'event_espresso'), | 
                                                        |
| 47 | -            'plural'   => esc_html__('html', 'event_espresso'), | 
                                                        |
| 48 | - ];  | 
                                                        |
| 49 | - $this->activate_on_install = true;  | 
                                                        |
| 50 | - // add the "powered by EE" credit link to the HTML receipt and invoice  | 
                                                        |
| 51 | - add_filter(  | 
                                                        |
| 52 | - 'FHEE__EE_Html_messenger___send_message__main_body',  | 
                                                        |
| 53 | - [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],  | 
                                                        |
| 54 | - 10,  | 
                                                        |
| 55 | - 3  | 
                                                        |
| 56 | - );  | 
                                                        |
| 57 | - parent::__construct();  | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | -  | 
                                                        |
| 61 | - /**  | 
                                                        |
| 62 | - * HTML Messenger desires execution immediately.  | 
                                                        |
| 63 | - *  | 
                                                        |
| 64 | - * @return bool  | 
                                                        |
| 65 | - * @since 4.9.0  | 
                                                        |
| 66 | - * @see parent::send_now() for documentation.  | 
                                                        |
| 67 | - */  | 
                                                        |
| 68 | - public function send_now(): bool  | 
                                                        |
| 69 | -    { | 
                                                        |
| 70 | - return true;  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | -  | 
                                                        |
| 74 | - /**  | 
                                                        |
| 75 | - * HTML Messenger allows an empty to field.  | 
                                                        |
| 76 | - *  | 
                                                        |
| 77 | - * @return bool  | 
                                                        |
| 78 | - * @since 4.9.0  | 
                                                        |
| 79 | - * @see parent::allow_empty_to_field() for documentation  | 
                                                        |
| 80 | - */  | 
                                                        |
| 81 | - public function allow_empty_to_field(): bool  | 
                                                        |
| 82 | -    { | 
                                                        |
| 83 | - return true;  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - /**  | 
                                                        |
| 88 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 89 | - */  | 
                                                        |
| 90 | - protected function _set_admin_pages()  | 
                                                        |
| 91 | -    { | 
                                                        |
| 92 | - $this->admin_registered_pages = ['events_edit' => true];  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 98 | - */  | 
                                                        |
| 99 | - protected function _set_valid_shortcodes()  | 
                                                        |
| 100 | -    { | 
                                                        |
| 101 | - $this->_valid_shortcodes = [];  | 
                                                        |
| 102 | - }  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | -  | 
                                                        |
| 105 | - /**  | 
                                                        |
| 106 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 107 | - */  | 
                                                        |
| 108 | - protected function _set_validator_config()  | 
                                                        |
| 109 | -    { | 
                                                        |
| 110 | - $this->_validator_config = [  | 
                                                        |
| 111 | - 'subject' => [  | 
                                                        |
| 112 | - 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],  | 
                                                        |
| 113 | - ],  | 
                                                        |
| 114 | - 'content' => [  | 
                                                        |
| 115 | - 'shortcodes' => [  | 
                                                        |
| 116 | - 'organization',  | 
                                                        |
| 117 | - 'primary_registration_list',  | 
                                                        |
| 118 | - 'primary_registration_details',  | 
                                                        |
| 119 | - 'email',  | 
                                                        |
| 120 | - 'transaction',  | 
                                                        |
| 121 | - 'event_list',  | 
                                                        |
| 122 | - 'payment_list',  | 
                                                        |
| 123 | - 'venue',  | 
                                                        |
| 124 | - 'line_item_list',  | 
                                                        |
| 125 | - 'messenger',  | 
                                                        |
| 126 | - 'ticket_list',  | 
                                                        |
| 127 | - ],  | 
                                                        |
| 128 | - ],  | 
                                                        |
| 129 | - 'event_list' => [  | 
                                                        |
| 130 | - 'shortcodes' => [  | 
                                                        |
| 131 | - 'event',  | 
                                                        |
| 132 | - 'ticket_list',  | 
                                                        |
| 133 | - 'venue',  | 
                                                        |
| 134 | - 'primary_registration_details',  | 
                                                        |
| 135 | - 'primary_registration_list',  | 
                                                        |
| 136 | - 'event_author',  | 
                                                        |
| 137 | - ],  | 
                                                        |
| 138 | - 'required' => ['[EVENT_LIST]'],  | 
                                                        |
| 139 | - ],  | 
                                                        |
| 140 | - 'ticket_list' => [  | 
                                                        |
| 141 | - 'shortcodes' => [  | 
                                                        |
| 142 | - 'attendee_list',  | 
                                                        |
| 143 | - 'ticket',  | 
                                                        |
| 144 | - 'datetime_list',  | 
                                                        |
| 145 | - 'primary_registration_details',  | 
                                                        |
| 146 | - 'line_item_list',  | 
                                                        |
| 147 | - 'venue',  | 
                                                        |
| 148 | - ],  | 
                                                        |
| 149 | - 'required' => ['[TICKET_LIST]'],  | 
                                                        |
| 150 | - ],  | 
                                                        |
| 151 | - 'ticket_line_item_no_pms' => [  | 
                                                        |
| 152 | - 'shortcodes' => ['line_item', 'ticket'],  | 
                                                        |
| 153 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 154 | - ],  | 
                                                        |
| 155 | - 'ticket_line_item_pms' => [  | 
                                                        |
| 156 | - 'shortcodes' => ['line_item', 'ticket', 'line_item_list'],  | 
                                                        |
| 157 | - 'required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 158 | - ],  | 
                                                        |
| 159 | - 'price_modifier_line_item_list' => [  | 
                                                        |
| 160 | - 'shortcodes' => ['line_item'],  | 
                                                        |
| 161 | - 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],  | 
                                                        |
| 162 | - ],  | 
                                                        |
| 163 | - 'datetime_list' => [  | 
                                                        |
| 164 | - 'shortcodes' => ['datetime'],  | 
                                                        |
| 165 | - 'required' => ['[DATETIME_LIST]'],  | 
                                                        |
| 166 | - ],  | 
                                                        |
| 167 | - 'attendee_list' => [  | 
                                                        |
| 168 | - 'shortcodes' => ['attendee'],  | 
                                                        |
| 169 | - 'required' => ['[ATTENDEE_LIST]'],  | 
                                                        |
| 170 | - ],  | 
                                                        |
| 171 | - 'tax_line_item_list' => [  | 
                                                        |
| 172 | - 'shortcodes' => ['line_item'],  | 
                                                        |
| 173 | - 'required' => ['[TAX_LINE_ITEM_LIST]'],  | 
                                                        |
| 174 | - ],  | 
                                                        |
| 175 | - 'additional_line_item_list' => [  | 
                                                        |
| 176 | - 'shortcodes' => ['line_item'],  | 
                                                        |
| 177 | - 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],  | 
                                                        |
| 178 | - ],  | 
                                                        |
| 179 | - 'payment_list' => [  | 
                                                        |
| 180 | - 'shortcodes' => ['payment'],  | 
                                                        |
| 181 | - 'required' => ['[PAYMENT_LIST_*]'],  | 
                                                        |
| 182 | - ],  | 
                                                        |
| 183 | - ];  | 
                                                        |
| 184 | - }  | 
                                                        |
| 185 | -  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - /**  | 
                                                        |
| 188 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger  | 
                                                        |
| 189 | - * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary  | 
                                                        |
| 190 | - * (i.e. swap out css files or something else).  | 
                                                        |
| 191 | - *  | 
                                                        |
| 192 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.  | 
                                                        |
| 193 | - * @return void  | 
                                                        |
| 194 | - * @since 4.5.0  | 
                                                        |
| 195 | - */  | 
                                                        |
| 196 | - public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 197 | -    { | 
                                                        |
| 198 | -        if ($sending_messenger_name === 'pdf') { | 
                                                        |
| 199 | -            add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); | 
                                                        |
| 200 | - }  | 
                                                        |
| 201 | - }  | 
                                                        |
| 202 | -  | 
                                                        |
| 203 | -  | 
                                                        |
| 204 | - /**  | 
                                                        |
| 205 | - * @param $variation_path  | 
                                                        |
| 206 | - * @param EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 207 | - * @param $messenger_name  | 
                                                        |
| 208 | - * @param $message_type_name  | 
                                                        |
| 209 | - * @param $url  | 
                                                        |
| 210 | - * @param $type  | 
                                                        |
| 211 | - * @param $variation  | 
                                                        |
| 212 | - * @param $skip_filters  | 
                                                        |
| 213 | - * @return string  | 
                                                        |
| 214 | - */  | 
                                                        |
| 215 | - public function add_html_css(  | 
                                                        |
| 216 | - $variation_path,  | 
                                                        |
| 217 | - EE_Messages_Template_Pack $template_pack,  | 
                                                        |
| 218 | - $messenger_name,  | 
                                                        |
| 219 | - $message_type_name,  | 
                                                        |
| 220 | - $url,  | 
                                                        |
| 221 | - $type,  | 
                                                        |
| 222 | - $variation,  | 
                                                        |
| 223 | - $skip_filters  | 
                                                        |
| 224 | -    ): string { | 
                                                        |
| 225 | - return $template_pack->get_variation(  | 
                                                        |
| 226 | - $this->name,  | 
                                                        |
| 227 | - $message_type_name,  | 
                                                        |
| 228 | - $type,  | 
                                                        |
| 229 | - $variation,  | 
                                                        |
| 230 | - $url,  | 
                                                        |
| 231 | - '.css',  | 
                                                        |
| 232 | - $skip_filters  | 
                                                        |
| 233 | - );  | 
                                                        |
| 234 | - }  | 
                                                        |
| 235 | -  | 
                                                        |
| 236 | -  | 
                                                        |
| 237 | - /**  | 
                                                        |
| 238 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this  | 
                                                        |
| 239 | - * messenger can add their own js.  | 
                                                        |
| 240 | - *  | 
                                                        |
| 241 | - * @return void.  | 
                                                        |
| 242 | - */  | 
                                                        |
| 243 | - public function enqueue_scripts_styles()  | 
                                                        |
| 244 | -    { | 
                                                        |
| 245 | - parent::enqueue_scripts_styles();  | 
                                                        |
| 246 | -        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); | 
                                                        |
| 247 | - }  | 
                                                        |
| 248 | -  | 
                                                        |
| 249 | -  | 
                                                        |
| 250 | - /**  | 
                                                        |
| 251 | - * _set_template_fields  | 
                                                        |
| 252 | - * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 253 | - *  | 
                                                        |
| 254 | - * @access protected  | 
                                                        |
| 255 | - * @return void  | 
                                                        |
| 256 | - */  | 
                                                        |
| 257 | - protected function _set_template_fields()  | 
                                                        |
| 258 | -    { | 
                                                        |
| 259 | - // any extra template fields that are NOT used by the messenger  | 
                                                        |
| 260 | - // but will get used by a messenger field for shortcode replacement  | 
                                                        |
| 261 | - // get added to the 'extra' key in an associated array  | 
                                                        |
| 262 | - // indexed by the messenger field they relate to.  | 
                                                        |
| 263 | - // This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 264 | - // Also, notice that the "values" are equal to the field type  | 
                                                        |
| 265 | - // that messages admin will use to know what kind of field to display.  | 
                                                        |
| 266 | - // The values ALSO have one index labeled "shortcode".  | 
                                                        |
| 267 | - // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])  | 
                                                        |
| 268 | - // is required in order for this extra field to be displayed.  | 
                                                        |
| 269 | - // If the required shortcode isn't part of the shortcodes array  | 
                                                        |
| 270 | - // then the field is not needed and will not be displayed/parsed.  | 
                                                        |
| 271 | - $this->_template_fields = [  | 
                                                        |
| 272 | - 'subject' => [  | 
                                                        |
| 273 | - 'input' => 'text',  | 
                                                        |
| 274 | -                'label'      => esc_html__('Page Title', 'event_espresso'), | 
                                                        |
| 275 | - 'type' => 'string',  | 
                                                        |
| 276 | - 'required' => true,  | 
                                                        |
| 277 | - 'validation' => true,  | 
                                                        |
| 278 | - 'css_class' => 'large-text',  | 
                                                        |
| 279 | - 'format' => '%s',  | 
                                                        |
| 280 | - ],  | 
                                                        |
| 281 | - 'content' => '',  | 
                                                        |
| 282 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 283 | - 'extra' => [  | 
                                                        |
| 284 | - 'content' => [  | 
                                                        |
| 285 | - 'main' => [  | 
                                                        |
| 286 | - 'input' => 'wp_editor',  | 
                                                        |
| 287 | -                        'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 288 | - 'type' => 'string',  | 
                                                        |
| 289 | - 'required' => true,  | 
                                                        |
| 290 | - 'validation' => true,  | 
                                                        |
| 291 | - 'format' => '%s',  | 
                                                        |
| 292 | - 'rows' => '15',  | 
                                                        |
| 293 | - ],  | 
                                                        |
| 294 | - 'event_list' => [  | 
                                                        |
| 295 | - 'input' => 'wp_editor',  | 
                                                        |
| 296 | - 'label' => '[EVENT_LIST]',  | 
                                                        |
| 297 | - 'type' => 'string',  | 
                                                        |
| 298 | - 'required' => false,  | 
                                                        |
| 299 | - 'validation' => true,  | 
                                                        |
| 300 | - 'format' => '%s',  | 
                                                        |
| 301 | - 'rows' => '15',  | 
                                                        |
| 302 | - 'shortcodes_required' => ['[EVENT_LIST]'],  | 
                                                        |
| 303 | - ],  | 
                                                        |
| 304 | - 'ticket_list' => [  | 
                                                        |
| 305 | - 'input' => 'textarea',  | 
                                                        |
| 306 | - 'label' => '[TICKET_LIST]',  | 
                                                        |
| 307 | - 'type' => 'string',  | 
                                                        |
| 308 | - 'required' => false,  | 
                                                        |
| 309 | - 'validation' => true,  | 
                                                        |
| 310 | - 'format' => '%s',  | 
                                                        |
| 311 | - 'css_class' => 'large-text',  | 
                                                        |
| 312 | - 'rows' => '10',  | 
                                                        |
| 313 | - 'shortcodes_required' => ['[TICKET_LIST]'],  | 
                                                        |
| 314 | - ],  | 
                                                        |
| 315 | - 'ticket_line_item_no_pms' => [  | 
                                                        |
| 316 | - 'input' => 'textarea',  | 
                                                        |
| 317 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(  | 
                                                        |
| 318 | - 'Ticket Line Item List with no Price Modifiers',  | 
                                                        |
| 319 | - 'event_espresso'  | 
                                                        |
| 320 | - ),  | 
                                                        |
| 321 | - 'type' => 'string',  | 
                                                        |
| 322 | - 'required' => false,  | 
                                                        |
| 323 | - 'validation' => true,  | 
                                                        |
| 324 | - 'format' => '%s',  | 
                                                        |
| 325 | - 'css_class' => 'large-text',  | 
                                                        |
| 326 | - 'rows' => '5',  | 
                                                        |
| 327 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 328 | - ],  | 
                                                        |
| 329 | - 'ticket_line_item_pms' => [  | 
                                                        |
| 330 | - 'input' => 'textarea',  | 
                                                        |
| 331 | - 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(  | 
                                                        |
| 332 | - 'Ticket Line Item List with Price Modifiers',  | 
                                                        |
| 333 | - 'event_espresso'  | 
                                                        |
| 334 | - ),  | 
                                                        |
| 335 | - 'type' => 'string',  | 
                                                        |
| 336 | - 'required' => false,  | 
                                                        |
| 337 | - 'validation' => true,  | 
                                                        |
| 338 | - 'format' => '%s',  | 
                                                        |
| 339 | - 'css_class' => 'large-text',  | 
                                                        |
| 340 | - 'rows' => '5',  | 
                                                        |
| 341 | - 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 342 | - ],  | 
                                                        |
| 343 | - 'price_modifier_line_item_list' => [  | 
                                                        |
| 344 | - 'input' => 'textarea',  | 
                                                        |
| 345 | - 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',  | 
                                                        |
| 346 | - 'type' => 'string',  | 
                                                        |
| 347 | - 'required' => false,  | 
                                                        |
| 348 | - 'validation' => true,  | 
                                                        |
| 349 | - 'format' => '%s',  | 
                                                        |
| 350 | - 'css_class' => 'large-text',  | 
                                                        |
| 351 | - 'rows' => '5',  | 
                                                        |
| 352 | - 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],  | 
                                                        |
| 353 | - ],  | 
                                                        |
| 354 | - 'datetime_list' => [  | 
                                                        |
| 355 | - 'input' => 'textarea',  | 
                                                        |
| 356 | - 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 357 | - 'type' => 'string',  | 
                                                        |
| 358 | - 'required' => false,  | 
                                                        |
| 359 | - 'validation' => true,  | 
                                                        |
| 360 | - 'format' => '%s',  | 
                                                        |
| 361 | - 'css_class' => 'large-text',  | 
                                                        |
| 362 | - 'rows' => '5',  | 
                                                        |
| 363 | - 'shortcodes_required' => ['[DATETIME_LIST]'],  | 
                                                        |
| 364 | - ],  | 
                                                        |
| 365 | - 'attendee_list' => [  | 
                                                        |
| 366 | - 'input' => 'textarea',  | 
                                                        |
| 367 | - 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 368 | - 'type' => 'string',  | 
                                                        |
| 369 | - 'required' => false,  | 
                                                        |
| 370 | - 'validation' => true,  | 
                                                        |
| 371 | - 'format' => '%s',  | 
                                                        |
| 372 | - 'css_class' => 'large-text',  | 
                                                        |
| 373 | - 'rows' => '5',  | 
                                                        |
| 374 | - 'shortcodes_required' => ['[ATTENDEE_LIST]'],  | 
                                                        |
| 375 | - ],  | 
                                                        |
| 376 | - 'tax_line_item_list' => [  | 
                                                        |
| 377 | - 'input' => 'textarea',  | 
                                                        |
| 378 | - 'label' => '[TAX_LINE_ITEM_LIST]',  | 
                                                        |
| 379 | - 'type' => 'string',  | 
                                                        |
| 380 | - 'required' => false,  | 
                                                        |
| 381 | - 'validation' => true,  | 
                                                        |
| 382 | - 'format' => '%s',  | 
                                                        |
| 383 | - 'css_class' => 'large-text',  | 
                                                        |
| 384 | - 'rows' => '5',  | 
                                                        |
| 385 | - 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],  | 
                                                        |
| 386 | - ],  | 
                                                        |
| 387 | - 'additional_line_item_list' => [  | 
                                                        |
| 388 | - 'input' => 'textarea',  | 
                                                        |
| 389 | - 'label' => '[ADDITIONAL_LINE_ITEM_LIST]',  | 
                                                        |
| 390 | - 'type' => 'string',  | 
                                                        |
| 391 | - 'required' => false,  | 
                                                        |
| 392 | - 'validation' => true,  | 
                                                        |
| 393 | - 'format' => '%s',  | 
                                                        |
| 394 | - 'css_class' => 'large-text',  | 
                                                        |
| 395 | - 'rows' => '5',  | 
                                                        |
| 396 | - 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],  | 
                                                        |
| 397 | - ],  | 
                                                        |
| 398 | - 'payment_list' => [  | 
                                                        |
| 399 | - 'input' => 'textarea',  | 
                                                        |
| 400 | - 'label' => '[PAYMENT_LIST]',  | 
                                                        |
| 401 | - 'type' => 'string',  | 
                                                        |
| 402 | - 'required' => false,  | 
                                                        |
| 403 | - 'validation' => true,  | 
                                                        |
| 404 | - 'format' => '%s',  | 
                                                        |
| 405 | - 'css_class' => 'large-text',  | 
                                                        |
| 406 | - 'rows' => '5',  | 
                                                        |
| 407 | - 'shortcodes_required' => ['[PAYMENT_LIST_*]'],  | 
                                                        |
| 408 | - ],  | 
                                                        |
| 409 | - ],  | 
                                                        |
| 410 | - ],  | 
                                                        |
| 411 | - ];  | 
                                                        |
| 412 | - }  | 
                                                        |
| 413 | -  | 
                                                        |
| 414 | -  | 
                                                        |
| 415 | - /**  | 
                                                        |
| 416 | - * @see definition of this method in parent  | 
                                                        |
| 417 | - * @since 4.5.0  | 
                                                        |
| 418 | - */  | 
                                                        |
| 419 | - protected function _set_default_message_types()  | 
                                                        |
| 420 | -    { | 
                                                        |
| 421 | - $this->_default_message_types = ['receipt', 'invoice'];  | 
                                                        |
| 422 | - }  | 
                                                        |
| 423 | -  | 
                                                        |
| 424 | -  | 
                                                        |
| 425 | - /**  | 
                                                        |
| 426 | - * @see definition of this method in parent  | 
                                                        |
| 427 | - * @since 4.5.0  | 
                                                        |
| 428 | - */  | 
                                                        |
| 429 | - protected function _set_valid_message_types()  | 
                                                        |
| 430 | -    { | 
                                                        |
| 431 | - $this->_valid_message_types = ['receipt', 'invoice'];  | 
                                                        |
| 432 | - }  | 
                                                        |
| 433 | -  | 
                                                        |
| 434 | -  | 
                                                        |
| 435 | - /**  | 
                                                        |
| 436 | - * Displays the message in the browser.  | 
                                                        |
| 437 | - *  | 
                                                        |
| 438 | - * @return void.  | 
                                                        |
| 439 | - * @since 4.5.0  | 
                                                        |
| 440 | - */  | 
                                                        |
| 441 | - protected function _send_message()  | 
                                                        |
| 442 | -    { | 
                                                        |
| 443 | - $this->_template_args = [  | 
                                                        |
| 444 | - 'page_title' => $this->_subject,  | 
                                                        |
| 445 | - 'base_css' => $this->get_variation(  | 
                                                        |
| 446 | - $this->_tmp_pack,  | 
                                                        |
| 447 | - $this->_incoming_message_type->name,  | 
                                                        |
| 448 | - true,  | 
                                                        |
| 449 | - 'base',  | 
                                                        |
| 450 | - $this->_variation  | 
                                                        |
| 451 | - ),  | 
                                                        |
| 452 | - 'print_css' => $this->get_variation(  | 
                                                        |
| 453 | - $this->_tmp_pack,  | 
                                                        |
| 454 | - $this->_incoming_message_type->name,  | 
                                                        |
| 455 | - true,  | 
                                                        |
| 456 | - 'print',  | 
                                                        |
| 457 | - $this->_variation  | 
                                                        |
| 458 | - ),  | 
                                                        |
| 459 | - 'main_css' => $this->get_variation(  | 
                                                        |
| 460 | - $this->_tmp_pack,  | 
                                                        |
| 461 | - $this->_incoming_message_type->name,  | 
                                                        |
| 462 | - true,  | 
                                                        |
| 463 | - 'main',  | 
                                                        |
| 464 | - $this->_variation  | 
                                                        |
| 465 | - ),  | 
                                                        |
| 466 | - 'main_body' => wpautop(  | 
                                                        |
| 467 | - apply_filters(  | 
                                                        |
| 468 | - 'FHEE__EE_Html_messenger___send_message__main_body',  | 
                                                        |
| 469 | - $this->_content,  | 
                                                        |
| 470 | - $this->_content,  | 
                                                        |
| 471 | - $this->_incoming_message_type  | 
                                                        |
| 472 | - )  | 
                                                        |
| 473 | - ),  | 
                                                        |
| 474 | - ];  | 
                                                        |
| 475 | - $this->_deregister_wp_hooks();  | 
                                                        |
| 476 | -        add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); | 
                                                        |
| 477 | - echo ($this->_get_main_template());  | 
                                                        |
| 478 | - exit();  | 
                                                        |
| 479 | - }  | 
                                                        |
| 480 | -  | 
                                                        |
| 481 | -  | 
                                                        |
| 482 | - /**  | 
                                                        |
| 483 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't  | 
                                                        |
| 484 | - * interfere with our templates. If users want to add any custom styles or scripts they must use the  | 
                                                        |
| 485 | - * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.  | 
                                                        |
| 486 | - *  | 
                                                        |
| 487 | - * @return void  | 
                                                        |
| 488 | - * @since 4.5.0  | 
                                                        |
| 489 | - */  | 
                                                        |
| 490 | - protected function _deregister_wp_hooks()  | 
                                                        |
| 491 | -    { | 
                                                        |
| 492 | -        remove_all_actions('wp_head'); | 
                                                        |
| 493 | -        remove_all_actions('wp_footer'); | 
                                                        |
| 494 | -        remove_all_actions('wp_print_footer_scripts'); | 
                                                        |
| 495 | -        remove_all_actions('wp_enqueue_scripts'); | 
                                                        |
| 496 | - global $wp_scripts, $wp_styles;  | 
                                                        |
| 497 | - $wp_scripts = $wp_styles = [];  | 
                                                        |
| 498 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.  | 
                                                        |
| 499 | -        add_action('wp_footer', 'wp_print_footer_scripts'); | 
                                                        |
| 500 | -        add_action('wp_print_footer_scripts', '_wp_footer_scripts'); | 
                                                        |
| 501 | -        add_action('wp_head', 'wp_enqueue_scripts'); | 
                                                        |
| 502 | - }  | 
                                                        |
| 503 | -  | 
                                                        |
| 504 | -  | 
                                                        |
| 505 | - /**  | 
                                                        |
| 506 | - * Overwrite parent _get_main_template for display_html purposes.  | 
                                                        |
| 507 | - *  | 
                                                        |
| 508 | - * @param bool $preview  | 
                                                        |
| 509 | - * @return string  | 
                                                        |
| 510 | - * @since 4.5.0  | 
                                                        |
| 511 | - */  | 
                                                        |
| 512 | - protected function _get_main_template($preview = false): string  | 
                                                        |
| 513 | -    { | 
                                                        |
| 514 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name);  | 
                                                        |
| 515 | - // include message type as a template arg  | 
                                                        |
| 516 | - $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 517 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 518 | - }  | 
                                                        |
| 519 | -  | 
                                                        |
| 520 | -  | 
                                                        |
| 521 | - /**  | 
                                                        |
| 522 | - * @return void  | 
                                                        |
| 523 | - */  | 
                                                        |
| 524 | - protected function _preview()  | 
                                                        |
| 525 | -    { | 
                                                        |
| 526 | - $this->_send_message();  | 
                                                        |
| 527 | - }  | 
                                                        |
| 528 | -  | 
                                                        |
| 529 | -  | 
                                                        |
| 530 | - protected function _set_admin_settings_fields()  | 
                                                        |
| 531 | -    { | 
                                                        |
| 532 | - }  | 
                                                        |
| 533 | -  | 
                                                        |
| 534 | -  | 
                                                        |
| 535 | - /**  | 
                                                        |
| 536 | - * add the "powered by EE" credit link to the HTML receipt and invoice  | 
                                                        |
| 537 | - *  | 
                                                        |
| 538 | - * @param string $content  | 
                                                        |
| 539 | - * @param string $content_again  | 
                                                        |
| 540 | - * @param EE_message_type $incoming_message_type  | 
                                                        |
| 541 | - * @return string  | 
                                                        |
| 542 | - */  | 
                                                        |
| 543 | - public function add_powered_by_credit_link_to_receipt_and_invoice(  | 
                                                        |
| 544 | - string $content,  | 
                                                        |
| 545 | - string $content_again,  | 
                                                        |
| 546 | - EE_message_type $incoming_message_type  | 
                                                        |
| 547 | -    ): string { | 
                                                        |
| 548 | - if (  | 
                                                        |
| 549 | - ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')  | 
                                                        |
| 550 | -            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) | 
                                                        |
| 551 | -        ) { | 
                                                        |
| 552 | - $content .= EEH_Template::powered_by_event_espresso(  | 
                                                        |
| 553 | - 'aln-cntr',  | 
                                                        |
| 554 | - '',  | 
                                                        |
| 555 | - ['utm_content' => 'messages_system']  | 
                                                        |
| 556 | -            ) . EEH_HTML::div(EEH_HTML::p(' ')); | 
                                                        |
| 557 | - }  | 
                                                        |
| 558 | - return $content;  | 
                                                        |
| 559 | - }  | 
                                                        |
| 15 | + /**  | 
                                                        |
| 16 | + * The following are the properties that this messenger requires for displaying the html  | 
                                                        |
| 17 | + */  | 
                                                        |
| 18 | + /**  | 
                                                        |
| 19 | + * This is the html body generated by the template via the message type.  | 
                                                        |
| 20 | + *  | 
                                                        |
| 21 | + * @var string  | 
                                                        |
| 22 | + */  | 
                                                        |
| 23 | + protected $_content = '';  | 
                                                        |
| 24 | +  | 
                                                        |
| 25 | + /**  | 
                                                        |
| 26 | + * This is for the page title that gets displayed. (Why use "subject"? Because the "title" tag in html is  | 
                                                        |
| 27 | + * equivalent to the "subject" of the page.  | 
                                                        |
| 28 | + *  | 
                                                        |
| 29 | + * @var string  | 
                                                        |
| 30 | + */  | 
                                                        |
| 31 | + protected $_subject = '';  | 
                                                        |
| 32 | +  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | + /**  | 
                                                        |
| 35 | + * EE_Html_messenger constructor.  | 
                                                        |
| 36 | + */  | 
                                                        |
| 37 | + public function __construct()  | 
                                                        |
| 38 | +	{ | 
                                                        |
| 39 | + // set properties  | 
                                                        |
| 40 | + $this->name = 'html';  | 
                                                        |
| 41 | + $this->description = esc_html__(  | 
                                                        |
| 42 | + 'This messenger outputs a message to a browser for display.',  | 
                                                        |
| 43 | + 'event_espresso'  | 
                                                        |
| 44 | + );  | 
                                                        |
| 45 | + $this->label = [  | 
                                                        |
| 46 | +			'singular' => esc_html__('html', 'event_espresso'), | 
                                                        |
| 47 | +			'plural'   => esc_html__('html', 'event_espresso'), | 
                                                        |
| 48 | + ];  | 
                                                        |
| 49 | + $this->activate_on_install = true;  | 
                                                        |
| 50 | + // add the "powered by EE" credit link to the HTML receipt and invoice  | 
                                                        |
| 51 | + add_filter(  | 
                                                        |
| 52 | + 'FHEE__EE_Html_messenger___send_message__main_body',  | 
                                                        |
| 53 | + [$this, 'add_powered_by_credit_link_to_receipt_and_invoice'],  | 
                                                        |
| 54 | + 10,  | 
                                                        |
| 55 | + 3  | 
                                                        |
| 56 | + );  | 
                                                        |
| 57 | + parent::__construct();  | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | +  | 
                                                        |
| 61 | + /**  | 
                                                        |
| 62 | + * HTML Messenger desires execution immediately.  | 
                                                        |
| 63 | + *  | 
                                                        |
| 64 | + * @return bool  | 
                                                        |
| 65 | + * @since 4.9.0  | 
                                                        |
| 66 | + * @see parent::send_now() for documentation.  | 
                                                        |
| 67 | + */  | 
                                                        |
| 68 | + public function send_now(): bool  | 
                                                        |
| 69 | +	{ | 
                                                        |
| 70 | + return true;  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | +  | 
                                                        |
| 74 | + /**  | 
                                                        |
| 75 | + * HTML Messenger allows an empty to field.  | 
                                                        |
| 76 | + *  | 
                                                        |
| 77 | + * @return bool  | 
                                                        |
| 78 | + * @since 4.9.0  | 
                                                        |
| 79 | + * @see parent::allow_empty_to_field() for documentation  | 
                                                        |
| 80 | + */  | 
                                                        |
| 81 | + public function allow_empty_to_field(): bool  | 
                                                        |
| 82 | +	{ | 
                                                        |
| 83 | + return true;  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + /**  | 
                                                        |
| 88 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 89 | + */  | 
                                                        |
| 90 | + protected function _set_admin_pages()  | 
                                                        |
| 91 | +	{ | 
                                                        |
| 92 | + $this->admin_registered_pages = ['events_edit' => true];  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 98 | + */  | 
                                                        |
| 99 | + protected function _set_valid_shortcodes()  | 
                                                        |
| 100 | +	{ | 
                                                        |
| 101 | + $this->_valid_shortcodes = [];  | 
                                                        |
| 102 | + }  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | +  | 
                                                        |
| 105 | + /**  | 
                                                        |
| 106 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 107 | + */  | 
                                                        |
| 108 | + protected function _set_validator_config()  | 
                                                        |
| 109 | +	{ | 
                                                        |
| 110 | + $this->_validator_config = [  | 
                                                        |
| 111 | + 'subject' => [  | 
                                                        |
| 112 | + 'shortcodes' => ['organization', 'primary_registration_details', 'email', 'transaction'],  | 
                                                        |
| 113 | + ],  | 
                                                        |
| 114 | + 'content' => [  | 
                                                        |
| 115 | + 'shortcodes' => [  | 
                                                        |
| 116 | + 'organization',  | 
                                                        |
| 117 | + 'primary_registration_list',  | 
                                                        |
| 118 | + 'primary_registration_details',  | 
                                                        |
| 119 | + 'email',  | 
                                                        |
| 120 | + 'transaction',  | 
                                                        |
| 121 | + 'event_list',  | 
                                                        |
| 122 | + 'payment_list',  | 
                                                        |
| 123 | + 'venue',  | 
                                                        |
| 124 | + 'line_item_list',  | 
                                                        |
| 125 | + 'messenger',  | 
                                                        |
| 126 | + 'ticket_list',  | 
                                                        |
| 127 | + ],  | 
                                                        |
| 128 | + ],  | 
                                                        |
| 129 | + 'event_list' => [  | 
                                                        |
| 130 | + 'shortcodes' => [  | 
                                                        |
| 131 | + 'event',  | 
                                                        |
| 132 | + 'ticket_list',  | 
                                                        |
| 133 | + 'venue',  | 
                                                        |
| 134 | + 'primary_registration_details',  | 
                                                        |
| 135 | + 'primary_registration_list',  | 
                                                        |
| 136 | + 'event_author',  | 
                                                        |
| 137 | + ],  | 
                                                        |
| 138 | + 'required' => ['[EVENT_LIST]'],  | 
                                                        |
| 139 | + ],  | 
                                                        |
| 140 | + 'ticket_list' => [  | 
                                                        |
| 141 | + 'shortcodes' => [  | 
                                                        |
| 142 | + 'attendee_list',  | 
                                                        |
| 143 | + 'ticket',  | 
                                                        |
| 144 | + 'datetime_list',  | 
                                                        |
| 145 | + 'primary_registration_details',  | 
                                                        |
| 146 | + 'line_item_list',  | 
                                                        |
| 147 | + 'venue',  | 
                                                        |
| 148 | + ],  | 
                                                        |
| 149 | + 'required' => ['[TICKET_LIST]'],  | 
                                                        |
| 150 | + ],  | 
                                                        |
| 151 | + 'ticket_line_item_no_pms' => [  | 
                                                        |
| 152 | + 'shortcodes' => ['line_item', 'ticket'],  | 
                                                        |
| 153 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 154 | + ],  | 
                                                        |
| 155 | + 'ticket_line_item_pms' => [  | 
                                                        |
| 156 | + 'shortcodes' => ['line_item', 'ticket', 'line_item_list'],  | 
                                                        |
| 157 | + 'required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 158 | + ],  | 
                                                        |
| 159 | + 'price_modifier_line_item_list' => [  | 
                                                        |
| 160 | + 'shortcodes' => ['line_item'],  | 
                                                        |
| 161 | + 'required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],  | 
                                                        |
| 162 | + ],  | 
                                                        |
| 163 | + 'datetime_list' => [  | 
                                                        |
| 164 | + 'shortcodes' => ['datetime'],  | 
                                                        |
| 165 | + 'required' => ['[DATETIME_LIST]'],  | 
                                                        |
| 166 | + ],  | 
                                                        |
| 167 | + 'attendee_list' => [  | 
                                                        |
| 168 | + 'shortcodes' => ['attendee'],  | 
                                                        |
| 169 | + 'required' => ['[ATTENDEE_LIST]'],  | 
                                                        |
| 170 | + ],  | 
                                                        |
| 171 | + 'tax_line_item_list' => [  | 
                                                        |
| 172 | + 'shortcodes' => ['line_item'],  | 
                                                        |
| 173 | + 'required' => ['[TAX_LINE_ITEM_LIST]'],  | 
                                                        |
| 174 | + ],  | 
                                                        |
| 175 | + 'additional_line_item_list' => [  | 
                                                        |
| 176 | + 'shortcodes' => ['line_item'],  | 
                                                        |
| 177 | + 'required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],  | 
                                                        |
| 178 | + ],  | 
                                                        |
| 179 | + 'payment_list' => [  | 
                                                        |
| 180 | + 'shortcodes' => ['payment'],  | 
                                                        |
| 181 | + 'required' => ['[PAYMENT_LIST_*]'],  | 
                                                        |
| 182 | + ],  | 
                                                        |
| 183 | + ];  | 
                                                        |
| 184 | + }  | 
                                                        |
| 185 | +  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + /**  | 
                                                        |
| 188 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger  | 
                                                        |
| 189 | + * is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary  | 
                                                        |
| 190 | + * (i.e. swap out css files or something else).  | 
                                                        |
| 191 | + *  | 
                                                        |
| 192 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.  | 
                                                        |
| 193 | + * @return void  | 
                                                        |
| 194 | + * @since 4.5.0  | 
                                                        |
| 195 | + */  | 
                                                        |
| 196 | + public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 197 | +	{ | 
                                                        |
| 198 | +		if ($sending_messenger_name === 'pdf') { | 
                                                        |
| 199 | +			add_filter('EE_messenger__get_variation__variation', [$this, 'add_html_css'], 10, 8); | 
                                                        |
| 200 | + }  | 
                                                        |
| 201 | + }  | 
                                                        |
| 202 | +  | 
                                                        |
| 203 | +  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * @param $variation_path  | 
                                                        |
| 206 | + * @param EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 207 | + * @param $messenger_name  | 
                                                        |
| 208 | + * @param $message_type_name  | 
                                                        |
| 209 | + * @param $url  | 
                                                        |
| 210 | + * @param $type  | 
                                                        |
| 211 | + * @param $variation  | 
                                                        |
| 212 | + * @param $skip_filters  | 
                                                        |
| 213 | + * @return string  | 
                                                        |
| 214 | + */  | 
                                                        |
| 215 | + public function add_html_css(  | 
                                                        |
| 216 | + $variation_path,  | 
                                                        |
| 217 | + EE_Messages_Template_Pack $template_pack,  | 
                                                        |
| 218 | + $messenger_name,  | 
                                                        |
| 219 | + $message_type_name,  | 
                                                        |
| 220 | + $url,  | 
                                                        |
| 221 | + $type,  | 
                                                        |
| 222 | + $variation,  | 
                                                        |
| 223 | + $skip_filters  | 
                                                        |
| 224 | +	): string { | 
                                                        |
| 225 | + return $template_pack->get_variation(  | 
                                                        |
| 226 | + $this->name,  | 
                                                        |
| 227 | + $message_type_name,  | 
                                                        |
| 228 | + $type,  | 
                                                        |
| 229 | + $variation,  | 
                                                        |
| 230 | + $url,  | 
                                                        |
| 231 | + '.css',  | 
                                                        |
| 232 | + $skip_filters  | 
                                                        |
| 233 | + );  | 
                                                        |
| 234 | + }  | 
                                                        |
| 235 | +  | 
                                                        |
| 236 | +  | 
                                                        |
| 237 | + /**  | 
                                                        |
| 238 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this  | 
                                                        |
| 239 | + * messenger can add their own js.  | 
                                                        |
| 240 | + *  | 
                                                        |
| 241 | + * @return void.  | 
                                                        |
| 242 | + */  | 
                                                        |
| 243 | + public function enqueue_scripts_styles()  | 
                                                        |
| 244 | +	{ | 
                                                        |
| 245 | + parent::enqueue_scripts_styles();  | 
                                                        |
| 246 | +		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles'); | 
                                                        |
| 247 | + }  | 
                                                        |
| 248 | +  | 
                                                        |
| 249 | +  | 
                                                        |
| 250 | + /**  | 
                                                        |
| 251 | + * _set_template_fields  | 
                                                        |
| 252 | + * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 253 | + *  | 
                                                        |
| 254 | + * @access protected  | 
                                                        |
| 255 | + * @return void  | 
                                                        |
| 256 | + */  | 
                                                        |
| 257 | + protected function _set_template_fields()  | 
                                                        |
| 258 | +	{ | 
                                                        |
| 259 | + // any extra template fields that are NOT used by the messenger  | 
                                                        |
| 260 | + // but will get used by a messenger field for shortcode replacement  | 
                                                        |
| 261 | + // get added to the 'extra' key in an associated array  | 
                                                        |
| 262 | + // indexed by the messenger field they relate to.  | 
                                                        |
| 263 | + // This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 264 | + // Also, notice that the "values" are equal to the field type  | 
                                                        |
| 265 | + // that messages admin will use to know what kind of field to display.  | 
                                                        |
| 266 | + // The values ALSO have one index labeled "shortcode".  | 
                                                        |
| 267 | + // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])  | 
                                                        |
| 268 | + // is required in order for this extra field to be displayed.  | 
                                                        |
| 269 | + // If the required shortcode isn't part of the shortcodes array  | 
                                                        |
| 270 | + // then the field is not needed and will not be displayed/parsed.  | 
                                                        |
| 271 | + $this->_template_fields = [  | 
                                                        |
| 272 | + 'subject' => [  | 
                                                        |
| 273 | + 'input' => 'text',  | 
                                                        |
| 274 | +				'label'      => esc_html__('Page Title', 'event_espresso'), | 
                                                        |
| 275 | + 'type' => 'string',  | 
                                                        |
| 276 | + 'required' => true,  | 
                                                        |
| 277 | + 'validation' => true,  | 
                                                        |
| 278 | + 'css_class' => 'large-text',  | 
                                                        |
| 279 | + 'format' => '%s',  | 
                                                        |
| 280 | + ],  | 
                                                        |
| 281 | + 'content' => '',  | 
                                                        |
| 282 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 283 | + 'extra' => [  | 
                                                        |
| 284 | + 'content' => [  | 
                                                        |
| 285 | + 'main' => [  | 
                                                        |
| 286 | + 'input' => 'wp_editor',  | 
                                                        |
| 287 | +						'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 288 | + 'type' => 'string',  | 
                                                        |
| 289 | + 'required' => true,  | 
                                                        |
| 290 | + 'validation' => true,  | 
                                                        |
| 291 | + 'format' => '%s',  | 
                                                        |
| 292 | + 'rows' => '15',  | 
                                                        |
| 293 | + ],  | 
                                                        |
| 294 | + 'event_list' => [  | 
                                                        |
| 295 | + 'input' => 'wp_editor',  | 
                                                        |
| 296 | + 'label' => '[EVENT_LIST]',  | 
                                                        |
| 297 | + 'type' => 'string',  | 
                                                        |
| 298 | + 'required' => false,  | 
                                                        |
| 299 | + 'validation' => true,  | 
                                                        |
| 300 | + 'format' => '%s',  | 
                                                        |
| 301 | + 'rows' => '15',  | 
                                                        |
| 302 | + 'shortcodes_required' => ['[EVENT_LIST]'],  | 
                                                        |
| 303 | + ],  | 
                                                        |
| 304 | + 'ticket_list' => [  | 
                                                        |
| 305 | + 'input' => 'textarea',  | 
                                                        |
| 306 | + 'label' => '[TICKET_LIST]',  | 
                                                        |
| 307 | + 'type' => 'string',  | 
                                                        |
| 308 | + 'required' => false,  | 
                                                        |
| 309 | + 'validation' => true,  | 
                                                        |
| 310 | + 'format' => '%s',  | 
                                                        |
| 311 | + 'css_class' => 'large-text',  | 
                                                        |
| 312 | + 'rows' => '10',  | 
                                                        |
| 313 | + 'shortcodes_required' => ['[TICKET_LIST]'],  | 
                                                        |
| 314 | + ],  | 
                                                        |
| 315 | + 'ticket_line_item_no_pms' => [  | 
                                                        |
| 316 | + 'input' => 'textarea',  | 
                                                        |
| 317 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(  | 
                                                        |
| 318 | + 'Ticket Line Item List with no Price Modifiers',  | 
                                                        |
| 319 | + 'event_espresso'  | 
                                                        |
| 320 | + ),  | 
                                                        |
| 321 | + 'type' => 'string',  | 
                                                        |
| 322 | + 'required' => false,  | 
                                                        |
| 323 | + 'validation' => true,  | 
                                                        |
| 324 | + 'format' => '%s',  | 
                                                        |
| 325 | + 'css_class' => 'large-text',  | 
                                                        |
| 326 | + 'rows' => '5',  | 
                                                        |
| 327 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 328 | + ],  | 
                                                        |
| 329 | + 'ticket_line_item_pms' => [  | 
                                                        |
| 330 | + 'input' => 'textarea',  | 
                                                        |
| 331 | + 'label' => '[TICKET_LINE_ITEM_LIST] <br>' . esc_html__(  | 
                                                        |
| 332 | + 'Ticket Line Item List with Price Modifiers',  | 
                                                        |
| 333 | + 'event_espresso'  | 
                                                        |
| 334 | + ),  | 
                                                        |
| 335 | + 'type' => 'string',  | 
                                                        |
| 336 | + 'required' => false,  | 
                                                        |
| 337 | + 'validation' => true,  | 
                                                        |
| 338 | + 'format' => '%s',  | 
                                                        |
| 339 | + 'css_class' => 'large-text',  | 
                                                        |
| 340 | + 'rows' => '5',  | 
                                                        |
| 341 | + 'shortcodes_required' => ['[TICKET_LINE_ITEM_LIST]'],  | 
                                                        |
| 342 | + ],  | 
                                                        |
| 343 | + 'price_modifier_line_item_list' => [  | 
                                                        |
| 344 | + 'input' => 'textarea',  | 
                                                        |
| 345 | + 'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',  | 
                                                        |
| 346 | + 'type' => 'string',  | 
                                                        |
| 347 | + 'required' => false,  | 
                                                        |
| 348 | + 'validation' => true,  | 
                                                        |
| 349 | + 'format' => '%s',  | 
                                                        |
| 350 | + 'css_class' => 'large-text',  | 
                                                        |
| 351 | + 'rows' => '5',  | 
                                                        |
| 352 | + 'shortcodes_required' => ['[PRICE_MODIFIER_LINE_ITEM_LIST]'],  | 
                                                        |
| 353 | + ],  | 
                                                        |
| 354 | + 'datetime_list' => [  | 
                                                        |
| 355 | + 'input' => 'textarea',  | 
                                                        |
| 356 | + 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 357 | + 'type' => 'string',  | 
                                                        |
| 358 | + 'required' => false,  | 
                                                        |
| 359 | + 'validation' => true,  | 
                                                        |
| 360 | + 'format' => '%s',  | 
                                                        |
| 361 | + 'css_class' => 'large-text',  | 
                                                        |
| 362 | + 'rows' => '5',  | 
                                                        |
| 363 | + 'shortcodes_required' => ['[DATETIME_LIST]'],  | 
                                                        |
| 364 | + ],  | 
                                                        |
| 365 | + 'attendee_list' => [  | 
                                                        |
| 366 | + 'input' => 'textarea',  | 
                                                        |
| 367 | + 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 368 | + 'type' => 'string',  | 
                                                        |
| 369 | + 'required' => false,  | 
                                                        |
| 370 | + 'validation' => true,  | 
                                                        |
| 371 | + 'format' => '%s',  | 
                                                        |
| 372 | + 'css_class' => 'large-text',  | 
                                                        |
| 373 | + 'rows' => '5',  | 
                                                        |
| 374 | + 'shortcodes_required' => ['[ATTENDEE_LIST]'],  | 
                                                        |
| 375 | + ],  | 
                                                        |
| 376 | + 'tax_line_item_list' => [  | 
                                                        |
| 377 | + 'input' => 'textarea',  | 
                                                        |
| 378 | + 'label' => '[TAX_LINE_ITEM_LIST]',  | 
                                                        |
| 379 | + 'type' => 'string',  | 
                                                        |
| 380 | + 'required' => false,  | 
                                                        |
| 381 | + 'validation' => true,  | 
                                                        |
| 382 | + 'format' => '%s',  | 
                                                        |
| 383 | + 'css_class' => 'large-text',  | 
                                                        |
| 384 | + 'rows' => '5',  | 
                                                        |
| 385 | + 'shortcodes_required' => ['[TAX_LINE_ITEM_LIST]'],  | 
                                                        |
| 386 | + ],  | 
                                                        |
| 387 | + 'additional_line_item_list' => [  | 
                                                        |
| 388 | + 'input' => 'textarea',  | 
                                                        |
| 389 | + 'label' => '[ADDITIONAL_LINE_ITEM_LIST]',  | 
                                                        |
| 390 | + 'type' => 'string',  | 
                                                        |
| 391 | + 'required' => false,  | 
                                                        |
| 392 | + 'validation' => true,  | 
                                                        |
| 393 | + 'format' => '%s',  | 
                                                        |
| 394 | + 'css_class' => 'large-text',  | 
                                                        |
| 395 | + 'rows' => '5',  | 
                                                        |
| 396 | + 'shortcodes_required' => ['[ADDITIONAL_LINE_ITEM_LIST]'],  | 
                                                        |
| 397 | + ],  | 
                                                        |
| 398 | + 'payment_list' => [  | 
                                                        |
| 399 | + 'input' => 'textarea',  | 
                                                        |
| 400 | + 'label' => '[PAYMENT_LIST]',  | 
                                                        |
| 401 | + 'type' => 'string',  | 
                                                        |
| 402 | + 'required' => false,  | 
                                                        |
| 403 | + 'validation' => true,  | 
                                                        |
| 404 | + 'format' => '%s',  | 
                                                        |
| 405 | + 'css_class' => 'large-text',  | 
                                                        |
| 406 | + 'rows' => '5',  | 
                                                        |
| 407 | + 'shortcodes_required' => ['[PAYMENT_LIST_*]'],  | 
                                                        |
| 408 | + ],  | 
                                                        |
| 409 | + ],  | 
                                                        |
| 410 | + ],  | 
                                                        |
| 411 | + ];  | 
                                                        |
| 412 | + }  | 
                                                        |
| 413 | +  | 
                                                        |
| 414 | +  | 
                                                        |
| 415 | + /**  | 
                                                        |
| 416 | + * @see definition of this method in parent  | 
                                                        |
| 417 | + * @since 4.5.0  | 
                                                        |
| 418 | + */  | 
                                                        |
| 419 | + protected function _set_default_message_types()  | 
                                                        |
| 420 | +	{ | 
                                                        |
| 421 | + $this->_default_message_types = ['receipt', 'invoice'];  | 
                                                        |
| 422 | + }  | 
                                                        |
| 423 | +  | 
                                                        |
| 424 | +  | 
                                                        |
| 425 | + /**  | 
                                                        |
| 426 | + * @see definition of this method in parent  | 
                                                        |
| 427 | + * @since 4.5.0  | 
                                                        |
| 428 | + */  | 
                                                        |
| 429 | + protected function _set_valid_message_types()  | 
                                                        |
| 430 | +	{ | 
                                                        |
| 431 | + $this->_valid_message_types = ['receipt', 'invoice'];  | 
                                                        |
| 432 | + }  | 
                                                        |
| 433 | +  | 
                                                        |
| 434 | +  | 
                                                        |
| 435 | + /**  | 
                                                        |
| 436 | + * Displays the message in the browser.  | 
                                                        |
| 437 | + *  | 
                                                        |
| 438 | + * @return void.  | 
                                                        |
| 439 | + * @since 4.5.0  | 
                                                        |
| 440 | + */  | 
                                                        |
| 441 | + protected function _send_message()  | 
                                                        |
| 442 | +	{ | 
                                                        |
| 443 | + $this->_template_args = [  | 
                                                        |
| 444 | + 'page_title' => $this->_subject,  | 
                                                        |
| 445 | + 'base_css' => $this->get_variation(  | 
                                                        |
| 446 | + $this->_tmp_pack,  | 
                                                        |
| 447 | + $this->_incoming_message_type->name,  | 
                                                        |
| 448 | + true,  | 
                                                        |
| 449 | + 'base',  | 
                                                        |
| 450 | + $this->_variation  | 
                                                        |
| 451 | + ),  | 
                                                        |
| 452 | + 'print_css' => $this->get_variation(  | 
                                                        |
| 453 | + $this->_tmp_pack,  | 
                                                        |
| 454 | + $this->_incoming_message_type->name,  | 
                                                        |
| 455 | + true,  | 
                                                        |
| 456 | + 'print',  | 
                                                        |
| 457 | + $this->_variation  | 
                                                        |
| 458 | + ),  | 
                                                        |
| 459 | + 'main_css' => $this->get_variation(  | 
                                                        |
| 460 | + $this->_tmp_pack,  | 
                                                        |
| 461 | + $this->_incoming_message_type->name,  | 
                                                        |
| 462 | + true,  | 
                                                        |
| 463 | + 'main',  | 
                                                        |
| 464 | + $this->_variation  | 
                                                        |
| 465 | + ),  | 
                                                        |
| 466 | + 'main_body' => wpautop(  | 
                                                        |
| 467 | + apply_filters(  | 
                                                        |
| 468 | + 'FHEE__EE_Html_messenger___send_message__main_body',  | 
                                                        |
| 469 | + $this->_content,  | 
                                                        |
| 470 | + $this->_content,  | 
                                                        |
| 471 | + $this->_incoming_message_type  | 
                                                        |
| 472 | + )  | 
                                                        |
| 473 | + ),  | 
                                                        |
| 474 | + ];  | 
                                                        |
| 475 | + $this->_deregister_wp_hooks();  | 
                                                        |
| 476 | +		add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts_styles']); | 
                                                        |
| 477 | + echo ($this->_get_main_template());  | 
                                                        |
| 478 | + exit();  | 
                                                        |
| 479 | + }  | 
                                                        |
| 480 | +  | 
                                                        |
| 481 | +  | 
                                                        |
| 482 | + /**  | 
                                                        |
| 483 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't  | 
                                                        |
| 484 | + * interfere with our templates. If users want to add any custom styles or scripts they must use the  | 
                                                        |
| 485 | + * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.  | 
                                                        |
| 486 | + *  | 
                                                        |
| 487 | + * @return void  | 
                                                        |
| 488 | + * @since 4.5.0  | 
                                                        |
| 489 | + */  | 
                                                        |
| 490 | + protected function _deregister_wp_hooks()  | 
                                                        |
| 491 | +	{ | 
                                                        |
| 492 | +		remove_all_actions('wp_head'); | 
                                                        |
| 493 | +		remove_all_actions('wp_footer'); | 
                                                        |
| 494 | +		remove_all_actions('wp_print_footer_scripts'); | 
                                                        |
| 495 | +		remove_all_actions('wp_enqueue_scripts'); | 
                                                        |
| 496 | + global $wp_scripts, $wp_styles;  | 
                                                        |
| 497 | + $wp_scripts = $wp_styles = [];  | 
                                                        |
| 498 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.  | 
                                                        |
| 499 | +		add_action('wp_footer', 'wp_print_footer_scripts'); | 
                                                        |
| 500 | +		add_action('wp_print_footer_scripts', '_wp_footer_scripts'); | 
                                                        |
| 501 | +		add_action('wp_head', 'wp_enqueue_scripts'); | 
                                                        |
| 502 | + }  | 
                                                        |
| 503 | +  | 
                                                        |
| 504 | +  | 
                                                        |
| 505 | + /**  | 
                                                        |
| 506 | + * Overwrite parent _get_main_template for display_html purposes.  | 
                                                        |
| 507 | + *  | 
                                                        |
| 508 | + * @param bool $preview  | 
                                                        |
| 509 | + * @return string  | 
                                                        |
| 510 | + * @since 4.5.0  | 
                                                        |
| 511 | + */  | 
                                                        |
| 512 | + protected function _get_main_template($preview = false): string  | 
                                                        |
| 513 | +	{ | 
                                                        |
| 514 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name);  | 
                                                        |
| 515 | + // include message type as a template arg  | 
                                                        |
| 516 | + $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 517 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 518 | + }  | 
                                                        |
| 519 | +  | 
                                                        |
| 520 | +  | 
                                                        |
| 521 | + /**  | 
                                                        |
| 522 | + * @return void  | 
                                                        |
| 523 | + */  | 
                                                        |
| 524 | + protected function _preview()  | 
                                                        |
| 525 | +	{ | 
                                                        |
| 526 | + $this->_send_message();  | 
                                                        |
| 527 | + }  | 
                                                        |
| 528 | +  | 
                                                        |
| 529 | +  | 
                                                        |
| 530 | + protected function _set_admin_settings_fields()  | 
                                                        |
| 531 | +	{ | 
                                                        |
| 532 | + }  | 
                                                        |
| 533 | +  | 
                                                        |
| 534 | +  | 
                                                        |
| 535 | + /**  | 
                                                        |
| 536 | + * add the "powered by EE" credit link to the HTML receipt and invoice  | 
                                                        |
| 537 | + *  | 
                                                        |
| 538 | + * @param string $content  | 
                                                        |
| 539 | + * @param string $content_again  | 
                                                        |
| 540 | + * @param EE_message_type $incoming_message_type  | 
                                                        |
| 541 | + * @return string  | 
                                                        |
| 542 | + */  | 
                                                        |
| 543 | + public function add_powered_by_credit_link_to_receipt_and_invoice(  | 
                                                        |
| 544 | + string $content,  | 
                                                        |
| 545 | + string $content_again,  | 
                                                        |
| 546 | + EE_message_type $incoming_message_type  | 
                                                        |
| 547 | +	): string { | 
                                                        |
| 548 | + if (  | 
                                                        |
| 549 | + ($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')  | 
                                                        |
| 550 | +			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true) | 
                                                        |
| 551 | +		) { | 
                                                        |
| 552 | + $content .= EEH_Template::powered_by_event_espresso(  | 
                                                        |
| 553 | + 'aln-cntr',  | 
                                                        |
| 554 | + '',  | 
                                                        |
| 555 | + ['utm_content' => 'messages_system']  | 
                                                        |
| 556 | +			) . EEH_HTML::div(EEH_HTML::p(' ')); | 
                                                        |
| 557 | + }  | 
                                                        |
| 558 | + return $content;  | 
                                                        |
| 559 | + }  | 
                                                        |
| 560 | 560 | }  | 
                                                        
@@ -5,648 +5,648 @@  | 
                                                    ||
| 5 | 5 | */  | 
                                                        
| 6 | 6 | class EE_Email_messenger extends EE_messenger  | 
                                                        
| 7 | 7 |  { | 
                                                        
| 8 | - /**  | 
                                                        |
| 9 | - * To field for email  | 
                                                        |
| 10 | - * @var string  | 
                                                        |
| 11 | - */  | 
                                                        |
| 12 | - protected $_to = '';  | 
                                                        |
| 13 | -  | 
                                                        |
| 14 | -  | 
                                                        |
| 15 | - /**  | 
                                                        |
| 16 | - * CC field for email.  | 
                                                        |
| 17 | - * @var string  | 
                                                        |
| 18 | - */  | 
                                                        |
| 19 | - protected $_cc = '';  | 
                                                        |
| 20 | -  | 
                                                        |
| 21 | - /**  | 
                                                        |
| 22 | - * From field for email  | 
                                                        |
| 23 | - * @var string  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - protected $_from = '';  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - /**  | 
                                                        |
| 29 | - * Subject field for email  | 
                                                        |
| 30 | - * @var string  | 
                                                        |
| 31 | - */  | 
                                                        |
| 32 | - protected $_subject = '';  | 
                                                        |
| 33 | -  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | - /**  | 
                                                        |
| 36 | - * Content field for email  | 
                                                        |
| 37 | - * @var string  | 
                                                        |
| 38 | - */  | 
                                                        |
| 39 | - protected $_content = '';  | 
                                                        |
| 40 | -  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - /**  | 
                                                        |
| 43 | - * constructor  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * @access public  | 
                                                        |
| 46 | - */  | 
                                                        |
| 47 | - public function __construct()  | 
                                                        |
| 48 | -    { | 
                                                        |
| 49 | - // set name and description properties  | 
                                                        |
| 50 | - $this->name = 'email';  | 
                                                        |
| 51 | - $this->description = sprintf(  | 
                                                        |
| 52 | - esc_html__(  | 
                                                        |
| 53 | - 'This messenger delivers messages via email using the built-in %s function included with WordPress',  | 
                                                        |
| 54 | - 'event_espresso'  | 
                                                        |
| 55 | - ),  | 
                                                        |
| 56 | - '<code>wp_mail</code>'  | 
                                                        |
| 57 | - );  | 
                                                        |
| 58 | - $this->label = array(  | 
                                                        |
| 59 | -            'singular' => esc_html__('email', 'event_espresso'), | 
                                                        |
| 60 | -            'plural'   => esc_html__('emails', 'event_espresso'), | 
                                                        |
| 61 | - );  | 
                                                        |
| 62 | - $this->activate_on_install = true;  | 
                                                        |
| 63 | -  | 
                                                        |
| 64 | - // we're using defaults so let's call parent constructor that will take care of setting up all the other  | 
                                                        |
| 65 | - // properties  | 
                                                        |
| 66 | - parent::__construct();  | 
                                                        |
| 67 | - }  | 
                                                        |
| 68 | -  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - /**  | 
                                                        |
| 71 | - * see abstract declaration in parent class for details.  | 
                                                        |
| 72 | - */  | 
                                                        |
| 73 | - protected function _set_admin_pages()  | 
                                                        |
| 74 | -    { | 
                                                        |
| 75 | - $this->admin_registered_pages = array(  | 
                                                        |
| 76 | - 'events_edit' => true,  | 
                                                        |
| 77 | - );  | 
                                                        |
| 78 | - }  | 
                                                        |
| 79 | -  | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | - /**  | 
                                                        |
| 82 | - * see abstract declaration in parent class for details  | 
                                                        |
| 83 | - */  | 
                                                        |
| 84 | - protected function _set_valid_shortcodes()  | 
                                                        |
| 85 | -    { | 
                                                        |
| 86 | - // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the  | 
                                                        |
| 87 | - // message type.  | 
                                                        |
| 88 | - $this->_valid_shortcodes = array(  | 
                                                        |
| 89 | -            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 90 | -            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 91 | -            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 92 | - );  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * see abstract declaration in parent class for details  | 
                                                        |
| 98 | - *  | 
                                                        |
| 99 | - * @access protected  | 
                                                        |
| 100 | - * @return void  | 
                                                        |
| 101 | - */  | 
                                                        |
| 102 | - protected function _set_validator_config()  | 
                                                        |
| 103 | -    { | 
                                                        |
| 104 | - $valid_shortcodes = $this->get_valid_shortcodes();  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | - $this->_validator_config = array(  | 
                                                        |
| 107 | - 'to' => array(  | 
                                                        |
| 108 | - 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 109 | - 'type' => 'email',  | 
                                                        |
| 110 | - ),  | 
                                                        |
| 111 | - 'cc' => array(  | 
                                                        |
| 112 | - 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 113 | - 'type' => 'email',  | 
                                                        |
| 114 | - ),  | 
                                                        |
| 115 | - 'from' => array(  | 
                                                        |
| 116 | - 'shortcodes' => $valid_shortcodes['from'],  | 
                                                        |
| 117 | - 'type' => 'email',  | 
                                                        |
| 118 | - ),  | 
                                                        |
| 119 | - 'subject' => array(  | 
                                                        |
| 120 | - 'shortcodes' => array(  | 
                                                        |
| 121 | - 'organization',  | 
                                                        |
| 122 | - 'primary_registration_details',  | 
                                                        |
| 123 | - 'event_author',  | 
                                                        |
| 124 | - 'primary_registration_details',  | 
                                                        |
| 125 | - 'recipient_details',  | 
                                                        |
| 126 | - ),  | 
                                                        |
| 127 | - ),  | 
                                                        |
| 128 | - 'content' => array(  | 
                                                        |
| 129 | - 'shortcodes' => array(  | 
                                                        |
| 130 | - 'event_list',  | 
                                                        |
| 131 | - 'attendee_list',  | 
                                                        |
| 132 | - 'ticket_list',  | 
                                                        |
| 133 | - 'organization',  | 
                                                        |
| 134 | - 'primary_registration_details',  | 
                                                        |
| 135 | - 'primary_registration_list',  | 
                                                        |
| 136 | - 'event_author',  | 
                                                        |
| 137 | - 'recipient_details',  | 
                                                        |
| 138 | - 'recipient_list',  | 
                                                        |
| 139 | - 'transaction',  | 
                                                        |
| 140 | - 'messenger',  | 
                                                        |
| 141 | - ),  | 
                                                        |
| 142 | - ),  | 
                                                        |
| 143 | - 'attendee_list' => array(  | 
                                                        |
| 144 | -                'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 145 | -                'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 146 | - ),  | 
                                                        |
| 147 | - 'event_list' => array(  | 
                                                        |
| 148 | - 'shortcodes' => array(  | 
                                                        |
| 149 | - 'event',  | 
                                                        |
| 150 | - 'attendee_list',  | 
                                                        |
| 151 | - 'ticket_list',  | 
                                                        |
| 152 | - 'venue',  | 
                                                        |
| 153 | - 'datetime_list',  | 
                                                        |
| 154 | - 'attendee',  | 
                                                        |
| 155 | - 'primary_registration_details',  | 
                                                        |
| 156 | - 'primary_registration_list',  | 
                                                        |
| 157 | - 'event_author',  | 
                                                        |
| 158 | - 'recipient_details',  | 
                                                        |
| 159 | - 'recipient_list',  | 
                                                        |
| 160 | - ),  | 
                                                        |
| 161 | -                'required'   => array('[EVENT_LIST]'), | 
                                                        |
| 162 | - ),  | 
                                                        |
| 163 | - 'ticket_list' => array(  | 
                                                        |
| 164 | - 'shortcodes' => array(  | 
                                                        |
| 165 | - 'event_list',  | 
                                                        |
| 166 | - 'attendee_list',  | 
                                                        |
| 167 | - 'ticket',  | 
                                                        |
| 168 | - 'datetime_list',  | 
                                                        |
| 169 | - 'primary_registration_details',  | 
                                                        |
| 170 | - 'recipient_details',  | 
                                                        |
| 171 | - ),  | 
                                                        |
| 172 | -                'required'   => array('[TICKET_LIST]'), | 
                                                        |
| 173 | - ),  | 
                                                        |
| 174 | - 'datetime_list' => array(  | 
                                                        |
| 175 | -                'shortcodes' => array('datetime'), | 
                                                        |
| 176 | -                'required'   => array('[DATETIME_LIST]'), | 
                                                        |
| 177 | - ),  | 
                                                        |
| 178 | - );  | 
                                                        |
| 179 | - }  | 
                                                        |
| 180 | -  | 
                                                        |
| 181 | -  | 
                                                        |
| 182 | - /**  | 
                                                        |
| 183 | - * @see parent EE_messenger class for docs  | 
                                                        |
| 184 | - * @since 4.5.0  | 
                                                        |
| 185 | - */  | 
                                                        |
| 186 | - public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 187 | -    { | 
                                                        |
| 188 | -        if ($sending_messenger_name === 'html') { | 
                                                        |
| 189 | -            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | - }  | 
                                                        |
| 192 | -  | 
                                                        |
| 193 | -  | 
                                                        |
| 194 | - public function add_email_css(  | 
                                                        |
| 195 | - $variation_path,  | 
                                                        |
| 196 | - $messenger,  | 
                                                        |
| 197 | - $message_type,  | 
                                                        |
| 198 | - $type,  | 
                                                        |
| 199 | - $variation,  | 
                                                        |
| 200 | - $file_extension,  | 
                                                        |
| 201 | - $url,  | 
                                                        |
| 202 | - EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 203 | -    ) { | 
                                                        |
| 204 | - // prevent recursion on this callback.  | 
                                                        |
| 205 | -        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); | 
                                                        |
| 206 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | -        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 209 | - return $variation;  | 
                                                        |
| 210 | - }  | 
                                                        |
| 211 | -  | 
                                                        |
| 212 | -  | 
                                                        |
| 213 | - /**  | 
                                                        |
| 214 | - * See parent for details  | 
                                                        |
| 215 | - *  | 
                                                        |
| 216 | - * @access protected  | 
                                                        |
| 217 | - * @return void  | 
                                                        |
| 218 | - */  | 
                                                        |
| 219 | - protected function _set_test_settings_fields()  | 
                                                        |
| 220 | -    { | 
                                                        |
| 221 | - $this->_test_settings_fields = array(  | 
                                                        |
| 222 | - 'to' => array(  | 
                                                        |
| 223 | - 'input' => 'text',  | 
                                                        |
| 224 | -                'label'      => esc_html__('Send a test email to', 'event_espresso'), | 
                                                        |
| 225 | - 'type' => 'email',  | 
                                                        |
| 226 | - 'required' => false,  | 
                                                        |
| 227 | - 'validation' => true,  | 
                                                        |
| 228 | - 'css_class' => 'large-text',  | 
                                                        |
| 229 | - 'format' => '%s',  | 
                                                        |
| 230 | -                'default'    => get_bloginfo('admin_email'), | 
                                                        |
| 231 | - ),  | 
                                                        |
| 232 | - 'subject' => array(  | 
                                                        |
| 233 | - 'input' => 'hidden',  | 
                                                        |
| 234 | - 'label' => '',  | 
                                                        |
| 235 | - 'type' => 'string',  | 
                                                        |
| 236 | - 'required' => false,  | 
                                                        |
| 237 | - 'validation' => false,  | 
                                                        |
| 238 | - 'format' => '%s',  | 
                                                        |
| 239 | -                'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), | 
                                                        |
| 240 | - 'default' => '',  | 
                                                        |
| 241 | - 'css_class' => '',  | 
                                                        |
| 242 | - ),  | 
                                                        |
| 243 | - );  | 
                                                        |
| 244 | - }  | 
                                                        |
| 245 | -  | 
                                                        |
| 246 | -  | 
                                                        |
| 247 | - /**  | 
                                                        |
| 248 | - * _set_template_fields  | 
                                                        |
| 249 | - * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 250 | - *  | 
                                                        |
| 251 | - * @access protected  | 
                                                        |
| 252 | - * @return void  | 
                                                        |
| 253 | - */  | 
                                                        |
| 254 | - protected function _set_template_fields()  | 
                                                        |
| 255 | -    { | 
                                                        |
| 256 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for  | 
                                                        |
| 257 | - // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field  | 
                                                        |
| 258 | - // they relate to. This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 259 | - // Also, notice that the "values" are equal to the field type that messages admin will use to know what  | 
                                                        |
| 260 | - // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array  | 
                                                        |
| 261 | - // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be  | 
                                                        |
| 262 | - // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and  | 
                                                        |
| 263 | - // will not be displayed/parsed.  | 
                                                        |
| 264 | - $this->_template_fields = array(  | 
                                                        |
| 265 | - 'to' => array(  | 
                                                        |
| 266 | - 'input' => 'text',  | 
                                                        |
| 267 | - 'label' => esc_html_x(  | 
                                                        |
| 268 | - 'To',  | 
                                                        |
| 269 | - 'Label for the "To" field for email addresses',  | 
                                                        |
| 270 | - 'event_espresso'  | 
                                                        |
| 271 | - ),  | 
                                                        |
| 272 | - 'type' => 'string',  | 
                                                        |
| 273 | - 'required' => true,  | 
                                                        |
| 274 | - 'validation' => true,  | 
                                                        |
| 275 | - 'css_class' => 'large-text',  | 
                                                        |
| 276 | - 'format' => '%s',  | 
                                                        |
| 277 | - ),  | 
                                                        |
| 278 | - 'cc' => array(  | 
                                                        |
| 279 | - 'input' => 'text',  | 
                                                        |
| 280 | - 'label' => esc_html_x(  | 
                                                        |
| 281 | - 'CC',  | 
                                                        |
| 282 | - 'Label for the "Carbon Copy" field used for additional email addresses',  | 
                                                        |
| 283 | - 'event_espresso'  | 
                                                        |
| 284 | - ),  | 
                                                        |
| 285 | - 'type' => 'string',  | 
                                                        |
| 286 | - 'required' => false,  | 
                                                        |
| 287 | - 'validation' => true,  | 
                                                        |
| 288 | - 'css_class' => 'large-text',  | 
                                                        |
| 289 | - 'format' => '%s',  | 
                                                        |
| 290 | - ),  | 
                                                        |
| 291 | - 'from' => array(  | 
                                                        |
| 292 | - 'input' => 'text',  | 
                                                        |
| 293 | - 'label' => esc_html_x(  | 
                                                        |
| 294 | - 'From',  | 
                                                        |
| 295 | - 'Label for the "From" field for email addresses.',  | 
                                                        |
| 296 | - 'event_espresso'  | 
                                                        |
| 297 | - ),  | 
                                                        |
| 298 | - 'type' => 'string',  | 
                                                        |
| 299 | - 'required' => true,  | 
                                                        |
| 300 | - 'validation' => true,  | 
                                                        |
| 301 | - 'css_class' => 'large-text',  | 
                                                        |
| 302 | - 'format' => '%s',  | 
                                                        |
| 303 | - ),  | 
                                                        |
| 304 | - 'subject' => array(  | 
                                                        |
| 305 | - 'input' => 'text',  | 
                                                        |
| 306 | - 'label' => esc_html_x(  | 
                                                        |
| 307 | - 'Subject',  | 
                                                        |
| 308 | - 'Label for the "Subject" field (short description of contents) for emails.',  | 
                                                        |
| 309 | - 'event_espresso'  | 
                                                        |
| 310 | - ),  | 
                                                        |
| 311 | - 'type' => 'string',  | 
                                                        |
| 312 | - 'required' => true,  | 
                                                        |
| 313 | - 'validation' => true,  | 
                                                        |
| 314 | - 'css_class' => 'large-text',  | 
                                                        |
| 315 | - 'format' => '%s',  | 
                                                        |
| 316 | - ),  | 
                                                        |
| 317 | - 'content' => '',  | 
                                                        |
| 318 | - // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 319 | - 'extra' => array(  | 
                                                        |
| 320 | - 'content' => array(  | 
                                                        |
| 321 | - 'main' => array(  | 
                                                        |
| 322 | - 'input' => 'wp_editor',  | 
                                                        |
| 323 | -                        'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 324 | - 'type' => 'string',  | 
                                                        |
| 325 | - 'required' => true,  | 
                                                        |
| 326 | - 'validation' => true,  | 
                                                        |
| 327 | - 'format' => '%s',  | 
                                                        |
| 328 | - 'rows' => '15',  | 
                                                        |
| 329 | - ),  | 
                                                        |
| 330 | - 'event_list' => array(  | 
                                                        |
| 331 | - 'input' => 'wp_editor',  | 
                                                        |
| 332 | - 'label' => '[EVENT_LIST]',  | 
                                                        |
| 333 | - 'type' => 'string',  | 
                                                        |
| 334 | - 'required' => false,  | 
                                                        |
| 335 | - 'validation' => true,  | 
                                                        |
| 336 | - 'format' => '%s',  | 
                                                        |
| 337 | - 'rows' => '15',  | 
                                                        |
| 338 | -                        'shortcodes_required' => array('[EVENT_LIST]'), | 
                                                        |
| 339 | - ),  | 
                                                        |
| 340 | - 'attendee_list' => array(  | 
                                                        |
| 341 | - 'input' => 'textarea',  | 
                                                        |
| 342 | - 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 343 | - 'type' => 'string',  | 
                                                        |
| 344 | - 'required' => false,  | 
                                                        |
| 345 | - 'validation' => true,  | 
                                                        |
| 346 | - 'format' => '%s',  | 
                                                        |
| 347 | - 'css_class' => 'large-text',  | 
                                                        |
| 348 | - 'rows' => '5',  | 
                                                        |
| 349 | -                        'shortcodes_required' => array('[ATTENDEE_LIST]'), | 
                                                        |
| 350 | - ),  | 
                                                        |
| 351 | - 'ticket_list' => array(  | 
                                                        |
| 352 | - 'input' => 'textarea',  | 
                                                        |
| 353 | - 'label' => '[TICKET_LIST]',  | 
                                                        |
| 354 | - 'type' => 'string',  | 
                                                        |
| 355 | - 'required' => false,  | 
                                                        |
| 356 | - 'validation' => true,  | 
                                                        |
| 357 | - 'format' => '%s',  | 
                                                        |
| 358 | - 'css_class' => 'large-text',  | 
                                                        |
| 359 | - 'rows' => '10',  | 
                                                        |
| 360 | -                        'shortcodes_required' => array('[TICKET_LIST]'), | 
                                                        |
| 361 | - ),  | 
                                                        |
| 362 | - 'datetime_list' => array(  | 
                                                        |
| 363 | - 'input' => 'textarea',  | 
                                                        |
| 364 | - 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 365 | - 'type' => 'string',  | 
                                                        |
| 366 | - 'required' => false,  | 
                                                        |
| 367 | - 'validation' => true,  | 
                                                        |
| 368 | - 'format' => '%s',  | 
                                                        |
| 369 | - 'css_class' => 'large-text',  | 
                                                        |
| 370 | - 'rows' => '10',  | 
                                                        |
| 371 | -                        'shortcodes_required' => array('[DATETIME_LIST]'), | 
                                                        |
| 372 | - ),  | 
                                                        |
| 373 | - ),  | 
                                                        |
| 374 | - ),  | 
                                                        |
| 375 | - );  | 
                                                        |
| 376 | - }  | 
                                                        |
| 377 | -  | 
                                                        |
| 378 | -  | 
                                                        |
| 379 | - /**  | 
                                                        |
| 380 | - * See definition of this class in parent  | 
                                                        |
| 381 | - */  | 
                                                        |
| 382 | - protected function _set_default_message_types()  | 
                                                        |
| 383 | -    { | 
                                                        |
| 384 | - $this->_default_message_types = array(  | 
                                                        |
| 385 | - 'payment',  | 
                                                        |
| 386 | - 'payment_refund',  | 
                                                        |
| 387 | - 'registration',  | 
                                                        |
| 388 | - 'not_approved_registration',  | 
                                                        |
| 389 | - 'pending_approval',  | 
                                                        |
| 390 | - );  | 
                                                        |
| 391 | - }  | 
                                                        |
| 392 | -  | 
                                                        |
| 393 | -  | 
                                                        |
| 394 | - /**  | 
                                                        |
| 395 | - * @see definition of this class in parent  | 
                                                        |
| 396 | - * @since 4.5.0  | 
                                                        |
| 397 | - */  | 
                                                        |
| 398 | - protected function _set_valid_message_types()  | 
                                                        |
| 399 | -    { | 
                                                        |
| 400 | - $this->_valid_message_types = array(  | 
                                                        |
| 401 | - 'payment',  | 
                                                        |
| 402 | - 'registration',  | 
                                                        |
| 403 | - 'not_approved_registration',  | 
                                                        |
| 404 | - 'declined_registration',  | 
                                                        |
| 405 | - 'cancelled_registration',  | 
                                                        |
| 406 | - 'pending_approval',  | 
                                                        |
| 407 | - 'registration_summary',  | 
                                                        |
| 408 | - 'payment_reminder',  | 
                                                        |
| 409 | - 'payment_declined',  | 
                                                        |
| 410 | - 'payment_refund',  | 
                                                        |
| 411 | - );  | 
                                                        |
| 412 | - }  | 
                                                        |
| 413 | -  | 
                                                        |
| 414 | -  | 
                                                        |
| 415 | - /**  | 
                                                        |
| 416 | - * setting up admin_settings_fields for messenger.  | 
                                                        |
| 417 | - */  | 
                                                        |
| 418 | - protected function _set_admin_settings_fields()  | 
                                                        |
| 419 | -    { | 
                                                        |
| 420 | - }  | 
                                                        |
| 421 | -  | 
                                                        |
| 422 | - /**  | 
                                                        |
| 423 | - * We just deliver the messages don't kill us!!  | 
                                                        |
| 424 | - *  | 
                                                        |
| 425 | - * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if  | 
                                                        |
| 426 | - * present.  | 
                                                        |
| 427 | - * @throws EE_Error  | 
                                                        |
| 428 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 429 | - */  | 
                                                        |
| 430 | - protected function _send_message()  | 
                                                        |
| 431 | -    { | 
                                                        |
| 432 | - $success = wp_mail(  | 
                                                        |
| 433 | - $this->_to,  | 
                                                        |
| 434 | - // some old values for subject may be expecting HTML entities to be decoded in the subject  | 
                                                        |
| 435 | - // and subjects aren't interpreted as HTML, so there should be no HTML in them  | 
                                                        |
| 436 | - wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),  | 
                                                        |
| 437 | - $this->_body(),  | 
                                                        |
| 438 | - $this->_headers()  | 
                                                        |
| 439 | - );  | 
                                                        |
| 440 | -        if (! $success) { | 
                                                        |
| 441 | - EE_Error::add_error(  | 
                                                        |
| 442 | - sprintf(  | 
                                                        |
| 443 | - esc_html__(  | 
                                                        |
| 444 | - 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',  | 
                                                        |
| 445 | - 'event_espresso'  | 
                                                        |
| 446 | - ),  | 
                                                        |
| 447 | - $this->_to,  | 
                                                        |
| 448 | - $this->_from,  | 
                                                        |
| 449 | - '<br />'  | 
                                                        |
| 450 | - ),  | 
                                                        |
| 451 | - __FILE__,  | 
                                                        |
| 452 | - __FUNCTION__,  | 
                                                        |
| 453 | - __LINE__  | 
                                                        |
| 454 | - );  | 
                                                        |
| 455 | - }  | 
                                                        |
| 456 | - return $success;  | 
                                                        |
| 457 | - }  | 
                                                        |
| 458 | -  | 
                                                        |
| 459 | -  | 
                                                        |
| 460 | - /**  | 
                                                        |
| 461 | - * see parent for definition  | 
                                                        |
| 462 | - *  | 
                                                        |
| 463 | - * @return string html body of the message content and the related css.  | 
                                                        |
| 464 | - * @throws EE_Error  | 
                                                        |
| 465 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 466 | - */  | 
                                                        |
| 467 | - protected function _preview()  | 
                                                        |
| 468 | -    { | 
                                                        |
| 469 | - return $this->_body(true);  | 
                                                        |
| 470 | - }  | 
                                                        |
| 471 | -  | 
                                                        |
| 472 | -  | 
                                                        |
| 473 | - /**  | 
                                                        |
| 474 | - * Setup headers for email  | 
                                                        |
| 475 | - *  | 
                                                        |
| 476 | - * @access protected  | 
                                                        |
| 477 | - * @return string formatted header for email  | 
                                                        |
| 478 | - */  | 
                                                        |
| 479 | - protected function _headers()  | 
                                                        |
| 480 | -    { | 
                                                        |
| 481 | - $this->_ensure_has_from_email_address();  | 
                                                        |
| 482 | - $from = $this->_from;  | 
                                                        |
| 483 | - $headers = array(  | 
                                                        |
| 484 | - 'From:' . $from,  | 
                                                        |
| 485 | - 'Reply-To:' . $from,  | 
                                                        |
| 486 | - 'Content-Type:text/html; charset=utf-8',  | 
                                                        |
| 487 | - );  | 
                                                        |
| 488 | -  | 
                                                        |
| 489 | - /**  | 
                                                        |
| 490 | - * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to  | 
                                                        |
| 491 | - * cover back compat where there may be users who have saved cc values in their db for the newsletter message  | 
                                                        |
| 492 | - * type which they are no longer able to change.  | 
                                                        |
| 493 | - */  | 
                                                        |
| 494 | -        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { | 
                                                        |
| 495 | - $headers[] = 'cc: ' . $this->_cc;  | 
                                                        |
| 496 | - }  | 
                                                        |
| 497 | -  | 
                                                        |
| 498 | - // but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the  | 
                                                        |
| 499 | - // header.  | 
                                                        |
| 500 | -        add_filter('wp_mail_from', array($this, 'set_from_address'), 100); | 
                                                        |
| 501 | -        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); | 
                                                        |
| 502 | -        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); | 
                                                        |
| 503 | - }  | 
                                                        |
| 504 | -  | 
                                                        |
| 505 | -  | 
                                                        |
| 506 | - /**  | 
                                                        |
| 507 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email  | 
                                                        |
| 508 | - * address for the from address to avoid problems with sending emails.  | 
                                                        |
| 509 | - */  | 
                                                        |
| 510 | - protected function _ensure_has_from_email_address()  | 
                                                        |
| 511 | -    { | 
                                                        |
| 512 | -        if (empty($this->_from)) { | 
                                                        |
| 513 | -            $this->_from = get_bloginfo('admin_email'); | 
                                                        |
| 514 | - }  | 
                                                        |
| 515 | - }  | 
                                                        |
| 516 | -  | 
                                                        |
| 517 | -  | 
                                                        |
| 518 | - /**  | 
                                                        |
| 519 | -     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> | 
                                                        |
| 520 | -     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* | 
                                                        |
| 521 | - * be empty  | 
                                                        |
| 522 | - *  | 
                                                        |
| 523 | - * @since 4.3.1  | 
                                                        |
| 524 | - * @return array  | 
                                                        |
| 525 | - */  | 
                                                        |
| 526 | - private function _parse_from()  | 
                                                        |
| 527 | -    { | 
                                                        |
| 528 | -        if (strpos($this->_from, '<') !== false) { | 
                                                        |
| 529 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);  | 
                                                        |
| 530 | -            $from_name = str_replace('"', '', $from_name); | 
                                                        |
| 531 | - $from_name = trim($from_name);  | 
                                                        |
| 532 | -  | 
                                                        |
| 533 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1);  | 
                                                        |
| 534 | -            $from_email = str_replace('>', '', $from_email); | 
                                                        |
| 535 | - $from_email = trim($from_email);  | 
                                                        |
| 536 | -        } elseif (trim($this->_from) !== '') { | 
                                                        |
| 537 | - $from_name = '';  | 
                                                        |
| 538 | - $from_email = trim($this->_from);  | 
                                                        |
| 539 | -        } else { | 
                                                        |
| 540 | - $from_name = $from_email = '';  | 
                                                        |
| 541 | - }  | 
                                                        |
| 542 | - return array($from_name, $from_email);  | 
                                                        |
| 543 | - }  | 
                                                        |
| 544 | -  | 
                                                        |
| 545 | -  | 
                                                        |
| 546 | - /**  | 
                                                        |
| 547 | - * Callback for the wp_mail_from filter.  | 
                                                        |
| 548 | - *  | 
                                                        |
| 549 | - * @since 4.3.1  | 
                                                        |
| 550 | - * @param string $from_email What the original from_email is.  | 
                                                        |
| 551 | - * @return string  | 
                                                        |
| 552 | - */  | 
                                                        |
| 553 | - public function set_from_address($from_email)  | 
                                                        |
| 554 | -    { | 
                                                        |
| 555 | - $parsed_from = $this->_parse_from();  | 
                                                        |
| 556 | - // includes fallback if the parsing failed.  | 
                                                        |
| 557 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1])  | 
                                                        |
| 558 | - ? $parsed_from[1]  | 
                                                        |
| 559 | -            : get_bloginfo('admin_email'); | 
                                                        |
| 560 | - return $from_email;  | 
                                                        |
| 561 | - }  | 
                                                        |
| 562 | -  | 
                                                        |
| 563 | -  | 
                                                        |
| 564 | - /**  | 
                                                        |
| 565 | - * Callback fro the wp_mail_from_name filter.  | 
                                                        |
| 566 | - *  | 
                                                        |
| 567 | - * @since 4.3.1  | 
                                                        |
| 568 | - * @param string $from_name The original from_name.  | 
                                                        |
| 569 | - * @return string  | 
                                                        |
| 570 | - */  | 
                                                        |
| 571 | - public function set_from_name($from_name)  | 
                                                        |
| 572 | -    { | 
                                                        |
| 573 | - $parsed_from = $this->_parse_from();  | 
                                                        |
| 574 | -        if (is_array($parsed_from) && ! empty($parsed_from[0])) { | 
                                                        |
| 575 | - $from_name = $parsed_from[0];  | 
                                                        |
| 576 | - }  | 
                                                        |
| 577 | -  | 
                                                        |
| 578 | - // if from name is "WordPress" let's sub in the site name instead (more friendly!)  | 
                                                        |
| 579 | - // but realize the default name is HTML entity-encoded  | 
                                                        |
| 580 | - $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;  | 
                                                        |
| 581 | -  | 
                                                        |
| 582 | - return $from_name;  | 
                                                        |
| 583 | - }  | 
                                                        |
| 584 | -  | 
                                                        |
| 585 | -  | 
                                                        |
| 586 | - /**  | 
                                                        |
| 587 | - * setup body for email  | 
                                                        |
| 588 | - *  | 
                                                        |
| 589 | - * @param bool $preview will determine whether this is preview template or not.  | 
                                                        |
| 590 | - * @return string formatted body for email.  | 
                                                        |
| 591 | - * @throws EE_Error  | 
                                                        |
| 592 | - * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 593 | - */  | 
                                                        |
| 594 | - protected function _body($preview = false)  | 
                                                        |
| 595 | -    { | 
                                                        |
| 596 | - // setup template args!  | 
                                                        |
| 597 | - $this->_template_args = array(  | 
                                                        |
| 598 | - 'subject' => $this->_subject,  | 
                                                        |
| 599 | - 'from' => $this->_from,  | 
                                                        |
| 600 | - 'main_body' => wpautop($this->_content),  | 
                                                        |
| 601 | - );  | 
                                                        |
| 602 | - $body = $this->_get_main_template($preview);  | 
                                                        |
| 603 | -  | 
                                                        |
| 604 | - /**  | 
                                                        |
| 605 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.  | 
                                                        |
| 606 | - *  | 
                                                        |
| 607 | - * @type bool $preview Indicates whether a preview is being generated or not.  | 
                                                        |
| 608 | - * @return bool true indicates to use the inliner, false bypasses it.  | 
                                                        |
| 609 | - */  | 
                                                        |
| 610 | -        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { | 
                                                        |
| 611 | - // require CssToInlineStyles library and its dependencies via composer autoloader  | 
                                                        |
| 612 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';  | 
                                                        |
| 613 | -  | 
                                                        |
| 614 | - // now if this isn't a preview, let's setup the body so it has inline styles  | 
                                                        |
| 615 | -            if (! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 616 | - $style = file_get_contents(  | 
                                                        |
| 617 | - $this->get_variation(  | 
                                                        |
| 618 | - $this->_tmp_pack,  | 
                                                        |
| 619 | - $this->_incoming_message_type->name,  | 
                                                        |
| 620 | - false,  | 
                                                        |
| 621 | - 'main',  | 
                                                        |
| 622 | - $this->_variation  | 
                                                        |
| 623 | - ),  | 
                                                        |
| 624 | - true  | 
                                                        |
| 625 | - );  | 
                                                        |
| 626 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);  | 
                                                        |
| 627 | - // for some reason the library has a bracket and new line at the beginning. This takes care of that.  | 
                                                        |
| 628 | - $body = ltrim($CSS->convert(true), ">\n");  | 
                                                        |
| 629 | - // see https://events.codebasehq.com/projects/event-espresso/tickets/8609  | 
                                                        |
| 630 | - $body = ltrim($body, "<?");  | 
                                                        |
| 631 | - }  | 
                                                        |
| 632 | - }  | 
                                                        |
| 633 | - return $body;  | 
                                                        |
| 634 | - }  | 
                                                        |
| 635 | -  | 
                                                        |
| 636 | -  | 
                                                        |
| 637 | - /**  | 
                                                        |
| 638 | - * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 639 | - *  | 
                                                        |
| 640 | - * @access public  | 
                                                        |
| 641 | - * @return array  | 
                                                        |
| 642 | - */  | 
                                                        |
| 643 | - public function get_existing_test_settings()  | 
                                                        |
| 644 | -    { | 
                                                        |
| 645 | - $settings = parent::get_existing_test_settings();  | 
                                                        |
| 646 | - // override subject if present because we always want it to be fresh.  | 
                                                        |
| 647 | -        if (is_array($settings) && ! empty($settings['subject'])) { | 
                                                        |
| 648 | -            $settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); | 
                                                        |
| 649 | - }  | 
                                                        |
| 650 | - return $settings;  | 
                                                        |
| 651 | - }  | 
                                                        |
| 8 | + /**  | 
                                                        |
| 9 | + * To field for email  | 
                                                        |
| 10 | + * @var string  | 
                                                        |
| 11 | + */  | 
                                                        |
| 12 | + protected $_to = '';  | 
                                                        |
| 13 | +  | 
                                                        |
| 14 | +  | 
                                                        |
| 15 | + /**  | 
                                                        |
| 16 | + * CC field for email.  | 
                                                        |
| 17 | + * @var string  | 
                                                        |
| 18 | + */  | 
                                                        |
| 19 | + protected $_cc = '';  | 
                                                        |
| 20 | +  | 
                                                        |
| 21 | + /**  | 
                                                        |
| 22 | + * From field for email  | 
                                                        |
| 23 | + * @var string  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + protected $_from = '';  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + /**  | 
                                                        |
| 29 | + * Subject field for email  | 
                                                        |
| 30 | + * @var string  | 
                                                        |
| 31 | + */  | 
                                                        |
| 32 | + protected $_subject = '';  | 
                                                        |
| 33 | +  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | + /**  | 
                                                        |
| 36 | + * Content field for email  | 
                                                        |
| 37 | + * @var string  | 
                                                        |
| 38 | + */  | 
                                                        |
| 39 | + protected $_content = '';  | 
                                                        |
| 40 | +  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + /**  | 
                                                        |
| 43 | + * constructor  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * @access public  | 
                                                        |
| 46 | + */  | 
                                                        |
| 47 | + public function __construct()  | 
                                                        |
| 48 | +	{ | 
                                                        |
| 49 | + // set name and description properties  | 
                                                        |
| 50 | + $this->name = 'email';  | 
                                                        |
| 51 | + $this->description = sprintf(  | 
                                                        |
| 52 | + esc_html__(  | 
                                                        |
| 53 | + 'This messenger delivers messages via email using the built-in %s function included with WordPress',  | 
                                                        |
| 54 | + 'event_espresso'  | 
                                                        |
| 55 | + ),  | 
                                                        |
| 56 | + '<code>wp_mail</code>'  | 
                                                        |
| 57 | + );  | 
                                                        |
| 58 | + $this->label = array(  | 
                                                        |
| 59 | +			'singular' => esc_html__('email', 'event_espresso'), | 
                                                        |
| 60 | +			'plural'   => esc_html__('emails', 'event_espresso'), | 
                                                        |
| 61 | + );  | 
                                                        |
| 62 | + $this->activate_on_install = true;  | 
                                                        |
| 63 | +  | 
                                                        |
| 64 | + // we're using defaults so let's call parent constructor that will take care of setting up all the other  | 
                                                        |
| 65 | + // properties  | 
                                                        |
| 66 | + parent::__construct();  | 
                                                        |
| 67 | + }  | 
                                                        |
| 68 | +  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + /**  | 
                                                        |
| 71 | + * see abstract declaration in parent class for details.  | 
                                                        |
| 72 | + */  | 
                                                        |
| 73 | + protected function _set_admin_pages()  | 
                                                        |
| 74 | +	{ | 
                                                        |
| 75 | + $this->admin_registered_pages = array(  | 
                                                        |
| 76 | + 'events_edit' => true,  | 
                                                        |
| 77 | + );  | 
                                                        |
| 78 | + }  | 
                                                        |
| 79 | +  | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | + /**  | 
                                                        |
| 82 | + * see abstract declaration in parent class for details  | 
                                                        |
| 83 | + */  | 
                                                        |
| 84 | + protected function _set_valid_shortcodes()  | 
                                                        |
| 85 | +	{ | 
                                                        |
| 86 | + // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the  | 
                                                        |
| 87 | + // message type.  | 
                                                        |
| 88 | + $this->_valid_shortcodes = array(  | 
                                                        |
| 89 | +			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 90 | +			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 91 | +			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 92 | + );  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * see abstract declaration in parent class for details  | 
                                                        |
| 98 | + *  | 
                                                        |
| 99 | + * @access protected  | 
                                                        |
| 100 | + * @return void  | 
                                                        |
| 101 | + */  | 
                                                        |
| 102 | + protected function _set_validator_config()  | 
                                                        |
| 103 | +	{ | 
                                                        |
| 104 | + $valid_shortcodes = $this->get_valid_shortcodes();  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | + $this->_validator_config = array(  | 
                                                        |
| 107 | + 'to' => array(  | 
                                                        |
| 108 | + 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 109 | + 'type' => 'email',  | 
                                                        |
| 110 | + ),  | 
                                                        |
| 111 | + 'cc' => array(  | 
                                                        |
| 112 | + 'shortcodes' => $valid_shortcodes['to'],  | 
                                                        |
| 113 | + 'type' => 'email',  | 
                                                        |
| 114 | + ),  | 
                                                        |
| 115 | + 'from' => array(  | 
                                                        |
| 116 | + 'shortcodes' => $valid_shortcodes['from'],  | 
                                                        |
| 117 | + 'type' => 'email',  | 
                                                        |
| 118 | + ),  | 
                                                        |
| 119 | + 'subject' => array(  | 
                                                        |
| 120 | + 'shortcodes' => array(  | 
                                                        |
| 121 | + 'organization',  | 
                                                        |
| 122 | + 'primary_registration_details',  | 
                                                        |
| 123 | + 'event_author',  | 
                                                        |
| 124 | + 'primary_registration_details',  | 
                                                        |
| 125 | + 'recipient_details',  | 
                                                        |
| 126 | + ),  | 
                                                        |
| 127 | + ),  | 
                                                        |
| 128 | + 'content' => array(  | 
                                                        |
| 129 | + 'shortcodes' => array(  | 
                                                        |
| 130 | + 'event_list',  | 
                                                        |
| 131 | + 'attendee_list',  | 
                                                        |
| 132 | + 'ticket_list',  | 
                                                        |
| 133 | + 'organization',  | 
                                                        |
| 134 | + 'primary_registration_details',  | 
                                                        |
| 135 | + 'primary_registration_list',  | 
                                                        |
| 136 | + 'event_author',  | 
                                                        |
| 137 | + 'recipient_details',  | 
                                                        |
| 138 | + 'recipient_list',  | 
                                                        |
| 139 | + 'transaction',  | 
                                                        |
| 140 | + 'messenger',  | 
                                                        |
| 141 | + ),  | 
                                                        |
| 142 | + ),  | 
                                                        |
| 143 | + 'attendee_list' => array(  | 
                                                        |
| 144 | +				'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 145 | +				'required'   => array('[ATTENDEE_LIST]'), | 
                                                        |
| 146 | + ),  | 
                                                        |
| 147 | + 'event_list' => array(  | 
                                                        |
| 148 | + 'shortcodes' => array(  | 
                                                        |
| 149 | + 'event',  | 
                                                        |
| 150 | + 'attendee_list',  | 
                                                        |
| 151 | + 'ticket_list',  | 
                                                        |
| 152 | + 'venue',  | 
                                                        |
| 153 | + 'datetime_list',  | 
                                                        |
| 154 | + 'attendee',  | 
                                                        |
| 155 | + 'primary_registration_details',  | 
                                                        |
| 156 | + 'primary_registration_list',  | 
                                                        |
| 157 | + 'event_author',  | 
                                                        |
| 158 | + 'recipient_details',  | 
                                                        |
| 159 | + 'recipient_list',  | 
                                                        |
| 160 | + ),  | 
                                                        |
| 161 | +				'required'   => array('[EVENT_LIST]'), | 
                                                        |
| 162 | + ),  | 
                                                        |
| 163 | + 'ticket_list' => array(  | 
                                                        |
| 164 | + 'shortcodes' => array(  | 
                                                        |
| 165 | + 'event_list',  | 
                                                        |
| 166 | + 'attendee_list',  | 
                                                        |
| 167 | + 'ticket',  | 
                                                        |
| 168 | + 'datetime_list',  | 
                                                        |
| 169 | + 'primary_registration_details',  | 
                                                        |
| 170 | + 'recipient_details',  | 
                                                        |
| 171 | + ),  | 
                                                        |
| 172 | +				'required'   => array('[TICKET_LIST]'), | 
                                                        |
| 173 | + ),  | 
                                                        |
| 174 | + 'datetime_list' => array(  | 
                                                        |
| 175 | +				'shortcodes' => array('datetime'), | 
                                                        |
| 176 | +				'required'   => array('[DATETIME_LIST]'), | 
                                                        |
| 177 | + ),  | 
                                                        |
| 178 | + );  | 
                                                        |
| 179 | + }  | 
                                                        |
| 180 | +  | 
                                                        |
| 181 | +  | 
                                                        |
| 182 | + /**  | 
                                                        |
| 183 | + * @see parent EE_messenger class for docs  | 
                                                        |
| 184 | + * @since 4.5.0  | 
                                                        |
| 185 | + */  | 
                                                        |
| 186 | + public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 187 | +	{ | 
                                                        |
| 188 | +		if ($sending_messenger_name === 'html') { | 
                                                        |
| 189 | +			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | + }  | 
                                                        |
| 192 | +  | 
                                                        |
| 193 | +  | 
                                                        |
| 194 | + public function add_email_css(  | 
                                                        |
| 195 | + $variation_path,  | 
                                                        |
| 196 | + $messenger,  | 
                                                        |
| 197 | + $message_type,  | 
                                                        |
| 198 | + $type,  | 
                                                        |
| 199 | + $variation,  | 
                                                        |
| 200 | + $file_extension,  | 
                                                        |
| 201 | + $url,  | 
                                                        |
| 202 | + EE_Messages_Template_Pack $template_pack  | 
                                                        |
| 203 | +	) { | 
                                                        |
| 204 | + // prevent recursion on this callback.  | 
                                                        |
| 205 | +		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); | 
                                                        |
| 206 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | +		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); | 
                                                        |
| 209 | + return $variation;  | 
                                                        |
| 210 | + }  | 
                                                        |
| 211 | +  | 
                                                        |
| 212 | +  | 
                                                        |
| 213 | + /**  | 
                                                        |
| 214 | + * See parent for details  | 
                                                        |
| 215 | + *  | 
                                                        |
| 216 | + * @access protected  | 
                                                        |
| 217 | + * @return void  | 
                                                        |
| 218 | + */  | 
                                                        |
| 219 | + protected function _set_test_settings_fields()  | 
                                                        |
| 220 | +	{ | 
                                                        |
| 221 | + $this->_test_settings_fields = array(  | 
                                                        |
| 222 | + 'to' => array(  | 
                                                        |
| 223 | + 'input' => 'text',  | 
                                                        |
| 224 | +				'label'      => esc_html__('Send a test email to', 'event_espresso'), | 
                                                        |
| 225 | + 'type' => 'email',  | 
                                                        |
| 226 | + 'required' => false,  | 
                                                        |
| 227 | + 'validation' => true,  | 
                                                        |
| 228 | + 'css_class' => 'large-text',  | 
                                                        |
| 229 | + 'format' => '%s',  | 
                                                        |
| 230 | +				'default'    => get_bloginfo('admin_email'), | 
                                                        |
| 231 | + ),  | 
                                                        |
| 232 | + 'subject' => array(  | 
                                                        |
| 233 | + 'input' => 'hidden',  | 
                                                        |
| 234 | + 'label' => '',  | 
                                                        |
| 235 | + 'type' => 'string',  | 
                                                        |
| 236 | + 'required' => false,  | 
                                                        |
| 237 | + 'validation' => false,  | 
                                                        |
| 238 | + 'format' => '%s',  | 
                                                        |
| 239 | +				'value'      => sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), | 
                                                        |
| 240 | + 'default' => '',  | 
                                                        |
| 241 | + 'css_class' => '',  | 
                                                        |
| 242 | + ),  | 
                                                        |
| 243 | + );  | 
                                                        |
| 244 | + }  | 
                                                        |
| 245 | +  | 
                                                        |
| 246 | +  | 
                                                        |
| 247 | + /**  | 
                                                        |
| 248 | + * _set_template_fields  | 
                                                        |
| 249 | + * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 250 | + *  | 
                                                        |
| 251 | + * @access protected  | 
                                                        |
| 252 | + * @return void  | 
                                                        |
| 253 | + */  | 
                                                        |
| 254 | + protected function _set_template_fields()  | 
                                                        |
| 255 | +	{ | 
                                                        |
| 256 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for  | 
                                                        |
| 257 | + // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field  | 
                                                        |
| 258 | + // they relate to. This is important for the Messages_admin to know what fields to display to the user.  | 
                                                        |
| 259 | + // Also, notice that the "values" are equal to the field type that messages admin will use to know what  | 
                                                        |
| 260 | + // kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array  | 
                                                        |
| 261 | + // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be  | 
                                                        |
| 262 | + // displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and  | 
                                                        |
| 263 | + // will not be displayed/parsed.  | 
                                                        |
| 264 | + $this->_template_fields = array(  | 
                                                        |
| 265 | + 'to' => array(  | 
                                                        |
| 266 | + 'input' => 'text',  | 
                                                        |
| 267 | + 'label' => esc_html_x(  | 
                                                        |
| 268 | + 'To',  | 
                                                        |
| 269 | + 'Label for the "To" field for email addresses',  | 
                                                        |
| 270 | + 'event_espresso'  | 
                                                        |
| 271 | + ),  | 
                                                        |
| 272 | + 'type' => 'string',  | 
                                                        |
| 273 | + 'required' => true,  | 
                                                        |
| 274 | + 'validation' => true,  | 
                                                        |
| 275 | + 'css_class' => 'large-text',  | 
                                                        |
| 276 | + 'format' => '%s',  | 
                                                        |
| 277 | + ),  | 
                                                        |
| 278 | + 'cc' => array(  | 
                                                        |
| 279 | + 'input' => 'text',  | 
                                                        |
| 280 | + 'label' => esc_html_x(  | 
                                                        |
| 281 | + 'CC',  | 
                                                        |
| 282 | + 'Label for the "Carbon Copy" field used for additional email addresses',  | 
                                                        |
| 283 | + 'event_espresso'  | 
                                                        |
| 284 | + ),  | 
                                                        |
| 285 | + 'type' => 'string',  | 
                                                        |
| 286 | + 'required' => false,  | 
                                                        |
| 287 | + 'validation' => true,  | 
                                                        |
| 288 | + 'css_class' => 'large-text',  | 
                                                        |
| 289 | + 'format' => '%s',  | 
                                                        |
| 290 | + ),  | 
                                                        |
| 291 | + 'from' => array(  | 
                                                        |
| 292 | + 'input' => 'text',  | 
                                                        |
| 293 | + 'label' => esc_html_x(  | 
                                                        |
| 294 | + 'From',  | 
                                                        |
| 295 | + 'Label for the "From" field for email addresses.',  | 
                                                        |
| 296 | + 'event_espresso'  | 
                                                        |
| 297 | + ),  | 
                                                        |
| 298 | + 'type' => 'string',  | 
                                                        |
| 299 | + 'required' => true,  | 
                                                        |
| 300 | + 'validation' => true,  | 
                                                        |
| 301 | + 'css_class' => 'large-text',  | 
                                                        |
| 302 | + 'format' => '%s',  | 
                                                        |
| 303 | + ),  | 
                                                        |
| 304 | + 'subject' => array(  | 
                                                        |
| 305 | + 'input' => 'text',  | 
                                                        |
| 306 | + 'label' => esc_html_x(  | 
                                                        |
| 307 | + 'Subject',  | 
                                                        |
| 308 | + 'Label for the "Subject" field (short description of contents) for emails.',  | 
                                                        |
| 309 | + 'event_espresso'  | 
                                                        |
| 310 | + ),  | 
                                                        |
| 311 | + 'type' => 'string',  | 
                                                        |
| 312 | + 'required' => true,  | 
                                                        |
| 313 | + 'validation' => true,  | 
                                                        |
| 314 | + 'css_class' => 'large-text',  | 
                                                        |
| 315 | + 'format' => '%s',  | 
                                                        |
| 316 | + ),  | 
                                                        |
| 317 | + 'content' => '',  | 
                                                        |
| 318 | + // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 319 | + 'extra' => array(  | 
                                                        |
| 320 | + 'content' => array(  | 
                                                        |
| 321 | + 'main' => array(  | 
                                                        |
| 322 | + 'input' => 'wp_editor',  | 
                                                        |
| 323 | +						'label'      => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 324 | + 'type' => 'string',  | 
                                                        |
| 325 | + 'required' => true,  | 
                                                        |
| 326 | + 'validation' => true,  | 
                                                        |
| 327 | + 'format' => '%s',  | 
                                                        |
| 328 | + 'rows' => '15',  | 
                                                        |
| 329 | + ),  | 
                                                        |
| 330 | + 'event_list' => array(  | 
                                                        |
| 331 | + 'input' => 'wp_editor',  | 
                                                        |
| 332 | + 'label' => '[EVENT_LIST]',  | 
                                                        |
| 333 | + 'type' => 'string',  | 
                                                        |
| 334 | + 'required' => false,  | 
                                                        |
| 335 | + 'validation' => true,  | 
                                                        |
| 336 | + 'format' => '%s',  | 
                                                        |
| 337 | + 'rows' => '15',  | 
                                                        |
| 338 | +						'shortcodes_required' => array('[EVENT_LIST]'), | 
                                                        |
| 339 | + ),  | 
                                                        |
| 340 | + 'attendee_list' => array(  | 
                                                        |
| 341 | + 'input' => 'textarea',  | 
                                                        |
| 342 | + 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 343 | + 'type' => 'string',  | 
                                                        |
| 344 | + 'required' => false,  | 
                                                        |
| 345 | + 'validation' => true,  | 
                                                        |
| 346 | + 'format' => '%s',  | 
                                                        |
| 347 | + 'css_class' => 'large-text',  | 
                                                        |
| 348 | + 'rows' => '5',  | 
                                                        |
| 349 | +						'shortcodes_required' => array('[ATTENDEE_LIST]'), | 
                                                        |
| 350 | + ),  | 
                                                        |
| 351 | + 'ticket_list' => array(  | 
                                                        |
| 352 | + 'input' => 'textarea',  | 
                                                        |
| 353 | + 'label' => '[TICKET_LIST]',  | 
                                                        |
| 354 | + 'type' => 'string',  | 
                                                        |
| 355 | + 'required' => false,  | 
                                                        |
| 356 | + 'validation' => true,  | 
                                                        |
| 357 | + 'format' => '%s',  | 
                                                        |
| 358 | + 'css_class' => 'large-text',  | 
                                                        |
| 359 | + 'rows' => '10',  | 
                                                        |
| 360 | +						'shortcodes_required' => array('[TICKET_LIST]'), | 
                                                        |
| 361 | + ),  | 
                                                        |
| 362 | + 'datetime_list' => array(  | 
                                                        |
| 363 | + 'input' => 'textarea',  | 
                                                        |
| 364 | + 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 365 | + 'type' => 'string',  | 
                                                        |
| 366 | + 'required' => false,  | 
                                                        |
| 367 | + 'validation' => true,  | 
                                                        |
| 368 | + 'format' => '%s',  | 
                                                        |
| 369 | + 'css_class' => 'large-text',  | 
                                                        |
| 370 | + 'rows' => '10',  | 
                                                        |
| 371 | +						'shortcodes_required' => array('[DATETIME_LIST]'), | 
                                                        |
| 372 | + ),  | 
                                                        |
| 373 | + ),  | 
                                                        |
| 374 | + ),  | 
                                                        |
| 375 | + );  | 
                                                        |
| 376 | + }  | 
                                                        |
| 377 | +  | 
                                                        |
| 378 | +  | 
                                                        |
| 379 | + /**  | 
                                                        |
| 380 | + * See definition of this class in parent  | 
                                                        |
| 381 | + */  | 
                                                        |
| 382 | + protected function _set_default_message_types()  | 
                                                        |
| 383 | +	{ | 
                                                        |
| 384 | + $this->_default_message_types = array(  | 
                                                        |
| 385 | + 'payment',  | 
                                                        |
| 386 | + 'payment_refund',  | 
                                                        |
| 387 | + 'registration',  | 
                                                        |
| 388 | + 'not_approved_registration',  | 
                                                        |
| 389 | + 'pending_approval',  | 
                                                        |
| 390 | + );  | 
                                                        |
| 391 | + }  | 
                                                        |
| 392 | +  | 
                                                        |
| 393 | +  | 
                                                        |
| 394 | + /**  | 
                                                        |
| 395 | + * @see definition of this class in parent  | 
                                                        |
| 396 | + * @since 4.5.0  | 
                                                        |
| 397 | + */  | 
                                                        |
| 398 | + protected function _set_valid_message_types()  | 
                                                        |
| 399 | +	{ | 
                                                        |
| 400 | + $this->_valid_message_types = array(  | 
                                                        |
| 401 | + 'payment',  | 
                                                        |
| 402 | + 'registration',  | 
                                                        |
| 403 | + 'not_approved_registration',  | 
                                                        |
| 404 | + 'declined_registration',  | 
                                                        |
| 405 | + 'cancelled_registration',  | 
                                                        |
| 406 | + 'pending_approval',  | 
                                                        |
| 407 | + 'registration_summary',  | 
                                                        |
| 408 | + 'payment_reminder',  | 
                                                        |
| 409 | + 'payment_declined',  | 
                                                        |
| 410 | + 'payment_refund',  | 
                                                        |
| 411 | + );  | 
                                                        |
| 412 | + }  | 
                                                        |
| 413 | +  | 
                                                        |
| 414 | +  | 
                                                        |
| 415 | + /**  | 
                                                        |
| 416 | + * setting up admin_settings_fields for messenger.  | 
                                                        |
| 417 | + */  | 
                                                        |
| 418 | + protected function _set_admin_settings_fields()  | 
                                                        |
| 419 | +	{ | 
                                                        |
| 420 | + }  | 
                                                        |
| 421 | +  | 
                                                        |
| 422 | + /**  | 
                                                        |
| 423 | + * We just deliver the messages don't kill us!!  | 
                                                        |
| 424 | + *  | 
                                                        |
| 425 | + * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if  | 
                                                        |
| 426 | + * present.  | 
                                                        |
| 427 | + * @throws EE_Error  | 
                                                        |
| 428 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 429 | + */  | 
                                                        |
| 430 | + protected function _send_message()  | 
                                                        |
| 431 | +	{ | 
                                                        |
| 432 | + $success = wp_mail(  | 
                                                        |
| 433 | + $this->_to,  | 
                                                        |
| 434 | + // some old values for subject may be expecting HTML entities to be decoded in the subject  | 
                                                        |
| 435 | + // and subjects aren't interpreted as HTML, so there should be no HTML in them  | 
                                                        |
| 436 | + wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),  | 
                                                        |
| 437 | + $this->_body(),  | 
                                                        |
| 438 | + $this->_headers()  | 
                                                        |
| 439 | + );  | 
                                                        |
| 440 | +		if (! $success) { | 
                                                        |
| 441 | + EE_Error::add_error(  | 
                                                        |
| 442 | + sprintf(  | 
                                                        |
| 443 | + esc_html__(  | 
                                                        |
| 444 | + 'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',  | 
                                                        |
| 445 | + 'event_espresso'  | 
                                                        |
| 446 | + ),  | 
                                                        |
| 447 | + $this->_to,  | 
                                                        |
| 448 | + $this->_from,  | 
                                                        |
| 449 | + '<br />'  | 
                                                        |
| 450 | + ),  | 
                                                        |
| 451 | + __FILE__,  | 
                                                        |
| 452 | + __FUNCTION__,  | 
                                                        |
| 453 | + __LINE__  | 
                                                        |
| 454 | + );  | 
                                                        |
| 455 | + }  | 
                                                        |
| 456 | + return $success;  | 
                                                        |
| 457 | + }  | 
                                                        |
| 458 | +  | 
                                                        |
| 459 | +  | 
                                                        |
| 460 | + /**  | 
                                                        |
| 461 | + * see parent for definition  | 
                                                        |
| 462 | + *  | 
                                                        |
| 463 | + * @return string html body of the message content and the related css.  | 
                                                        |
| 464 | + * @throws EE_Error  | 
                                                        |
| 465 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 466 | + */  | 
                                                        |
| 467 | + protected function _preview()  | 
                                                        |
| 468 | +	{ | 
                                                        |
| 469 | + return $this->_body(true);  | 
                                                        |
| 470 | + }  | 
                                                        |
| 471 | +  | 
                                                        |
| 472 | +  | 
                                                        |
| 473 | + /**  | 
                                                        |
| 474 | + * Setup headers for email  | 
                                                        |
| 475 | + *  | 
                                                        |
| 476 | + * @access protected  | 
                                                        |
| 477 | + * @return string formatted header for email  | 
                                                        |
| 478 | + */  | 
                                                        |
| 479 | + protected function _headers()  | 
                                                        |
| 480 | +	{ | 
                                                        |
| 481 | + $this->_ensure_has_from_email_address();  | 
                                                        |
| 482 | + $from = $this->_from;  | 
                                                        |
| 483 | + $headers = array(  | 
                                                        |
| 484 | + 'From:' . $from,  | 
                                                        |
| 485 | + 'Reply-To:' . $from,  | 
                                                        |
| 486 | + 'Content-Type:text/html; charset=utf-8',  | 
                                                        |
| 487 | + );  | 
                                                        |
| 488 | +  | 
                                                        |
| 489 | + /**  | 
                                                        |
| 490 | + * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to  | 
                                                        |
| 491 | + * cover back compat where there may be users who have saved cc values in their db for the newsletter message  | 
                                                        |
| 492 | + * type which they are no longer able to change.  | 
                                                        |
| 493 | + */  | 
                                                        |
| 494 | +		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) { | 
                                                        |
| 495 | + $headers[] = 'cc: ' . $this->_cc;  | 
                                                        |
| 496 | + }  | 
                                                        |
| 497 | +  | 
                                                        |
| 498 | + // but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the  | 
                                                        |
| 499 | + // header.  | 
                                                        |
| 500 | +		add_filter('wp_mail_from', array($this, 'set_from_address'), 100); | 
                                                        |
| 501 | +		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); | 
                                                        |
| 502 | +		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); | 
                                                        |
| 503 | + }  | 
                                                        |
| 504 | +  | 
                                                        |
| 505 | +  | 
                                                        |
| 506 | + /**  | 
                                                        |
| 507 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email  | 
                                                        |
| 508 | + * address for the from address to avoid problems with sending emails.  | 
                                                        |
| 509 | + */  | 
                                                        |
| 510 | + protected function _ensure_has_from_email_address()  | 
                                                        |
| 511 | +	{ | 
                                                        |
| 512 | +		if (empty($this->_from)) { | 
                                                        |
| 513 | +			$this->_from = get_bloginfo('admin_email'); | 
                                                        |
| 514 | + }  | 
                                                        |
| 515 | + }  | 
                                                        |
| 516 | +  | 
                                                        |
| 517 | +  | 
                                                        |
| 518 | + /**  | 
                                                        |
| 519 | +	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> | 
                                                        |
| 520 | +	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* | 
                                                        |
| 521 | + * be empty  | 
                                                        |
| 522 | + *  | 
                                                        |
| 523 | + * @since 4.3.1  | 
                                                        |
| 524 | + * @return array  | 
                                                        |
| 525 | + */  | 
                                                        |
| 526 | + private function _parse_from()  | 
                                                        |
| 527 | +	{ | 
                                                        |
| 528 | +		if (strpos($this->_from, '<') !== false) { | 
                                                        |
| 529 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);  | 
                                                        |
| 530 | +			$from_name = str_replace('"', '', $from_name); | 
                                                        |
| 531 | + $from_name = trim($from_name);  | 
                                                        |
| 532 | +  | 
                                                        |
| 533 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1);  | 
                                                        |
| 534 | +			$from_email = str_replace('>', '', $from_email); | 
                                                        |
| 535 | + $from_email = trim($from_email);  | 
                                                        |
| 536 | +		} elseif (trim($this->_from) !== '') { | 
                                                        |
| 537 | + $from_name = '';  | 
                                                        |
| 538 | + $from_email = trim($this->_from);  | 
                                                        |
| 539 | +		} else { | 
                                                        |
| 540 | + $from_name = $from_email = '';  | 
                                                        |
| 541 | + }  | 
                                                        |
| 542 | + return array($from_name, $from_email);  | 
                                                        |
| 543 | + }  | 
                                                        |
| 544 | +  | 
                                                        |
| 545 | +  | 
                                                        |
| 546 | + /**  | 
                                                        |
| 547 | + * Callback for the wp_mail_from filter.  | 
                                                        |
| 548 | + *  | 
                                                        |
| 549 | + * @since 4.3.1  | 
                                                        |
| 550 | + * @param string $from_email What the original from_email is.  | 
                                                        |
| 551 | + * @return string  | 
                                                        |
| 552 | + */  | 
                                                        |
| 553 | + public function set_from_address($from_email)  | 
                                                        |
| 554 | +	{ | 
                                                        |
| 555 | + $parsed_from = $this->_parse_from();  | 
                                                        |
| 556 | + // includes fallback if the parsing failed.  | 
                                                        |
| 557 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1])  | 
                                                        |
| 558 | + ? $parsed_from[1]  | 
                                                        |
| 559 | +			: get_bloginfo('admin_email'); | 
                                                        |
| 560 | + return $from_email;  | 
                                                        |
| 561 | + }  | 
                                                        |
| 562 | +  | 
                                                        |
| 563 | +  | 
                                                        |
| 564 | + /**  | 
                                                        |
| 565 | + * Callback fro the wp_mail_from_name filter.  | 
                                                        |
| 566 | + *  | 
                                                        |
| 567 | + * @since 4.3.1  | 
                                                        |
| 568 | + * @param string $from_name The original from_name.  | 
                                                        |
| 569 | + * @return string  | 
                                                        |
| 570 | + */  | 
                                                        |
| 571 | + public function set_from_name($from_name)  | 
                                                        |
| 572 | +	{ | 
                                                        |
| 573 | + $parsed_from = $this->_parse_from();  | 
                                                        |
| 574 | +		if (is_array($parsed_from) && ! empty($parsed_from[0])) { | 
                                                        |
| 575 | + $from_name = $parsed_from[0];  | 
                                                        |
| 576 | + }  | 
                                                        |
| 577 | +  | 
                                                        |
| 578 | + // if from name is "WordPress" let's sub in the site name instead (more friendly!)  | 
                                                        |
| 579 | + // but realize the default name is HTML entity-encoded  | 
                                                        |
| 580 | + $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;  | 
                                                        |
| 581 | +  | 
                                                        |
| 582 | + return $from_name;  | 
                                                        |
| 583 | + }  | 
                                                        |
| 584 | +  | 
                                                        |
| 585 | +  | 
                                                        |
| 586 | + /**  | 
                                                        |
| 587 | + * setup body for email  | 
                                                        |
| 588 | + *  | 
                                                        |
| 589 | + * @param bool $preview will determine whether this is preview template or not.  | 
                                                        |
| 590 | + * @return string formatted body for email.  | 
                                                        |
| 591 | + * @throws EE_Error  | 
                                                        |
| 592 | + * @throws \TijsVerkoyen\CssToInlineStyles\Exception  | 
                                                        |
| 593 | + */  | 
                                                        |
| 594 | + protected function _body($preview = false)  | 
                                                        |
| 595 | +	{ | 
                                                        |
| 596 | + // setup template args!  | 
                                                        |
| 597 | + $this->_template_args = array(  | 
                                                        |
| 598 | + 'subject' => $this->_subject,  | 
                                                        |
| 599 | + 'from' => $this->_from,  | 
                                                        |
| 600 | + 'main_body' => wpautop($this->_content),  | 
                                                        |
| 601 | + );  | 
                                                        |
| 602 | + $body = $this->_get_main_template($preview);  | 
                                                        |
| 603 | +  | 
                                                        |
| 604 | + /**  | 
                                                        |
| 605 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.  | 
                                                        |
| 606 | + *  | 
                                                        |
| 607 | + * @type bool $preview Indicates whether a preview is being generated or not.  | 
                                                        |
| 608 | + * @return bool true indicates to use the inliner, false bypasses it.  | 
                                                        |
| 609 | + */  | 
                                                        |
| 610 | +		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { | 
                                                        |
| 611 | + // require CssToInlineStyles library and its dependencies via composer autoloader  | 
                                                        |
| 612 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';  | 
                                                        |
| 613 | +  | 
                                                        |
| 614 | + // now if this isn't a preview, let's setup the body so it has inline styles  | 
                                                        |
| 615 | +			if (! $preview || ($preview && defined('DOING_AJAX'))) { | 
                                                        |
| 616 | + $style = file_get_contents(  | 
                                                        |
| 617 | + $this->get_variation(  | 
                                                        |
| 618 | + $this->_tmp_pack,  | 
                                                        |
| 619 | + $this->_incoming_message_type->name,  | 
                                                        |
| 620 | + false,  | 
                                                        |
| 621 | + 'main',  | 
                                                        |
| 622 | + $this->_variation  | 
                                                        |
| 623 | + ),  | 
                                                        |
| 624 | + true  | 
                                                        |
| 625 | + );  | 
                                                        |
| 626 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);  | 
                                                        |
| 627 | + // for some reason the library has a bracket and new line at the beginning. This takes care of that.  | 
                                                        |
| 628 | + $body = ltrim($CSS->convert(true), ">\n");  | 
                                                        |
| 629 | + // see https://events.codebasehq.com/projects/event-espresso/tickets/8609  | 
                                                        |
| 630 | + $body = ltrim($body, "<?");  | 
                                                        |
| 631 | + }  | 
                                                        |
| 632 | + }  | 
                                                        |
| 633 | + return $body;  | 
                                                        |
| 634 | + }  | 
                                                        |
| 635 | +  | 
                                                        |
| 636 | +  | 
                                                        |
| 637 | + /**  | 
                                                        |
| 638 | + * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 639 | + *  | 
                                                        |
| 640 | + * @access public  | 
                                                        |
| 641 | + * @return array  | 
                                                        |
| 642 | + */  | 
                                                        |
| 643 | + public function get_existing_test_settings()  | 
                                                        |
| 644 | +	{ | 
                                                        |
| 645 | + $settings = parent::get_existing_test_settings();  | 
                                                        |
| 646 | + // override subject if present because we always want it to be fresh.  | 
                                                        |
| 647 | +		if (is_array($settings) && ! empty($settings['subject'])) { | 
                                                        |
| 648 | +			$settings['subject'] = sprintf(esc_html__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); | 
                                                        |
| 649 | + }  | 
                                                        |
| 650 | + return $settings;  | 
                                                        |
| 651 | + }  | 
                                                        |
| 652 | 652 | }  | 
                                                        
@@ -13,349 +13,349 @@  | 
                                                    ||
| 13 | 13 | */  | 
                                                        
| 14 | 14 | class EE_Pdf_messenger extends EE_messenger  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | - /**  | 
                                                        |
| 17 | - * The following are the properties that this messenger requires for generating pdf  | 
                                                        |
| 18 | - */  | 
                                                        |
| 19 | -  | 
                                                        |
| 20 | - /**  | 
                                                        |
| 21 | - * This is the pdf body generated by the template via the message type.  | 
                                                        |
| 22 | - *  | 
                                                        |
| 23 | - * @var string  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - protected $_content;  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | -  | 
                                                        |
| 28 | - /**  | 
                                                        |
| 29 | - * This is for the page title that gets displayed. This will end up being the filename for the generated pdf.  | 
                                                        |
| 30 | - *  | 
                                                        |
| 31 | - * @var string  | 
                                                        |
| 32 | - */  | 
                                                        |
| 33 | - protected $_subject;  | 
                                                        |
| 34 | -  | 
                                                        |
| 35 | -  | 
                                                        |
| 36 | - /**  | 
                                                        |
| 37 | - * @return EE_Pdf_messenger  | 
                                                        |
| 38 | - */  | 
                                                        |
| 39 | - public function __construct()  | 
                                                        |
| 40 | -    { | 
                                                        |
| 41 | - // set properties  | 
                                                        |
| 42 | - $this->name = 'pdf';  | 
                                                        |
| 43 | -        $this->description = esc_html__('This messenger is used for generating a pdf version of the message.', 'event_espresso'); | 
                                                        |
| 44 | - $this->label = array(  | 
                                                        |
| 45 | -            'singular' => esc_html__('PDF', 'event_espresso'), | 
                                                        |
| 46 | -            'plural' => esc_html__('PDFs', 'event_espresso') | 
                                                        |
| 47 | - );  | 
                                                        |
| 48 | - $this->activate_on_install = true;  | 
                                                        |
| 49 | -  | 
                                                        |
| 50 | - parent::__construct();  | 
                                                        |
| 51 | - }  | 
                                                        |
| 52 | -  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /**  | 
                                                        |
| 55 | - * PDF Messenger desires execution immediately.  | 
                                                        |
| 56 | - * @see parent::send_now() for documentation.  | 
                                                        |
| 57 | - * @since 4.9.0  | 
                                                        |
| 58 | - * @return bool  | 
                                                        |
| 59 | - */  | 
                                                        |
| 60 | - public function send_now()  | 
                                                        |
| 61 | -    { | 
                                                        |
| 62 | - return true;  | 
                                                        |
| 63 | - }  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - /**  | 
                                                        |
| 67 | - * HTML Messenger allows an empty to field.  | 
                                                        |
| 68 | - * @see parent::allow_empty_to_field() for documentation  | 
                                                        |
| 69 | - * @since 4.9.0  | 
                                                        |
| 70 | - * @return bool  | 
                                                        |
| 71 | - */  | 
                                                        |
| 72 | - public function allow_empty_to_field()  | 
                                                        |
| 73 | -    { | 
                                                        |
| 74 | - return true;  | 
                                                        |
| 75 | - }  | 
                                                        |
| 76 | -  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - /**  | 
                                                        |
| 79 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 80 | - */  | 
                                                        |
| 81 | - protected function _set_admin_pages()  | 
                                                        |
| 82 | -    { | 
                                                        |
| 83 | -        $this->admin_registered_pages = array('events_edit' => false); | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | -  | 
                                                        |
| 86 | -  | 
                                                        |
| 87 | - /**  | 
                                                        |
| 88 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 89 | - */  | 
                                                        |
| 90 | - protected function _set_valid_shortcodes()  | 
                                                        |
| 91 | -    { | 
                                                        |
| 92 | - $this->_valid_shortcodes = array();  | 
                                                        |
| 93 | - }  | 
                                                        |
| 94 | -  | 
                                                        |
| 95 | -  | 
                                                        |
| 96 | - /**  | 
                                                        |
| 97 | - * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 98 | - */  | 
                                                        |
| 99 | - protected function _set_validator_config()  | 
                                                        |
| 100 | -    { | 
                                                        |
| 101 | - $this->_validator_config = array(  | 
                                                        |
| 102 | - 'subject' => array(  | 
                                                        |
| 103 | -                'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') | 
                                                        |
| 104 | - ),  | 
                                                        |
| 105 | - 'content' => array(  | 
                                                        |
| 106 | -                'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') | 
                                                        |
| 107 | - ),  | 
                                                        |
| 108 | - 'attendee_list' => array(  | 
                                                        |
| 109 | -                'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 110 | -                'required' => array('[ATTENDEE_LIST]') | 
                                                        |
| 111 | - ),  | 
                                                        |
| 112 | - 'event_list' => array(  | 
                                                        |
| 113 | -                'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), | 
                                                        |
| 114 | -                'required' => array('[EVENT_LIST]') | 
                                                        |
| 115 | - ),  | 
                                                        |
| 116 | - 'ticket_list' => array(  | 
                                                        |
| 117 | -                'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 118 | -                'required' => array('[TICKET_LIST]') | 
                                                        |
| 119 | - ),  | 
                                                        |
| 120 | - 'datetime_list' => array(  | 
                                                        |
| 121 | -                'shortcodes' => array('datetime'), | 
                                                        |
| 122 | -                'required' => array('[DATETIME_LIST]') | 
                                                        |
| 123 | - ),  | 
                                                        |
| 124 | - );  | 
                                                        |
| 125 | - }  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | -  | 
                                                        |
| 128 | - /**  | 
                                                        |
| 129 | - * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js.  | 
                                                        |
| 130 | - *  | 
                                                        |
| 131 | - * @return void.  | 
                                                        |
| 132 | - */  | 
                                                        |
| 133 | - public function enqueue_scripts_styles()  | 
                                                        |
| 134 | -    { | 
                                                        |
| 135 | - parent::enqueue_scripts_styles();  | 
                                                        |
| 136 | -        do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); | 
                                                        |
| 137 | - }  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | - /**  | 
                                                        |
| 141 | - * _set_template_fields  | 
                                                        |
| 142 | - * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 143 | - *  | 
                                                        |
| 144 | - * @access protected  | 
                                                        |
| 145 | - * @return void  | 
                                                        |
| 146 | - */  | 
                                                        |
| 147 | - protected function _set_template_fields()  | 
                                                        |
| 148 | -    { | 
                                                        |
| 149 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.  | 
                                                        |
| 150 | - $this->_template_fields = array(  | 
                                                        |
| 151 | - 'subject' => array(  | 
                                                        |
| 152 | - 'input' => 'text',  | 
                                                        |
| 153 | -                'label' => esc_html__('Page Title', 'event_espresso'), | 
                                                        |
| 154 | - 'type' => 'string',  | 
                                                        |
| 155 | - 'required' => true,  | 
                                                        |
| 156 | - 'validation' => true,  | 
                                                        |
| 157 | - 'css_class' => 'large-text',  | 
                                                        |
| 158 | - 'format' => '%s'  | 
                                                        |
| 159 | - ),  | 
                                                        |
| 160 | - 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 161 | - 'extra' => array(  | 
                                                        |
| 162 | - 'content' => array(  | 
                                                        |
| 163 | - 'main' => array(  | 
                                                        |
| 164 | - 'input' => 'wp_editor',  | 
                                                        |
| 165 | -                        'label' => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 166 | - 'type' => 'string',  | 
                                                        |
| 167 | - 'required' => true,  | 
                                                        |
| 168 | - 'validation' => true,  | 
                                                        |
| 169 | - 'format' => '%s',  | 
                                                        |
| 170 | - 'rows' => '15'  | 
                                                        |
| 171 | - ),  | 
                                                        |
| 172 | - 'event_list' => array(  | 
                                                        |
| 173 | - 'input' => 'wp_editor',  | 
                                                        |
| 174 | - 'label' => '[EVENT_LIST]',  | 
                                                        |
| 175 | - 'type' => 'string',  | 
                                                        |
| 176 | - 'required' => false,  | 
                                                        |
| 177 | - 'validation' => true,  | 
                                                        |
| 178 | - 'format' => '%s',  | 
                                                        |
| 179 | - 'rows' => '15',  | 
                                                        |
| 180 | -                        'shortcodes_required' => array('[EVENT_LIST]') | 
                                                        |
| 181 | - ),  | 
                                                        |
| 182 | - 'attendee_list' => array(  | 
                                                        |
| 183 | - 'input' => 'textarea',  | 
                                                        |
| 184 | - 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 185 | - 'type' => 'string',  | 
                                                        |
| 186 | - 'required' => false,  | 
                                                        |
| 187 | - 'validation' => true,  | 
                                                        |
| 188 | - 'format' => '%s',  | 
                                                        |
| 189 | - 'css_class' => 'large-text',  | 
                                                        |
| 190 | - 'rows' => '5',  | 
                                                        |
| 191 | -                        'shortcodes_required' => array('[ATTENDEE_LIST]') | 
                                                        |
| 192 | - ),  | 
                                                        |
| 193 | - 'ticket_list' => array(  | 
                                                        |
| 194 | - 'input' => 'textarea',  | 
                                                        |
| 195 | - 'label' => '[TICKET_LIST]',  | 
                                                        |
| 196 | - 'type' => 'string',  | 
                                                        |
| 197 | - 'required' => false,  | 
                                                        |
| 198 | - 'validation' => true,  | 
                                                        |
| 199 | - 'format' => '%s',  | 
                                                        |
| 200 | - 'css_class' => 'large-text',  | 
                                                        |
| 201 | - 'rows' => '10',  | 
                                                        |
| 202 | -                        'shortcodes_required' => array('[TICKET_LIST]') | 
                                                        |
| 203 | - ),  | 
                                                        |
| 204 | - 'datetime_list' => array(  | 
                                                        |
| 205 | - 'input' => 'textarea',  | 
                                                        |
| 206 | - 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 207 | - 'type' => 'string',  | 
                                                        |
| 208 | - 'required' => false,  | 
                                                        |
| 209 | - 'validation' => true,  | 
                                                        |
| 210 | - 'format' => '%s',  | 
                                                        |
| 211 | - 'css_class' => 'large-text',  | 
                                                        |
| 212 | - 'rows' => '10',  | 
                                                        |
| 213 | -                        'shortcodes_required' => array('[DATETIME_LIST]') | 
                                                        |
| 214 | - )  | 
                                                        |
| 215 | - )  | 
                                                        |
| 216 | - )  | 
                                                        |
| 217 | - );  | 
                                                        |
| 218 | - }  | 
                                                        |
| 219 | -  | 
                                                        |
| 220 | -  | 
                                                        |
| 221 | - /**  | 
                                                        |
| 222 | - * @see definition of this method in parent  | 
                                                        |
| 223 | - *  | 
                                                        |
| 224 | - * @since 4.5.0  | 
                                                        |
| 225 | - *  | 
                                                        |
| 226 | - */  | 
                                                        |
| 227 | - protected function _set_default_message_types()  | 
                                                        |
| 228 | -    { | 
                                                        |
| 229 | - // note currently PDF is only a secondary messenger so it never has any associated message types.  | 
                                                        |
| 230 | - $this->_default_message_types = array();  | 
                                                        |
| 231 | - }  | 
                                                        |
| 232 | -  | 
                                                        |
| 233 | -  | 
                                                        |
| 234 | - /**  | 
                                                        |
| 235 | - * @see definition of this method in parent  | 
                                                        |
| 236 | - *  | 
                                                        |
| 237 | - * @since 4.5.0  | 
                                                        |
| 238 | - */  | 
                                                        |
| 239 | - protected function _set_valid_message_types()  | 
                                                        |
| 240 | -    { | 
                                                        |
| 241 | - $this->_valid_message_types = array();  | 
                                                        |
| 242 | - }  | 
                                                        |
| 243 | -  | 
                                                        |
| 244 | -  | 
                                                        |
| 245 | - /**  | 
                                                        |
| 246 | - * Generates html version of the message content and then sends it to the pdf generator.  | 
                                                        |
| 247 | - *  | 
                                                        |
| 248 | - *  | 
                                                        |
| 249 | - * @since 4.5.0  | 
                                                        |
| 250 | - *  | 
                                                        |
| 251 | - * @return string.  | 
                                                        |
| 252 | - */  | 
                                                        |
| 253 | - protected function _send_message()  | 
                                                        |
| 254 | -    { | 
                                                        |
| 255 | - $this->_template_args = array(  | 
                                                        |
| 256 | - 'page_title' => $this->_subject,  | 
                                                        |
| 257 | - 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation),  | 
                                                        |
| 258 | - 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation),  | 
                                                        |
| 259 | - 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation),  | 
                                                        |
| 260 | - 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',  | 
                                                        |
| 261 | -            'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) | 
                                                        |
| 262 | - );  | 
                                                        |
| 263 | - $this->_deregister_wp_hooks();  | 
                                                        |
| 264 | -        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); | 
                                                        |
| 265 | - $content = $this->_get_main_template();  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * The following are the properties that this messenger requires for generating pdf  | 
                                                        |
| 18 | + */  | 
                                                        |
| 19 | +  | 
                                                        |
| 20 | + /**  | 
                                                        |
| 21 | + * This is the pdf body generated by the template via the message type.  | 
                                                        |
| 22 | + *  | 
                                                        |
| 23 | + * @var string  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + protected $_content;  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | +  | 
                                                        |
| 28 | + /**  | 
                                                        |
| 29 | + * This is for the page title that gets displayed. This will end up being the filename for the generated pdf.  | 
                                                        |
| 30 | + *  | 
                                                        |
| 31 | + * @var string  | 
                                                        |
| 32 | + */  | 
                                                        |
| 33 | + protected $_subject;  | 
                                                        |
| 34 | +  | 
                                                        |
| 35 | +  | 
                                                        |
| 36 | + /**  | 
                                                        |
| 37 | + * @return EE_Pdf_messenger  | 
                                                        |
| 38 | + */  | 
                                                        |
| 39 | + public function __construct()  | 
                                                        |
| 40 | +	{ | 
                                                        |
| 41 | + // set properties  | 
                                                        |
| 42 | + $this->name = 'pdf';  | 
                                                        |
| 43 | +		$this->description = esc_html__('This messenger is used for generating a pdf version of the message.', 'event_espresso'); | 
                                                        |
| 44 | + $this->label = array(  | 
                                                        |
| 45 | +			'singular' => esc_html__('PDF', 'event_espresso'), | 
                                                        |
| 46 | +			'plural' => esc_html__('PDFs', 'event_espresso') | 
                                                        |
| 47 | + );  | 
                                                        |
| 48 | + $this->activate_on_install = true;  | 
                                                        |
| 49 | +  | 
                                                        |
| 50 | + parent::__construct();  | 
                                                        |
| 51 | + }  | 
                                                        |
| 52 | +  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /**  | 
                                                        |
| 55 | + * PDF Messenger desires execution immediately.  | 
                                                        |
| 56 | + * @see parent::send_now() for documentation.  | 
                                                        |
| 57 | + * @since 4.9.0  | 
                                                        |
| 58 | + * @return bool  | 
                                                        |
| 59 | + */  | 
                                                        |
| 60 | + public function send_now()  | 
                                                        |
| 61 | +	{ | 
                                                        |
| 62 | + return true;  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + /**  | 
                                                        |
| 67 | + * HTML Messenger allows an empty to field.  | 
                                                        |
| 68 | + * @see parent::allow_empty_to_field() for documentation  | 
                                                        |
| 69 | + * @since 4.9.0  | 
                                                        |
| 70 | + * @return bool  | 
                                                        |
| 71 | + */  | 
                                                        |
| 72 | + public function allow_empty_to_field()  | 
                                                        |
| 73 | +	{ | 
                                                        |
| 74 | + return true;  | 
                                                        |
| 75 | + }  | 
                                                        |
| 76 | +  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + /**  | 
                                                        |
| 79 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 80 | + */  | 
                                                        |
| 81 | + protected function _set_admin_pages()  | 
                                                        |
| 82 | +	{ | 
                                                        |
| 83 | +		$this->admin_registered_pages = array('events_edit' => false); | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | +  | 
                                                        |
| 86 | +  | 
                                                        |
| 87 | + /**  | 
                                                        |
| 88 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 89 | + */  | 
                                                        |
| 90 | + protected function _set_valid_shortcodes()  | 
                                                        |
| 91 | +	{ | 
                                                        |
| 92 | + $this->_valid_shortcodes = array();  | 
                                                        |
| 93 | + }  | 
                                                        |
| 94 | +  | 
                                                        |
| 95 | +  | 
                                                        |
| 96 | + /**  | 
                                                        |
| 97 | + * @see abstract declaration in EE_messenger for details.  | 
                                                        |
| 98 | + */  | 
                                                        |
| 99 | + protected function _set_validator_config()  | 
                                                        |
| 100 | +	{ | 
                                                        |
| 101 | + $this->_validator_config = array(  | 
                                                        |
| 102 | + 'subject' => array(  | 
                                                        |
| 103 | +				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') | 
                                                        |
| 104 | + ),  | 
                                                        |
| 105 | + 'content' => array(  | 
                                                        |
| 106 | +				'shortcodes' => array('recipient_details', 'organization', 'event', 'ticket', 'venue', 'primary_registration_details', 'event_author', 'email', 'event_meta', 'recipient_list', 'transaction', 'datetime_list', 'datetime') | 
                                                        |
| 107 | + ),  | 
                                                        |
| 108 | + 'attendee_list' => array(  | 
                                                        |
| 109 | +				'shortcodes' => array('attendee', 'event_list', 'ticket_list'), | 
                                                        |
| 110 | +				'required' => array('[ATTENDEE_LIST]') | 
                                                        |
| 111 | + ),  | 
                                                        |
| 112 | + 'event_list' => array(  | 
                                                        |
| 113 | +				'shortcodes' => array('event', 'attendee_list', 'ticket_list', 'venue', 'datetime_list', 'attendee', 'primary_registration_details', 'primary_registration_list', 'event_author', 'recipient_details', 'recipient_list'), | 
                                                        |
| 114 | +				'required' => array('[EVENT_LIST]') | 
                                                        |
| 115 | + ),  | 
                                                        |
| 116 | + 'ticket_list' => array(  | 
                                                        |
| 117 | +				'shortcodes' => array('event_list', 'attendee_list', 'ticket', 'datetime_list', 'primary_registration_details', 'recipient_details'), | 
                                                        |
| 118 | +				'required' => array('[TICKET_LIST]') | 
                                                        |
| 119 | + ),  | 
                                                        |
| 120 | + 'datetime_list' => array(  | 
                                                        |
| 121 | +				'shortcodes' => array('datetime'), | 
                                                        |
| 122 | +				'required' => array('[DATETIME_LIST]') | 
                                                        |
| 123 | + ),  | 
                                                        |
| 124 | + );  | 
                                                        |
| 125 | + }  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | +  | 
                                                        |
| 128 | + /**  | 
                                                        |
| 129 | + * Takes care of enqueuing any necessary scripts or styles for the page. A do_action() so message types using this messenger can add their own js.  | 
                                                        |
| 130 | + *  | 
                                                        |
| 131 | + * @return void.  | 
                                                        |
| 132 | + */  | 
                                                        |
| 133 | + public function enqueue_scripts_styles()  | 
                                                        |
| 134 | +	{ | 
                                                        |
| 135 | + parent::enqueue_scripts_styles();  | 
                                                        |
| 136 | +		do_action('AHEE__EE_Pdf_messenger__enqueue_scripts_styles'); | 
                                                        |
| 137 | + }  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | + /**  | 
                                                        |
| 141 | + * _set_template_fields  | 
                                                        |
| 142 | + * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 143 | + *  | 
                                                        |
| 144 | + * @access protected  | 
                                                        |
| 145 | + * @return void  | 
                                                        |
| 146 | + */  | 
                                                        |
| 147 | + protected function _set_template_fields()  | 
                                                        |
| 148 | +	{ | 
                                                        |
| 149 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed.  | 
                                                        |
| 150 | + $this->_template_fields = array(  | 
                                                        |
| 151 | + 'subject' => array(  | 
                                                        |
| 152 | + 'input' => 'text',  | 
                                                        |
| 153 | +				'label' => esc_html__('Page Title', 'event_espresso'), | 
                                                        |
| 154 | + 'type' => 'string',  | 
                                                        |
| 155 | + 'required' => true,  | 
                                                        |
| 156 | + 'validation' => true,  | 
                                                        |
| 157 | + 'css_class' => 'large-text',  | 
                                                        |
| 158 | + 'format' => '%s'  | 
                                                        |
| 159 | + ),  | 
                                                        |
| 160 | + 'content' => '', // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.  | 
                                                        |
| 161 | + 'extra' => array(  | 
                                                        |
| 162 | + 'content' => array(  | 
                                                        |
| 163 | + 'main' => array(  | 
                                                        |
| 164 | + 'input' => 'wp_editor',  | 
                                                        |
| 165 | +						'label' => esc_html__('Main Content', 'event_espresso'), | 
                                                        |
| 166 | + 'type' => 'string',  | 
                                                        |
| 167 | + 'required' => true,  | 
                                                        |
| 168 | + 'validation' => true,  | 
                                                        |
| 169 | + 'format' => '%s',  | 
                                                        |
| 170 | + 'rows' => '15'  | 
                                                        |
| 171 | + ),  | 
                                                        |
| 172 | + 'event_list' => array(  | 
                                                        |
| 173 | + 'input' => 'wp_editor',  | 
                                                        |
| 174 | + 'label' => '[EVENT_LIST]',  | 
                                                        |
| 175 | + 'type' => 'string',  | 
                                                        |
| 176 | + 'required' => false,  | 
                                                        |
| 177 | + 'validation' => true,  | 
                                                        |
| 178 | + 'format' => '%s',  | 
                                                        |
| 179 | + 'rows' => '15',  | 
                                                        |
| 180 | +						'shortcodes_required' => array('[EVENT_LIST]') | 
                                                        |
| 181 | + ),  | 
                                                        |
| 182 | + 'attendee_list' => array(  | 
                                                        |
| 183 | + 'input' => 'textarea',  | 
                                                        |
| 184 | + 'label' => '[ATTENDEE_LIST]',  | 
                                                        |
| 185 | + 'type' => 'string',  | 
                                                        |
| 186 | + 'required' => false,  | 
                                                        |
| 187 | + 'validation' => true,  | 
                                                        |
| 188 | + 'format' => '%s',  | 
                                                        |
| 189 | + 'css_class' => 'large-text',  | 
                                                        |
| 190 | + 'rows' => '5',  | 
                                                        |
| 191 | +						'shortcodes_required' => array('[ATTENDEE_LIST]') | 
                                                        |
| 192 | + ),  | 
                                                        |
| 193 | + 'ticket_list' => array(  | 
                                                        |
| 194 | + 'input' => 'textarea',  | 
                                                        |
| 195 | + 'label' => '[TICKET_LIST]',  | 
                                                        |
| 196 | + 'type' => 'string',  | 
                                                        |
| 197 | + 'required' => false,  | 
                                                        |
| 198 | + 'validation' => true,  | 
                                                        |
| 199 | + 'format' => '%s',  | 
                                                        |
| 200 | + 'css_class' => 'large-text',  | 
                                                        |
| 201 | + 'rows' => '10',  | 
                                                        |
| 202 | +						'shortcodes_required' => array('[TICKET_LIST]') | 
                                                        |
| 203 | + ),  | 
                                                        |
| 204 | + 'datetime_list' => array(  | 
                                                        |
| 205 | + 'input' => 'textarea',  | 
                                                        |
| 206 | + 'label' => '[DATETIME_LIST]',  | 
                                                        |
| 207 | + 'type' => 'string',  | 
                                                        |
| 208 | + 'required' => false,  | 
                                                        |
| 209 | + 'validation' => true,  | 
                                                        |
| 210 | + 'format' => '%s',  | 
                                                        |
| 211 | + 'css_class' => 'large-text',  | 
                                                        |
| 212 | + 'rows' => '10',  | 
                                                        |
| 213 | +						'shortcodes_required' => array('[DATETIME_LIST]') | 
                                                        |
| 214 | + )  | 
                                                        |
| 215 | + )  | 
                                                        |
| 216 | + )  | 
                                                        |
| 217 | + );  | 
                                                        |
| 218 | + }  | 
                                                        |
| 219 | +  | 
                                                        |
| 220 | +  | 
                                                        |
| 221 | + /**  | 
                                                        |
| 222 | + * @see definition of this method in parent  | 
                                                        |
| 223 | + *  | 
                                                        |
| 224 | + * @since 4.5.0  | 
                                                        |
| 225 | + *  | 
                                                        |
| 226 | + */  | 
                                                        |
| 227 | + protected function _set_default_message_types()  | 
                                                        |
| 228 | +	{ | 
                                                        |
| 229 | + // note currently PDF is only a secondary messenger so it never has any associated message types.  | 
                                                        |
| 230 | + $this->_default_message_types = array();  | 
                                                        |
| 231 | + }  | 
                                                        |
| 232 | +  | 
                                                        |
| 233 | +  | 
                                                        |
| 234 | + /**  | 
                                                        |
| 235 | + * @see definition of this method in parent  | 
                                                        |
| 236 | + *  | 
                                                        |
| 237 | + * @since 4.5.0  | 
                                                        |
| 238 | + */  | 
                                                        |
| 239 | + protected function _set_valid_message_types()  | 
                                                        |
| 240 | +	{ | 
                                                        |
| 241 | + $this->_valid_message_types = array();  | 
                                                        |
| 242 | + }  | 
                                                        |
| 243 | +  | 
                                                        |
| 244 | +  | 
                                                        |
| 245 | + /**  | 
                                                        |
| 246 | + * Generates html version of the message content and then sends it to the pdf generator.  | 
                                                        |
| 247 | + *  | 
                                                        |
| 248 | + *  | 
                                                        |
| 249 | + * @since 4.5.0  | 
                                                        |
| 250 | + *  | 
                                                        |
| 251 | + * @return string.  | 
                                                        |
| 252 | + */  | 
                                                        |
| 253 | + protected function _send_message()  | 
                                                        |
| 254 | +	{ | 
                                                        |
| 255 | + $this->_template_args = array(  | 
                                                        |
| 256 | + 'page_title' => $this->_subject,  | 
                                                        |
| 257 | + 'base_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'base', $this->_variation),  | 
                                                        |
| 258 | + 'print_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'print', $this->_variation),  | 
                                                        |
| 259 | + 'main_css' => $this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, true, 'main', $this->_variation),  | 
                                                        |
| 260 | + 'extra_css' => EE_LIBRARIES_URL . 'messages/defaults/default/variations/pdf_base_default.css',  | 
                                                        |
| 261 | +			'main_body' => apply_filters('FHEE__EE_Pdf_messenger___send_message__main_body', wpautop($this->_content), $this->_content) | 
                                                        |
| 262 | + );  | 
                                                        |
| 263 | + $this->_deregister_wp_hooks();  | 
                                                        |
| 264 | +		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles')); | 
                                                        |
| 265 | + $content = $this->_get_main_template();  | 
                                                        |
| 266 | 266 | // die( $content );  | 
                                                        
| 267 | - $this->_do_pdf($content);  | 
                                                        |
| 268 | - exit(0);  | 
                                                        |
| 269 | - }  | 
                                                        |
| 270 | -  | 
                                                        |
| 271 | -  | 
                                                        |
| 272 | - /**  | 
                                                        |
| 273 | - * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook.  | 
                                                        |
| 274 | - *  | 
                                                        |
| 275 | - * @since 4.5.0  | 
                                                        |
| 276 | - *  | 
                                                        |
| 277 | - * @return void  | 
                                                        |
| 278 | - */  | 
                                                        |
| 279 | - protected function _deregister_wp_hooks()  | 
                                                        |
| 280 | -    { | 
                                                        |
| 281 | -        remove_all_actions('wp_head'); | 
                                                        |
| 282 | -        remove_all_actions('wp_footer'); | 
                                                        |
| 283 | -        remove_all_actions('wp_print_footer_scripts'); | 
                                                        |
| 284 | -        remove_all_actions('wp_enqueue_scripts'); | 
                                                        |
| 285 | - global $wp_scripts, $wp_styles;  | 
                                                        |
| 286 | - $wp_scripts = $wp_styles = array();  | 
                                                        |
| 287 | -  | 
                                                        |
| 288 | - // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.  | 
                                                        |
| 289 | -        add_action('wp_head', 'wp_enqueue_scripts'); | 
                                                        |
| 290 | -        add_action('wp_footer', 'wp_print_footer_scripts'); | 
                                                        |
| 291 | -        add_action('wp_print_footer_scripts', '_wp_footer_scripts'); | 
                                                        |
| 292 | - }  | 
                                                        |
| 293 | -  | 
                                                        |
| 294 | -  | 
                                                        |
| 295 | - /**  | 
                                                        |
| 296 | - * Overwrite parent _get_main_template for pdf purposes.  | 
                                                        |
| 297 | - *  | 
                                                        |
| 298 | - * @since 4.5.0  | 
                                                        |
| 299 | - *  | 
                                                        |
| 300 | - * @param bool $preview  | 
                                                        |
| 301 | - * @return string  | 
                                                        |
| 302 | - */  | 
                                                        |
| 303 | - protected function _get_main_template($preview = false)  | 
                                                        |
| 304 | -    { | 
                                                        |
| 305 | -        $wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); | 
                                                        |
| 306 | - // add message type to template_args  | 
                                                        |
| 307 | - $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 308 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 309 | - }  | 
                                                        |
| 310 | -  | 
                                                        |
| 311 | -  | 
                                                        |
| 312 | - /**  | 
                                                        |
| 313 | - * This takes care of loading the dompdf library and generating the actual pdf  | 
                                                        |
| 314 | - *  | 
                                                        |
| 315 | - * @param string $content This is the generated html content being converted into a pdf.  | 
                                                        |
| 316 | - *  | 
                                                        |
| 317 | - * @return void  | 
                                                        |
| 318 | - */  | 
                                                        |
| 319 | - protected function _do_pdf($content = '')  | 
                                                        |
| 320 | -    { | 
                                                        |
| 321 | - $invoice_name = $this->_subject;  | 
                                                        |
| 322 | -  | 
                                                        |
| 323 | - // only load dompdf if nobody else has yet...  | 
                                                        |
| 324 | -        if (! class_exists('Dompdf\Dompdf')) { | 
                                                        |
| 325 | - require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php');  | 
                                                        |
| 326 | - Dompdf\Autoloader::register();  | 
                                                        |
| 327 | - }  | 
                                                        |
| 328 | - $options = new Dompdf\Options();  | 
                                                        |
| 329 | -        $options->set('isRemoteEnabled', true); | 
                                                        |
| 330 | -        $options->set('isJavascriptEnabled', false); | 
                                                        |
| 331 | -        if (defined('DOMPDF_FONT_DIR')) { | 
                                                        |
| 332 | - $options->setFontDir(DOMPDF_FONT_DIR);  | 
                                                        |
| 333 | - $options->setFontCache(DOMPDF_FONT_DIR);  | 
                                                        |
| 334 | - }  | 
                                                        |
| 335 | - // Allow changing the paper size.  | 
                                                        |
| 336 | -        if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) { | 
                                                        |
| 337 | -            $options->set('defaultPaperSize', DOMPDF_DEFAULT_PAPER_SIZE); | 
                                                        |
| 338 | - }  | 
                                                        |
| 339 | - $dompdf = new Dompdf\Dompdf($options);  | 
                                                        |
| 340 | - // Remove all spaces between HTML tags  | 
                                                        |
| 341 | -        $content = preg_replace('/>\s+</', '><', $content); | 
                                                        |
| 342 | - $dompdf->loadHtml($content);  | 
                                                        |
| 343 | - $dompdf->render();  | 
                                                        |
| 344 | - // forcing the browser to open a download dialog.  | 
                                                        |
| 345 | -        $dompdf->stream($invoice_name . ".pdf", array('Attachment' => true)); | 
                                                        |
| 346 | - }  | 
                                                        |
| 347 | -  | 
                                                        |
| 348 | -  | 
                                                        |
| 349 | - /**  | 
                                                        |
| 350 | - * @return string  | 
                                                        |
| 351 | - */  | 
                                                        |
| 352 | - protected function _preview()  | 
                                                        |
| 353 | -    { | 
                                                        |
| 354 | - return $this->_send_message();  | 
                                                        |
| 355 | - }  | 
                                                        |
| 356 | -  | 
                                                        |
| 357 | -  | 
                                                        |
| 358 | - protected function _set_admin_settings_fields()  | 
                                                        |
| 359 | -    { | 
                                                        |
| 360 | - }  | 
                                                        |
| 267 | + $this->_do_pdf($content);  | 
                                                        |
| 268 | + exit(0);  | 
                                                        |
| 269 | + }  | 
                                                        |
| 270 | +  | 
                                                        |
| 271 | +  | 
                                                        |
| 272 | + /**  | 
                                                        |
| 273 | + * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't interfere with our templates. If users want to add any custom styles or scripts they must use the AHEE__EE_Pdf_messenger__enqueue_scripts_styles hook.  | 
                                                        |
| 274 | + *  | 
                                                        |
| 275 | + * @since 4.5.0  | 
                                                        |
| 276 | + *  | 
                                                        |
| 277 | + * @return void  | 
                                                        |
| 278 | + */  | 
                                                        |
| 279 | + protected function _deregister_wp_hooks()  | 
                                                        |
| 280 | +	{ | 
                                                        |
| 281 | +		remove_all_actions('wp_head'); | 
                                                        |
| 282 | +		remove_all_actions('wp_footer'); | 
                                                        |
| 283 | +		remove_all_actions('wp_print_footer_scripts'); | 
                                                        |
| 284 | +		remove_all_actions('wp_enqueue_scripts'); | 
                                                        |
| 285 | + global $wp_scripts, $wp_styles;  | 
                                                        |
| 286 | + $wp_scripts = $wp_styles = array();  | 
                                                        |
| 287 | +  | 
                                                        |
| 288 | + // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.  | 
                                                        |
| 289 | +		add_action('wp_head', 'wp_enqueue_scripts'); | 
                                                        |
| 290 | +		add_action('wp_footer', 'wp_print_footer_scripts'); | 
                                                        |
| 291 | +		add_action('wp_print_footer_scripts', '_wp_footer_scripts'); | 
                                                        |
| 292 | + }  | 
                                                        |
| 293 | +  | 
                                                        |
| 294 | +  | 
                                                        |
| 295 | + /**  | 
                                                        |
| 296 | + * Overwrite parent _get_main_template for pdf purposes.  | 
                                                        |
| 297 | + *  | 
                                                        |
| 298 | + * @since 4.5.0  | 
                                                        |
| 299 | + *  | 
                                                        |
| 300 | + * @param bool $preview  | 
                                                        |
| 301 | + * @return string  | 
                                                        |
| 302 | + */  | 
                                                        |
| 303 | + protected function _get_main_template($preview = false)  | 
                                                        |
| 304 | +	{ | 
                                                        |
| 305 | +		$wrapper_template = $this->_tmp_pack->get_wrapper('html', 'main'); | 
                                                        |
| 306 | + // add message type to template_args  | 
                                                        |
| 307 | + $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 308 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 309 | + }  | 
                                                        |
| 310 | +  | 
                                                        |
| 311 | +  | 
                                                        |
| 312 | + /**  | 
                                                        |
| 313 | + * This takes care of loading the dompdf library and generating the actual pdf  | 
                                                        |
| 314 | + *  | 
                                                        |
| 315 | + * @param string $content This is the generated html content being converted into a pdf.  | 
                                                        |
| 316 | + *  | 
                                                        |
| 317 | + * @return void  | 
                                                        |
| 318 | + */  | 
                                                        |
| 319 | + protected function _do_pdf($content = '')  | 
                                                        |
| 320 | +	{ | 
                                                        |
| 321 | + $invoice_name = $this->_subject;  | 
                                                        |
| 322 | +  | 
                                                        |
| 323 | + // only load dompdf if nobody else has yet...  | 
                                                        |
| 324 | +		if (! class_exists('Dompdf\Dompdf')) { | 
                                                        |
| 325 | + require_once(EE_THIRD_PARTY . 'dompdf/src/Autoloader.php');  | 
                                                        |
| 326 | + Dompdf\Autoloader::register();  | 
                                                        |
| 327 | + }  | 
                                                        |
| 328 | + $options = new Dompdf\Options();  | 
                                                        |
| 329 | +		$options->set('isRemoteEnabled', true); | 
                                                        |
| 330 | +		$options->set('isJavascriptEnabled', false); | 
                                                        |
| 331 | +		if (defined('DOMPDF_FONT_DIR')) { | 
                                                        |
| 332 | + $options->setFontDir(DOMPDF_FONT_DIR);  | 
                                                        |
| 333 | + $options->setFontCache(DOMPDF_FONT_DIR);  | 
                                                        |
| 334 | + }  | 
                                                        |
| 335 | + // Allow changing the paper size.  | 
                                                        |
| 336 | +		if (defined('DOMPDF_DEFAULT_PAPER_SIZE')) { | 
                                                        |
| 337 | +			$options->set('defaultPaperSize', DOMPDF_DEFAULT_PAPER_SIZE); | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | + $dompdf = new Dompdf\Dompdf($options);  | 
                                                        |
| 340 | + // Remove all spaces between HTML tags  | 
                                                        |
| 341 | +		$content = preg_replace('/>\s+</', '><', $content); | 
                                                        |
| 342 | + $dompdf->loadHtml($content);  | 
                                                        |
| 343 | + $dompdf->render();  | 
                                                        |
| 344 | + // forcing the browser to open a download dialog.  | 
                                                        |
| 345 | +		$dompdf->stream($invoice_name . ".pdf", array('Attachment' => true)); | 
                                                        |
| 346 | + }  | 
                                                        |
| 347 | +  | 
                                                        |
| 348 | +  | 
                                                        |
| 349 | + /**  | 
                                                        |
| 350 | + * @return string  | 
                                                        |
| 351 | + */  | 
                                                        |
| 352 | + protected function _preview()  | 
                                                        |
| 353 | +	{ | 
                                                        |
| 354 | + return $this->_send_message();  | 
                                                        |
| 355 | + }  | 
                                                        |
| 356 | +  | 
                                                        |
| 357 | +  | 
                                                        |
| 358 | + protected function _set_admin_settings_fields()  | 
                                                        |
| 359 | +	{ | 
                                                        |
| 360 | + }  | 
                                                        |
| 361 | 361 | }  | 
                                                        
@@ -16,182 +16,182 @@ discard block  | 
                                                    ||
| 16 | 16 | */  | 
                                                        
| 17 | 17 | abstract class EE_messenger extends EE_Messages_Base  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | - /**  | 
                                                        |
| 20 | - * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.  | 
                                                        |
| 21 | - * This property gets set by the _set_default_message_types() method.  | 
                                                        |
| 22 | - *  | 
                                                        |
| 23 | - * @var array  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - protected $_default_message_types = array();  | 
                                                        |
| 19 | + /**  | 
                                                        |
| 20 | + * This property holds the default message types associated with this messenger when it is activated. The values of the array must match a valid message type.  | 
                                                        |
| 21 | + * This property gets set by the _set_default_message_types() method.  | 
                                                        |
| 22 | + *  | 
                                                        |
| 23 | + * @var array  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + protected $_default_message_types = array();  | 
                                                        |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /**  | 
                                                        |
| 31 | - * This property holds the message types that are valid for use with this messenger.  | 
                                                        |
| 32 | - * It gets set by the _set_valid_message_types() method.  | 
                                                        |
| 33 | - *  | 
                                                        |
| 34 | - * @var array  | 
                                                        |
| 35 | - */  | 
                                                        |
| 36 | - protected $_valid_message_types = array();  | 
                                                        |
| 30 | + /**  | 
                                                        |
| 31 | + * This property holds the message types that are valid for use with this messenger.  | 
                                                        |
| 32 | + * It gets set by the _set_valid_message_types() method.  | 
                                                        |
| 33 | + *  | 
                                                        |
| 34 | + * @var array  | 
                                                        |
| 35 | + */  | 
                                                        |
| 36 | + protected $_valid_message_types = array();  | 
                                                        |
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /**  | 
                                                        |
| 41 | - * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context. So message types don't need to set a $_validator_config property.  | 
                                                        |
| 42 | - *  | 
                                                        |
| 43 | - * Remember, ALL fields must be declared in this array. However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).  | 
                                                        |
| 44 | - *  | 
                                                        |
| 45 | - * Array should be in this format:  | 
                                                        |
| 46 | - *  | 
                                                        |
| 47 | - * array(  | 
                                                        |
| 48 | - * 'field_name(i.e.to)' => array(  | 
                                                        |
| 49 | -     *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match). | 
                                                        |
| 50 | -     *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label. | 
                                                        |
| 51 | - * 'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types). If not required you can just leave empty.,  | 
                                                        |
| 52 | - * 'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation. Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.  | 
                                                        |
| 53 | - * )  | 
                                                        |
| 54 | - * )  | 
                                                        |
| 55 | - *  | 
                                                        |
| 56 | - * @var array  | 
                                                        |
| 57 | - */  | 
                                                        |
| 58 | - protected $_validator_config = array();  | 
                                                        |
| 40 | + /**  | 
                                                        |
| 41 | + * Holds the configuration for the EE_Messages_Validator class to know how to validated the different fields. Note that the Validator will match each field here with the allowed shortcodes set in the "valid_shortcodes" array for the matched message type context. So message types don't need to set a $_validator_config property.  | 
                                                        |
| 42 | + *  | 
                                                        |
| 43 | + * Remember, ALL fields must be declared in this array. However, an empty value for the field means that the field will accept all valid shortcodes set for the given context in the message type (by default).  | 
                                                        |
| 44 | + *  | 
                                                        |
| 45 | + * Array should be in this format:  | 
                                                        |
| 46 | + *  | 
                                                        |
| 47 | + * array(  | 
                                                        |
| 48 | + * 'field_name(i.e.to)' => array(  | 
                                                        |
| 49 | +	 *      'shortcodes' => array('email'), //an array of shortcode groups (correspond to EE_Shortcodes library class) that are allowed in the field. Typically you can just include $this->_valid_shortcodes['field_name'] as the value here (because they will match). | 
                                                        |
| 50 | +	 *      'specific_shortcodes' => array( array('[EVENT_AUTHOR_EMAIL]' => esc_html__('Admin Email', 'event_espresso')), //if this index is present you can further restrict the field to ONLY specific shortcodes if an entire group isn't sufficient. Specific shortcodes need to be listed as an array with the index the shortcode and the value = the label. | 
                                                        |
| 51 | + * 'type' => 'email' //this is the field type and should match one of the validator types (see EE_Messages_Validator::validator() for all the possible types). If not required you can just leave empty.,  | 
                                                        |
| 52 | + * 'required' => array'[SHORTCODE]') //this is used to indicate the shortcodes that MUST be in the assembled array of shortcodes by the validator in order for this field to be included in validation. Otherwise the validator will always assign shortcodes for this field (regardless of whether the field settings for the given messenger/message_type/context use the field or not.).. please note, this does NOT mean that the shortcodes listed here MUST be in the given field.  | 
                                                        |
| 53 | + * )  | 
                                                        |
| 54 | + * )  | 
                                                        |
| 55 | + *  | 
                                                        |
| 56 | + * @var array  | 
                                                        |
| 57 | + */  | 
                                                        |
| 58 | + protected $_validator_config = array();  | 
                                                        |
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /**  | 
                                                        |
| 63 | - * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger  | 
                                                        |
| 64 | - * @var object  | 
                                                        |
| 65 | - */  | 
                                                        |
| 66 | - protected $_EEM_data;  | 
                                                        |
| 62 | + /**  | 
                                                        |
| 63 | + * This will hold the EEM_message_templates model for interacting with the database and retrieving active templates for the messenger  | 
                                                        |
| 64 | + * @var object  | 
                                                        |
| 65 | + */  | 
                                                        |
| 66 | + protected $_EEM_data;  | 
                                                        |
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /**  | 
                                                        |
| 71 | - * this property just holds an array of the various template refs.  | 
                                                        |
| 72 | - * @var array  | 
                                                        |
| 73 | - */  | 
                                                        |
| 74 | - protected $_template_fields = array();  | 
                                                        |
| 70 | + /**  | 
                                                        |
| 71 | + * this property just holds an array of the various template refs.  | 
                                                        |
| 72 | + * @var array  | 
                                                        |
| 73 | + */  | 
                                                        |
| 74 | + protected $_template_fields = array();  | 
                                                        |
| 75 | 75 | |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | |
| 79 | - /**  | 
                                                        |
| 80 | - * This holds an array of the arguments used in parsing a template for the sender.  | 
                                                        |
| 81 | - * @var array  | 
                                                        |
| 82 | - */  | 
                                                        |
| 83 | - protected $_template_args = array();  | 
                                                        |
| 79 | + /**  | 
                                                        |
| 80 | + * This holds an array of the arguments used in parsing a template for the sender.  | 
                                                        |
| 81 | + * @var array  | 
                                                        |
| 82 | + */  | 
                                                        |
| 83 | + protected $_template_args = array();  | 
                                                        |
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
| 87 | 87 | |
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /**  | 
                                                        |
| 91 | - * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger  | 
                                                        |
| 92 | - *  | 
                                                        |
| 93 | - * @protected  | 
                                                        |
| 94 | - * @var array  | 
                                                        |
| 95 | - */  | 
                                                        |
| 96 | - protected $_test_settings_fields = array();  | 
                                                        |
| 90 | + /**  | 
                                                        |
| 91 | + * This property will hold the configuration for any test settings fields that are required for the "test" button that is used to trigger an actual test of this messenger  | 
                                                        |
| 92 | + *  | 
                                                        |
| 93 | + * @protected  | 
                                                        |
| 94 | + * @var array  | 
                                                        |
| 95 | + */  | 
                                                        |
| 96 | + protected $_test_settings_fields = array();  | 
                                                        |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /**  | 
                                                        |
| 104 | - * This will hold the EE_Messages_Template_Pack object when set on the messenger. This is set via the validate and setup method which grabs the template pack from the incoming messages object.  | 
                                                        |
| 105 | - *  | 
                                                        |
| 106 | - * @since 4.5.0  | 
                                                        |
| 107 | - *  | 
                                                        |
| 108 | - * @var EE_Messages_Template_Pack  | 
                                                        |
| 109 | - */  | 
                                                        |
| 110 | - protected $_tmp_pack;  | 
                                                        |
| 103 | + /**  | 
                                                        |
| 104 | + * This will hold the EE_Messages_Template_Pack object when set on the messenger. This is set via the validate and setup method which grabs the template pack from the incoming messages object.  | 
                                                        |
| 105 | + *  | 
                                                        |
| 106 | + * @since 4.5.0  | 
                                                        |
| 107 | + *  | 
                                                        |
| 108 | + * @var EE_Messages_Template_Pack  | 
                                                        |
| 109 | + */  | 
                                                        |
| 110 | + protected $_tmp_pack;  | 
                                                        |
| 111 | 111 | |
| 112 | 112 | |
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /**  | 
                                                        |
| 116 | - * This will hold the variation to use when performing a send. It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.  | 
                                                        |
| 117 | - *  | 
                                                        |
| 118 | - * @since 4.5.0  | 
                                                        |
| 119 | - *  | 
                                                        |
| 120 | - * @var string  | 
                                                        |
| 121 | - */  | 
                                                        |
| 122 | - protected $_variation;  | 
                                                        |
| 115 | + /**  | 
                                                        |
| 116 | + * This will hold the variation to use when performing a send. It is set via the validate and setup method which grabs the variation from the incoming messages object on the send method.  | 
                                                        |
| 117 | + *  | 
                                                        |
| 118 | + * @since 4.5.0  | 
                                                        |
| 119 | + *  | 
                                                        |
| 120 | + * @var string  | 
                                                        |
| 121 | + */  | 
                                                        |
| 122 | + protected $_variation;  | 
                                                        |
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - /**  | 
                                                        |
| 129 | - * This property is a stdClass that holds labels for all the various supporting properties for this messenger. These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:  | 
                                                        |
| 130 | - *  | 
                                                        |
| 131 | - * - template pack  | 
                                                        |
| 132 | - * - template variation  | 
                                                        |
| 133 | - *  | 
                                                        |
| 134 | - * @since 4.5.0  | 
                                                        |
| 135 | - *  | 
                                                        |
| 136 | - * @var stdClass  | 
                                                        |
| 137 | - */  | 
                                                        |
| 138 | - protected $_supports_labels;  | 
                                                        |
| 128 | + /**  | 
                                                        |
| 129 | + * This property is a stdClass that holds labels for all the various supporting properties for this messenger. These labels are set via the _set_supports_labels() method in children classes. Initially this will include the label for:  | 
                                                        |
| 130 | + *  | 
                                                        |
| 131 | + * - template pack  | 
                                                        |
| 132 | + * - template variation  | 
                                                        |
| 133 | + *  | 
                                                        |
| 134 | + * @since 4.5.0  | 
                                                        |
| 135 | + *  | 
                                                        |
| 136 | + * @var stdClass  | 
                                                        |
| 137 | + */  | 
                                                        |
| 138 | + protected $_supports_labels;  | 
                                                        |
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | |
| 142 | 142 | |
| 143 | 143 | |
| 144 | - /**  | 
                                                        |
| 145 | - * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.  | 
                                                        |
| 146 | - *  | 
                                                        |
| 147 | - * @var EE_message_type  | 
                                                        |
| 148 | - */  | 
                                                        |
| 149 | - protected $_incoming_message_type;  | 
                                                        |
| 144 | + /**  | 
                                                        |
| 145 | + * This property is set when the send_message() method is called and holds the Message Type used to generate templates with this messenger for the messages.  | 
                                                        |
| 146 | + *  | 
                                                        |
| 147 | + * @var EE_message_type  | 
                                                        |
| 148 | + */  | 
                                                        |
| 149 | + protected $_incoming_message_type;  | 
                                                        |
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | |
| 153 | - /**  | 
                                                        |
| 154 | - * This flag sets whether a messenger is activated by default on installation (or reactivation) of EE core or not.  | 
                                                        |
| 155 | - *  | 
                                                        |
| 156 | - * @var bool  | 
                                                        |
| 157 | - */  | 
                                                        |
| 158 | - public $activate_on_install = false;  | 
                                                        |
| 153 | + /**  | 
                                                        |
| 154 | + * This flag sets whether a messenger is activated by default on installation (or reactivation) of EE core or not.  | 
                                                        |
| 155 | + *  | 
                                                        |
| 156 | + * @var bool  | 
                                                        |
| 157 | + */  | 
                                                        |
| 158 | + public $activate_on_install = false;  | 
                                                        |
| 159 | 159 | |
| 160 | 160 | |
| 161 | 161 | |
| 162 | 162 | |
| 163 | 163 | |
| 164 | - public function __construct()  | 
                                                        |
| 165 | -    { | 
                                                        |
| 166 | - $this->_EEM_data = EEM_Message_Template_Group::instance();  | 
                                                        |
| 167 | - $this->_messages_item_type = 'messenger';  | 
                                                        |
| 164 | + public function __construct()  | 
                                                        |
| 165 | +	{ | 
                                                        |
| 166 | + $this->_EEM_data = EEM_Message_Template_Group::instance();  | 
                                                        |
| 167 | + $this->_messages_item_type = 'messenger';  | 
                                                        |
| 168 | 168 | |
| 169 | - parent::__construct();  | 
                                                        |
| 169 | + parent::__construct();  | 
                                                        |
| 170 | 170 | |
| 171 | - $this->_set_test_settings_fields();  | 
                                                        |
| 172 | - $this->_set_template_fields();  | 
                                                        |
| 173 | - $this->_set_default_message_types();  | 
                                                        |
| 174 | - $this->_set_valid_message_types();  | 
                                                        |
| 175 | - $this->_set_validator_config();  | 
                                                        |
| 171 | + $this->_set_test_settings_fields();  | 
                                                        |
| 172 | + $this->_set_template_fields();  | 
                                                        |
| 173 | + $this->_set_default_message_types();  | 
                                                        |
| 174 | + $this->_set_valid_message_types();  | 
                                                        |
| 175 | + $this->_set_validator_config();  | 
                                                        |
| 176 | 176 | |
| 177 | 177 | |
| 178 | - $this->_supports_labels = new stdClass();  | 
                                                        |
| 179 | - $this->_set_supports_labels();  | 
                                                        |
| 180 | - }  | 
                                                        |
| 178 | + $this->_supports_labels = new stdClass();  | 
                                                        |
| 179 | + $this->_set_supports_labels();  | 
                                                        |
| 180 | + }  | 
                                                        |
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | |
| 184 | 184 | |
| 185 | 185 | |
| 186 | - /**  | 
                                                        |
| 187 | - * _set_template_fields  | 
                                                        |
| 188 | - * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 189 | - *  | 
                                                        |
| 190 | - * @abstract  | 
                                                        |
| 191 | - * @access protected  | 
                                                        |
| 192 | - * @return void  | 
                                                        |
| 193 | - */  | 
                                                        |
| 194 | - abstract protected function _set_template_fields();  | 
                                                        |
| 186 | + /**  | 
                                                        |
| 187 | + * _set_template_fields  | 
                                                        |
| 188 | + * This sets up the fields that a messenger requires for the message to go out.  | 
                                                        |
| 189 | + *  | 
                                                        |
| 190 | + * @abstract  | 
                                                        |
| 191 | + * @access protected  | 
                                                        |
| 192 | + * @return void  | 
                                                        |
| 193 | + */  | 
                                                        |
| 194 | + abstract protected function _set_template_fields();  | 
                                                        |
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | |
@@ -201,14 +201,14 @@ discard block  | 
                                                    ||
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | |
| 204 | - /**  | 
                                                        |
| 205 | - * This method sets the _default_message_type property (see definition in docs attached to property)  | 
                                                        |
| 206 | - *  | 
                                                        |
| 207 | - * @abstract  | 
                                                        |
| 208 | - * @access protected  | 
                                                        |
| 209 | - * @return void  | 
                                                        |
| 210 | - */  | 
                                                        |
| 211 | - abstract protected function _set_default_message_types();  | 
                                                        |
| 204 | + /**  | 
                                                        |
| 205 | + * This method sets the _default_message_type property (see definition in docs attached to property)  | 
                                                        |
| 206 | + *  | 
                                                        |
| 207 | + * @abstract  | 
                                                        |
| 208 | + * @access protected  | 
                                                        |
| 209 | + * @return void  | 
                                                        |
| 210 | + */  | 
                                                        |
| 211 | + abstract protected function _set_default_message_types();  | 
                                                        |
| 212 | 212 | |
| 213 | 213 | |
| 214 | 214 | |
@@ -216,15 +216,15 @@ discard block  | 
                                                    ||
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | |
| 219 | - /**  | 
                                                        |
| 220 | - * Sets the _valid_message_types property (see definition in cods attached to property)  | 
                                                        |
| 221 | - *  | 
                                                        |
| 222 | - * @since 4.5.0  | 
                                                        |
| 223 | - *  | 
                                                        |
| 224 | - * @abstract  | 
                                                        |
| 225 | - * @return void  | 
                                                        |
| 226 | - */  | 
                                                        |
| 227 | - abstract protected function _set_valid_message_types();  | 
                                                        |
| 219 | + /**  | 
                                                        |
| 220 | + * Sets the _valid_message_types property (see definition in cods attached to property)  | 
                                                        |
| 221 | + *  | 
                                                        |
| 222 | + * @since 4.5.0  | 
                                                        |
| 223 | + *  | 
                                                        |
| 224 | + * @abstract  | 
                                                        |
| 225 | + * @return void  | 
                                                        |
| 226 | + */  | 
                                                        |
| 227 | + abstract protected function _set_valid_message_types();  | 
                                                        |
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | |
@@ -232,171 +232,171 @@ discard block  | 
                                                    ||
| 232 | 232 | |
| 233 | 233 | |
| 234 | 234 | |
| 235 | - /**  | 
                                                        |
| 236 | - * Child classes must declare the $_validator_config property using this method.  | 
                                                        |
| 237 | - * See comments for $_validator_config for details on what it is used for.  | 
                                                        |
| 238 | - *  | 
                                                        |
| 239 | -     * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes. | 
                                                        |
| 240 | - *  | 
                                                        |
| 241 | - * @access protected  | 
                                                        |
| 242 | - * @return void  | 
                                                        |
| 243 | - */  | 
                                                        |
| 244 | - abstract protected function _set_validator_config();  | 
                                                        |
| 235 | + /**  | 
                                                        |
| 236 | + * Child classes must declare the $_validator_config property using this method.  | 
                                                        |
| 237 | + * See comments for $_validator_config for details on what it is used for.  | 
                                                        |
| 238 | + *  | 
                                                        |
| 239 | +	 * NOTE:  messengers should set an array of valid shortcodes for ALL scenarios.  The corresponding validator class (validators/{messenger}) can be used to restrict only certain shortcodes per template so users cannot add certain shortcodes. | 
                                                        |
| 240 | + *  | 
                                                        |
| 241 | + * @access protected  | 
                                                        |
| 242 | + * @return void  | 
                                                        |
| 243 | + */  | 
                                                        |
| 244 | + abstract protected function _set_validator_config();  | 
                                                        |
| 245 | 245 | |
| 246 | 246 | |
| 247 | 247 | |
| 248 | 248 | |
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /**  | 
                                                        |
| 252 | - * We just deliver the messages don't kill us!! This method will need to be modified by child classes for whatever action is taken to actually send a message.  | 
                                                        |
| 253 | - *  | 
                                                        |
| 254 | - * @return bool|WP_Error  | 
                                                        |
| 255 | - * @throw \Exception  | 
                                                        |
| 256 | - */  | 
                                                        |
| 257 | - abstract protected function _send_message();  | 
                                                        |
| 251 | + /**  | 
                                                        |
| 252 | + * We just deliver the messages don't kill us!! This method will need to be modified by child classes for whatever action is taken to actually send a message.  | 
                                                        |
| 253 | + *  | 
                                                        |
| 254 | + * @return bool|WP_Error  | 
                                                        |
| 255 | + * @throw \Exception  | 
                                                        |
| 256 | + */  | 
                                                        |
| 257 | + abstract protected function _send_message();  | 
                                                        |
| 258 | 258 | |
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | |
| 262 | - /**  | 
                                                        |
| 263 | - * We give you pretty previews of the messages!  | 
                                                        |
| 264 | - * @return string html body for message content.  | 
                                                        |
| 265 | - */  | 
                                                        |
| 266 | - abstract protected function _preview();  | 
                                                        |
| 262 | + /**  | 
                                                        |
| 263 | + * We give you pretty previews of the messages!  | 
                                                        |
| 264 | + * @return string html body for message content.  | 
                                                        |
| 265 | + */  | 
                                                        |
| 266 | + abstract protected function _preview();  | 
                                                        |
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | |
| 270 | 270 | |
| 271 | - /**  | 
                                                        |
| 272 | - * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.  | 
                                                        |
| 273 | - *  | 
                                                        |
| 274 | - * @since 4.5.0  | 
                                                        |
| 275 | - *  | 
                                                        |
| 276 | - * @return void  | 
                                                        |
| 277 | - */  | 
                                                        |
| 278 | - public function enqueue_scripts_styles()  | 
                                                        |
| 279 | -    { | 
                                                        |
| 280 | -        do_action('AHEE__EE_messenger__enqueue_scripts_styles'); | 
                                                        |
| 281 | - }  | 
                                                        |
| 271 | + /**  | 
                                                        |
| 272 | + * Used by messengers (or preview) for enqueueing any scripts or styles need in message generation.  | 
                                                        |
| 273 | + *  | 
                                                        |
| 274 | + * @since 4.5.0  | 
                                                        |
| 275 | + *  | 
                                                        |
| 276 | + * @return void  | 
                                                        |
| 277 | + */  | 
                                                        |
| 278 | + public function enqueue_scripts_styles()  | 
                                                        |
| 279 | +	{ | 
                                                        |
| 280 | +		do_action('AHEE__EE_messenger__enqueue_scripts_styles'); | 
                                                        |
| 281 | + }  | 
                                                        |
| 282 | 282 | |
| 283 | 283 | |
| 284 | 284 | |
| 285 | 285 | |
| 286 | 286 | |
| 287 | - /**  | 
                                                        |
| 288 | - * This is used to indicate whether a messenger must be sent immediately or not.  | 
                                                        |
| 289 | - * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right  | 
                                                        |
| 290 | - * away. The PDF messenger is similar.  | 
                                                        |
| 291 | - *  | 
                                                        |
| 292 | - * This flag thus overrides any priorities that may be set on the message type used to generate the message.  | 
                                                        |
| 293 | - *  | 
                                                        |
| 294 | - * Default for this is false. So children classes must override this if they want a message to be executed immediately.  | 
                                                        |
| 295 | - *  | 
                                                        |
| 296 | - * @since 4.9.0  | 
                                                        |
| 297 | - * @return bool  | 
                                                        |
| 298 | - */  | 
                                                        |
| 299 | - public function send_now()  | 
                                                        |
| 300 | -    { | 
                                                        |
| 301 | - return false;  | 
                                                        |
| 302 | - }  | 
                                                        |
| 287 | + /**  | 
                                                        |
| 288 | + * This is used to indicate whether a messenger must be sent immediately or not.  | 
                                                        |
| 289 | + * eg. The HTML messenger will override this to return true because it should be displayed in user's browser right  | 
                                                        |
| 290 | + * away. The PDF messenger is similar.  | 
                                                        |
| 291 | + *  | 
                                                        |
| 292 | + * This flag thus overrides any priorities that may be set on the message type used to generate the message.  | 
                                                        |
| 293 | + *  | 
                                                        |
| 294 | + * Default for this is false. So children classes must override this if they want a message to be executed immediately.  | 
                                                        |
| 295 | + *  | 
                                                        |
| 296 | + * @since 4.9.0  | 
                                                        |
| 297 | + * @return bool  | 
                                                        |
| 298 | + */  | 
                                                        |
| 299 | + public function send_now()  | 
                                                        |
| 300 | +	{ | 
                                                        |
| 301 | + return false;  | 
                                                        |
| 302 | + }  | 
                                                        |
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | |
| 306 | 306 | |
| 307 | 307 | |
| 308 | - /**  | 
                                                        |
| 309 | - * This is a way for a messenger to indicate whether it allows an empty to field or not.  | 
                                                        |
| 310 | - * Note: If the generated message is a for a preview, this value is ignored.  | 
                                                        |
| 311 | - * @since 4.9.0  | 
                                                        |
| 312 | - * @return bool  | 
                                                        |
| 313 | - */  | 
                                                        |
| 314 | - public function allow_empty_to_field()  | 
                                                        |
| 315 | -    { | 
                                                        |
| 316 | - return false;  | 
                                                        |
| 317 | - }  | 
                                                        |
| 308 | + /**  | 
                                                        |
| 309 | + * This is a way for a messenger to indicate whether it allows an empty to field or not.  | 
                                                        |
| 310 | + * Note: If the generated message is a for a preview, this value is ignored.  | 
                                                        |
| 311 | + * @since 4.9.0  | 
                                                        |
| 312 | + * @return bool  | 
                                                        |
| 313 | + */  | 
                                                        |
| 314 | + public function allow_empty_to_field()  | 
                                                        |
| 315 | +	{ | 
                                                        |
| 316 | + return false;  | 
                                                        |
| 317 | + }  | 
                                                        |
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | |
| 321 | 321 | |
| 322 | 322 | |
| 323 | - /**  | 
                                                        |
| 324 | - * Sets the defaults for the _supports_labels property. Can be overridden by child classes.  | 
                                                        |
| 325 | - * @see property definition for info on how its formatted.  | 
                                                        |
| 326 | - *  | 
                                                        |
| 327 | - * @since 4.5.0;  | 
                                                        |
| 328 | - * @return void  | 
                                                        |
| 329 | - */  | 
                                                        |
| 330 | - protected function _set_supports_labels()  | 
                                                        |
| 331 | -    { | 
                                                        |
| 332 | - $this->_set_supports_labels_defaults();  | 
                                                        |
| 333 | - }  | 
                                                        |
| 323 | + /**  | 
                                                        |
| 324 | + * Sets the defaults for the _supports_labels property. Can be overridden by child classes.  | 
                                                        |
| 325 | + * @see property definition for info on how its formatted.  | 
                                                        |
| 326 | + *  | 
                                                        |
| 327 | + * @since 4.5.0;  | 
                                                        |
| 328 | + * @return void  | 
                                                        |
| 329 | + */  | 
                                                        |
| 330 | + protected function _set_supports_labels()  | 
                                                        |
| 331 | +	{ | 
                                                        |
| 332 | + $this->_set_supports_labels_defaults();  | 
                                                        |
| 333 | + }  | 
                                                        |
| 334 | 334 | |
| 335 | 335 | |
| 336 | 336 | |
| 337 | 337 | |
| 338 | 338 | |
| 339 | - /**  | 
                                                        |
| 340 | - * Sets the defaults for the _supports_labels property.  | 
                                                        |
| 341 | - *  | 
                                                        |
| 342 | - * @since 4.5.0  | 
                                                        |
| 343 | - *  | 
                                                        |
| 344 | - * @return void  | 
                                                        |
| 345 | - */  | 
                                                        |
| 346 | - private function _set_supports_labels_defaults()  | 
                                                        |
| 347 | -    { | 
                                                        |
| 348 | -        $this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso'); | 
                                                        |
| 349 | -        $this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso'); | 
                                                        |
| 350 | -        $this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso'); | 
                                                        |
| 339 | + /**  | 
                                                        |
| 340 | + * Sets the defaults for the _supports_labels property.  | 
                                                        |
| 341 | + *  | 
                                                        |
| 342 | + * @since 4.5.0  | 
                                                        |
| 343 | + *  | 
                                                        |
| 344 | + * @return void  | 
                                                        |
| 345 | + */  | 
                                                        |
| 346 | + private function _set_supports_labels_defaults()  | 
                                                        |
| 347 | +	{ | 
                                                        |
| 348 | +		$this->_supports_labels->template_pack = esc_html__('Template Structure', 'event_espresso'); | 
                                                        |
| 349 | +		$this->_supports_labels->template_variation = esc_html__('Template Style', 'event_espresso'); | 
                                                        |
| 350 | +		$this->_supports_labels->template_pack_description = esc_html__('Template Structure options are bundled structural changes for templates.', 'event_espresso'); | 
                                                        |
| 351 | 351 | |
| 352 | -        $this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso'); | 
                                                        |
| 352 | +		$this->_supports_labels->template_variation_description = esc_html__('These are different styles to choose from for the selected template structure.  Usually these affect things like font style, color, borders etc.  In some cases the styles will also make minor layout changes.', 'event_espresso'); | 
                                                        |
| 353 | 353 | |
| 354 | -        $this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); | 
                                                        |
| 355 | - }  | 
                                                        |
| 354 | +		$this->_supports_labels = apply_filters('FHEE__EE_messenger___set_supports_labels_defaults___supports_labels', $this->_supports_labels, $this); | 
                                                        |
| 355 | + }  | 
                                                        |
| 356 | 356 | |
| 357 | 357 | |
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | |
| 361 | - /**  | 
                                                        |
| 362 | - * This returns the _supports_labels property.  | 
                                                        |
| 363 | - *  | 
                                                        |
| 364 | - * @since 4.5.0  | 
                                                        |
| 365 | - *  | 
                                                        |
| 366 | - * @return stdClass  | 
                                                        |
| 367 | - */  | 
                                                        |
| 368 | - public function get_supports_labels()  | 
                                                        |
| 369 | -    { | 
                                                        |
| 370 | -        if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { | 
                                                        |
| 371 | - $this->_set_supports_labels_defaults();  | 
                                                        |
| 372 | - }  | 
                                                        |
| 373 | -        return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); | 
                                                        |
| 374 | - }  | 
                                                        |
| 361 | + /**  | 
                                                        |
| 362 | + * This returns the _supports_labels property.  | 
                                                        |
| 363 | + *  | 
                                                        |
| 364 | + * @since 4.5.0  | 
                                                        |
| 365 | + *  | 
                                                        |
| 366 | + * @return stdClass  | 
                                                        |
| 367 | + */  | 
                                                        |
| 368 | + public function get_supports_labels()  | 
                                                        |
| 369 | +	{ | 
                                                        |
| 370 | +		if (empty($this->_supports_labels->template_pack) || empty($this->_supports_labels->template_variation)) { | 
                                                        |
| 371 | + $this->_set_supports_labels_defaults();  | 
                                                        |
| 372 | + }  | 
                                                        |
| 373 | +		return apply_filters('FHEE__EE_messenger__get_supports_labels', $this->_supports_labels, $this); | 
                                                        |
| 374 | + }  | 
                                                        |
| 375 | 375 | |
| 376 | 376 | |
| 377 | 377 | |
| 378 | 378 | |
| 379 | - /**  | 
                                                        |
| 380 | - * Used to retrieve a variation (typically the path/url to a css file)  | 
                                                        |
| 381 | - *  | 
                                                        |
| 382 | - * @since 4.5.0  | 
                                                        |
| 383 | - *  | 
                                                        |
| 384 | - * @param EE_Messages_Template_Pack $pack The template pack used for retrieving the variation.  | 
                                                        |
| 385 | - * @param string $message_type_name The name property of the message type that we need the variation for.  | 
                                                        |
| 386 | - * @param bool $url Whether to return url (true) or path (false). Default is false.  | 
                                                        |
| 387 | - * @param string $type What variation type to return. Default is 'main'.  | 
                                                        |
| 388 | - * @param string $variation What variation for the template pack  | 
                                                        |
| 389 | - * @param bool $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.  | 
                                                        |
| 390 | - *  | 
                                                        |
| 391 | - * @return string path or url for the requested variation.  | 
                                                        |
| 392 | - */  | 
                                                        |
| 393 | - public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)  | 
                                                        |
| 394 | -    { | 
                                                        |
| 395 | - $this->_tmp_pack = $pack;  | 
                                                        |
| 396 | -        $variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); | 
                                                        |
| 397 | - $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;  | 
                                                        |
| 398 | - return $variation_path;  | 
                                                        |
| 399 | - }  | 
                                                        |
| 379 | + /**  | 
                                                        |
| 380 | + * Used to retrieve a variation (typically the path/url to a css file)  | 
                                                        |
| 381 | + *  | 
                                                        |
| 382 | + * @since 4.5.0  | 
                                                        |
| 383 | + *  | 
                                                        |
| 384 | + * @param EE_Messages_Template_Pack $pack The template pack used for retrieving the variation.  | 
                                                        |
| 385 | + * @param string $message_type_name The name property of the message type that we need the variation for.  | 
                                                        |
| 386 | + * @param bool $url Whether to return url (true) or path (false). Default is false.  | 
                                                        |
| 387 | + * @param string $type What variation type to return. Default is 'main'.  | 
                                                        |
| 388 | + * @param string $variation What variation for the template pack  | 
                                                        |
| 389 | + * @param bool $skip_filters This allows messengers to add a filter for another messengers get_variation but call skip filters on the callback so there is no recursion on apply_filters.  | 
                                                        |
| 390 | + *  | 
                                                        |
| 391 | + * @return string path or url for the requested variation.  | 
                                                        |
| 392 | + */  | 
                                                        |
| 393 | + public function get_variation(EE_Messages_Template_Pack $pack, $message_type_name, $url = false, $type = 'main', $variation = 'default', $skip_filters = false)  | 
                                                        |
| 394 | +	{ | 
                                                        |
| 395 | + $this->_tmp_pack = $pack;  | 
                                                        |
| 396 | +		$variation_path = apply_filters('EE_messenger__get_variation__variation', false, $pack, $this->name, $message_type_name, $url, $type, $variation, $skip_filters); | 
                                                        |
| 397 | + $variation_path = empty($variation_path) ? $this->_tmp_pack->get_variation($this->name, $message_type_name, $type, $variation, $url, '.css', $skip_filters) : $variation_path;  | 
                                                        |
| 398 | + return $variation_path;  | 
                                                        |
| 399 | + }  | 
                                                        |
| 400 | 400 | |
| 401 | 401 | |
| 402 | 402 | |
@@ -404,205 +404,205 @@ discard block  | 
                                                    ||
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | |
| 407 | - /**  | 
                                                        |
| 408 | - * This just returns the default message types associated with this messenger when it is first activated.  | 
                                                        |
| 409 | - *  | 
                                                        |
| 410 | - * @access public  | 
                                                        |
| 411 | - * @return array  | 
                                                        |
| 412 | - */  | 
                                                        |
| 413 | - public function get_default_message_types()  | 
                                                        |
| 414 | -    { | 
                                                        |
| 415 | - $class = get_class($this);  | 
                                                        |
| 407 | + /**  | 
                                                        |
| 408 | + * This just returns the default message types associated with this messenger when it is first activated.  | 
                                                        |
| 409 | + *  | 
                                                        |
| 410 | + * @access public  | 
                                                        |
| 411 | + * @return array  | 
                                                        |
| 412 | + */  | 
                                                        |
| 413 | + public function get_default_message_types()  | 
                                                        |
| 414 | +	{ | 
                                                        |
| 415 | + $class = get_class($this);  | 
                                                        |
| 416 | 416 | |
| 417 | - // messenger specific filter  | 
                                                        |
| 418 | -        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this); | 
                                                        |
| 417 | + // messenger specific filter  | 
                                                        |
| 418 | +		$default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this); | 
                                                        |
| 419 | 419 | |
| 420 | - // all messengers filter  | 
                                                        |
| 421 | -        $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); | 
                                                        |
| 422 | - return $default_types;  | 
                                                        |
| 423 | - }  | 
                                                        |
| 420 | + // all messengers filter  | 
                                                        |
| 421 | +		$default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); | 
                                                        |
| 422 | + return $default_types;  | 
                                                        |
| 423 | + }  | 
                                                        |
| 424 | 424 | |
| 425 | 425 | |
| 426 | 426 | |
| 427 | 427 | |
| 428 | - /**  | 
                                                        |
| 429 | - * Returns the valid message types associated with this messenger.  | 
                                                        |
| 430 | - *  | 
                                                        |
| 431 | - * @since 4.5.0  | 
                                                        |
| 432 | - *  | 
                                                        |
| 433 | - * @return array  | 
                                                        |
| 434 | - */  | 
                                                        |
| 435 | - public function get_valid_message_types()  | 
                                                        |
| 436 | -    { | 
                                                        |
| 437 | - $class = get_class($this);  | 
                                                        |
| 438 | -  | 
                                                        |
| 439 | - // messenger specific filter  | 
                                                        |
| 440 | - // messenger specific filter  | 
                                                        |
| 441 | -        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this); | 
                                                        |
| 442 | -  | 
                                                        |
| 443 | - // all messengers filter  | 
                                                        |
| 444 | -        $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); | 
                                                        |
| 445 | - return $valid_types;  | 
                                                        |
| 446 | - }  | 
                                                        |
| 447 | -  | 
                                                        |
| 448 | -  | 
                                                        |
| 449 | -  | 
                                                        |
| 450 | -  | 
                                                        |
| 451 | -  | 
                                                        |
| 452 | - /**  | 
                                                        |
| 453 | - * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.  | 
                                                        |
| 454 | - *  | 
                                                        |
| 455 | - * @access public  | 
                                                        |
| 456 | - * @param array $new_config Whatever is put in here will reset the _validator_config property  | 
                                                        |
| 457 | - */  | 
                                                        |
| 458 | - public function set_validator_config($new_config)  | 
                                                        |
| 459 | -    { | 
                                                        |
| 460 | - $this->_validator_config = $new_config;  | 
                                                        |
| 461 | - }  | 
                                                        |
| 462 | -  | 
                                                        |
| 463 | -  | 
                                                        |
| 464 | -  | 
                                                        |
| 465 | -  | 
                                                        |
| 466 | - /**  | 
                                                        |
| 467 | - * This returns the _validator_config property  | 
                                                        |
| 468 | - *  | 
                                                        |
| 469 | - * @access public  | 
                                                        |
| 470 | - * @return array  | 
                                                        |
| 471 | - */  | 
                                                        |
| 472 | - public function get_validator_config()  | 
                                                        |
| 473 | -    { | 
                                                        |
| 474 | - $class = get_class($this);  | 
                                                        |
| 475 | -  | 
                                                        |
| 476 | -        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this); | 
                                                        |
| 477 | -        $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); | 
                                                        |
| 478 | - return $config;  | 
                                                        |
| 479 | - }  | 
                                                        |
| 480 | -  | 
                                                        |
| 481 | -  | 
                                                        |
| 482 | -  | 
                                                        |
| 483 | -  | 
                                                        |
| 484 | - /**  | 
                                                        |
| 485 | - * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.  | 
                                                        |
| 486 | - *  | 
                                                        |
| 487 | - * @param string $page the slug of the EE admin page  | 
                                                        |
| 488 | - * @param array $message_types an array of active message type objects  | 
                                                        |
| 489 | - * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)  | 
                                                        |
| 490 | - * @param array $extra This is just an extra argument that can be used to pass additional data for setting up page content.  | 
                                                        |
| 491 | - * @access public  | 
                                                        |
| 492 | - * @return string content for page  | 
                                                        |
| 493 | - */  | 
                                                        |
| 494 | - public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())  | 
                                                        |
| 495 | -    { | 
                                                        |
| 496 | - return $this->_get_admin_page_content($page, $action, $extra, $message_types);  | 
                                                        |
| 497 | - }  | 
                                                        |
| 498 | -  | 
                                                        |
| 499 | -  | 
                                                        |
| 500 | -  | 
                                                        |
| 501 | - /**  | 
                                                        |
| 502 | - * @param $message_types  | 
                                                        |
| 503 | - * @param array $extra  | 
                                                        |
| 504 | - * @return mixed|string  | 
                                                        |
| 505 | - */  | 
                                                        |
| 506 | - protected function _get_admin_content_events_edit($message_types, $extra)  | 
                                                        |
| 507 | -    { | 
                                                        |
| 508 | - // defaults  | 
                                                        |
| 509 | - $template_args = array();  | 
                                                        |
| 510 | - $selector_rows = '';  | 
                                                        |
| 511 | -  | 
                                                        |
| 512 | - // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.  | 
                                                        |
| 513 | - $event_id = isset($extra['event']) ? $extra['event'] : null;  | 
                                                        |
| 514 | -  | 
                                                        |
| 515 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';  | 
                                                        |
| 516 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';  | 
                                                        |
| 517 | -  | 
                                                        |
| 518 | - // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)  | 
                                                        |
| 519 | - $global_templates = EEM_Message_Template_Group::instance()->get_all(  | 
                                                        |
| 520 | - array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )  | 
                                                        |
| 521 | - );  | 
                                                        |
| 522 | - $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(  | 
                                                        |
| 523 | - $event_id,  | 
                                                        |
| 524 | - array(  | 
                                                        |
| 525 | - 'MTP_messenger' => $this->name,  | 
                                                        |
| 526 | - 'MTP_is_active' => true  | 
                                                        |
| 527 | - )  | 
                                                        |
| 528 | - );  | 
                                                        |
| 529 | - $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();  | 
                                                        |
| 530 | -  | 
                                                        |
| 531 | - $msg_type_status_map = [  | 
                                                        |
| 532 | - 'payment' => 'PAP',  | 
                                                        |
| 533 | - 'payment_refund' => 'PRF',  | 
                                                        |
| 534 | - 'payment_reminder' => 'PPN',  | 
                                                        |
| 535 | - 'registration' => 'RAP',  | 
                                                        |
| 536 | - 'not_approved_registration' => 'RNA',  | 
                                                        |
| 537 | - 'pending_approval' => 'RPP',  | 
                                                        |
| 538 | - 'payment_declined' => 'PDC',  | 
                                                        |
| 539 | - 'declined_registration' => 'RDC',  | 
                                                        |
| 540 | - 'cancelled_registration' => 'RCN',  | 
                                                        |
| 541 | - 'payment_failed' => 'PFL',  | 
                                                        |
| 542 | - 'payment_cancelled' => 'PCN',  | 
                                                        |
| 543 | - ];  | 
                                                        |
| 544 | -  | 
                                                        |
| 545 | - // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)  | 
                                                        |
| 546 | -        foreach ($global_templates as $mtpgID => $mtpg) { | 
                                                        |
| 547 | -            if ($mtpg instanceof EE_Message_Template_Group) { | 
                                                        |
| 548 | - // verify this message type is supposed to show on this page  | 
                                                        |
| 549 | - $mtp_obj = $mtpg->message_type_obj();  | 
                                                        |
| 550 | -                if (! $mtp_obj instanceof EE_message_type) { | 
                                                        |
| 551 | - continue;  | 
                                                        |
| 552 | - }  | 
                                                        |
| 553 | - $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;  | 
                                                        |
| 554 | -                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) { | 
                                                        |
| 555 | - continue;  | 
                                                        |
| 556 | - }  | 
                                                        |
| 557 | - $select_values = array();  | 
                                                        |
| 558 | -                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso'); | 
                                                        |
| 559 | -                $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; | 
                                                        |
| 560 | - // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.  | 
                                                        |
| 561 | -                if (! $mtpg->get('MTP_is_override')) { | 
                                                        |
| 562 | - // any custom templates for this message type?  | 
                                                        |
| 563 | - $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());  | 
                                                        |
| 564 | -                    foreach ($custom_templates as $cmtpgID => $cmtpg) { | 
                                                        |
| 565 | - $select_values[ $cmtpgID ] = $cmtpg->name();  | 
                                                        |
| 566 | - $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;  | 
                                                        |
| 567 | - }  | 
                                                        |
| 568 | - }  | 
                                                        |
| 569 | - // if there is no $default_value then we set it as the global  | 
                                                        |
| 570 | - $default_value = empty($default_value) ? $mtpgID : $default_value;  | 
                                                        |
| 571 | - $c_config = $mtpg->contexts_config();  | 
                                                        |
| 572 | - $edit_context = key(array_slice($c_config, -1));  | 
                                                        |
| 573 | - $edit_url_query_args = [  | 
                                                        |
| 574 | - 'page' => 'espresso_messages',  | 
                                                        |
| 575 | - 'action' => 'edit_message_template',  | 
                                                        |
| 576 | - 'id' => $default_value,  | 
                                                        |
| 577 | - 'evt_id' => $event_id,  | 
                                                        |
| 578 | - 'context' => $edit_context,  | 
                                                        |
| 579 | - ];  | 
                                                        |
| 580 | -                $edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php')); | 
                                                        |
| 581 | - $create_url_query_args = [  | 
                                                        |
| 582 | - 'page' => 'espresso_messages',  | 
                                                        |
| 583 | - 'action' => 'add_new_message_template',  | 
                                                        |
| 584 | - 'GRP_ID' => $default_value,  | 
                                                        |
| 585 | - 'message_type' => $mtpg->message_type(),  | 
                                                        |
| 586 | - 'messenger' => $this->name  | 
                                                        |
| 587 | - ];  | 
                                                        |
| 588 | - $mt_slug = $mtpg->message_type();  | 
                                                        |
| 589 | -                $create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php')); | 
                                                        |
| 590 | - $st_args['mtpgID'] = $mtpgID;  | 
                                                        |
| 591 | - $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);  | 
                                                        |
| 592 | - $st_args['mt_slug'] = $mt_slug;  | 
                                                        |
| 593 | - $st_args['messenger_slug'] = $this->name;  | 
                                                        |
| 594 | - $st_args['status_code'] = $msg_type_status_map[ $mt_slug ] ?? '';  | 
                                                        |
| 595 | - $st_args['selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 596 | - 'event_message_templates_relation[' . $mtpgID . ']',  | 
                                                        |
| 597 | - $select_values,  | 
                                                        |
| 598 | - $default_value,  | 
                                                        |
| 599 | - 'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',  | 
                                                        |
| 600 | - 'message-template-selector'  | 
                                                        |
| 601 | - );  | 
                                                        |
| 602 | - // note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).  | 
                                                        |
| 603 | -                $st_args['create_button'] = $mtpg->get('MTP_is_override') | 
                                                        |
| 604 | - ? ''  | 
                                                        |
| 605 | - : '  | 
                                                        |
| 428 | + /**  | 
                                                        |
| 429 | + * Returns the valid message types associated with this messenger.  | 
                                                        |
| 430 | + *  | 
                                                        |
| 431 | + * @since 4.5.0  | 
                                                        |
| 432 | + *  | 
                                                        |
| 433 | + * @return array  | 
                                                        |
| 434 | + */  | 
                                                        |
| 435 | + public function get_valid_message_types()  | 
                                                        |
| 436 | +	{ | 
                                                        |
| 437 | + $class = get_class($this);  | 
                                                        |
| 438 | +  | 
                                                        |
| 439 | + // messenger specific filter  | 
                                                        |
| 440 | + // messenger specific filter  | 
                                                        |
| 441 | +		$valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this); | 
                                                        |
| 442 | +  | 
                                                        |
| 443 | + // all messengers filter  | 
                                                        |
| 444 | +		$valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); | 
                                                        |
| 445 | + return $valid_types;  | 
                                                        |
| 446 | + }  | 
                                                        |
| 447 | +  | 
                                                        |
| 448 | +  | 
                                                        |
| 449 | +  | 
                                                        |
| 450 | +  | 
                                                        |
| 451 | +  | 
                                                        |
| 452 | + /**  | 
                                                        |
| 453 | + * this is just used by the custom validators (EE_Messages_Validator classes) to modify the _validator_config for certain message_type/messenger combos where a context may only use certain shortcodes etc.  | 
                                                        |
| 454 | + *  | 
                                                        |
| 455 | + * @access public  | 
                                                        |
| 456 | + * @param array $new_config Whatever is put in here will reset the _validator_config property  | 
                                                        |
| 457 | + */  | 
                                                        |
| 458 | + public function set_validator_config($new_config)  | 
                                                        |
| 459 | +	{ | 
                                                        |
| 460 | + $this->_validator_config = $new_config;  | 
                                                        |
| 461 | + }  | 
                                                        |
| 462 | +  | 
                                                        |
| 463 | +  | 
                                                        |
| 464 | +  | 
                                                        |
| 465 | +  | 
                                                        |
| 466 | + /**  | 
                                                        |
| 467 | + * This returns the _validator_config property  | 
                                                        |
| 468 | + *  | 
                                                        |
| 469 | + * @access public  | 
                                                        |
| 470 | + * @return array  | 
                                                        |
| 471 | + */  | 
                                                        |
| 472 | + public function get_validator_config()  | 
                                                        |
| 473 | +	{ | 
                                                        |
| 474 | + $class = get_class($this);  | 
                                                        |
| 475 | +  | 
                                                        |
| 476 | +		$config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this); | 
                                                        |
| 477 | +		$config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); | 
                                                        |
| 478 | + return $config;  | 
                                                        |
| 479 | + }  | 
                                                        |
| 480 | +  | 
                                                        |
| 481 | +  | 
                                                        |
| 482 | +  | 
                                                        |
| 483 | +  | 
                                                        |
| 484 | + /**  | 
                                                        |
| 485 | + * this public method accepts a page slug (for an EE_admin page) and will return the response from the child class callback function if that page is registered via the `_admin_registered_page` property set by the child class.  | 
                                                        |
| 486 | + *  | 
                                                        |
| 487 | + * @param string $page the slug of the EE admin page  | 
                                                        |
| 488 | + * @param array $message_types an array of active message type objects  | 
                                                        |
| 489 | + * @param string $action the page action (to allow for more specific handling - i.e. edit vs. add pages)  | 
                                                        |
| 490 | + * @param array $extra This is just an extra argument that can be used to pass additional data for setting up page content.  | 
                                                        |
| 491 | + * @access public  | 
                                                        |
| 492 | + * @return string content for page  | 
                                                        |
| 493 | + */  | 
                                                        |
| 494 | + public function get_messenger_admin_page_content($page, $action = null, $extra = array(), $message_types = array())  | 
                                                        |
| 495 | +	{ | 
                                                        |
| 496 | + return $this->_get_admin_page_content($page, $action, $extra, $message_types);  | 
                                                        |
| 497 | + }  | 
                                                        |
| 498 | +  | 
                                                        |
| 499 | +  | 
                                                        |
| 500 | +  | 
                                                        |
| 501 | + /**  | 
                                                        |
| 502 | + * @param $message_types  | 
                                                        |
| 503 | + * @param array $extra  | 
                                                        |
| 504 | + * @return mixed|string  | 
                                                        |
| 505 | + */  | 
                                                        |
| 506 | + protected function _get_admin_content_events_edit($message_types, $extra)  | 
                                                        |
| 507 | +	{ | 
                                                        |
| 508 | + // defaults  | 
                                                        |
| 509 | + $template_args = array();  | 
                                                        |
| 510 | + $selector_rows = '';  | 
                                                        |
| 511 | +  | 
                                                        |
| 512 | + // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.  | 
                                                        |
| 513 | + $event_id = isset($extra['event']) ? $extra['event'] : null;  | 
                                                        |
| 514 | +  | 
                                                        |
| 515 | + $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';  | 
                                                        |
| 516 | + $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';  | 
                                                        |
| 517 | +  | 
                                                        |
| 518 | + // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)  | 
                                                        |
| 519 | + $global_templates = EEM_Message_Template_Group::instance()->get_all(  | 
                                                        |
| 520 | + array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )  | 
                                                        |
| 521 | + );  | 
                                                        |
| 522 | + $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(  | 
                                                        |
| 523 | + $event_id,  | 
                                                        |
| 524 | + array(  | 
                                                        |
| 525 | + 'MTP_messenger' => $this->name,  | 
                                                        |
| 526 | + 'MTP_is_active' => true  | 
                                                        |
| 527 | + )  | 
                                                        |
| 528 | + );  | 
                                                        |
| 529 | + $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();  | 
                                                        |
| 530 | +  | 
                                                        |
| 531 | + $msg_type_status_map = [  | 
                                                        |
| 532 | + 'payment' => 'PAP',  | 
                                                        |
| 533 | + 'payment_refund' => 'PRF',  | 
                                                        |
| 534 | + 'payment_reminder' => 'PPN',  | 
                                                        |
| 535 | + 'registration' => 'RAP',  | 
                                                        |
| 536 | + 'not_approved_registration' => 'RNA',  | 
                                                        |
| 537 | + 'pending_approval' => 'RPP',  | 
                                                        |
| 538 | + 'payment_declined' => 'PDC',  | 
                                                        |
| 539 | + 'declined_registration' => 'RDC',  | 
                                                        |
| 540 | + 'cancelled_registration' => 'RCN',  | 
                                                        |
| 541 | + 'payment_failed' => 'PFL',  | 
                                                        |
| 542 | + 'payment_cancelled' => 'PCN',  | 
                                                        |
| 543 | + ];  | 
                                                        |
| 544 | +  | 
                                                        |
| 545 | + // so we need to setup the rows for the selectors and we use the global mtpgs (cause those will the active message template groups)  | 
                                                        |
| 546 | +		foreach ($global_templates as $mtpgID => $mtpg) { | 
                                                        |
| 547 | +			if ($mtpg instanceof EE_Message_Template_Group) { | 
                                                        |
| 548 | + // verify this message type is supposed to show on this page  | 
                                                        |
| 549 | + $mtp_obj = $mtpg->message_type_obj();  | 
                                                        |
| 550 | +				if (! $mtp_obj instanceof EE_message_type) { | 
                                                        |
| 551 | + continue;  | 
                                                        |
| 552 | + }  | 
                                                        |
| 553 | + $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;  | 
                                                        |
| 554 | +				if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) { | 
                                                        |
| 555 | + continue;  | 
                                                        |
| 556 | + }  | 
                                                        |
| 557 | + $select_values = array();  | 
                                                        |
| 558 | +				$select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso'); | 
                                                        |
| 559 | +				$default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; | 
                                                        |
| 560 | + // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.  | 
                                                        |
| 561 | +				if (! $mtpg->get('MTP_is_override')) { | 
                                                        |
| 562 | + // any custom templates for this message type?  | 
                                                        |
| 563 | + $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());  | 
                                                        |
| 564 | +					foreach ($custom_templates as $cmtpgID => $cmtpg) { | 
                                                        |
| 565 | + $select_values[ $cmtpgID ] = $cmtpg->name();  | 
                                                        |
| 566 | + $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;  | 
                                                        |
| 567 | + }  | 
                                                        |
| 568 | + }  | 
                                                        |
| 569 | + // if there is no $default_value then we set it as the global  | 
                                                        |
| 570 | + $default_value = empty($default_value) ? $mtpgID : $default_value;  | 
                                                        |
| 571 | + $c_config = $mtpg->contexts_config();  | 
                                                        |
| 572 | + $edit_context = key(array_slice($c_config, -1));  | 
                                                        |
| 573 | + $edit_url_query_args = [  | 
                                                        |
| 574 | + 'page' => 'espresso_messages',  | 
                                                        |
| 575 | + 'action' => 'edit_message_template',  | 
                                                        |
| 576 | + 'id' => $default_value,  | 
                                                        |
| 577 | + 'evt_id' => $event_id,  | 
                                                        |
| 578 | + 'context' => $edit_context,  | 
                                                        |
| 579 | + ];  | 
                                                        |
| 580 | +				$edit_url = EEH_URL::add_query_args_and_nonce($edit_url_query_args, admin_url('admin.php')); | 
                                                        |
| 581 | + $create_url_query_args = [  | 
                                                        |
| 582 | + 'page' => 'espresso_messages',  | 
                                                        |
| 583 | + 'action' => 'add_new_message_template',  | 
                                                        |
| 584 | + 'GRP_ID' => $default_value,  | 
                                                        |
| 585 | + 'message_type' => $mtpg->message_type(),  | 
                                                        |
| 586 | + 'messenger' => $this->name  | 
                                                        |
| 587 | + ];  | 
                                                        |
| 588 | + $mt_slug = $mtpg->message_type();  | 
                                                        |
| 589 | +				$create_url = EEH_URL::add_query_args_and_nonce($create_url_query_args, admin_url('admin.php')); | 
                                                        |
| 590 | + $st_args['mtpgID'] = $mtpgID;  | 
                                                        |
| 591 | + $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);  | 
                                                        |
| 592 | + $st_args['mt_slug'] = $mt_slug;  | 
                                                        |
| 593 | + $st_args['messenger_slug'] = $this->name;  | 
                                                        |
| 594 | + $st_args['status_code'] = $msg_type_status_map[ $mt_slug ] ?? '';  | 
                                                        |
| 595 | + $st_args['selector'] = EEH_Form_Fields::select_input(  | 
                                                        |
| 596 | + 'event_message_templates_relation[' . $mtpgID . ']',  | 
                                                        |
| 597 | + $select_values,  | 
                                                        |
| 598 | + $default_value,  | 
                                                        |
| 599 | + 'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',  | 
                                                        |
| 600 | + 'message-template-selector'  | 
                                                        |
| 601 | + );  | 
                                                        |
| 602 | + // note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).  | 
                                                        |
| 603 | +				$st_args['create_button'] = $mtpg->get('MTP_is_override') | 
                                                        |
| 604 | + ? ''  | 
                                                        |
| 605 | + : '  | 
                                                        |
| 606 | 606 | <a data-messenger="' . $this->name . '"  | 
                                                        
| 607 | 607 | data-messagetype="' . $mt_slug . '"  | 
                                                        
| 608 | 608 | data-grpid="' . $default_value . '"  | 
                                                        
@@ -612,18 +612,18 @@ discard block  | 
                                                    ||
| 612 | 612 | >  | 
                                                        
| 613 | 613 |                          ' . esc_html__('Create New Custom', 'event_espresso') . ' | 
                                                        
| 614 | 614 | </a>';  | 
                                                        
| 615 | - $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 616 | - 'ee_edit_messages',  | 
                                                        |
| 617 | - 'espresso_messages_add_new_message_template'  | 
                                                        |
| 618 | - )  | 
                                                        |
| 619 | - ? $st_args['create_button']  | 
                                                        |
| 620 | - : '';  | 
                                                        |
| 621 | - $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 622 | - 'ee_edit_message',  | 
                                                        |
| 623 | - 'espresso_messages_edit_message_template',  | 
                                                        |
| 624 | - $mtpgID  | 
                                                        |
| 625 | - )  | 
                                                        |
| 626 | - ? '  | 
                                                        |
| 615 | + $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 616 | + 'ee_edit_messages',  | 
                                                        |
| 617 | + 'espresso_messages_add_new_message_template'  | 
                                                        |
| 618 | + )  | 
                                                        |
| 619 | + ? $st_args['create_button']  | 
                                                        |
| 620 | + : '';  | 
                                                        |
| 621 | + $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 622 | + 'ee_edit_message',  | 
                                                        |
| 623 | + 'espresso_messages_edit_message_template',  | 
                                                        |
| 624 | + $mtpgID  | 
                                                        |
| 625 | + )  | 
                                                        |
| 626 | + ? '  | 
                                                        |
| 627 | 627 | <a data-messagetype="' . $mt_slug . '"  | 
                                                        
| 628 | 628 | data-grpid="' . $default_value . '"  | 
                                                        
| 629 | 629 | target="_blank"  | 
                                                        
@@ -632,326 +632,326 @@ discard block  | 
                                                    ||
| 632 | 632 | >  | 
                                                        
| 633 | 633 |                          ' . esc_html__('Edit', 'event_espresso') . ' | 
                                                        
| 634 | 634 | </a>'  | 
                                                        
| 635 | - : '';  | 
                                                        |
| 636 | - $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);  | 
                                                        |
| 637 | - }  | 
                                                        |
| 638 | - }  | 
                                                        |
| 639 | -  | 
                                                        |
| 640 | - // if no selectors present then get out.  | 
                                                        |
| 641 | -        if (empty($selector_rows)) { | 
                                                        |
| 642 | - return '';  | 
                                                        |
| 643 | - }  | 
                                                        |
| 644 | -  | 
                                                        |
| 645 | - $template_args['selector_rows'] = $selector_rows;  | 
                                                        |
| 646 | - return EEH_Template::display_template($template_wrapper_path, $template_args, true);  | 
                                                        |
| 647 | - }  | 
                                                        |
| 648 | -  | 
                                                        |
| 649 | -  | 
                                                        |
| 650 | -  | 
                                                        |
| 651 | -  | 
                                                        |
| 652 | -  | 
                                                        |
| 653 | -  | 
                                                        |
| 654 | - /**  | 
                                                        |
| 655 | - * returns $this->_template_fields,  | 
                                                        |
| 656 | - * filtered first by child class specific filter named something like  | 
                                                        |
| 657 | - * FHEE__EE_Email_messenger__get_template_fields,  | 
                                                        |
| 658 | - * followed by global FHEE__EE_messenger__get_template_fields filter  | 
                                                        |
| 659 | - *  | 
                                                        |
| 660 | - * @return array  | 
                                                        |
| 661 | - */  | 
                                                        |
| 662 | - public function get_template_fields(): array  | 
                                                        |
| 663 | -    { | 
                                                        |
| 664 | - return (array) apply_filters(  | 
                                                        |
| 665 | - 'FHEE__EE_messenger__get_template_fields',  | 
                                                        |
| 666 | -            apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this), | 
                                                        |
| 667 | - $this  | 
                                                        |
| 668 | - );  | 
                                                        |
| 669 | - }  | 
                                                        |
| 670 | -  | 
                                                        |
| 671 | -  | 
                                                        |
| 672 | -  | 
                                                        |
| 673 | -  | 
                                                        |
| 674 | - /** SETUP METHODS **/  | 
                                                        |
| 675 | - /**  | 
                                                        |
| 676 | - * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger  | 
                                                        |
| 677 | - * @param string $item  | 
                                                        |
| 678 | - * @param mixed $value  | 
                                                        |
| 679 | - */  | 
                                                        |
| 680 | - protected function _set_template_value($item, $value)  | 
                                                        |
| 681 | -    { | 
                                                        |
| 682 | -        if (array_key_exists($item, $this->_template_fields)) { | 
                                                        |
| 683 | - $prop = '_' . $item;  | 
                                                        |
| 684 | -            $this->{$prop} = $value; | 
                                                        |
| 685 | - }  | 
                                                        |
| 686 | - }  | 
                                                        |
| 687 | -  | 
                                                        |
| 688 | - /**  | 
                                                        |
| 689 | - * Sets up the message for sending.  | 
                                                        |
| 690 | - *  | 
                                                        |
| 691 | - * @param EE_message $message the message object that contains details about the message.  | 
                                                        |
| 692 | - * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.  | 
                                                        |
| 693 | - *  | 
                                                        |
| 694 | - * @return bool Very important that all messengers return bool for successful send or not. Error messages can be  | 
                                                        |
| 695 | - * added to EE_Error.  | 
                                                        |
| 696 | - * true = message sent successfully  | 
                                                        |
| 697 | - * false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).  | 
                                                        |
| 698 | - * Throwing a SendMessageException means the message failed sending and cannot be retried.  | 
                                                        |
| 699 | - *  | 
                                                        |
| 700 | - * @throws SendMessageException  | 
                                                        |
| 701 | - */  | 
                                                        |
| 702 | - final public function send_message($message, EE_message_type $message_type)  | 
                                                        |
| 703 | -    { | 
                                                        |
| 704 | -        try { | 
                                                        |
| 705 | - $this->_validate_and_setup($message);  | 
                                                        |
| 706 | - $this->_incoming_message_type = $message_type;  | 
                                                        |
| 707 | - $response = $this->_send_message();  | 
                                                        |
| 708 | -            if ($response instanceof WP_Error) { | 
                                                        |
| 709 | - EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 710 | - $response = false;  | 
                                                        |
| 711 | - }  | 
                                                        |
| 712 | -        } catch (\Exception $e) { | 
                                                        |
| 713 | - // convert to an instance of SendMessageException  | 
                                                        |
| 714 | - throw new SendMessageException($e->getMessage());  | 
                                                        |
| 715 | - }  | 
                                                        |
| 716 | - return $response;  | 
                                                        |
| 717 | - }  | 
                                                        |
| 718 | -  | 
                                                        |
| 719 | -  | 
                                                        |
| 720 | -  | 
                                                        |
| 721 | - /**  | 
                                                        |
| 722 | - * Sets up and returns message preview  | 
                                                        |
| 723 | - * @param EE_Message $message incoming message object  | 
                                                        |
| 724 | - * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.  | 
                                                        |
| 725 | - * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview  | 
                                                        |
| 726 | - * @return string return the message html content  | 
                                                        |
| 727 | - */  | 
                                                        |
| 728 | - public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)  | 
                                                        |
| 729 | -    { | 
                                                        |
| 730 | - $this->_validate_and_setup($message);  | 
                                                        |
| 731 | -  | 
                                                        |
| 732 | - $this->_incoming_message_type = $message_type;  | 
                                                        |
| 733 | -  | 
                                                        |
| 734 | -        if ($send) { | 
                                                        |
| 735 | - // are we overriding any existing template fields?  | 
                                                        |
| 736 | - $settings = apply_filters(  | 
                                                        |
| 737 | - 'FHEE__EE_messenger__get_preview__messenger_test_settings',  | 
                                                        |
| 738 | - $this->get_existing_test_settings(),  | 
                                                        |
| 739 | - $this,  | 
                                                        |
| 740 | - $send,  | 
                                                        |
| 741 | - $message,  | 
                                                        |
| 742 | - $message_type  | 
                                                        |
| 743 | - );  | 
                                                        |
| 744 | -            if (! empty($settings)) { | 
                                                        |
| 745 | -                foreach ($settings as $field => $value) { | 
                                                        |
| 746 | - $this->_set_template_value($field, $value);  | 
                                                        |
| 747 | - }  | 
                                                        |
| 748 | - }  | 
                                                        |
| 749 | - }  | 
                                                        |
| 750 | -  | 
                                                        |
| 751 | - // enqueue preview js so that any links/buttons on the page are disabled.  | 
                                                        |
| 752 | -        if (! $send) { | 
                                                        |
| 753 | - // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles,  | 
                                                        |
| 754 | - // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup.  | 
                                                        |
| 755 | -            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 756 | -            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 757 | -            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 758 | - }  | 
                                                        |
| 759 | -  | 
                                                        |
| 760 | - return $send ? $this->_send_message() : $this->_preview();  | 
                                                        |
| 761 | - }  | 
                                                        |
| 762 | -  | 
                                                        |
| 763 | -  | 
                                                        |
| 764 | -  | 
                                                        |
| 765 | -  | 
                                                        |
| 766 | - /**  | 
                                                        |
| 767 | - * Callback for enqueue_scripts so that we setup the preview script for all previews.  | 
                                                        |
| 768 | - *  | 
                                                        |
| 769 | - * @since 4.5.0  | 
                                                        |
| 770 | - *  | 
                                                        |
| 771 | - * @return void  | 
                                                        |
| 772 | - */  | 
                                                        |
| 773 | - public function add_preview_script()  | 
                                                        |
| 774 | -    { | 
                                                        |
| 775 | - // error message  | 
                                                        |
| 776 | - EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(  | 
                                                        |
| 777 | -            __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso') | 
                                                        |
| 778 | - );  | 
                                                        |
| 779 | -        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 780 | -        wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); | 
                                                        |
| 781 | -        wp_enqueue_script('ee-messages-preview-js'); | 
                                                        |
| 782 | - }  | 
                                                        |
| 783 | -  | 
                                                        |
| 784 | -  | 
                                                        |
| 785 | -  | 
                                                        |
| 786 | -  | 
                                                        |
| 787 | - /**  | 
                                                        |
| 788 | - * simply validates the incoming message object and then sets up the properties for the messenger  | 
                                                        |
| 789 | - * @param EE_Message $message  | 
                                                        |
| 790 | - * @throws EE_Error  | 
                                                        |
| 791 | - */  | 
                                                        |
| 792 | - protected function _validate_and_setup(EE_Message $message)  | 
                                                        |
| 793 | -    { | 
                                                        |
| 794 | - $template_pack = $message->get_template_pack();  | 
                                                        |
| 795 | - $variation = $message->get_template_pack_variation();  | 
                                                        |
| 796 | -  | 
                                                        |
| 797 | - // verify we have the required template pack value on the $message object.  | 
                                                        |
| 798 | -        if (! $template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 799 | -            throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); | 
                                                        |
| 800 | - }  | 
                                                        |
| 801 | -  | 
                                                        |
| 802 | - $this->_tmp_pack = $template_pack;  | 
                                                        |
| 803 | -  | 
                                                        |
| 804 | - $this->_variation = $variation ? $variation : 'default';  | 
                                                        |
| 805 | -  | 
                                                        |
| 806 | - $template_fields = $this->get_template_fields();  | 
                                                        |
| 807 | -  | 
                                                        |
| 808 | -        foreach ($template_fields as $template => $value) { | 
                                                        |
| 809 | -            if ($template !== 'extra') { | 
                                                        |
| 810 | -                $column_value = $message->get_field_or_extra_meta('MSG_' . $template); | 
                                                        |
| 811 | - $message_template_value = $column_value ? $column_value : null;  | 
                                                        |
| 812 | - $this->_set_template_value($template, $message_template_value);  | 
                                                        |
| 813 | - }  | 
                                                        |
| 814 | - }  | 
                                                        |
| 815 | - }  | 
                                                        |
| 816 | -  | 
                                                        |
| 817 | -  | 
                                                        |
| 818 | -  | 
                                                        |
| 819 | - /**  | 
                                                        |
| 820 | - * Utility method for child classes to get the contents of a template file and return  | 
                                                        |
| 821 | - *  | 
                                                        |
| 822 | - * We're assuming the child messenger class has already setup template args!  | 
                                                        |
| 823 | - * @param bool $preview if true we use the preview wrapper otherwise we use main wrapper.  | 
                                                        |
| 824 | - * @return string  | 
                                                        |
| 825 | - * @throws \EE_Error  | 
                                                        |
| 826 | - */  | 
                                                        |
| 827 | - protected function _get_main_template($preview = false)  | 
                                                        |
| 828 | -    { | 
                                                        |
| 829 | - $type = $preview ? 'preview' : 'main';  | 
                                                        |
| 830 | -  | 
                                                        |
| 831 | - $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);  | 
                                                        |
| 832 | -  | 
                                                        |
| 833 | - // check file exists and is readable  | 
                                                        |
| 834 | -        if (!is_readable($wrapper_template)) { | 
                                                        |
| 835 | -            throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); | 
                                                        |
| 836 | - }  | 
                                                        |
| 837 | -  | 
                                                        |
| 838 | - // add message type to template args  | 
                                                        |
| 839 | - $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 840 | -  | 
                                                        |
| 841 | - return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 842 | - }  | 
                                                        |
| 843 | -  | 
                                                        |
| 844 | -  | 
                                                        |
| 845 | -  | 
                                                        |
| 846 | - /**  | 
                                                        |
| 847 | - * set the _test_settings_fields property  | 
                                                        |
| 848 | - *  | 
                                                        |
| 849 | - * @access protected  | 
                                                        |
| 850 | - * @return void  | 
                                                        |
| 851 | - */  | 
                                                        |
| 852 | - protected function _set_test_settings_fields()  | 
                                                        |
| 853 | -    { | 
                                                        |
| 854 | - $this->_test_settings_fields = array();  | 
                                                        |
| 855 | - }  | 
                                                        |
| 856 | -  | 
                                                        |
| 857 | -  | 
                                                        |
| 858 | -  | 
                                                        |
| 859 | - /**  | 
                                                        |
| 860 | - * return the _test_settings_fields property  | 
                                                        |
| 861 | - * @return array  | 
                                                        |
| 862 | - */  | 
                                                        |
| 863 | - public function get_test_settings_fields()  | 
                                                        |
| 864 | -    { | 
                                                        |
| 865 | - return $this->_test_settings_fields;  | 
                                                        |
| 866 | - }  | 
                                                        |
| 867 | -  | 
                                                        |
| 868 | -  | 
                                                        |
| 869 | -  | 
                                                        |
| 870 | -  | 
                                                        |
| 871 | - /**  | 
                                                        |
| 872 | - * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 873 | - *  | 
                                                        |
| 874 | - * @access public  | 
                                                        |
| 875 | - * @return array  | 
                                                        |
| 876 | - */  | 
                                                        |
| 877 | - public function get_existing_test_settings()  | 
                                                        |
| 878 | -    { | 
                                                        |
| 879 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 880 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 881 | - $settings = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 882 | - return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();  | 
                                                        |
| 883 | - }  | 
                                                        |
| 884 | -  | 
                                                        |
| 885 | -  | 
                                                        |
| 886 | -  | 
                                                        |
| 887 | - /**  | 
                                                        |
| 888 | - * All this does is set the existing test settings (in the db) for the messenger  | 
                                                        |
| 889 | - *  | 
                                                        |
| 890 | - * @access public  | 
                                                        |
| 891 | - * @param $settings  | 
                                                        |
| 892 | - * @return bool success/fail  | 
                                                        |
| 893 | - */  | 
                                                        |
| 894 | - public function set_existing_test_settings($settings)  | 
                                                        |
| 895 | -    { | 
                                                        |
| 896 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 897 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 898 | - $existing = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 899 | - $existing[ $this->name ]['test_settings'] = $settings;  | 
                                                        |
| 900 | - return $Message_Resource_Manager->update_active_messengers_option($existing);  | 
                                                        |
| 901 | - }  | 
                                                        |
| 902 | -  | 
                                                        |
| 903 | -  | 
                                                        |
| 904 | -  | 
                                                        |
| 905 | - /**  | 
                                                        |
| 906 | - * This just returns the field label for a given field setup in the _template_fields property.  | 
                                                        |
| 907 | - *  | 
                                                        |
| 908 | - * @since 4.3.0  | 
                                                        |
| 909 | - *  | 
                                                        |
| 910 | - * @param string $field The field to retrieve the label for  | 
                                                        |
| 911 | - * @return string The label  | 
                                                        |
| 912 | - */  | 
                                                        |
| 913 | - public function get_field_label($field)  | 
                                                        |
| 914 | -    { | 
                                                        |
| 915 | - // first let's see if the field requests is in the top level array.  | 
                                                        |
| 916 | -        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) { | 
                                                        |
| 917 | - return $this->_template[ $field ]['label'];  | 
                                                        |
| 918 | - }  | 
                                                        |
| 919 | -  | 
                                                        |
| 920 | - // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.  | 
                                                        |
| 921 | -        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) { | 
                                                        |
| 922 | - return $this->_template_fields['extra'][ $field ]['main']['label'];  | 
                                                        |
| 923 | - }  | 
                                                        |
| 924 | -  | 
                                                        |
| 925 | - // now it's possible this field may just be existing in any of the extra array items.  | 
                                                        |
| 926 | -        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { | 
                                                        |
| 927 | -            foreach ($this->_template_fields['extra'] as $main_field => $subfields) { | 
                                                        |
| 928 | -                if (!is_array($subfields)) { | 
                                                        |
| 929 | - continue;  | 
                                                        |
| 930 | - }  | 
                                                        |
| 931 | -                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) { | 
                                                        |
| 932 | - return $subfields[ $field ]['label'];  | 
                                                        |
| 933 | - }  | 
                                                        |
| 934 | - }  | 
                                                        |
| 935 | - }  | 
                                                        |
| 936 | -  | 
                                                        |
| 937 | - // if we made it here then there's no label set so let's just return the $field.  | 
                                                        |
| 938 | - return $field;  | 
                                                        |
| 939 | - }  | 
                                                        |
| 940 | -  | 
                                                        |
| 941 | -  | 
                                                        |
| 942 | -  | 
                                                        |
| 943 | -  | 
                                                        |
| 944 | - /**  | 
                                                        |
| 945 | - * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).  | 
                                                        |
| 946 | - *  | 
                                                        |
| 947 | - * @since 4.5.0  | 
                                                        |
| 948 | - *  | 
                                                        |
| 949 | - * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.  | 
                                                        |
| 950 | - *  | 
                                                        |
| 951 | - * @return void  | 
                                                        |
| 952 | - */  | 
                                                        |
| 953 | - public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 954 | -    { | 
                                                        |
| 955 | - return;  | 
                                                        |
| 956 | - }  | 
                                                        |
| 635 | + : '';  | 
                                                        |
| 636 | + $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);  | 
                                                        |
| 637 | + }  | 
                                                        |
| 638 | + }  | 
                                                        |
| 639 | +  | 
                                                        |
| 640 | + // if no selectors present then get out.  | 
                                                        |
| 641 | +		if (empty($selector_rows)) { | 
                                                        |
| 642 | + return '';  | 
                                                        |
| 643 | + }  | 
                                                        |
| 644 | +  | 
                                                        |
| 645 | + $template_args['selector_rows'] = $selector_rows;  | 
                                                        |
| 646 | + return EEH_Template::display_template($template_wrapper_path, $template_args, true);  | 
                                                        |
| 647 | + }  | 
                                                        |
| 648 | +  | 
                                                        |
| 649 | +  | 
                                                        |
| 650 | +  | 
                                                        |
| 651 | +  | 
                                                        |
| 652 | +  | 
                                                        |
| 653 | +  | 
                                                        |
| 654 | + /**  | 
                                                        |
| 655 | + * returns $this->_template_fields,  | 
                                                        |
| 656 | + * filtered first by child class specific filter named something like  | 
                                                        |
| 657 | + * FHEE__EE_Email_messenger__get_template_fields,  | 
                                                        |
| 658 | + * followed by global FHEE__EE_messenger__get_template_fields filter  | 
                                                        |
| 659 | + *  | 
                                                        |
| 660 | + * @return array  | 
                                                        |
| 661 | + */  | 
                                                        |
| 662 | + public function get_template_fields(): array  | 
                                                        |
| 663 | +	{ | 
                                                        |
| 664 | + return (array) apply_filters(  | 
                                                        |
| 665 | + 'FHEE__EE_messenger__get_template_fields',  | 
                                                        |
| 666 | +			apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this), | 
                                                        |
| 667 | + $this  | 
                                                        |
| 668 | + );  | 
                                                        |
| 669 | + }  | 
                                                        |
| 670 | +  | 
                                                        |
| 671 | +  | 
                                                        |
| 672 | +  | 
                                                        |
| 673 | +  | 
                                                        |
| 674 | + /** SETUP METHODS **/  | 
                                                        |
| 675 | + /**  | 
                                                        |
| 676 | + * The following method doesn't NEED to be used by child classes but might be modified by the specific messenger  | 
                                                        |
| 677 | + * @param string $item  | 
                                                        |
| 678 | + * @param mixed $value  | 
                                                        |
| 679 | + */  | 
                                                        |
| 680 | + protected function _set_template_value($item, $value)  | 
                                                        |
| 681 | +	{ | 
                                                        |
| 682 | +		if (array_key_exists($item, $this->_template_fields)) { | 
                                                        |
| 683 | + $prop = '_' . $item;  | 
                                                        |
| 684 | +			$this->{$prop} = $value; | 
                                                        |
| 685 | + }  | 
                                                        |
| 686 | + }  | 
                                                        |
| 687 | +  | 
                                                        |
| 688 | + /**  | 
                                                        |
| 689 | + * Sets up the message for sending.  | 
                                                        |
| 690 | + *  | 
                                                        |
| 691 | + * @param EE_message $message the message object that contains details about the message.  | 
                                                        |
| 692 | + * @param EE_message_type $message_type The message type object used in combination with this messenger to generate the provided message.  | 
                                                        |
| 693 | + *  | 
                                                        |
| 694 | + * @return bool Very important that all messengers return bool for successful send or not. Error messages can be  | 
                                                        |
| 695 | + * added to EE_Error.  | 
                                                        |
| 696 | + * true = message sent successfully  | 
                                                        |
| 697 | + * false = message not sent but can be retried (i.e. the failure might be just due to communication issues at the time of send).  | 
                                                        |
| 698 | + * Throwing a SendMessageException means the message failed sending and cannot be retried.  | 
                                                        |
| 699 | + *  | 
                                                        |
| 700 | + * @throws SendMessageException  | 
                                                        |
| 701 | + */  | 
                                                        |
| 702 | + final public function send_message($message, EE_message_type $message_type)  | 
                                                        |
| 703 | +	{ | 
                                                        |
| 704 | +		try { | 
                                                        |
| 705 | + $this->_validate_and_setup($message);  | 
                                                        |
| 706 | + $this->_incoming_message_type = $message_type;  | 
                                                        |
| 707 | + $response = $this->_send_message();  | 
                                                        |
| 708 | +			if ($response instanceof WP_Error) { | 
                                                        |
| 709 | + EE_Error::add_error($response->get_error_message(), __FILE__, __FUNCTION__, __LINE__);  | 
                                                        |
| 710 | + $response = false;  | 
                                                        |
| 711 | + }  | 
                                                        |
| 712 | +		} catch (\Exception $e) { | 
                                                        |
| 713 | + // convert to an instance of SendMessageException  | 
                                                        |
| 714 | + throw new SendMessageException($e->getMessage());  | 
                                                        |
| 715 | + }  | 
                                                        |
| 716 | + return $response;  | 
                                                        |
| 717 | + }  | 
                                                        |
| 718 | +  | 
                                                        |
| 719 | +  | 
                                                        |
| 720 | +  | 
                                                        |
| 721 | + /**  | 
                                                        |
| 722 | + * Sets up and returns message preview  | 
                                                        |
| 723 | + * @param EE_Message $message incoming message object  | 
                                                        |
| 724 | + * @param EE_message_type $message_type This is whatever message type was used in combination with this messenger to generate the message.  | 
                                                        |
| 725 | + * @param bool $send true we will actually use the _send method (for test sends). FALSE we just return preview  | 
                                                        |
| 726 | + * @return string return the message html content  | 
                                                        |
| 727 | + */  | 
                                                        |
| 728 | + public function get_preview(EE_Message $message, EE_message_type $message_type, $send = false)  | 
                                                        |
| 729 | +	{ | 
                                                        |
| 730 | + $this->_validate_and_setup($message);  | 
                                                        |
| 731 | +  | 
                                                        |
| 732 | + $this->_incoming_message_type = $message_type;  | 
                                                        |
| 733 | +  | 
                                                        |
| 734 | +		if ($send) { | 
                                                        |
| 735 | + // are we overriding any existing template fields?  | 
                                                        |
| 736 | + $settings = apply_filters(  | 
                                                        |
| 737 | + 'FHEE__EE_messenger__get_preview__messenger_test_settings',  | 
                                                        |
| 738 | + $this->get_existing_test_settings(),  | 
                                                        |
| 739 | + $this,  | 
                                                        |
| 740 | + $send,  | 
                                                        |
| 741 | + $message,  | 
                                                        |
| 742 | + $message_type  | 
                                                        |
| 743 | + );  | 
                                                        |
| 744 | +			if (! empty($settings)) { | 
                                                        |
| 745 | +				foreach ($settings as $field => $value) { | 
                                                        |
| 746 | + $this->_set_template_value($field, $value);  | 
                                                        |
| 747 | + }  | 
                                                        |
| 748 | + }  | 
                                                        |
| 749 | + }  | 
                                                        |
| 750 | +  | 
                                                        |
| 751 | + // enqueue preview js so that any links/buttons on the page are disabled.  | 
                                                        |
| 752 | +		if (! $send) { | 
                                                        |
| 753 | + // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles,  | 
                                                        |
| 754 | + // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup.  | 
                                                        |
| 755 | +			add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 756 | +			add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 757 | +			add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 758 | + }  | 
                                                        |
| 759 | +  | 
                                                        |
| 760 | + return $send ? $this->_send_message() : $this->_preview();  | 
                                                        |
| 761 | + }  | 
                                                        |
| 762 | +  | 
                                                        |
| 763 | +  | 
                                                        |
| 764 | +  | 
                                                        |
| 765 | +  | 
                                                        |
| 766 | + /**  | 
                                                        |
| 767 | + * Callback for enqueue_scripts so that we setup the preview script for all previews.  | 
                                                        |
| 768 | + *  | 
                                                        |
| 769 | + * @since 4.5.0  | 
                                                        |
| 770 | + *  | 
                                                        |
| 771 | + * @return void  | 
                                                        |
| 772 | + */  | 
                                                        |
| 773 | + public function add_preview_script()  | 
                                                        |
| 774 | +	{ | 
                                                        |
| 775 | + // error message  | 
                                                        |
| 776 | + EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(  | 
                                                        |
| 777 | +			__('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso') | 
                                                        |
| 778 | + );  | 
                                                        |
| 779 | +		wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 780 | +		wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); | 
                                                        |
| 781 | +		wp_enqueue_script('ee-messages-preview-js'); | 
                                                        |
| 782 | + }  | 
                                                        |
| 783 | +  | 
                                                        |
| 784 | +  | 
                                                        |
| 785 | +  | 
                                                        |
| 786 | +  | 
                                                        |
| 787 | + /**  | 
                                                        |
| 788 | + * simply validates the incoming message object and then sets up the properties for the messenger  | 
                                                        |
| 789 | + * @param EE_Message $message  | 
                                                        |
| 790 | + * @throws EE_Error  | 
                                                        |
| 791 | + */  | 
                                                        |
| 792 | + protected function _validate_and_setup(EE_Message $message)  | 
                                                        |
| 793 | +	{ | 
                                                        |
| 794 | + $template_pack = $message->get_template_pack();  | 
                                                        |
| 795 | + $variation = $message->get_template_pack_variation();  | 
                                                        |
| 796 | +  | 
                                                        |
| 797 | + // verify we have the required template pack value on the $message object.  | 
                                                        |
| 798 | +		if (! $template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 799 | +			throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); | 
                                                        |
| 800 | + }  | 
                                                        |
| 801 | +  | 
                                                        |
| 802 | + $this->_tmp_pack = $template_pack;  | 
                                                        |
| 803 | +  | 
                                                        |
| 804 | + $this->_variation = $variation ? $variation : 'default';  | 
                                                        |
| 805 | +  | 
                                                        |
| 806 | + $template_fields = $this->get_template_fields();  | 
                                                        |
| 807 | +  | 
                                                        |
| 808 | +		foreach ($template_fields as $template => $value) { | 
                                                        |
| 809 | +			if ($template !== 'extra') { | 
                                                        |
| 810 | +				$column_value = $message->get_field_or_extra_meta('MSG_' . $template); | 
                                                        |
| 811 | + $message_template_value = $column_value ? $column_value : null;  | 
                                                        |
| 812 | + $this->_set_template_value($template, $message_template_value);  | 
                                                        |
| 813 | + }  | 
                                                        |
| 814 | + }  | 
                                                        |
| 815 | + }  | 
                                                        |
| 816 | +  | 
                                                        |
| 817 | +  | 
                                                        |
| 818 | +  | 
                                                        |
| 819 | + /**  | 
                                                        |
| 820 | + * Utility method for child classes to get the contents of a template file and return  | 
                                                        |
| 821 | + *  | 
                                                        |
| 822 | + * We're assuming the child messenger class has already setup template args!  | 
                                                        |
| 823 | + * @param bool $preview if true we use the preview wrapper otherwise we use main wrapper.  | 
                                                        |
| 824 | + * @return string  | 
                                                        |
| 825 | + * @throws \EE_Error  | 
                                                        |
| 826 | + */  | 
                                                        |
| 827 | + protected function _get_main_template($preview = false)  | 
                                                        |
| 828 | +	{ | 
                                                        |
| 829 | + $type = $preview ? 'preview' : 'main';  | 
                                                        |
| 830 | +  | 
                                                        |
| 831 | + $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);  | 
                                                        |
| 832 | +  | 
                                                        |
| 833 | + // check file exists and is readable  | 
                                                        |
| 834 | +		if (!is_readable($wrapper_template)) { | 
                                                        |
| 835 | +			throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); | 
                                                        |
| 836 | + }  | 
                                                        |
| 837 | +  | 
                                                        |
| 838 | + // add message type to template args  | 
                                                        |
| 839 | + $this->_template_args['message_type'] = $this->_incoming_message_type;  | 
                                                        |
| 840 | +  | 
                                                        |
| 841 | + return EEH_Template::display_template($wrapper_template, $this->_template_args, true);  | 
                                                        |
| 842 | + }  | 
                                                        |
| 843 | +  | 
                                                        |
| 844 | +  | 
                                                        |
| 845 | +  | 
                                                        |
| 846 | + /**  | 
                                                        |
| 847 | + * set the _test_settings_fields property  | 
                                                        |
| 848 | + *  | 
                                                        |
| 849 | + * @access protected  | 
                                                        |
| 850 | + * @return void  | 
                                                        |
| 851 | + */  | 
                                                        |
| 852 | + protected function _set_test_settings_fields()  | 
                                                        |
| 853 | +	{ | 
                                                        |
| 854 | + $this->_test_settings_fields = array();  | 
                                                        |
| 855 | + }  | 
                                                        |
| 856 | +  | 
                                                        |
| 857 | +  | 
                                                        |
| 858 | +  | 
                                                        |
| 859 | + /**  | 
                                                        |
| 860 | + * return the _test_settings_fields property  | 
                                                        |
| 861 | + * @return array  | 
                                                        |
| 862 | + */  | 
                                                        |
| 863 | + public function get_test_settings_fields()  | 
                                                        |
| 864 | +	{ | 
                                                        |
| 865 | + return $this->_test_settings_fields;  | 
                                                        |
| 866 | + }  | 
                                                        |
| 867 | +  | 
                                                        |
| 868 | +  | 
                                                        |
| 869 | +  | 
                                                        |
| 870 | +  | 
                                                        |
| 871 | + /**  | 
                                                        |
| 872 | + * This just returns any existing test settings that might be saved in the database  | 
                                                        |
| 873 | + *  | 
                                                        |
| 874 | + * @access public  | 
                                                        |
| 875 | + * @return array  | 
                                                        |
| 876 | + */  | 
                                                        |
| 877 | + public function get_existing_test_settings()  | 
                                                        |
| 878 | +	{ | 
                                                        |
| 879 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 880 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 881 | + $settings = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 882 | + return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();  | 
                                                        |
| 883 | + }  | 
                                                        |
| 884 | +  | 
                                                        |
| 885 | +  | 
                                                        |
| 886 | +  | 
                                                        |
| 887 | + /**  | 
                                                        |
| 888 | + * All this does is set the existing test settings (in the db) for the messenger  | 
                                                        |
| 889 | + *  | 
                                                        |
| 890 | + * @access public  | 
                                                        |
| 891 | + * @param $settings  | 
                                                        |
| 892 | + * @return bool success/fail  | 
                                                        |
| 893 | + */  | 
                                                        |
| 894 | + public function set_existing_test_settings($settings)  | 
                                                        |
| 895 | +	{ | 
                                                        |
| 896 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 897 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 898 | + $existing = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 899 | + $existing[ $this->name ]['test_settings'] = $settings;  | 
                                                        |
| 900 | + return $Message_Resource_Manager->update_active_messengers_option($existing);  | 
                                                        |
| 901 | + }  | 
                                                        |
| 902 | +  | 
                                                        |
| 903 | +  | 
                                                        |
| 904 | +  | 
                                                        |
| 905 | + /**  | 
                                                        |
| 906 | + * This just returns the field label for a given field setup in the _template_fields property.  | 
                                                        |
| 907 | + *  | 
                                                        |
| 908 | + * @since 4.3.0  | 
                                                        |
| 909 | + *  | 
                                                        |
| 910 | + * @param string $field The field to retrieve the label for  | 
                                                        |
| 911 | + * @return string The label  | 
                                                        |
| 912 | + */  | 
                                                        |
| 913 | + public function get_field_label($field)  | 
                                                        |
| 914 | +	{ | 
                                                        |
| 915 | + // first let's see if the field requests is in the top level array.  | 
                                                        |
| 916 | +		if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) { | 
                                                        |
| 917 | + return $this->_template[ $field ]['label'];  | 
                                                        |
| 918 | + }  | 
                                                        |
| 919 | +  | 
                                                        |
| 920 | + // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.  | 
                                                        |
| 921 | +		if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) { | 
                                                        |
| 922 | + return $this->_template_fields['extra'][ $field ]['main']['label'];  | 
                                                        |
| 923 | + }  | 
                                                        |
| 924 | +  | 
                                                        |
| 925 | + // now it's possible this field may just be existing in any of the extra array items.  | 
                                                        |
| 926 | +		if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { | 
                                                        |
| 927 | +			foreach ($this->_template_fields['extra'] as $main_field => $subfields) { | 
                                                        |
| 928 | +				if (!is_array($subfields)) { | 
                                                        |
| 929 | + continue;  | 
                                                        |
| 930 | + }  | 
                                                        |
| 931 | +				if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) { | 
                                                        |
| 932 | + return $subfields[ $field ]['label'];  | 
                                                        |
| 933 | + }  | 
                                                        |
| 934 | + }  | 
                                                        |
| 935 | + }  | 
                                                        |
| 936 | +  | 
                                                        |
| 937 | + // if we made it here then there's no label set so let's just return the $field.  | 
                                                        |
| 938 | + return $field;  | 
                                                        |
| 939 | + }  | 
                                                        |
| 940 | +  | 
                                                        |
| 941 | +  | 
                                                        |
| 942 | +  | 
                                                        |
| 943 | +  | 
                                                        |
| 944 | + /**  | 
                                                        |
| 945 | + * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger is a different messenger. Child messengers can set hooks for the sending messenger to callback on if necessary (i.e. swap out css files or something else).  | 
                                                        |
| 946 | + *  | 
                                                        |
| 947 | + * @since 4.5.0  | 
                                                        |
| 948 | + *  | 
                                                        |
| 949 | + * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.  | 
                                                        |
| 950 | + *  | 
                                                        |
| 951 | + * @return void  | 
                                                        |
| 952 | + */  | 
                                                        |
| 953 | + public function do_secondary_messenger_hooks($sending_messenger_name)  | 
                                                        |
| 954 | +	{ | 
                                                        |
| 955 | + return;  | 
                                                        |
| 956 | + }  | 
                                                        |
| 957 | 957 | }  | 
                                                        
@@ -415,7 +415,7 @@ discard block  | 
                                                    ||
| 415 | 415 | $class = get_class($this);  | 
                                                        
| 416 | 416 | |
| 417 | 417 | // messenger specific filter  | 
                                                        
| 418 | -        $default_types = apply_filters('FHEE__' . $class . '__get_default_message_types__default_types', $this->_default_message_types, $this); | 
                                                        |
| 418 | +        $default_types = apply_filters('FHEE__'.$class.'__get_default_message_types__default_types', $this->_default_message_types, $this); | 
                                                        |
| 419 | 419 | |
| 420 | 420 | // all messengers filter  | 
                                                        
| 421 | 421 |          $default_types = apply_filters('FHEE__EE_messenger__get_default_message_types__default_types', $default_types, $this); | 
                                                        
@@ -438,7 +438,7 @@ discard block  | 
                                                    ||
| 438 | 438 | |
| 439 | 439 | // messenger specific filter  | 
                                                        
| 440 | 440 | // messenger specific filter  | 
                                                        
| 441 | -        $valid_types = apply_filters('FHEE__' . $class . '__get_valid_message_types__valid_types', $this->_valid_message_types, $this); | 
                                                        |
| 441 | +        $valid_types = apply_filters('FHEE__'.$class.'__get_valid_message_types__valid_types', $this->_valid_message_types, $this); | 
                                                        |
| 442 | 442 | |
| 443 | 443 | // all messengers filter  | 
                                                        
| 444 | 444 |          $valid_types = apply_filters('FHEE__EE_messenger__get_valid_message_types__valid_types', $valid_types, $this); | 
                                                        
@@ -473,7 +473,7 @@ discard block  | 
                                                    ||
| 473 | 473 |      { | 
                                                        
| 474 | 474 | $class = get_class($this);  | 
                                                        
| 475 | 475 | |
| 476 | -        $config = apply_filters('FHEE__' . $class . '__get_validator_config', $this->_validator_config, $this); | 
                                                        |
| 476 | +        $config = apply_filters('FHEE__'.$class.'__get_validator_config', $this->_validator_config, $this); | 
                                                        |
| 477 | 477 |          $config = apply_filters('FHEE__EE_messenger__get_validator_config', $config, $this); | 
                                                        
| 478 | 478 | return $config;  | 
                                                        
| 479 | 479 | }  | 
                                                        
@@ -512,12 +512,12 @@ discard block  | 
                                                    ||
| 512 | 512 | // we don't need message types here so we're just going to ignore. we do, however, expect the event id here. The event id is needed to provide a link to setup a custom template for this event.  | 
                                                        
| 513 | 513 | $event_id = isset($extra['event']) ? $extra['event'] : null;  | 
                                                        
| 514 | 514 | |
| 515 | - $template_wrapper_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_wrapper.template.php';  | 
                                                        |
| 516 | - $template_row_path = EE_LIBRARIES . 'messages/messenger/admin_templates/event_switcher_row.template.php';  | 
                                                        |
| 515 | + $template_wrapper_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_wrapper.template.php';  | 
                                                        |
| 516 | + $template_row_path = EE_LIBRARIES.'messages/messenger/admin_templates/event_switcher_row.template.php';  | 
                                                        |
| 517 | 517 | |
| 518 | 518 | // array of template objects for global and custom (non-trashed) (but remember just for this messenger!)  | 
                                                        
| 519 | 519 | $global_templates = EEM_Message_Template_Group::instance()->get_all(  | 
                                                        
| 520 | - array( array( 'MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true ) )  | 
                                                        |
| 520 | +            array(array('MTP_messenger' => $this->name, 'MTP_is_global' => true, 'MTP_is_active' => true)) | 
                                                        |
| 521 | 521 | );  | 
                                                        
| 522 | 522 | $templates_for_event = EEM_Message_Template_Group::instance()->get_all_custom_templates_by_event(  | 
                                                        
| 523 | 523 | $event_id,  | 
                                                        
@@ -526,7 +526,7 @@ discard block  | 
                                                    ||
| 526 | 526 | 'MTP_is_active' => true  | 
                                                        
| 527 | 527 | )  | 
                                                        
| 528 | 528 | );  | 
                                                        
| 529 | - $templates_for_event = !empty($templates_for_event) ? $templates_for_event : array();  | 
                                                        |
| 529 | + $templates_for_event = ! empty($templates_for_event) ? $templates_for_event : array();  | 
                                                        |
| 530 | 530 | |
| 531 | 531 | $msg_type_status_map = [  | 
                                                        
| 532 | 532 | 'payment' => 'PAP',  | 
                                                        
@@ -547,22 +547,22 @@ discard block  | 
                                                    ||
| 547 | 547 |              if ($mtpg instanceof EE_Message_Template_Group) { | 
                                                        
| 548 | 548 | // verify this message type is supposed to show on this page  | 
                                                        
| 549 | 549 | $mtp_obj = $mtpg->message_type_obj();  | 
                                                        
| 550 | -                if (! $mtp_obj instanceof EE_message_type) { | 
                                                        |
| 550 | +                if ( ! $mtp_obj instanceof EE_message_type) { | 
                                                        |
| 551 | 551 | continue;  | 
                                                        
| 552 | 552 | }  | 
                                                        
| 553 | 553 | $mtp_obj->admin_registered_pages = (array) $mtp_obj->admin_registered_pages;  | 
                                                        
| 554 | -                if (! in_array('events_edit', $mtp_obj->admin_registered_pages)) { | 
                                                        |
| 554 | +                if ( ! in_array('events_edit', $mtp_obj->admin_registered_pages)) { | 
                                                        |
| 555 | 555 | continue;  | 
                                                        
| 556 | 556 | }  | 
                                                        
| 557 | 557 | $select_values = array();  | 
                                                        
| 558 | -                $select_values[ $mtpgID ] = esc_html__('Global', 'event_espresso'); | 
                                                        |
| 558 | +                $select_values[$mtpgID] = esc_html__('Global', 'event_espresso'); | 
                                                        |
| 559 | 559 |                  $default_value = array_key_exists($mtpgID, $templates_for_event) && ! $mtpg->get('MTP_is_override') ? $mtpgID : null; | 
                                                        
| 560 | 560 | // if the override has been set for the global template, then that means even if there are custom templates already created we ignore them because of the set override.  | 
                                                        
| 561 | -                if (! $mtpg->get('MTP_is_override')) { | 
                                                        |
| 561 | +                if ( ! $mtpg->get('MTP_is_override')) { | 
                                                        |
| 562 | 562 | // any custom templates for this message type?  | 
                                                        
| 563 | 563 | $custom_templates = EEM_Message_Template_Group::instance()->get_custom_message_template_by_m_and_mt($this->name, $mtpg->message_type());  | 
                                                        
| 564 | 564 |                      foreach ($custom_templates as $cmtpgID => $cmtpg) { | 
                                                        
| 565 | - $select_values[ $cmtpgID ] = $cmtpg->name();  | 
                                                        |
| 565 | + $select_values[$cmtpgID] = $cmtpg->name();  | 
                                                        |
| 566 | 566 | $default_value = array_key_exists($cmtpgID, $templates_for_event) ? $cmtpgID : $default_value;  | 
                                                        
| 567 | 567 | }  | 
                                                        
| 568 | 568 | }  | 
                                                        
@@ -591,26 +591,26 @@ discard block  | 
                                                    ||
| 591 | 591 | $st_args['mt_name'] = ucwords($mtp_obj->label['singular']);  | 
                                                        
| 592 | 592 | $st_args['mt_slug'] = $mt_slug;  | 
                                                        
| 593 | 593 | $st_args['messenger_slug'] = $this->name;  | 
                                                        
| 594 | - $st_args['status_code'] = $msg_type_status_map[ $mt_slug ] ?? '';  | 
                                                        |
| 594 | + $st_args['status_code'] = $msg_type_status_map[$mt_slug] ?? '';  | 
                                                        |
| 595 | 595 | $st_args['selector'] = EEH_Form_Fields::select_input(  | 
                                                        
| 596 | - 'event_message_templates_relation[' . $mtpgID . ']',  | 
                                                        |
| 596 | + 'event_message_templates_relation['.$mtpgID.']',  | 
                                                        |
| 597 | 597 | $select_values,  | 
                                                        
| 598 | 598 | $default_value,  | 
                                                        
| 599 | - 'data-messenger="' . $this->name . '" data-messagetype="' . $mt_slug . '"',  | 
                                                        |
| 599 | + 'data-messenger="'.$this->name.'" data-messagetype="'.$mt_slug.'"',  | 
                                                        |
| 600 | 600 | 'message-template-selector'  | 
                                                        
| 601 | 601 | );  | 
                                                        
| 602 | 602 | // note that message template group that has override_all_custom set will remove the ability to set a custom message template based off of the global (and that also in turn overrides any other custom templates).  | 
                                                        
| 603 | 603 |                  $st_args['create_button'] = $mtpg->get('MTP_is_override') | 
                                                        
| 604 | 604 | ? ''  | 
                                                        
| 605 | 605 | : '  | 
                                                        
| 606 | - <a data-messenger="' . $this->name . '"  | 
                                                        |
| 607 | - data-messagetype="' . $mt_slug . '"  | 
                                                        |
| 608 | - data-grpid="' . $default_value . '"  | 
                                                        |
| 606 | + <a data-messenger="' . $this->name.'"  | 
                                                        |
| 607 | + data-messagetype="' . $mt_slug.'"  | 
                                                        |
| 608 | + data-grpid="' . $default_value.'"  | 
                                                        |
| 609 | 609 | target="_blank"  | 
                                                        
| 610 | - href="' . $create_url . '"  | 
                                                        |
| 610 | + href="' . $create_url.'"  | 
                                                        |
| 611 | 611 | class="button button--secondary button--tiny create-mtpg-button"  | 
                                                        
| 612 | 612 | >  | 
                                                        
| 613 | -                        ' . esc_html__('Create New Custom', 'event_espresso') . ' | 
                                                        |
| 613 | +                        ' . esc_html__('Create New Custom', 'event_espresso').' | 
                                                        |
| 614 | 614 | </a>';  | 
                                                        
| 615 | 615 | $st_args['create_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        
| 616 | 616 | 'ee_edit_messages',  | 
                                                        
@@ -618,19 +618,19 @@ discard block  | 
                                                    ||
| 618 | 618 | )  | 
                                                        
| 619 | 619 | ? $st_args['create_button']  | 
                                                        
| 620 | 620 | : '';  | 
                                                        
| 621 | - $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 621 | + $st_args['edit_button'] = EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 622 | 622 | 'ee_edit_message',  | 
                                                        
| 623 | 623 | 'espresso_messages_edit_message_template',  | 
                                                        
| 624 | 624 | $mtpgID  | 
                                                        
| 625 | 625 | )  | 
                                                        
| 626 | 626 | ? '  | 
                                                        
| 627 | - <a data-messagetype="' . $mt_slug . '"  | 
                                                        |
| 628 | - data-grpid="' . $default_value . '"  | 
                                                        |
| 627 | + <a data-messagetype="' . $mt_slug.'"  | 
                                                        |
| 628 | + data-grpid="' . $default_value.'"  | 
                                                        |
| 629 | 629 | target="_blank"  | 
                                                        
| 630 | - href="' . $edit_url . '"  | 
                                                        |
| 630 | + href="' . $edit_url.'"  | 
                                                        |
| 631 | 631 | class="button button--secondary button--tiny edit-mtpg-button"  | 
                                                        
| 632 | 632 | >  | 
                                                        
| 633 | -                        ' . esc_html__('Edit', 'event_espresso') . ' | 
                                                        |
| 633 | +                        ' . esc_html__('Edit', 'event_espresso').' | 
                                                        |
| 634 | 634 | </a>'  | 
                                                        
| 635 | 635 | : '';  | 
                                                        
| 636 | 636 | $selector_rows .= EEH_Template::display_template($template_row_path, $st_args, true);  | 
                                                        
@@ -663,7 +663,7 @@ discard block  | 
                                                    ||
| 663 | 663 |      { | 
                                                        
| 664 | 664 | return (array) apply_filters(  | 
                                                        
| 665 | 665 | 'FHEE__EE_messenger__get_template_fields',  | 
                                                        
| 666 | -            apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this), | 
                                                        |
| 666 | +            apply_filters('FHEE__'.get_class($this).'__get_template_fields', $this->_template_fields, $this), | 
                                                        |
| 667 | 667 | $this  | 
                                                        
| 668 | 668 | );  | 
                                                        
| 669 | 669 | }  | 
                                                        
@@ -680,7 +680,7 @@ discard block  | 
                                                    ||
| 680 | 680 | protected function _set_template_value($item, $value)  | 
                                                        
| 681 | 681 |      { | 
                                                        
| 682 | 682 |          if (array_key_exists($item, $this->_template_fields)) { | 
                                                        
| 683 | - $prop = '_' . $item;  | 
                                                        |
| 683 | + $prop = '_'.$item;  | 
                                                        |
| 684 | 684 |              $this->{$prop} = $value; | 
                                                        
| 685 | 685 | }  | 
                                                        
| 686 | 686 | }  | 
                                                        
@@ -741,7 +741,7 @@ discard block  | 
                                                    ||
| 741 | 741 | $message,  | 
                                                        
| 742 | 742 | $message_type  | 
                                                        
| 743 | 743 | );  | 
                                                        
| 744 | -            if (! empty($settings)) { | 
                                                        |
| 744 | +            if ( ! empty($settings)) { | 
                                                        |
| 745 | 745 |                  foreach ($settings as $field => $value) { | 
                                                        
| 746 | 746 | $this->_set_template_value($field, $value);  | 
                                                        
| 747 | 747 | }  | 
                                                        
@@ -749,12 +749,12 @@ discard block  | 
                                                    ||
| 749 | 749 | }  | 
                                                        
| 750 | 750 | |
| 751 | 751 | // enqueue preview js so that any links/buttons on the page are disabled.  | 
                                                        
| 752 | -        if (! $send) { | 
                                                        |
| 752 | +        if ( ! $send) { | 
                                                        |
| 753 | 753 | // the below may seem like duplication. However, typically if a messenger enqueues scripts/styles,  | 
                                                        
| 754 | 754 | // it deregisters all existing wp scripts and styles first. So the second hook ensures our previewer still gets setup.  | 
                                                        
| 755 | -            add_action('admin_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 756 | -            add_action('wp_enqueue_scripts', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 757 | -            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array( $this, 'add_preview_script' ), 10); | 
                                                        |
| 755 | +            add_action('admin_enqueue_scripts', array($this, 'add_preview_script'), 10); | 
                                                        |
| 756 | +            add_action('wp_enqueue_scripts', array($this, 'add_preview_script'), 10); | 
                                                        |
| 757 | +            add_action('AHEE__EE_messenger__enqueue_scripts_styles', array($this, 'add_preview_script'), 10); | 
                                                        |
| 758 | 758 | }  | 
                                                        
| 759 | 759 | |
| 760 | 760 | return $send ? $this->_send_message() : $this->_preview();  | 
                                                        
@@ -776,7 +776,7 @@ discard block  | 
                                                    ||
| 776 | 776 | EE_Registry::$i18n_js_strings['links_disabled'] = wp_strip_all_tags(  | 
                                                        
| 777 | 777 |              __('All the links on this page have been disabled because this is a generated preview message for the purpose of ensuring layout, style, and content setup.  To test generated links, you must trigger an actual message notification.', 'event_espresso') | 
                                                        
| 778 | 778 | );  | 
                                                        
| 779 | -        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL . 'messages/messenger/assets/js/ee-messages-preview.js', array( 'jquery' ), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 779 | +        wp_register_script('ee-messages-preview-js', EE_LIBRARIES_URL.'messages/messenger/assets/js/ee-messages-preview.js', array('jquery'), EVENT_ESPRESSO_VERSION, true); | 
                                                        |
| 780 | 780 |          wp_localize_script('ee-messages-preview-js', 'eei18n', EE_Registry::$i18n_js_strings); | 
                                                        
| 781 | 781 |          wp_enqueue_script('ee-messages-preview-js'); | 
                                                        
| 782 | 782 | }  | 
                                                        
@@ -795,7 +795,7 @@ discard block  | 
                                                    ||
| 795 | 795 | $variation = $message->get_template_pack_variation();  | 
                                                        
| 796 | 796 | |
| 797 | 797 | // verify we have the required template pack value on the $message object.  | 
                                                        
| 798 | -        if (! $template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 798 | +        if ( ! $template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 799 | 799 |              throw new EE_Error(esc_html__('Incoming $message object must have an EE_Messages_Template_Pack object available.', 'event_espresso')); | 
                                                        
| 800 | 800 | }  | 
                                                        
| 801 | 801 | |
@@ -807,7 +807,7 @@ discard block  | 
                                                    ||
| 807 | 807 | |
| 808 | 808 |          foreach ($template_fields as $template => $value) { | 
                                                        
| 809 | 809 |              if ($template !== 'extra') { | 
                                                        
| 810 | -                $column_value = $message->get_field_or_extra_meta('MSG_' . $template); | 
                                                        |
| 810 | +                $column_value = $message->get_field_or_extra_meta('MSG_'.$template); | 
                                                        |
| 811 | 811 | $message_template_value = $column_value ? $column_value : null;  | 
                                                        
| 812 | 812 | $this->_set_template_value($template, $message_template_value);  | 
                                                        
| 813 | 813 | }  | 
                                                        
@@ -831,7 +831,7 @@ discard block  | 
                                                    ||
| 831 | 831 | $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, $type);  | 
                                                        
| 832 | 832 | |
| 833 | 833 | // check file exists and is readable  | 
                                                        
| 834 | -        if (!is_readable($wrapper_template)) { | 
                                                        |
| 834 | +        if ( ! is_readable($wrapper_template)) { | 
                                                        |
| 835 | 835 |              throw new EE_Error(sprintf(esc_html__('Unable to access the template file for the %s messenger main content wrapper.  The location being attempted is %s.', 'event_espresso'), ucwords($this->label['singular']), $wrapper_template)); | 
                                                        
| 836 | 836 | }  | 
                                                        
| 837 | 837 | |
@@ -879,7 +879,7 @@ discard block  | 
                                                    ||
| 879 | 879 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        
| 880 | 880 |          $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        
| 881 | 881 | $settings = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        
| 882 | - return isset($settings[ $this->name ]['test_settings']) ? $settings[ $this->name ]['test_settings'] : array();  | 
                                                        |
| 882 | + return isset($settings[$this->name]['test_settings']) ? $settings[$this->name]['test_settings'] : array();  | 
                                                        |
| 883 | 883 | }  | 
                                                        
| 884 | 884 | |
| 885 | 885 | |
@@ -896,7 +896,7 @@ discard block  | 
                                                    ||
| 896 | 896 | /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        
| 897 | 897 |          $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        
| 898 | 898 | $existing = $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        
| 899 | - $existing[ $this->name ]['test_settings'] = $settings;  | 
                                                        |
| 899 | + $existing[$this->name]['test_settings'] = $settings;  | 
                                                        |
| 900 | 900 | return $Message_Resource_Manager->update_active_messengers_option($existing);  | 
                                                        
| 901 | 901 | }  | 
                                                        
| 902 | 902 | |
@@ -913,23 +913,23 @@ discard block  | 
                                                    ||
| 913 | 913 | public function get_field_label($field)  | 
                                                        
| 914 | 914 |      { | 
                                                        
| 915 | 915 | // first let's see if the field requests is in the top level array.  | 
                                                        
| 916 | -        if (isset($this->_template_fields[ $field ]) && !empty($this->_template_fields[ $field ]['label'])) { | 
                                                        |
| 917 | - return $this->_template[ $field ]['label'];  | 
                                                        |
| 916 | +        if (isset($this->_template_fields[$field]) && ! empty($this->_template_fields[$field]['label'])) { | 
                                                        |
| 917 | + return $this->_template[$field]['label'];  | 
                                                        |
| 918 | 918 | }  | 
                                                        
| 919 | 919 | |
| 920 | 920 | // nope so let's look in the extra array to see if it's there HOWEVER if the field exists as a top level index in the extra array then we know the label is in the 'main' index.  | 
                                                        
| 921 | -        if (isset($this->_template_fields['extra']) && !empty($this->_template_fields['extra'][ $field ]) && !empty($this->_template_fields['extra'][ $field ]['main']['label'])) { | 
                                                        |
| 922 | - return $this->_template_fields['extra'][ $field ]['main']['label'];  | 
                                                        |
| 921 | +        if (isset($this->_template_fields['extra']) && ! empty($this->_template_fields['extra'][$field]) && ! empty($this->_template_fields['extra'][$field]['main']['label'])) { | 
                                                        |
| 922 | + return $this->_template_fields['extra'][$field]['main']['label'];  | 
                                                        |
| 923 | 923 | }  | 
                                                        
| 924 | 924 | |
| 925 | 925 | // now it's possible this field may just be existing in any of the extra array items.  | 
                                                        
| 926 | -        if (!empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { | 
                                                        |
| 926 | +        if ( ! empty($this->_template_fields['extra']) && is_array($this->_template_fields['extra'])) { | 
                                                        |
| 927 | 927 |              foreach ($this->_template_fields['extra'] as $main_field => $subfields) { | 
                                                        
| 928 | -                if (!is_array($subfields)) { | 
                                                        |
| 928 | +                if ( ! is_array($subfields)) { | 
                                                        |
| 929 | 929 | continue;  | 
                                                        
| 930 | 930 | }  | 
                                                        
| 931 | -                if (isset($subfields[ $field ]) && !empty($subfields[ $field ]['label'])) { | 
                                                        |
| 932 | - return $subfields[ $field ]['label'];  | 
                                                        |
| 931 | +                if (isset($subfields[$field]) && ! empty($subfields[$field]['label'])) { | 
                                                        |
| 932 | + return $subfields[$field]['label'];  | 
                                                        |
| 933 | 933 | }  | 
                                                        
| 934 | 934 | }  | 
                                                        
| 935 | 935 | }  | 
                                                        
@@ -13,1266 +13,1266 @@  | 
                                                    ||
| 13 | 13 | */  | 
                                                        
| 14 | 14 | class EEH_MSG_Template  | 
                                                        
| 15 | 15 |  { | 
                                                        
| 16 | - /**  | 
                                                        |
| 17 | - * Holds a collection of EE_Message_Template_Pack objects.  | 
                                                        |
| 18 | - * @type EE_Messages_Template_Pack_Collection  | 
                                                        |
| 19 | - */  | 
                                                        |
| 20 | - protected static $_template_pack_collection;  | 
                                                        |
| 21 | -  | 
                                                        |
| 22 | -  | 
                                                        |
| 23 | - /**  | 
                                                        |
| 24 | - * @throws EE_Error  | 
                                                        |
| 25 | - */  | 
                                                        |
| 26 | - private static function _set_autoloader()  | 
                                                        |
| 27 | -    { | 
                                                        |
| 28 | - EED_Messages::set_autoloaders();  | 
                                                        |
| 29 | - }  | 
                                                        |
| 30 | -  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | - /**  | 
                                                        |
| 33 | - * generate_new_templates  | 
                                                        |
| 34 | - * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 35 | - * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 36 | - * for the event.  | 
                                                        |
| 37 | - *  | 
                                                        |
| 38 | - * @access protected  | 
                                                        |
| 39 | - * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 40 | - * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 41 | - * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID  | 
                                                        |
| 42 | - * to use as the base for the new generated template.  | 
                                                        |
| 43 | - * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID  | 
                                                        |
| 44 | - * for event specific template generation.  | 
                                                        |
| 45 | - * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array  | 
                                                        |
| 46 | - * for templates that are generated. If this is an empty array then it means no templates were  | 
                                                        |
| 47 | - * generated which usually means there was an error. Anything in the array with an empty value for  | 
                                                        |
| 48 | - * `MTP_context` means that it was not a new generated template but just reactivated (which only  | 
                                                        |
| 49 | - * happens for global templates that already exist in the database.  | 
                                                        |
| 50 | - * @throws EE_Error  | 
                                                        |
| 51 | - * @throws ReflectionException  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 54 | -    { | 
                                                        |
| 55 | - // make sure message_type is an array.  | 
                                                        |
| 56 | - $message_types = (array) $message_types;  | 
                                                        |
| 57 | - $templates = array();  | 
                                                        |
| 58 | -  | 
                                                        |
| 59 | -        if (empty($messenger)) { | 
                                                        |
| 60 | -            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.  | 
                                                        |
| 64 | -        if (empty($message_types)) { | 
                                                        |
| 65 | -            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); | 
                                                        |
| 66 | - }  | 
                                                        |
| 67 | -  | 
                                                        |
| 68 | - EEH_MSG_Template::_set_autoloader();  | 
                                                        |
| 69 | -        foreach ($message_types as $message_type) { | 
                                                        |
| 70 | - // if this is global template generation.  | 
                                                        |
| 71 | -            if ($global) { | 
                                                        |
| 72 | - // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.  | 
                                                        |
| 73 | -                if (empty($GRP_ID)) { | 
                                                        |
| 74 | - $GRP_ID = EEM_Message_Template_Group::instance()->get_one(  | 
                                                        |
| 75 | - array(  | 
                                                        |
| 76 | - array(  | 
                                                        |
| 77 | - 'MTP_messenger' => $messenger,  | 
                                                        |
| 78 | - 'MTP_message_type' => $message_type,  | 
                                                        |
| 79 | - 'MTP_is_global' => true,  | 
                                                        |
| 80 | - ),  | 
                                                        |
| 81 | - )  | 
                                                        |
| 82 | - );  | 
                                                        |
| 83 | - $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | - // First let's determine if we already HAVE global templates for this messenger and message_type combination.  | 
                                                        |
| 86 | - // If we do then NO generation!!  | 
                                                        |
| 87 | -                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { | 
                                                        |
| 88 | - $templates[] = array(  | 
                                                        |
| 89 | - 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 90 | - 'MTP_context' => '',  | 
                                                        |
| 91 | - );  | 
                                                        |
| 92 | - // we already have generated templates for this so let's go to the next message type.  | 
                                                        |
| 93 | - continue;  | 
                                                        |
| 94 | - }  | 
                                                        |
| 95 | - }  | 
                                                        |
| 96 | - $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);  | 
                                                        |
| 97 | -  | 
                                                        |
| 98 | -            if (! $new_message_template_group) { | 
                                                        |
| 99 | - continue;  | 
                                                        |
| 100 | - }  | 
                                                        |
| 101 | - $templates[] = $new_message_template_group;  | 
                                                        |
| 102 | - }  | 
                                                        |
| 103 | -  | 
                                                        |
| 104 | - return $templates;  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | -  | 
                                                        |
| 108 | - /**  | 
                                                        |
| 109 | - * The purpose of this method is to determine if there are already generated templates in the database for the  | 
                                                        |
| 110 | - * given variables.  | 
                                                        |
| 111 | - *  | 
                                                        |
| 112 | - * @param string $messenger messenger  | 
                                                        |
| 113 | - * @param string $message_type message type  | 
                                                        |
| 114 | - * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global  | 
                                                        |
| 115 | - * template check)  | 
                                                        |
| 116 | - * @return bool true = generated, false = hasn't been generated.  | 
                                                        |
| 117 | - * @throws EE_Error  | 
                                                        |
| 118 | - */  | 
                                                        |
| 119 | - public static function already_generated($messenger, $message_type, $GRP_ID = 0)  | 
                                                        |
| 120 | -    { | 
                                                        |
| 121 | - EEH_MSG_Template::_set_autoloader();  | 
                                                        |
| 122 | - // what method we use depends on whether we have an GRP_ID or not  | 
                                                        |
| 123 | - $count = empty($GRP_ID)  | 
                                                        |
| 124 | - ? EEM_Message_Template::instance()->count(  | 
                                                        |
| 125 | - array(  | 
                                                        |
| 126 | - array(  | 
                                                        |
| 127 | - 'Message_Template_Group.MTP_messenger' => $messenger,  | 
                                                        |
| 128 | - 'Message_Template_Group.MTP_message_type' => $message_type,  | 
                                                        |
| 129 | - 'Message_Template_Group.MTP_is_global' => true  | 
                                                        |
| 130 | - )  | 
                                                        |
| 131 | - )  | 
                                                        |
| 132 | - )  | 
                                                        |
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));  | 
                                                        |
| 134 | -  | 
                                                        |
| 135 | - return $count > 0;  | 
                                                        |
| 136 | - }  | 
                                                        |
| 137 | -  | 
                                                        |
| 138 | -  | 
                                                        |
| 139 | - /**  | 
                                                        |
| 140 | - * Updates all message templates matching the incoming messengers and message types to active status.  | 
                                                        |
| 141 | - *  | 
                                                        |
| 142 | - * @static  | 
                                                        |
| 143 | - * @param array $messenger_names Messenger slug  | 
                                                        |
| 144 | - * @param array $message_type_names Message type slug  | 
                                                        |
| 145 | - * @return int count of updated records.  | 
                                                        |
| 146 | - * @throws EE_Error  | 
                                                        |
| 147 | - */  | 
                                                        |
| 148 | - public static function update_to_active($messenger_names, $message_type_names)  | 
                                                        |
| 149 | -    { | 
                                                        |
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );  | 
                                                        |
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );  | 
                                                        |
| 152 | - return EEM_Message_Template_Group::instance()->update(  | 
                                                        |
| 153 | - array( 'MTP_is_active' => 1 ),  | 
                                                        |
| 154 | - array(  | 
                                                        |
| 155 | - array(  | 
                                                        |
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ),  | 
                                                        |
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names )  | 
                                                        |
| 158 | - )  | 
                                                        |
| 159 | - )  | 
                                                        |
| 160 | - );  | 
                                                        |
| 161 | - }  | 
                                                        |
| 162 | -  | 
                                                        |
| 163 | -  | 
                                                        |
| 164 | - /**  | 
                                                        |
| 165 | - * Updates all message template groups matching the incoming arguments to inactive status.  | 
                                                        |
| 166 | - *  | 
                                                        |
| 167 | - * @static  | 
                                                        |
| 168 | - * @param array $messenger_names The messenger slugs.  | 
                                                        |
| 169 | - * If empty then all templates matching the message types are marked inactive.  | 
                                                        |
| 170 | - * Otherwise only templates matching the messengers and message types.  | 
                                                        |
| 171 | - * @param array $message_type_names The message type slugs.  | 
                                                        |
| 172 | - * If empty then all templates matching the messengers are marked inactive.  | 
                                                        |
| 173 | - * Otherwise only templates matching the messengers and message types.  | 
                                                        |
| 174 | - *  | 
                                                        |
| 175 | - * @return int count of updated records.  | 
                                                        |
| 176 | - * @throws EE_Error  | 
                                                        |
| 177 | - */  | 
                                                        |
| 178 | - public static function update_to_inactive($messenger_names = array(), $message_type_names = array())  | 
                                                        |
| 179 | -    { | 
                                                        |
| 180 | - return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(  | 
                                                        |
| 181 | - $messenger_names,  | 
                                                        |
| 182 | - $message_type_names  | 
                                                        |
| 183 | - );  | 
                                                        |
| 184 | - }  | 
                                                        |
| 185 | -  | 
                                                        |
| 186 | -  | 
                                                        |
| 187 | - /**  | 
                                                        |
| 188 | - * The purpose of this function is to return all installed message objects  | 
                                                        |
| 189 | - * (messengers and message type regardless of whether they are ACTIVE or not)  | 
                                                        |
| 190 | - *  | 
                                                        |
| 191 | - * @param string $type  | 
                                                        |
| 192 | - * @return array array consisting of installed messenger objects and installed message type objects.  | 
                                                        |
| 193 | - * @throws EE_Error  | 
                                                        |
| 194 | - * @throws ReflectionException  | 
                                                        |
| 195 | - * @deprecated 4.9.0  | 
                                                        |
| 196 | - * @static  | 
                                                        |
| 197 | - */  | 
                                                        |
| 198 | - public static function get_installed_message_objects($type = 'all')  | 
                                                        |
| 199 | -    { | 
                                                        |
| 200 | - self::_set_autoloader();  | 
                                                        |
| 201 | -        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 202 | - return array(  | 
                                                        |
| 203 | - 'messenger' => $message_resource_manager->installed_messengers(),  | 
                                                        |
| 204 | - 'message_type' => $message_resource_manager->installed_message_types()  | 
                                                        |
| 205 | - );  | 
                                                        |
| 206 | - }  | 
                                                        |
| 207 | -  | 
                                                        |
| 208 | -  | 
                                                        |
| 209 | - /**  | 
                                                        |
| 210 | - * This will return an array of shortcodes => labels from the  | 
                                                        |
| 211 | - * messenger and message_type objects associated with this  | 
                                                        |
| 212 | - * template.  | 
                                                        |
| 213 | - *  | 
                                                        |
| 214 | - * @param string $message_type  | 
                                                        |
| 215 | - * @param string $messenger  | 
                                                        |
| 216 | - * @param array $fields What fields we're returning valid shortcodes for.  | 
                                                        |
| 217 | - * If empty then we assume all fields are to be returned. Optional.  | 
                                                        |
| 218 | - * @param string $context What context we're going to return shortcodes for. Optional.  | 
                                                        |
| 219 | - * @param bool $merged If TRUE then we don't return shortcodes indexed by field,  | 
                                                        |
| 220 | - * but instead an array of the unique shortcodes for all the given (  | 
                                                        |
| 221 | - * or all) fields. Optional.  | 
                                                        |
| 222 | - * @return array an array of shortcodes in the format  | 
                                                        |
| 223 | - * array( '[shortcode] => 'label')  | 
                                                        |
| 224 | - * OR  | 
                                                        |
| 225 | - * FALSE if no shortcodes found.  | 
                                                        |
| 226 | - * @throws ReflectionException  | 
                                                        |
| 227 | - * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 228 | - *  | 
                                                        |
| 229 | - */  | 
                                                        |
| 230 | - public static function get_shortcodes(  | 
                                                        |
| 231 | - $message_type,  | 
                                                        |
| 232 | - $messenger,  | 
                                                        |
| 233 | - $fields = array(),  | 
                                                        |
| 234 | - $context = 'admin',  | 
                                                        |
| 235 | - $merged = false  | 
                                                        |
| 236 | -    ) { | 
                                                        |
| 237 | -        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); | 
                                                        |
| 238 | -        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); | 
                                                        |
| 239 | - /** @var EE_Message_Resource_Manager $message_resource_manager */  | 
                                                        |
| 240 | -        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 241 | - // convert slug to object  | 
                                                        |
| 242 | - $messenger = $message_resource_manager->get_messenger($messenger);  | 
                                                        |
| 243 | -  | 
                                                        |
| 244 | - // if messenger isn't a EE_messenger resource then bail.  | 
                                                        |
| 245 | -        if (! $messenger instanceof EE_messenger) { | 
                                                        |
| 246 | - return array();  | 
                                                        |
| 247 | - }  | 
                                                        |
| 248 | -  | 
                                                        |
| 249 | - // validate class for getting our list of shortcodes  | 
                                                        |
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';  | 
                                                        |
| 251 | -        if (! class_exists($classname)) { | 
                                                        |
| 252 | -            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); | 
                                                        |
| 253 | - $msg[] = sprintf(  | 
                                                        |
| 254 | -                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), | 
                                                        |
| 255 | - $classname  | 
                                                        |
| 256 | - );  | 
                                                        |
| 257 | -            throw new EE_Error(implode('||', $msg)); | 
                                                        |
| 258 | - }  | 
                                                        |
| 259 | -  | 
                                                        |
| 260 | - /** @type EE_Messages_Validator $_VLD */  | 
                                                        |
| 261 | - $_VLD = new $classname(array(), $context);  | 
                                                        |
| 262 | - $valid_shortcodes = $_VLD->get_validators();  | 
                                                        |
| 263 | -  | 
                                                        |
| 264 | - // let's make sure we're only getting the shortcode part of the validators  | 
                                                        |
| 265 | - $shortcodes = array();  | 
                                                        |
| 266 | -        foreach ($valid_shortcodes as $field => $validators) { | 
                                                        |
| 267 | - $shortcodes[ $field ] = $validators['shortcodes'];  | 
                                                        |
| 268 | - }  | 
                                                        |
| 269 | - $valid_shortcodes = $shortcodes;  | 
                                                        |
| 270 | -  | 
                                                        |
| 271 | - // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.  | 
                                                        |
| 272 | -        if (! empty($fields)) { | 
                                                        |
| 273 | - $specified_shortcodes = array();  | 
                                                        |
| 274 | -            foreach ($fields as $field) { | 
                                                        |
| 275 | -                if (isset($valid_shortcodes[ $field ])) { | 
                                                        |
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];  | 
                                                        |
| 277 | - }  | 
                                                        |
| 278 | - }  | 
                                                        |
| 279 | - $valid_shortcodes = $specified_shortcodes;  | 
                                                        |
| 280 | - }  | 
                                                        |
| 281 | -  | 
                                                        |
| 282 | - // if not merged then let's replace the fields with the localized fields  | 
                                                        |
| 283 | -        if (! $merged) { | 
                                                        |
| 284 | - // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.  | 
                                                        |
| 285 | - $field_settings = $messenger->get_template_fields();  | 
                                                        |
| 286 | - $localized = array();  | 
                                                        |
| 287 | -            foreach ($valid_shortcodes as $field => $shortcodes) { | 
                                                        |
| 288 | - // get localized field label  | 
                                                        |
| 289 | -                if (isset($field_settings[ $field ])) { | 
                                                        |
| 290 | - // possible that this is used as a main field.  | 
                                                        |
| 291 | -                    if (empty($field_settings[ $field ])) { | 
                                                        |
| 292 | -                        if (isset($field_settings['extra'][ $field ])) { | 
                                                        |
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label'];  | 
                                                        |
| 294 | -                        } else { | 
                                                        |
| 295 | - $_field = $field;  | 
                                                        |
| 296 | - }  | 
                                                        |
| 297 | -                    } else { | 
                                                        |
| 298 | - $_field = $field_settings[ $field ]['label'];  | 
                                                        |
| 299 | - }  | 
                                                        |
| 300 | -                } elseif (isset($field_settings['extra'])) { | 
                                                        |
| 301 | - // loop through extra "main fields" and see if any of their children have our field  | 
                                                        |
| 302 | -                    foreach ($field_settings['extra'] as $fields) { | 
                                                        |
| 303 | -                        if (isset($fields[ $field ])) { | 
                                                        |
| 304 | - $_field = $fields[ $field ]['label'];  | 
                                                        |
| 305 | -                        } else { | 
                                                        |
| 306 | - $_field = $field;  | 
                                                        |
| 307 | - }  | 
                                                        |
| 308 | - }  | 
                                                        |
| 309 | -                } else { | 
                                                        |
| 310 | - $_field = $field;  | 
                                                        |
| 311 | - }  | 
                                                        |
| 312 | -                if (isset($_field)) { | 
                                                        |
| 313 | - $localized[ (string) $_field ] = $shortcodes;  | 
                                                        |
| 314 | - }  | 
                                                        |
| 315 | - }  | 
                                                        |
| 316 | - $valid_shortcodes = $localized;  | 
                                                        |
| 317 | - }  | 
                                                        |
| 318 | -  | 
                                                        |
| 319 | - // if $merged then let's merge all the shortcodes into one list NOT indexed by field.  | 
                                                        |
| 320 | -        if ($merged) { | 
                                                        |
| 321 | - $merged_codes = array();  | 
                                                        |
| 322 | -            foreach ($valid_shortcodes as $shortcode) { | 
                                                        |
| 323 | -                foreach ($shortcode as $code => $label) { | 
                                                        |
| 324 | -                    if (isset($merged_codes[ $code ])) { | 
                                                        |
| 325 | - continue;  | 
                                                        |
| 326 | -                    } else { | 
                                                        |
| 327 | - $merged_codes[ $code ] = $label;  | 
                                                        |
| 328 | - }  | 
                                                        |
| 329 | - }  | 
                                                        |
| 330 | - }  | 
                                                        |
| 331 | - $valid_shortcodes = $merged_codes;  | 
                                                        |
| 332 | - }  | 
                                                        |
| 333 | -  | 
                                                        |
| 334 | - return $valid_shortcodes;  | 
                                                        |
| 335 | - }  | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | -  | 
                                                        |
| 338 | - /**  | 
                                                        |
| 339 | - * Get Messenger object.  | 
                                                        |
| 340 | - *  | 
                                                        |
| 341 | - * @param string $messenger messenger slug for the messenger object we want to retrieve.  | 
                                                        |
| 342 | - * @return EE_messenger  | 
                                                        |
| 343 | - * @throws ReflectionException  | 
                                                        |
| 344 | - * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 345 | - * @deprecated 4.9.0  | 
                                                        |
| 346 | - */  | 
                                                        |
| 347 | - public static function messenger_obj($messenger)  | 
                                                        |
| 348 | -    { | 
                                                        |
| 349 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 350 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 351 | - return $Message_Resource_Manager->get_messenger($messenger);  | 
                                                        |
| 352 | - }  | 
                                                        |
| 353 | -  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | - /**  | 
                                                        |
| 356 | - * get Message type object  | 
                                                        |
| 357 | - *  | 
                                                        |
| 358 | - * @param string $message_type the slug for the message type object to retrieve  | 
                                                        |
| 359 | - * @return EE_message_type  | 
                                                        |
| 360 | - * @throws ReflectionException  | 
                                                        |
| 361 | - * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 362 | - * @deprecated 4.9.0  | 
                                                        |
| 363 | - */  | 
                                                        |
| 364 | - public static function message_type_obj($message_type)  | 
                                                        |
| 365 | -    { | 
                                                        |
| 366 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 367 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 368 | - return $Message_Resource_Manager->get_message_type($message_type);  | 
                                                        |
| 369 | - }  | 
                                                        |
| 370 | -  | 
                                                        |
| 371 | -  | 
                                                        |
| 372 | - /**  | 
                                                        |
| 373 | - * Given a message_type slug, will return whether that message type is active in the system or not.  | 
                                                        |
| 374 | - *  | 
                                                        |
| 375 | - * @since 4.3.0  | 
                                                        |
| 376 | - * @param string $message_type message type to check for.  | 
                                                        |
| 377 | - * @return boolean  | 
                                                        |
| 378 | - * @throws EE_Error  | 
                                                        |
| 379 | - * @throws ReflectionException  | 
                                                        |
| 380 | - */  | 
                                                        |
| 381 | - public static function is_mt_active($message_type)  | 
                                                        |
| 382 | -    { | 
                                                        |
| 383 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 384 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 385 | - $active_mts = $Message_Resource_Manager->list_of_active_message_types();  | 
                                                        |
| 386 | - return in_array($message_type, $active_mts);  | 
                                                        |
| 387 | - }  | 
                                                        |
| 388 | -  | 
                                                        |
| 389 | -  | 
                                                        |
| 390 | - /**  | 
                                                        |
| 391 | - * Given a messenger slug, will return whether that messenger is active in the system or not.  | 
                                                        |
| 392 | - *  | 
                                                        |
| 393 | - * @since 4.3.0  | 
                                                        |
| 394 | - *  | 
                                                        |
| 395 | - * @param string $messenger slug for messenger to check.  | 
                                                        |
| 396 | - * @return boolean  | 
                                                        |
| 397 | - * @throws EE_Error  | 
                                                        |
| 398 | - * @throws ReflectionException  | 
                                                        |
| 399 | - */  | 
                                                        |
| 400 | - public static function is_messenger_active($messenger)  | 
                                                        |
| 401 | -    { | 
                                                        |
| 402 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 403 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 404 | - $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);  | 
                                                        |
| 405 | - return $active_messenger instanceof EE_messenger;  | 
                                                        |
| 406 | - }  | 
                                                        |
| 407 | -  | 
                                                        |
| 408 | -  | 
                                                        |
| 409 | - /**  | 
                                                        |
| 410 | - * Used to return active messengers array stored in the wp options table.  | 
                                                        |
| 411 | - * If no value is present in the option then an empty array is returned.  | 
                                                        |
| 412 | - *  | 
                                                        |
| 413 | - * @deprecated 4.9  | 
                                                        |
| 414 | - * @since 4.3.1  | 
                                                        |
| 415 | - *  | 
                                                        |
| 416 | - * @return array  | 
                                                        |
| 417 | - * @throws EE_Error  | 
                                                        |
| 418 | - * @throws ReflectionException  | 
                                                        |
| 419 | - */  | 
                                                        |
| 420 | - public static function get_active_messengers_in_db()  | 
                                                        |
| 421 | -    { | 
                                                        |
| 422 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 423 | - __METHOD__,  | 
                                                        |
| 424 | -            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), | 
                                                        |
| 425 | - '4.9.0'  | 
                                                        |
| 426 | - );  | 
                                                        |
| 427 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 428 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 429 | - return $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 430 | - }  | 
                                                        |
| 431 | -  | 
                                                        |
| 432 | -  | 
                                                        |
| 433 | - /**  | 
                                                        |
| 434 | - * Used to update the active messengers array stored in the wp options table.  | 
                                                        |
| 435 | - *  | 
                                                        |
| 436 | - * @since 4.3.1  | 
                                                        |
| 437 | - * @deprecated 4.9.0  | 
                                                        |
| 438 | - *  | 
                                                        |
| 439 | - * @param array $data_to_save Incoming data to save.  | 
                                                        |
| 440 | - *  | 
                                                        |
| 441 | - * @return bool FALSE if not updated, TRUE if updated.  | 
                                                        |
| 442 | - * @throws EE_Error  | 
                                                        |
| 443 | - * @throws ReflectionException  | 
                                                        |
| 444 | - */  | 
                                                        |
| 445 | - public static function update_active_messengers_in_db($data_to_save)  | 
                                                        |
| 446 | -    { | 
                                                        |
| 447 | - EE_Error::doing_it_wrong(  | 
                                                        |
| 448 | - __METHOD__,  | 
                                                        |
| 449 | -            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), | 
                                                        |
| 450 | - '4.9.0'  | 
                                                        |
| 451 | - );  | 
                                                        |
| 452 | - /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 453 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 454 | - return $Message_Resource_Manager->update_active_messengers_option($data_to_save);  | 
                                                        |
| 455 | - }  | 
                                                        |
| 456 | -  | 
                                                        |
| 457 | -  | 
                                                        |
| 458 | - /**  | 
                                                        |
| 459 | - * This does some validation of incoming params, determines what type of url is being prepped and returns the  | 
                                                        |
| 460 | - * appropriate url trigger  | 
                                                        |
| 461 | - *  | 
                                                        |
| 462 | - * @param EE_message_type $message_type  | 
                                                        |
| 463 | - * @param EE_Message $message  | 
                                                        |
| 464 | - * @param EE_Registration | null $registration The registration object must be included if this  | 
                                                        |
| 465 | - * is going to be a registration trigger url.  | 
                                                        |
| 466 | - * @param string $sending_messenger The (optional) sending messenger for the url.  | 
                                                        |
| 467 | - *  | 
                                                        |
| 468 | - * @return string  | 
                                                        |
| 469 | - * @throws EE_Error  | 
                                                        |
| 470 | - */  | 
                                                        |
| 471 | - public static function get_url_trigger(  | 
                                                        |
| 472 | - EE_message_type $message_type,  | 
                                                        |
| 473 | - EE_Message $message,  | 
                                                        |
| 474 | - $registration = null,  | 
                                                        |
| 475 | - $sending_messenger = ''  | 
                                                        |
| 476 | -    ) { | 
                                                        |
| 477 | - // first determine if the url can be to the EE_Message object.  | 
                                                        |
| 478 | -        if (! $message_type->always_generate()) { | 
                                                        |
| 479 | - return EEH_MSG_Template::generate_browser_trigger($message);  | 
                                                        |
| 480 | - }  | 
                                                        |
| 481 | -  | 
                                                        |
| 482 | - // if $registration object is not valid then exit early because there's nothing that can be generated.  | 
                                                        |
| 483 | -        if (! $registration instanceof EE_Registration) { | 
                                                        |
| 484 | - throw new EE_Error(  | 
                                                        |
| 485 | -                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') | 
                                                        |
| 486 | - );  | 
                                                        |
| 487 | - }  | 
                                                        |
| 488 | -  | 
                                                        |
| 489 | - // validate given context  | 
                                                        |
| 490 | - $contexts = $message_type->get_contexts();  | 
                                                        |
| 491 | -        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { | 
                                                        |
| 492 | - throw new EE_Error(  | 
                                                        |
| 493 | - sprintf(  | 
                                                        |
| 494 | -                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), | 
                                                        |
| 495 | - $message->context(),  | 
                                                        |
| 496 | - get_class($message_type)  | 
                                                        |
| 497 | - )  | 
                                                        |
| 498 | - );  | 
                                                        |
| 499 | - }  | 
                                                        |
| 500 | -  | 
                                                        |
| 501 | - // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used.  | 
                                                        |
| 502 | -        if (! empty($sending_messenger)) { | 
                                                        |
| 503 | - $with_messengers = $message_type->with_messengers();  | 
                                                        |
| 504 | - if (  | 
                                                        |
| 505 | - ! isset($with_messengers[ $message->messenger() ])  | 
                                                        |
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])  | 
                                                        |
| 507 | -            ) { | 
                                                        |
| 508 | - throw new EE_Error(  | 
                                                        |
| 509 | - sprintf(  | 
                                                        |
| 510 | - esc_html__(  | 
                                                        |
| 511 | - 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',  | 
                                                        |
| 512 | - 'event_espresso'  | 
                                                        |
| 513 | - ),  | 
                                                        |
| 514 | - $sending_messenger,  | 
                                                        |
| 515 | - get_class($message_type)  | 
                                                        |
| 516 | - )  | 
                                                        |
| 517 | - );  | 
                                                        |
| 518 | - }  | 
                                                        |
| 519 | -        } else { | 
                                                        |
| 520 | - $sending_messenger = $message->messenger();  | 
                                                        |
| 521 | - }  | 
                                                        |
| 522 | - return EEH_MSG_Template::generate_url_trigger(  | 
                                                        |
| 523 | - $sending_messenger,  | 
                                                        |
| 524 | - $message->messenger(),  | 
                                                        |
| 525 | - $message->context(),  | 
                                                        |
| 526 | - $message->message_type(),  | 
                                                        |
| 527 | - $registration,  | 
                                                        |
| 528 | - $message->GRP_ID()  | 
                                                        |
| 529 | - );  | 
                                                        |
| 530 | - }  | 
                                                        |
| 531 | -  | 
                                                        |
| 532 | -  | 
                                                        |
| 533 | - /**  | 
                                                        |
| 534 | - * This returns the url for triggering a in browser view of a specific EE_Message object.  | 
                                                        |
| 535 | - * @param EE_Message $message  | 
                                                        |
| 536 | - * @return string.  | 
                                                        |
| 537 | - */  | 
                                                        |
| 538 | - public static function generate_browser_trigger(EE_Message $message)  | 
                                                        |
| 539 | -    { | 
                                                        |
| 540 | - $query_args = array(  | 
                                                        |
| 541 | - 'ee' => 'msg_browser_trigger',  | 
                                                        |
| 542 | - 'token' => $message->MSG_token()  | 
                                                        |
| 543 | - );  | 
                                                        |
| 544 | - return apply_filters(  | 
                                                        |
| 545 | - 'FHEE__EEH_MSG_Template__generate_browser_trigger',  | 
                                                        |
| 546 | - add_query_arg($query_args, site_url()),  | 
                                                        |
| 547 | - $message  | 
                                                        |
| 548 | - );  | 
                                                        |
| 549 | - }  | 
                                                        |
| 550 | -  | 
                                                        |
| 551 | -  | 
                                                        |
| 552 | -  | 
                                                        |
| 553 | -  | 
                                                        |
| 554 | -  | 
                                                        |
| 555 | -  | 
                                                        |
| 556 | - /**  | 
                                                        |
| 557 | - * This returns the url for triggering an in browser view of the error saved on the incoming message object.  | 
                                                        |
| 558 | - * @param EE_Message $message  | 
                                                        |
| 559 | - * @return string  | 
                                                        |
| 560 | - */  | 
                                                        |
| 561 | - public static function generate_error_display_trigger(EE_Message $message)  | 
                                                        |
| 562 | -    { | 
                                                        |
| 563 | - return apply_filters(  | 
                                                        |
| 564 | - 'FHEE__EEH_MSG_Template__generate_error_display_trigger',  | 
                                                        |
| 565 | - add_query_arg(  | 
                                                        |
| 566 | - array(  | 
                                                        |
| 567 | - 'ee' => 'msg_browser_error_trigger',  | 
                                                        |
| 568 | - 'token' => $message->MSG_token()  | 
                                                        |
| 569 | - ),  | 
                                                        |
| 570 | - site_url()  | 
                                                        |
| 571 | - ),  | 
                                                        |
| 572 | - $message  | 
                                                        |
| 573 | - );  | 
                                                        |
| 574 | - }  | 
                                                        |
| 575 | -  | 
                                                        |
| 576 | -  | 
                                                        |
| 577 | - /**  | 
                                                        |
| 578 | - * This generates a url trigger for the msg_url_trigger route using the given arguments  | 
                                                        |
| 579 | - *  | 
                                                        |
| 580 | - * @param string $sending_messenger The sending messenger slug.  | 
                                                        |
| 581 | - * @param string $generating_messenger The generating messenger slug.  | 
                                                        |
| 582 | - * @param string $context The context for the template.  | 
                                                        |
| 583 | - * @param string $message_type The message type slug  | 
                                                        |
| 584 | - * @param EE_Registration $registration  | 
                                                        |
| 585 | - * @param integer $message_template_group id The EE_Message_Template_Group ID for the template.  | 
                                                        |
| 586 | - * @param integer $data_id The id to the EE_Base_Class for getting the data used by the  | 
                                                        |
| 587 | - * trigger.  | 
                                                        |
| 588 | - * @return string The generated url.  | 
                                                        |
| 589 | - * @throws EE_Error  | 
                                                        |
| 590 | - */  | 
                                                        |
| 591 | - public static function generate_url_trigger(  | 
                                                        |
| 592 | - $sending_messenger,  | 
                                                        |
| 593 | - $generating_messenger,  | 
                                                        |
| 594 | - $context,  | 
                                                        |
| 595 | - $message_type,  | 
                                                        |
| 596 | - EE_Registration $registration,  | 
                                                        |
| 597 | - $message_template_group,  | 
                                                        |
| 598 | - $data_id = 0  | 
                                                        |
| 599 | -    ) { | 
                                                        |
| 600 | - $query_args = array(  | 
                                                        |
| 601 | - 'ee' => 'msg_url_trigger',  | 
                                                        |
| 602 | - 'snd_msgr' => $sending_messenger,  | 
                                                        |
| 603 | - 'gen_msgr' => $generating_messenger,  | 
                                                        |
| 604 | - 'message_type' => $message_type,  | 
                                                        |
| 605 | - 'context' => $context,  | 
                                                        |
| 606 | - 'token' => $registration->reg_url_link(),  | 
                                                        |
| 607 | - 'GRP_ID' => $message_template_group,  | 
                                                        |
| 608 | - 'id' => $data_id  | 
                                                        |
| 609 | - );  | 
                                                        |
| 610 | - $url = add_query_arg($query_args, get_home_url());  | 
                                                        |
| 611 | -  | 
                                                        |
| 612 | - // made it here so now we can just get the url and filter it. Filtered globally and by message type.  | 
                                                        |
| 613 | - return apply_filters(  | 
                                                        |
| 614 | - 'FHEE__EEH_MSG_Template__generate_url_trigger',  | 
                                                        |
| 615 | - $url,  | 
                                                        |
| 616 | - $sending_messenger,  | 
                                                        |
| 617 | - $generating_messenger,  | 
                                                        |
| 618 | - $context,  | 
                                                        |
| 619 | - $message_type,  | 
                                                        |
| 620 | - $registration,  | 
                                                        |
| 621 | - $message_template_group,  | 
                                                        |
| 622 | - $data_id  | 
                                                        |
| 623 | - );  | 
                                                        |
| 624 | - }  | 
                                                        |
| 625 | -  | 
                                                        |
| 626 | -  | 
                                                        |
| 627 | -  | 
                                                        |
| 628 | -  | 
                                                        |
| 629 | - /**  | 
                                                        |
| 630 | - * Return the specific css for the action icon given.  | 
                                                        |
| 631 | - *  | 
                                                        |
| 632 | - * @param string $type What action to return.  | 
                                                        |
| 633 | - * @return string[]  | 
                                                        |
| 634 | - * @since 4.9.0  | 
                                                        |
| 635 | - */  | 
                                                        |
| 636 | - public static function get_message_action_icon($type)  | 
                                                        |
| 637 | -    { | 
                                                        |
| 638 | - $action_icons = self::get_message_action_icons();  | 
                                                        |
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];  | 
                                                        |
| 640 | - }  | 
                                                        |
| 641 | -  | 
                                                        |
| 642 | -  | 
                                                        |
| 643 | - /**  | 
                                                        |
| 644 | - * This is used for retrieving the css classes used for the icons representing message actions.  | 
                                                        |
| 645 | - *  | 
                                                        |
| 646 | - * @since 4.9.0  | 
                                                        |
| 647 | - *  | 
                                                        |
| 648 | - * @return array  | 
                                                        |
| 649 | - */  | 
                                                        |
| 650 | - public static function get_message_action_icons()  | 
                                                        |
| 651 | -    { | 
                                                        |
| 652 | - return apply_filters(  | 
                                                        |
| 653 | - 'FHEE__EEH_MSG_Template__message_action_icons',  | 
                                                        |
| 654 | - array(  | 
                                                        |
| 655 | - 'view' => array(  | 
                                                        |
| 656 | -                    'label' => esc_html__('View Message', 'event_espresso'), | 
                                                        |
| 657 | - 'css_class' => 'dashicons dashicons-visibility',  | 
                                                        |
| 658 | - ),  | 
                                                        |
| 659 | - 'error' => array(  | 
                                                        |
| 660 | -                    'label' => esc_html__('View Error Message', 'event_espresso'), | 
                                                        |
| 661 | - 'css_class' => 'dashicons dashicons-info',  | 
                                                        |
| 662 | - ),  | 
                                                        |
| 663 | - 'see_notifications_for' => array(  | 
                                                        |
| 664 | -                    'label' => esc_html__('View Related Messages', 'event_espresso'), | 
                                                        |
| 665 | - 'css_class' => 'dashicons dashicons-megaphone',  | 
                                                        |
| 666 | - ),  | 
                                                        |
| 667 | - 'generate_now' => array(  | 
                                                        |
| 668 | -                    'label' => esc_html__('Generate the message now.', 'event_espresso'), | 
                                                        |
| 669 | - 'css_class' => 'dashicons dashicons-admin-tools',  | 
                                                        |
| 670 | - ),  | 
                                                        |
| 671 | - 'send_now' => array(  | 
                                                        |
| 672 | -                    'label' => esc_html__('Send Immediately', 'event_espresso'), | 
                                                        |
| 673 | - 'css_class' => 'dashicons dashicons-controls-forward',  | 
                                                        |
| 674 | - ),  | 
                                                        |
| 675 | - 'queue_for_resending' => array(  | 
                                                        |
| 676 | -                    'label' => esc_html__('Queue for Resending', 'event_espresso'), | 
                                                        |
| 677 | - 'css_class' => 'dashicons dashicons-controls-repeat',  | 
                                                        |
| 678 | - ),  | 
                                                        |
| 679 | - 'view_transaction' => array(  | 
                                                        |
| 680 | -                    'label' => esc_html__('View related Transaction', 'event_espresso'), | 
                                                        |
| 681 | - 'css_class' => 'dashicons dashicons-cart',  | 
                                                        |
| 682 | - )  | 
                                                        |
| 683 | - )  | 
                                                        |
| 684 | - );  | 
                                                        |
| 685 | - }  | 
                                                        |
| 686 | -  | 
                                                        |
| 687 | -  | 
                                                        |
| 688 | - /**  | 
                                                        |
| 689 | - * This returns the url for a given action related to EE_Message.  | 
                                                        |
| 690 | - *  | 
                                                        |
| 691 | - * @param string $type What type of action to return the url for.  | 
                                                        |
| 692 | - * @param EE_Message $message Required for generating the correct url for some types.  | 
                                                        |
| 693 | - * @param array $query_params Any additional query params to be included with the generated url.  | 
                                                        |
| 694 | - *  | 
                                                        |
| 695 | - * @return string  | 
                                                        |
| 696 | - * @throws EE_Error  | 
                                                        |
| 697 | - * @throws ReflectionException  | 
                                                        |
| 698 | - * @since 4.9.0  | 
                                                        |
| 699 | - *  | 
                                                        |
| 700 | - */  | 
                                                        |
| 701 | - public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())  | 
                                                        |
| 702 | -    { | 
                                                        |
| 703 | - $action_urls = self::get_message_action_urls($message, $query_params);  | 
                                                        |
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : '';  | 
                                                        |
| 705 | - }  | 
                                                        |
| 706 | -  | 
                                                        |
| 707 | -  | 
                                                        |
| 708 | - /**  | 
                                                        |
| 709 | - * This returns all the current urls for EE_Message actions.  | 
                                                        |
| 710 | - *  | 
                                                        |
| 711 | - * @since 4.9.0  | 
                                                        |
| 712 | - *  | 
                                                        |
| 713 | - * @param EE_Message $message The EE_Message object required to generate correct urls for some types.  | 
                                                        |
| 714 | - * @param array $query_params Any additional query_params to be included with the generated url.  | 
                                                        |
| 715 | - *  | 
                                                        |
| 716 | - * @return array  | 
                                                        |
| 717 | - * @throws EE_Error  | 
                                                        |
| 718 | - * @throws ReflectionException  | 
                                                        |
| 719 | - */  | 
                                                        |
| 720 | - public static function get_message_action_urls(EE_Message $message = null, $query_params = array())  | 
                                                        |
| 721 | -    { | 
                                                        |
| 722 | -        EE_Registry::instance()->load_helper('URL'); | 
                                                        |
| 723 | - // if $message is not an instance of EE_Message then let's just do a dummy.  | 
                                                        |
| 724 | - $message = empty($message) ? EE_Message_Factory::create() : $message;  | 
                                                        |
| 725 | - $action_urls = apply_filters(  | 
                                                        |
| 726 | - 'FHEE__EEH_MSG_Template__get_message_action_url',  | 
                                                        |
| 727 | - array(  | 
                                                        |
| 728 | - 'view' => EEH_MSG_Template::generate_browser_trigger($message),  | 
                                                        |
| 729 | - 'error' => EEH_MSG_Template::generate_error_display_trigger($message),  | 
                                                        |
| 730 | - 'see_notifications_for' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 731 | - array_merge(  | 
                                                        |
| 732 | - array(  | 
                                                        |
| 733 | - 'page' => 'espresso_messages',  | 
                                                        |
| 734 | - 'action' => 'default',  | 
                                                        |
| 735 | - 'filterby' => 1,  | 
                                                        |
| 736 | - ),  | 
                                                        |
| 737 | - $query_params  | 
                                                        |
| 738 | - ),  | 
                                                        |
| 739 | -                    admin_url('admin.php') | 
                                                        |
| 740 | - ),  | 
                                                        |
| 741 | - 'generate_now' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 742 | - array(  | 
                                                        |
| 743 | - 'page' => 'espresso_messages',  | 
                                                        |
| 744 | - 'action' => 'generate_now',  | 
                                                        |
| 745 | - 'MSG_ID' => $message->ID()  | 
                                                        |
| 746 | - ),  | 
                                                        |
| 747 | -                    admin_url('admin.php') | 
                                                        |
| 748 | - ),  | 
                                                        |
| 749 | - 'send_now' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 750 | - array(  | 
                                                        |
| 751 | - 'page' => 'espresso_messages',  | 
                                                        |
| 752 | - 'action' => 'send_now',  | 
                                                        |
| 753 | - 'MSG_ID' => $message->ID()  | 
                                                        |
| 754 | - ),  | 
                                                        |
| 755 | -                    admin_url('admin.php') | 
                                                        |
| 756 | - ),  | 
                                                        |
| 757 | - 'queue_for_resending' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 758 | - array(  | 
                                                        |
| 759 | - 'page' => 'espresso_messages',  | 
                                                        |
| 760 | - 'action' => 'queue_for_resending',  | 
                                                        |
| 761 | - 'MSG_ID' => $message->ID()  | 
                                                        |
| 762 | - ),  | 
                                                        |
| 763 | -                    admin_url('admin.php') | 
                                                        |
| 764 | - ),  | 
                                                        |
| 765 | - )  | 
                                                        |
| 766 | - );  | 
                                                        |
| 767 | - if (  | 
                                                        |
| 768 | - $message->TXN_ID() > 0  | 
                                                        |
| 769 | - && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 770 | - 'ee_read_transaction',  | 
                                                        |
| 771 | - 'espresso_transactions_default',  | 
                                                        |
| 772 | - $message->TXN_ID()  | 
                                                        |
| 773 | - )  | 
                                                        |
| 774 | -        ) { | 
                                                        |
| 775 | - $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 776 | - array(  | 
                                                        |
| 777 | - 'page' => 'espresso_transactions',  | 
                                                        |
| 778 | - 'action' => 'view_transaction',  | 
                                                        |
| 779 | - 'TXN_ID' => $message->TXN_ID()  | 
                                                        |
| 780 | - ),  | 
                                                        |
| 781 | -                admin_url('admin.php') | 
                                                        |
| 782 | - );  | 
                                                        |
| 783 | -        } else { | 
                                                        |
| 784 | - $action_urls['view_transaction'] = '';  | 
                                                        |
| 785 | - }  | 
                                                        |
| 786 | - return $action_urls;  | 
                                                        |
| 787 | - }  | 
                                                        |
| 788 | -  | 
                                                        |
| 789 | -  | 
                                                        |
| 790 | - /**  | 
                                                        |
| 791 | - * This returns a generated link html including the icon used for the action link for EE_Message actions.  | 
                                                        |
| 792 | - *  | 
                                                        |
| 793 | - * @param string $type What type of action the link is for (if invalid type is passed in then an  | 
                                                        |
| 794 | - * empty string is returned)  | 
                                                        |
| 795 | - * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly)  | 
                                                        |
| 796 | - * @param array $query_params Any extra query params to include in the generated link.  | 
                                                        |
| 797 | - *  | 
                                                        |
| 798 | - * @return string  | 
                                                        |
| 799 | - * @throws EE_Error  | 
                                                        |
| 800 | - * @throws ReflectionException  | 
                                                        |
| 801 | - * @since 4.9.0  | 
                                                        |
| 802 | - *  | 
                                                        |
| 803 | - */  | 
                                                        |
| 804 | - public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())  | 
                                                        |
| 805 | -    { | 
                                                        |
| 806 | - $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);  | 
                                                        |
| 807 | - $icon_css = EEH_MSG_Template::get_message_action_icon($type);  | 
                                                        |
| 808 | - $label = $icon_css['label'] ?? null;  | 
                                                        |
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : '';  | 
                                                        |
| 810 | - $class = $label ? ' ee-aria-tooltip' : '';  | 
                                                        |
| 811 | -  | 
                                                        |
| 812 | -        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { | 
                                                        |
| 813 | - return '';  | 
                                                        |
| 814 | - }  | 
                                                        |
| 815 | -  | 
                                                        |
| 816 | - $icon_css['css_class'] .= esc_attr(  | 
                                                        |
| 817 | - apply_filters(  | 
                                                        |
| 818 | - 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',  | 
                                                        |
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type,  | 
                                                        |
| 820 | - $type,  | 
                                                        |
| 821 | - $message,  | 
                                                        |
| 822 | - $query_params  | 
                                                        |
| 823 | - )  | 
                                                        |
| 824 | - );  | 
                                                        |
| 825 | -  | 
                                                        |
| 826 | - return '  | 
                                                        |
| 16 | + /**  | 
                                                        |
| 17 | + * Holds a collection of EE_Message_Template_Pack objects.  | 
                                                        |
| 18 | + * @type EE_Messages_Template_Pack_Collection  | 
                                                        |
| 19 | + */  | 
                                                        |
| 20 | + protected static $_template_pack_collection;  | 
                                                        |
| 21 | +  | 
                                                        |
| 22 | +  | 
                                                        |
| 23 | + /**  | 
                                                        |
| 24 | + * @throws EE_Error  | 
                                                        |
| 25 | + */  | 
                                                        |
| 26 | + private static function _set_autoloader()  | 
                                                        |
| 27 | +	{ | 
                                                        |
| 28 | + EED_Messages::set_autoloaders();  | 
                                                        |
| 29 | + }  | 
                                                        |
| 30 | +  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | + /**  | 
                                                        |
| 33 | + * generate_new_templates  | 
                                                        |
| 34 | + * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will  | 
                                                        |
| 35 | + * automatically create the defaults for the event. The user would then be redirected to edit the default context  | 
                                                        |
| 36 | + * for the event.  | 
                                                        |
| 37 | + *  | 
                                                        |
| 38 | + * @access protected  | 
                                                        |
| 39 | + * @param string $messenger the messenger we are generating templates for  | 
                                                        |
| 40 | + * @param array $message_types array of message types that the templates are generated for.  | 
                                                        |
| 41 | + * @param int $GRP_ID If a non global template is being generated then it is expected we'll have a GRP_ID  | 
                                                        |
| 42 | + * to use as the base for the new generated template.  | 
                                                        |
| 43 | + * @param bool $global true indicates generating templates on messenger activation. false requires GRP_ID  | 
                                                        |
| 44 | + * for event specific template generation.  | 
                                                        |
| 45 | + * @return array @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array  | 
                                                        |
| 46 | + * for templates that are generated. If this is an empty array then it means no templates were  | 
                                                        |
| 47 | + * generated which usually means there was an error. Anything in the array with an empty value for  | 
                                                        |
| 48 | + * `MTP_context` means that it was not a new generated template but just reactivated (which only  | 
                                                        |
| 49 | + * happens for global templates that already exist in the database.  | 
                                                        |
| 50 | + * @throws EE_Error  | 
                                                        |
| 51 | + * @throws ReflectionException  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)  | 
                                                        |
| 54 | +	{ | 
                                                        |
| 55 | + // make sure message_type is an array.  | 
                                                        |
| 56 | + $message_types = (array) $message_types;  | 
                                                        |
| 57 | + $templates = array();  | 
                                                        |
| 58 | +  | 
                                                        |
| 59 | +		if (empty($messenger)) { | 
                                                        |
| 60 | +			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso')); | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.  | 
                                                        |
| 64 | +		if (empty($message_types)) { | 
                                                        |
| 65 | +			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso')); | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | +  | 
                                                        |
| 68 | + EEH_MSG_Template::_set_autoloader();  | 
                                                        |
| 69 | +		foreach ($message_types as $message_type) { | 
                                                        |
| 70 | + // if this is global template generation.  | 
                                                        |
| 71 | +			if ($global) { | 
                                                        |
| 72 | + // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.  | 
                                                        |
| 73 | +				if (empty($GRP_ID)) { | 
                                                        |
| 74 | + $GRP_ID = EEM_Message_Template_Group::instance()->get_one(  | 
                                                        |
| 75 | + array(  | 
                                                        |
| 76 | + array(  | 
                                                        |
| 77 | + 'MTP_messenger' => $messenger,  | 
                                                        |
| 78 | + 'MTP_message_type' => $message_type,  | 
                                                        |
| 79 | + 'MTP_is_global' => true,  | 
                                                        |
| 80 | + ),  | 
                                                        |
| 81 | + )  | 
                                                        |
| 82 | + );  | 
                                                        |
| 83 | + $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | + // First let's determine if we already HAVE global templates for this messenger and message_type combination.  | 
                                                        |
| 86 | + // If we do then NO generation!!  | 
                                                        |
| 87 | +				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) { | 
                                                        |
| 88 | + $templates[] = array(  | 
                                                        |
| 89 | + 'GRP_ID' => $GRP_ID,  | 
                                                        |
| 90 | + 'MTP_context' => '',  | 
                                                        |
| 91 | + );  | 
                                                        |
| 92 | + // we already have generated templates for this so let's go to the next message type.  | 
                                                        |
| 93 | + continue;  | 
                                                        |
| 94 | + }  | 
                                                        |
| 95 | + }  | 
                                                        |
| 96 | + $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);  | 
                                                        |
| 97 | +  | 
                                                        |
| 98 | +			if (! $new_message_template_group) { | 
                                                        |
| 99 | + continue;  | 
                                                        |
| 100 | + }  | 
                                                        |
| 101 | + $templates[] = $new_message_template_group;  | 
                                                        |
| 102 | + }  | 
                                                        |
| 103 | +  | 
                                                        |
| 104 | + return $templates;  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | +  | 
                                                        |
| 108 | + /**  | 
                                                        |
| 109 | + * The purpose of this method is to determine if there are already generated templates in the database for the  | 
                                                        |
| 110 | + * given variables.  | 
                                                        |
| 111 | + *  | 
                                                        |
| 112 | + * @param string $messenger messenger  | 
                                                        |
| 113 | + * @param string $message_type message type  | 
                                                        |
| 114 | + * @param int $GRP_ID GRP ID ( if a custom template) (if not provided then we're just doing global  | 
                                                        |
| 115 | + * template check)  | 
                                                        |
| 116 | + * @return bool true = generated, false = hasn't been generated.  | 
                                                        |
| 117 | + * @throws EE_Error  | 
                                                        |
| 118 | + */  | 
                                                        |
| 119 | + public static function already_generated($messenger, $message_type, $GRP_ID = 0)  | 
                                                        |
| 120 | +	{ | 
                                                        |
| 121 | + EEH_MSG_Template::_set_autoloader();  | 
                                                        |
| 122 | + // what method we use depends on whether we have an GRP_ID or not  | 
                                                        |
| 123 | + $count = empty($GRP_ID)  | 
                                                        |
| 124 | + ? EEM_Message_Template::instance()->count(  | 
                                                        |
| 125 | + array(  | 
                                                        |
| 126 | + array(  | 
                                                        |
| 127 | + 'Message_Template_Group.MTP_messenger' => $messenger,  | 
                                                        |
| 128 | + 'Message_Template_Group.MTP_message_type' => $message_type,  | 
                                                        |
| 129 | + 'Message_Template_Group.MTP_is_global' => true  | 
                                                        |
| 130 | + )  | 
                                                        |
| 131 | + )  | 
                                                        |
| 132 | + )  | 
                                                        |
| 133 | + : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));  | 
                                                        |
| 134 | +  | 
                                                        |
| 135 | + return $count > 0;  | 
                                                        |
| 136 | + }  | 
                                                        |
| 137 | +  | 
                                                        |
| 138 | +  | 
                                                        |
| 139 | + /**  | 
                                                        |
| 140 | + * Updates all message templates matching the incoming messengers and message types to active status.  | 
                                                        |
| 141 | + *  | 
                                                        |
| 142 | + * @static  | 
                                                        |
| 143 | + * @param array $messenger_names Messenger slug  | 
                                                        |
| 144 | + * @param array $message_type_names Message type slug  | 
                                                        |
| 145 | + * @return int count of updated records.  | 
                                                        |
| 146 | + * @throws EE_Error  | 
                                                        |
| 147 | + */  | 
                                                        |
| 148 | + public static function update_to_active($messenger_names, $message_type_names)  | 
                                                        |
| 149 | +	{ | 
                                                        |
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );  | 
                                                        |
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );  | 
                                                        |
| 152 | + return EEM_Message_Template_Group::instance()->update(  | 
                                                        |
| 153 | + array( 'MTP_is_active' => 1 ),  | 
                                                        |
| 154 | + array(  | 
                                                        |
| 155 | + array(  | 
                                                        |
| 156 | + 'MTP_messenger' => array( 'IN', $messenger_names ),  | 
                                                        |
| 157 | + 'MTP_message_type' => array( 'IN', $message_type_names )  | 
                                                        |
| 158 | + )  | 
                                                        |
| 159 | + )  | 
                                                        |
| 160 | + );  | 
                                                        |
| 161 | + }  | 
                                                        |
| 162 | +  | 
                                                        |
| 163 | +  | 
                                                        |
| 164 | + /**  | 
                                                        |
| 165 | + * Updates all message template groups matching the incoming arguments to inactive status.  | 
                                                        |
| 166 | + *  | 
                                                        |
| 167 | + * @static  | 
                                                        |
| 168 | + * @param array $messenger_names The messenger slugs.  | 
                                                        |
| 169 | + * If empty then all templates matching the message types are marked inactive.  | 
                                                        |
| 170 | + * Otherwise only templates matching the messengers and message types.  | 
                                                        |
| 171 | + * @param array $message_type_names The message type slugs.  | 
                                                        |
| 172 | + * If empty then all templates matching the messengers are marked inactive.  | 
                                                        |
| 173 | + * Otherwise only templates matching the messengers and message types.  | 
                                                        |
| 174 | + *  | 
                                                        |
| 175 | + * @return int count of updated records.  | 
                                                        |
| 176 | + * @throws EE_Error  | 
                                                        |
| 177 | + */  | 
                                                        |
| 178 | + public static function update_to_inactive($messenger_names = array(), $message_type_names = array())  | 
                                                        |
| 179 | +	{ | 
                                                        |
| 180 | + return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(  | 
                                                        |
| 181 | + $messenger_names,  | 
                                                        |
| 182 | + $message_type_names  | 
                                                        |
| 183 | + );  | 
                                                        |
| 184 | + }  | 
                                                        |
| 185 | +  | 
                                                        |
| 186 | +  | 
                                                        |
| 187 | + /**  | 
                                                        |
| 188 | + * The purpose of this function is to return all installed message objects  | 
                                                        |
| 189 | + * (messengers and message type regardless of whether they are ACTIVE or not)  | 
                                                        |
| 190 | + *  | 
                                                        |
| 191 | + * @param string $type  | 
                                                        |
| 192 | + * @return array array consisting of installed messenger objects and installed message type objects.  | 
                                                        |
| 193 | + * @throws EE_Error  | 
                                                        |
| 194 | + * @throws ReflectionException  | 
                                                        |
| 195 | + * @deprecated 4.9.0  | 
                                                        |
| 196 | + * @static  | 
                                                        |
| 197 | + */  | 
                                                        |
| 198 | + public static function get_installed_message_objects($type = 'all')  | 
                                                        |
| 199 | +	{ | 
                                                        |
| 200 | + self::_set_autoloader();  | 
                                                        |
| 201 | +		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 202 | + return array(  | 
                                                        |
| 203 | + 'messenger' => $message_resource_manager->installed_messengers(),  | 
                                                        |
| 204 | + 'message_type' => $message_resource_manager->installed_message_types()  | 
                                                        |
| 205 | + );  | 
                                                        |
| 206 | + }  | 
                                                        |
| 207 | +  | 
                                                        |
| 208 | +  | 
                                                        |
| 209 | + /**  | 
                                                        |
| 210 | + * This will return an array of shortcodes => labels from the  | 
                                                        |
| 211 | + * messenger and message_type objects associated with this  | 
                                                        |
| 212 | + * template.  | 
                                                        |
| 213 | + *  | 
                                                        |
| 214 | + * @param string $message_type  | 
                                                        |
| 215 | + * @param string $messenger  | 
                                                        |
| 216 | + * @param array $fields What fields we're returning valid shortcodes for.  | 
                                                        |
| 217 | + * If empty then we assume all fields are to be returned. Optional.  | 
                                                        |
| 218 | + * @param string $context What context we're going to return shortcodes for. Optional.  | 
                                                        |
| 219 | + * @param bool $merged If TRUE then we don't return shortcodes indexed by field,  | 
                                                        |
| 220 | + * but instead an array of the unique shortcodes for all the given (  | 
                                                        |
| 221 | + * or all) fields. Optional.  | 
                                                        |
| 222 | + * @return array an array of shortcodes in the format  | 
                                                        |
| 223 | + * array( '[shortcode] => 'label')  | 
                                                        |
| 224 | + * OR  | 
                                                        |
| 225 | + * FALSE if no shortcodes found.  | 
                                                        |
| 226 | + * @throws ReflectionException  | 
                                                        |
| 227 | + * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 228 | + *  | 
                                                        |
| 229 | + */  | 
                                                        |
| 230 | + public static function get_shortcodes(  | 
                                                        |
| 231 | + $message_type,  | 
                                                        |
| 232 | + $messenger,  | 
                                                        |
| 233 | + $fields = array(),  | 
                                                        |
| 234 | + $context = 'admin',  | 
                                                        |
| 235 | + $merged = false  | 
                                                        |
| 236 | +	) { | 
                                                        |
| 237 | +		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger))); | 
                                                        |
| 238 | +		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type))); | 
                                                        |
| 239 | + /** @var EE_Message_Resource_Manager $message_resource_manager */  | 
                                                        |
| 240 | +		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 241 | + // convert slug to object  | 
                                                        |
| 242 | + $messenger = $message_resource_manager->get_messenger($messenger);  | 
                                                        |
| 243 | +  | 
                                                        |
| 244 | + // if messenger isn't a EE_messenger resource then bail.  | 
                                                        |
| 245 | +		if (! $messenger instanceof EE_messenger) { | 
                                                        |
| 246 | + return array();  | 
                                                        |
| 247 | + }  | 
                                                        |
| 248 | +  | 
                                                        |
| 249 | + // validate class for getting our list of shortcodes  | 
                                                        |
| 250 | + $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';  | 
                                                        |
| 251 | +		if (! class_exists($classname)) { | 
                                                        |
| 252 | +			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); | 
                                                        |
| 253 | + $msg[] = sprintf(  | 
                                                        |
| 254 | +				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), | 
                                                        |
| 255 | + $classname  | 
                                                        |
| 256 | + );  | 
                                                        |
| 257 | +			throw new EE_Error(implode('||', $msg)); | 
                                                        |
| 258 | + }  | 
                                                        |
| 259 | +  | 
                                                        |
| 260 | + /** @type EE_Messages_Validator $_VLD */  | 
                                                        |
| 261 | + $_VLD = new $classname(array(), $context);  | 
                                                        |
| 262 | + $valid_shortcodes = $_VLD->get_validators();  | 
                                                        |
| 263 | +  | 
                                                        |
| 264 | + // let's make sure we're only getting the shortcode part of the validators  | 
                                                        |
| 265 | + $shortcodes = array();  | 
                                                        |
| 266 | +		foreach ($valid_shortcodes as $field => $validators) { | 
                                                        |
| 267 | + $shortcodes[ $field ] = $validators['shortcodes'];  | 
                                                        |
| 268 | + }  | 
                                                        |
| 269 | + $valid_shortcodes = $shortcodes;  | 
                                                        |
| 270 | +  | 
                                                        |
| 271 | + // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.  | 
                                                        |
| 272 | +		if (! empty($fields)) { | 
                                                        |
| 273 | + $specified_shortcodes = array();  | 
                                                        |
| 274 | +			foreach ($fields as $field) { | 
                                                        |
| 275 | +				if (isset($valid_shortcodes[ $field ])) { | 
                                                        |
| 276 | + $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];  | 
                                                        |
| 277 | + }  | 
                                                        |
| 278 | + }  | 
                                                        |
| 279 | + $valid_shortcodes = $specified_shortcodes;  | 
                                                        |
| 280 | + }  | 
                                                        |
| 281 | +  | 
                                                        |
| 282 | + // if not merged then let's replace the fields with the localized fields  | 
                                                        |
| 283 | +		if (! $merged) { | 
                                                        |
| 284 | + // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.  | 
                                                        |
| 285 | + $field_settings = $messenger->get_template_fields();  | 
                                                        |
| 286 | + $localized = array();  | 
                                                        |
| 287 | +			foreach ($valid_shortcodes as $field => $shortcodes) { | 
                                                        |
| 288 | + // get localized field label  | 
                                                        |
| 289 | +				if (isset($field_settings[ $field ])) { | 
                                                        |
| 290 | + // possible that this is used as a main field.  | 
                                                        |
| 291 | +					if (empty($field_settings[ $field ])) { | 
                                                        |
| 292 | +						if (isset($field_settings['extra'][ $field ])) { | 
                                                        |
| 293 | + $_field = $field_settings['extra'][ $field ]['main']['label'];  | 
                                                        |
| 294 | +						} else { | 
                                                        |
| 295 | + $_field = $field;  | 
                                                        |
| 296 | + }  | 
                                                        |
| 297 | +					} else { | 
                                                        |
| 298 | + $_field = $field_settings[ $field ]['label'];  | 
                                                        |
| 299 | + }  | 
                                                        |
| 300 | +				} elseif (isset($field_settings['extra'])) { | 
                                                        |
| 301 | + // loop through extra "main fields" and see if any of their children have our field  | 
                                                        |
| 302 | +					foreach ($field_settings['extra'] as $fields) { | 
                                                        |
| 303 | +						if (isset($fields[ $field ])) { | 
                                                        |
| 304 | + $_field = $fields[ $field ]['label'];  | 
                                                        |
| 305 | +						} else { | 
                                                        |
| 306 | + $_field = $field;  | 
                                                        |
| 307 | + }  | 
                                                        |
| 308 | + }  | 
                                                        |
| 309 | +				} else { | 
                                                        |
| 310 | + $_field = $field;  | 
                                                        |
| 311 | + }  | 
                                                        |
| 312 | +				if (isset($_field)) { | 
                                                        |
| 313 | + $localized[ (string) $_field ] = $shortcodes;  | 
                                                        |
| 314 | + }  | 
                                                        |
| 315 | + }  | 
                                                        |
| 316 | + $valid_shortcodes = $localized;  | 
                                                        |
| 317 | + }  | 
                                                        |
| 318 | +  | 
                                                        |
| 319 | + // if $merged then let's merge all the shortcodes into one list NOT indexed by field.  | 
                                                        |
| 320 | +		if ($merged) { | 
                                                        |
| 321 | + $merged_codes = array();  | 
                                                        |
| 322 | +			foreach ($valid_shortcodes as $shortcode) { | 
                                                        |
| 323 | +				foreach ($shortcode as $code => $label) { | 
                                                        |
| 324 | +					if (isset($merged_codes[ $code ])) { | 
                                                        |
| 325 | + continue;  | 
                                                        |
| 326 | +					} else { | 
                                                        |
| 327 | + $merged_codes[ $code ] = $label;  | 
                                                        |
| 328 | + }  | 
                                                        |
| 329 | + }  | 
                                                        |
| 330 | + }  | 
                                                        |
| 331 | + $valid_shortcodes = $merged_codes;  | 
                                                        |
| 332 | + }  | 
                                                        |
| 333 | +  | 
                                                        |
| 334 | + return $valid_shortcodes;  | 
                                                        |
| 335 | + }  | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | +  | 
                                                        |
| 338 | + /**  | 
                                                        |
| 339 | + * Get Messenger object.  | 
                                                        |
| 340 | + *  | 
                                                        |
| 341 | + * @param string $messenger messenger slug for the messenger object we want to retrieve.  | 
                                                        |
| 342 | + * @return EE_messenger  | 
                                                        |
| 343 | + * @throws ReflectionException  | 
                                                        |
| 344 | + * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 345 | + * @deprecated 4.9.0  | 
                                                        |
| 346 | + */  | 
                                                        |
| 347 | + public static function messenger_obj($messenger)  | 
                                                        |
| 348 | +	{ | 
                                                        |
| 349 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 350 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 351 | + return $Message_Resource_Manager->get_messenger($messenger);  | 
                                                        |
| 352 | + }  | 
                                                        |
| 353 | +  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | + /**  | 
                                                        |
| 356 | + * get Message type object  | 
                                                        |
| 357 | + *  | 
                                                        |
| 358 | + * @param string $message_type the slug for the message type object to retrieve  | 
                                                        |
| 359 | + * @return EE_message_type  | 
                                                        |
| 360 | + * @throws ReflectionException  | 
                                                        |
| 361 | + * @throws EE_Error*@since 4.3.0  | 
                                                        |
| 362 | + * @deprecated 4.9.0  | 
                                                        |
| 363 | + */  | 
                                                        |
| 364 | + public static function message_type_obj($message_type)  | 
                                                        |
| 365 | +	{ | 
                                                        |
| 366 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 367 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 368 | + return $Message_Resource_Manager->get_message_type($message_type);  | 
                                                        |
| 369 | + }  | 
                                                        |
| 370 | +  | 
                                                        |
| 371 | +  | 
                                                        |
| 372 | + /**  | 
                                                        |
| 373 | + * Given a message_type slug, will return whether that message type is active in the system or not.  | 
                                                        |
| 374 | + *  | 
                                                        |
| 375 | + * @since 4.3.0  | 
                                                        |
| 376 | + * @param string $message_type message type to check for.  | 
                                                        |
| 377 | + * @return boolean  | 
                                                        |
| 378 | + * @throws EE_Error  | 
                                                        |
| 379 | + * @throws ReflectionException  | 
                                                        |
| 380 | + */  | 
                                                        |
| 381 | + public static function is_mt_active($message_type)  | 
                                                        |
| 382 | +	{ | 
                                                        |
| 383 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 384 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 385 | + $active_mts = $Message_Resource_Manager->list_of_active_message_types();  | 
                                                        |
| 386 | + return in_array($message_type, $active_mts);  | 
                                                        |
| 387 | + }  | 
                                                        |
| 388 | +  | 
                                                        |
| 389 | +  | 
                                                        |
| 390 | + /**  | 
                                                        |
| 391 | + * Given a messenger slug, will return whether that messenger is active in the system or not.  | 
                                                        |
| 392 | + *  | 
                                                        |
| 393 | + * @since 4.3.0  | 
                                                        |
| 394 | + *  | 
                                                        |
| 395 | + * @param string $messenger slug for messenger to check.  | 
                                                        |
| 396 | + * @return boolean  | 
                                                        |
| 397 | + * @throws EE_Error  | 
                                                        |
| 398 | + * @throws ReflectionException  | 
                                                        |
| 399 | + */  | 
                                                        |
| 400 | + public static function is_messenger_active($messenger)  | 
                                                        |
| 401 | +	{ | 
                                                        |
| 402 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 403 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 404 | + $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);  | 
                                                        |
| 405 | + return $active_messenger instanceof EE_messenger;  | 
                                                        |
| 406 | + }  | 
                                                        |
| 407 | +  | 
                                                        |
| 408 | +  | 
                                                        |
| 409 | + /**  | 
                                                        |
| 410 | + * Used to return active messengers array stored in the wp options table.  | 
                                                        |
| 411 | + * If no value is present in the option then an empty array is returned.  | 
                                                        |
| 412 | + *  | 
                                                        |
| 413 | + * @deprecated 4.9  | 
                                                        |
| 414 | + * @since 4.3.1  | 
                                                        |
| 415 | + *  | 
                                                        |
| 416 | + * @return array  | 
                                                        |
| 417 | + * @throws EE_Error  | 
                                                        |
| 418 | + * @throws ReflectionException  | 
                                                        |
| 419 | + */  | 
                                                        |
| 420 | + public static function get_active_messengers_in_db()  | 
                                                        |
| 421 | +	{ | 
                                                        |
| 422 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 423 | + __METHOD__,  | 
                                                        |
| 424 | +			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'), | 
                                                        |
| 425 | + '4.9.0'  | 
                                                        |
| 426 | + );  | 
                                                        |
| 427 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 428 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 429 | + return $Message_Resource_Manager->get_active_messengers_option();  | 
                                                        |
| 430 | + }  | 
                                                        |
| 431 | +  | 
                                                        |
| 432 | +  | 
                                                        |
| 433 | + /**  | 
                                                        |
| 434 | + * Used to update the active messengers array stored in the wp options table.  | 
                                                        |
| 435 | + *  | 
                                                        |
| 436 | + * @since 4.3.1  | 
                                                        |
| 437 | + * @deprecated 4.9.0  | 
                                                        |
| 438 | + *  | 
                                                        |
| 439 | + * @param array $data_to_save Incoming data to save.  | 
                                                        |
| 440 | + *  | 
                                                        |
| 441 | + * @return bool FALSE if not updated, TRUE if updated.  | 
                                                        |
| 442 | + * @throws EE_Error  | 
                                                        |
| 443 | + * @throws ReflectionException  | 
                                                        |
| 444 | + */  | 
                                                        |
| 445 | + public static function update_active_messengers_in_db($data_to_save)  | 
                                                        |
| 446 | +	{ | 
                                                        |
| 447 | + EE_Error::doing_it_wrong(  | 
                                                        |
| 448 | + __METHOD__,  | 
                                                        |
| 449 | +			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'), | 
                                                        |
| 450 | + '4.9.0'  | 
                                                        |
| 451 | + );  | 
                                                        |
| 452 | + /** @var EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 453 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 454 | + return $Message_Resource_Manager->update_active_messengers_option($data_to_save);  | 
                                                        |
| 455 | + }  | 
                                                        |
| 456 | +  | 
                                                        |
| 457 | +  | 
                                                        |
| 458 | + /**  | 
                                                        |
| 459 | + * This does some validation of incoming params, determines what type of url is being prepped and returns the  | 
                                                        |
| 460 | + * appropriate url trigger  | 
                                                        |
| 461 | + *  | 
                                                        |
| 462 | + * @param EE_message_type $message_type  | 
                                                        |
| 463 | + * @param EE_Message $message  | 
                                                        |
| 464 | + * @param EE_Registration | null $registration The registration object must be included if this  | 
                                                        |
| 465 | + * is going to be a registration trigger url.  | 
                                                        |
| 466 | + * @param string $sending_messenger The (optional) sending messenger for the url.  | 
                                                        |
| 467 | + *  | 
                                                        |
| 468 | + * @return string  | 
                                                        |
| 469 | + * @throws EE_Error  | 
                                                        |
| 470 | + */  | 
                                                        |
| 471 | + public static function get_url_trigger(  | 
                                                        |
| 472 | + EE_message_type $message_type,  | 
                                                        |
| 473 | + EE_Message $message,  | 
                                                        |
| 474 | + $registration = null,  | 
                                                        |
| 475 | + $sending_messenger = ''  | 
                                                        |
| 476 | +	) { | 
                                                        |
| 477 | + // first determine if the url can be to the EE_Message object.  | 
                                                        |
| 478 | +		if (! $message_type->always_generate()) { | 
                                                        |
| 479 | + return EEH_MSG_Template::generate_browser_trigger($message);  | 
                                                        |
| 480 | + }  | 
                                                        |
| 481 | +  | 
                                                        |
| 482 | + // if $registration object is not valid then exit early because there's nothing that can be generated.  | 
                                                        |
| 483 | +		if (! $registration instanceof EE_Registration) { | 
                                                        |
| 484 | + throw new EE_Error(  | 
                                                        |
| 485 | +				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') | 
                                                        |
| 486 | + );  | 
                                                        |
| 487 | + }  | 
                                                        |
| 488 | +  | 
                                                        |
| 489 | + // validate given context  | 
                                                        |
| 490 | + $contexts = $message_type->get_contexts();  | 
                                                        |
| 491 | +		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { | 
                                                        |
| 492 | + throw new EE_Error(  | 
                                                        |
| 493 | + sprintf(  | 
                                                        |
| 494 | +					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), | 
                                                        |
| 495 | + $message->context(),  | 
                                                        |
| 496 | + get_class($message_type)  | 
                                                        |
| 497 | + )  | 
                                                        |
| 498 | + );  | 
                                                        |
| 499 | + }  | 
                                                        |
| 500 | +  | 
                                                        |
| 501 | + // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used.  | 
                                                        |
| 502 | +		if (! empty($sending_messenger)) { | 
                                                        |
| 503 | + $with_messengers = $message_type->with_messengers();  | 
                                                        |
| 504 | + if (  | 
                                                        |
| 505 | + ! isset($with_messengers[ $message->messenger() ])  | 
                                                        |
| 506 | + || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])  | 
                                                        |
| 507 | +			) { | 
                                                        |
| 508 | + throw new EE_Error(  | 
                                                        |
| 509 | + sprintf(  | 
                                                        |
| 510 | + esc_html__(  | 
                                                        |
| 511 | + 'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s. If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',  | 
                                                        |
| 512 | + 'event_espresso'  | 
                                                        |
| 513 | + ),  | 
                                                        |
| 514 | + $sending_messenger,  | 
                                                        |
| 515 | + get_class($message_type)  | 
                                                        |
| 516 | + )  | 
                                                        |
| 517 | + );  | 
                                                        |
| 518 | + }  | 
                                                        |
| 519 | +		} else { | 
                                                        |
| 520 | + $sending_messenger = $message->messenger();  | 
                                                        |
| 521 | + }  | 
                                                        |
| 522 | + return EEH_MSG_Template::generate_url_trigger(  | 
                                                        |
| 523 | + $sending_messenger,  | 
                                                        |
| 524 | + $message->messenger(),  | 
                                                        |
| 525 | + $message->context(),  | 
                                                        |
| 526 | + $message->message_type(),  | 
                                                        |
| 527 | + $registration,  | 
                                                        |
| 528 | + $message->GRP_ID()  | 
                                                        |
| 529 | + );  | 
                                                        |
| 530 | + }  | 
                                                        |
| 531 | +  | 
                                                        |
| 532 | +  | 
                                                        |
| 533 | + /**  | 
                                                        |
| 534 | + * This returns the url for triggering a in browser view of a specific EE_Message object.  | 
                                                        |
| 535 | + * @param EE_Message $message  | 
                                                        |
| 536 | + * @return string.  | 
                                                        |
| 537 | + */  | 
                                                        |
| 538 | + public static function generate_browser_trigger(EE_Message $message)  | 
                                                        |
| 539 | +	{ | 
                                                        |
| 540 | + $query_args = array(  | 
                                                        |
| 541 | + 'ee' => 'msg_browser_trigger',  | 
                                                        |
| 542 | + 'token' => $message->MSG_token()  | 
                                                        |
| 543 | + );  | 
                                                        |
| 544 | + return apply_filters(  | 
                                                        |
| 545 | + 'FHEE__EEH_MSG_Template__generate_browser_trigger',  | 
                                                        |
| 546 | + add_query_arg($query_args, site_url()),  | 
                                                        |
| 547 | + $message  | 
                                                        |
| 548 | + );  | 
                                                        |
| 549 | + }  | 
                                                        |
| 550 | +  | 
                                                        |
| 551 | +  | 
                                                        |
| 552 | +  | 
                                                        |
| 553 | +  | 
                                                        |
| 554 | +  | 
                                                        |
| 555 | +  | 
                                                        |
| 556 | + /**  | 
                                                        |
| 557 | + * This returns the url for triggering an in browser view of the error saved on the incoming message object.  | 
                                                        |
| 558 | + * @param EE_Message $message  | 
                                                        |
| 559 | + * @return string  | 
                                                        |
| 560 | + */  | 
                                                        |
| 561 | + public static function generate_error_display_trigger(EE_Message $message)  | 
                                                        |
| 562 | +	{ | 
                                                        |
| 563 | + return apply_filters(  | 
                                                        |
| 564 | + 'FHEE__EEH_MSG_Template__generate_error_display_trigger',  | 
                                                        |
| 565 | + add_query_arg(  | 
                                                        |
| 566 | + array(  | 
                                                        |
| 567 | + 'ee' => 'msg_browser_error_trigger',  | 
                                                        |
| 568 | + 'token' => $message->MSG_token()  | 
                                                        |
| 569 | + ),  | 
                                                        |
| 570 | + site_url()  | 
                                                        |
| 571 | + ),  | 
                                                        |
| 572 | + $message  | 
                                                        |
| 573 | + );  | 
                                                        |
| 574 | + }  | 
                                                        |
| 575 | +  | 
                                                        |
| 576 | +  | 
                                                        |
| 577 | + /**  | 
                                                        |
| 578 | + * This generates a url trigger for the msg_url_trigger route using the given arguments  | 
                                                        |
| 579 | + *  | 
                                                        |
| 580 | + * @param string $sending_messenger The sending messenger slug.  | 
                                                        |
| 581 | + * @param string $generating_messenger The generating messenger slug.  | 
                                                        |
| 582 | + * @param string $context The context for the template.  | 
                                                        |
| 583 | + * @param string $message_type The message type slug  | 
                                                        |
| 584 | + * @param EE_Registration $registration  | 
                                                        |
| 585 | + * @param integer $message_template_group id The EE_Message_Template_Group ID for the template.  | 
                                                        |
| 586 | + * @param integer $data_id The id to the EE_Base_Class for getting the data used by the  | 
                                                        |
| 587 | + * trigger.  | 
                                                        |
| 588 | + * @return string The generated url.  | 
                                                        |
| 589 | + * @throws EE_Error  | 
                                                        |
| 590 | + */  | 
                                                        |
| 591 | + public static function generate_url_trigger(  | 
                                                        |
| 592 | + $sending_messenger,  | 
                                                        |
| 593 | + $generating_messenger,  | 
                                                        |
| 594 | + $context,  | 
                                                        |
| 595 | + $message_type,  | 
                                                        |
| 596 | + EE_Registration $registration,  | 
                                                        |
| 597 | + $message_template_group,  | 
                                                        |
| 598 | + $data_id = 0  | 
                                                        |
| 599 | +	) { | 
                                                        |
| 600 | + $query_args = array(  | 
                                                        |
| 601 | + 'ee' => 'msg_url_trigger',  | 
                                                        |
| 602 | + 'snd_msgr' => $sending_messenger,  | 
                                                        |
| 603 | + 'gen_msgr' => $generating_messenger,  | 
                                                        |
| 604 | + 'message_type' => $message_type,  | 
                                                        |
| 605 | + 'context' => $context,  | 
                                                        |
| 606 | + 'token' => $registration->reg_url_link(),  | 
                                                        |
| 607 | + 'GRP_ID' => $message_template_group,  | 
                                                        |
| 608 | + 'id' => $data_id  | 
                                                        |
| 609 | + );  | 
                                                        |
| 610 | + $url = add_query_arg($query_args, get_home_url());  | 
                                                        |
| 611 | +  | 
                                                        |
| 612 | + // made it here so now we can just get the url and filter it. Filtered globally and by message type.  | 
                                                        |
| 613 | + return apply_filters(  | 
                                                        |
| 614 | + 'FHEE__EEH_MSG_Template__generate_url_trigger',  | 
                                                        |
| 615 | + $url,  | 
                                                        |
| 616 | + $sending_messenger,  | 
                                                        |
| 617 | + $generating_messenger,  | 
                                                        |
| 618 | + $context,  | 
                                                        |
| 619 | + $message_type,  | 
                                                        |
| 620 | + $registration,  | 
                                                        |
| 621 | + $message_template_group,  | 
                                                        |
| 622 | + $data_id  | 
                                                        |
| 623 | + );  | 
                                                        |
| 624 | + }  | 
                                                        |
| 625 | +  | 
                                                        |
| 626 | +  | 
                                                        |
| 627 | +  | 
                                                        |
| 628 | +  | 
                                                        |
| 629 | + /**  | 
                                                        |
| 630 | + * Return the specific css for the action icon given.  | 
                                                        |
| 631 | + *  | 
                                                        |
| 632 | + * @param string $type What action to return.  | 
                                                        |
| 633 | + * @return string[]  | 
                                                        |
| 634 | + * @since 4.9.0  | 
                                                        |
| 635 | + */  | 
                                                        |
| 636 | + public static function get_message_action_icon($type)  | 
                                                        |
| 637 | +	{ | 
                                                        |
| 638 | + $action_icons = self::get_message_action_icons();  | 
                                                        |
| 639 | + return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];  | 
                                                        |
| 640 | + }  | 
                                                        |
| 641 | +  | 
                                                        |
| 642 | +  | 
                                                        |
| 643 | + /**  | 
                                                        |
| 644 | + * This is used for retrieving the css classes used for the icons representing message actions.  | 
                                                        |
| 645 | + *  | 
                                                        |
| 646 | + * @since 4.9.0  | 
                                                        |
| 647 | + *  | 
                                                        |
| 648 | + * @return array  | 
                                                        |
| 649 | + */  | 
                                                        |
| 650 | + public static function get_message_action_icons()  | 
                                                        |
| 651 | +	{ | 
                                                        |
| 652 | + return apply_filters(  | 
                                                        |
| 653 | + 'FHEE__EEH_MSG_Template__message_action_icons',  | 
                                                        |
| 654 | + array(  | 
                                                        |
| 655 | + 'view' => array(  | 
                                                        |
| 656 | +					'label' => esc_html__('View Message', 'event_espresso'), | 
                                                        |
| 657 | + 'css_class' => 'dashicons dashicons-visibility',  | 
                                                        |
| 658 | + ),  | 
                                                        |
| 659 | + 'error' => array(  | 
                                                        |
| 660 | +					'label' => esc_html__('View Error Message', 'event_espresso'), | 
                                                        |
| 661 | + 'css_class' => 'dashicons dashicons-info',  | 
                                                        |
| 662 | + ),  | 
                                                        |
| 663 | + 'see_notifications_for' => array(  | 
                                                        |
| 664 | +					'label' => esc_html__('View Related Messages', 'event_espresso'), | 
                                                        |
| 665 | + 'css_class' => 'dashicons dashicons-megaphone',  | 
                                                        |
| 666 | + ),  | 
                                                        |
| 667 | + 'generate_now' => array(  | 
                                                        |
| 668 | +					'label' => esc_html__('Generate the message now.', 'event_espresso'), | 
                                                        |
| 669 | + 'css_class' => 'dashicons dashicons-admin-tools',  | 
                                                        |
| 670 | + ),  | 
                                                        |
| 671 | + 'send_now' => array(  | 
                                                        |
| 672 | +					'label' => esc_html__('Send Immediately', 'event_espresso'), | 
                                                        |
| 673 | + 'css_class' => 'dashicons dashicons-controls-forward',  | 
                                                        |
| 674 | + ),  | 
                                                        |
| 675 | + 'queue_for_resending' => array(  | 
                                                        |
| 676 | +					'label' => esc_html__('Queue for Resending', 'event_espresso'), | 
                                                        |
| 677 | + 'css_class' => 'dashicons dashicons-controls-repeat',  | 
                                                        |
| 678 | + ),  | 
                                                        |
| 679 | + 'view_transaction' => array(  | 
                                                        |
| 680 | +					'label' => esc_html__('View related Transaction', 'event_espresso'), | 
                                                        |
| 681 | + 'css_class' => 'dashicons dashicons-cart',  | 
                                                        |
| 682 | + )  | 
                                                        |
| 683 | + )  | 
                                                        |
| 684 | + );  | 
                                                        |
| 685 | + }  | 
                                                        |
| 686 | +  | 
                                                        |
| 687 | +  | 
                                                        |
| 688 | + /**  | 
                                                        |
| 689 | + * This returns the url for a given action related to EE_Message.  | 
                                                        |
| 690 | + *  | 
                                                        |
| 691 | + * @param string $type What type of action to return the url for.  | 
                                                        |
| 692 | + * @param EE_Message $message Required for generating the correct url for some types.  | 
                                                        |
| 693 | + * @param array $query_params Any additional query params to be included with the generated url.  | 
                                                        |
| 694 | + *  | 
                                                        |
| 695 | + * @return string  | 
                                                        |
| 696 | + * @throws EE_Error  | 
                                                        |
| 697 | + * @throws ReflectionException  | 
                                                        |
| 698 | + * @since 4.9.0  | 
                                                        |
| 699 | + *  | 
                                                        |
| 700 | + */  | 
                                                        |
| 701 | + public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())  | 
                                                        |
| 702 | +	{ | 
                                                        |
| 703 | + $action_urls = self::get_message_action_urls($message, $query_params);  | 
                                                        |
| 704 | + return isset($action_urls[ $type ]) ? $action_urls[ $type ] : '';  | 
                                                        |
| 705 | + }  | 
                                                        |
| 706 | +  | 
                                                        |
| 707 | +  | 
                                                        |
| 708 | + /**  | 
                                                        |
| 709 | + * This returns all the current urls for EE_Message actions.  | 
                                                        |
| 710 | + *  | 
                                                        |
| 711 | + * @since 4.9.0  | 
                                                        |
| 712 | + *  | 
                                                        |
| 713 | + * @param EE_Message $message The EE_Message object required to generate correct urls for some types.  | 
                                                        |
| 714 | + * @param array $query_params Any additional query_params to be included with the generated url.  | 
                                                        |
| 715 | + *  | 
                                                        |
| 716 | + * @return array  | 
                                                        |
| 717 | + * @throws EE_Error  | 
                                                        |
| 718 | + * @throws ReflectionException  | 
                                                        |
| 719 | + */  | 
                                                        |
| 720 | + public static function get_message_action_urls(EE_Message $message = null, $query_params = array())  | 
                                                        |
| 721 | +	{ | 
                                                        |
| 722 | +		EE_Registry::instance()->load_helper('URL'); | 
                                                        |
| 723 | + // if $message is not an instance of EE_Message then let's just do a dummy.  | 
                                                        |
| 724 | + $message = empty($message) ? EE_Message_Factory::create() : $message;  | 
                                                        |
| 725 | + $action_urls = apply_filters(  | 
                                                        |
| 726 | + 'FHEE__EEH_MSG_Template__get_message_action_url',  | 
                                                        |
| 727 | + array(  | 
                                                        |
| 728 | + 'view' => EEH_MSG_Template::generate_browser_trigger($message),  | 
                                                        |
| 729 | + 'error' => EEH_MSG_Template::generate_error_display_trigger($message),  | 
                                                        |
| 730 | + 'see_notifications_for' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 731 | + array_merge(  | 
                                                        |
| 732 | + array(  | 
                                                        |
| 733 | + 'page' => 'espresso_messages',  | 
                                                        |
| 734 | + 'action' => 'default',  | 
                                                        |
| 735 | + 'filterby' => 1,  | 
                                                        |
| 736 | + ),  | 
                                                        |
| 737 | + $query_params  | 
                                                        |
| 738 | + ),  | 
                                                        |
| 739 | +					admin_url('admin.php') | 
                                                        |
| 740 | + ),  | 
                                                        |
| 741 | + 'generate_now' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 742 | + array(  | 
                                                        |
| 743 | + 'page' => 'espresso_messages',  | 
                                                        |
| 744 | + 'action' => 'generate_now',  | 
                                                        |
| 745 | + 'MSG_ID' => $message->ID()  | 
                                                        |
| 746 | + ),  | 
                                                        |
| 747 | +					admin_url('admin.php') | 
                                                        |
| 748 | + ),  | 
                                                        |
| 749 | + 'send_now' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 750 | + array(  | 
                                                        |
| 751 | + 'page' => 'espresso_messages',  | 
                                                        |
| 752 | + 'action' => 'send_now',  | 
                                                        |
| 753 | + 'MSG_ID' => $message->ID()  | 
                                                        |
| 754 | + ),  | 
                                                        |
| 755 | +					admin_url('admin.php') | 
                                                        |
| 756 | + ),  | 
                                                        |
| 757 | + 'queue_for_resending' => EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 758 | + array(  | 
                                                        |
| 759 | + 'page' => 'espresso_messages',  | 
                                                        |
| 760 | + 'action' => 'queue_for_resending',  | 
                                                        |
| 761 | + 'MSG_ID' => $message->ID()  | 
                                                        |
| 762 | + ),  | 
                                                        |
| 763 | +					admin_url('admin.php') | 
                                                        |
| 764 | + ),  | 
                                                        |
| 765 | + )  | 
                                                        |
| 766 | + );  | 
                                                        |
| 767 | + if (  | 
                                                        |
| 768 | + $message->TXN_ID() > 0  | 
                                                        |
| 769 | + && EE_Registry::instance()->CAP->current_user_can(  | 
                                                        |
| 770 | + 'ee_read_transaction',  | 
                                                        |
| 771 | + 'espresso_transactions_default',  | 
                                                        |
| 772 | + $message->TXN_ID()  | 
                                                        |
| 773 | + )  | 
                                                        |
| 774 | +		) { | 
                                                        |
| 775 | + $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(  | 
                                                        |
| 776 | + array(  | 
                                                        |
| 777 | + 'page' => 'espresso_transactions',  | 
                                                        |
| 778 | + 'action' => 'view_transaction',  | 
                                                        |
| 779 | + 'TXN_ID' => $message->TXN_ID()  | 
                                                        |
| 780 | + ),  | 
                                                        |
| 781 | +				admin_url('admin.php') | 
                                                        |
| 782 | + );  | 
                                                        |
| 783 | +		} else { | 
                                                        |
| 784 | + $action_urls['view_transaction'] = '';  | 
                                                        |
| 785 | + }  | 
                                                        |
| 786 | + return $action_urls;  | 
                                                        |
| 787 | + }  | 
                                                        |
| 788 | +  | 
                                                        |
| 789 | +  | 
                                                        |
| 790 | + /**  | 
                                                        |
| 791 | + * This returns a generated link html including the icon used for the action link for EE_Message actions.  | 
                                                        |
| 792 | + *  | 
                                                        |
| 793 | + * @param string $type What type of action the link is for (if invalid type is passed in then an  | 
                                                        |
| 794 | + * empty string is returned)  | 
                                                        |
| 795 | + * @param EE_Message|null $message The EE_Message object (required for some actions to generate correctly)  | 
                                                        |
| 796 | + * @param array $query_params Any extra query params to include in the generated link.  | 
                                                        |
| 797 | + *  | 
                                                        |
| 798 | + * @return string  | 
                                                        |
| 799 | + * @throws EE_Error  | 
                                                        |
| 800 | + * @throws ReflectionException  | 
                                                        |
| 801 | + * @since 4.9.0  | 
                                                        |
| 802 | + *  | 
                                                        |
| 803 | + */  | 
                                                        |
| 804 | + public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())  | 
                                                        |
| 805 | +	{ | 
                                                        |
| 806 | + $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);  | 
                                                        |
| 807 | + $icon_css = EEH_MSG_Template::get_message_action_icon($type);  | 
                                                        |
| 808 | + $label = $icon_css['label'] ?? null;  | 
                                                        |
| 809 | + $label = $label ? 'aria-label="' . $label . '"' : '';  | 
                                                        |
| 810 | + $class = $label ? ' ee-aria-tooltip' : '';  | 
                                                        |
| 811 | +  | 
                                                        |
| 812 | +		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { | 
                                                        |
| 813 | + return '';  | 
                                                        |
| 814 | + }  | 
                                                        |
| 815 | +  | 
                                                        |
| 816 | + $icon_css['css_class'] .= esc_attr(  | 
                                                        |
| 817 | + apply_filters(  | 
                                                        |
| 818 | + 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',  | 
                                                        |
| 819 | + ' js-ee-message-action-link ee-message-action-link-' . $type,  | 
                                                        |
| 820 | + $type,  | 
                                                        |
| 821 | + $message,  | 
                                                        |
| 822 | + $query_params  | 
                                                        |
| 823 | + )  | 
                                                        |
| 824 | + );  | 
                                                        |
| 825 | +  | 
                                                        |
| 826 | + return '  | 
                                                        |
| 827 | 827 | <a href="' . $url . '" ' . $label . ' class="button button--icon-only' . $class . '">  | 
                                                        
| 828 | 828 | <span class="' . esc_attr($icon_css['css_class']) . '"></span>  | 
                                                        
| 829 | 829 | </a>';  | 
                                                        
| 830 | - }  | 
                                                        |
| 831 | -  | 
                                                        |
| 832 | -  | 
                                                        |
| 833 | -  | 
                                                        |
| 834 | -  | 
                                                        |
| 835 | -  | 
                                                        |
| 836 | - /**  | 
                                                        |
| 837 | - * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).  | 
                                                        |
| 838 | - *  | 
                                                        |
| 839 | - * @since 4.9.0  | 
                                                        |
| 840 | - * @return array  | 
                                                        |
| 841 | - */  | 
                                                        |
| 842 | - public static function reg_status_to_message_type_array()  | 
                                                        |
| 843 | -    { | 
                                                        |
| 844 | - return (array) apply_filters(  | 
                                                        |
| 845 | - 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',  | 
                                                        |
| 846 | - array(  | 
                                                        |
| 847 | - EEM_Registration::status_id_approved => 'registration',  | 
                                                        |
| 848 | - EEM_Registration::status_id_pending_payment => 'pending_approval',  | 
                                                        |
| 849 | - EEM_Registration::status_id_not_approved => 'not_approved_registration',  | 
                                                        |
| 850 | - EEM_Registration::status_id_cancelled => 'cancelled_registration',  | 
                                                        |
| 851 | - EEM_Registration::status_id_declined => 'declined_registration'  | 
                                                        |
| 852 | - )  | 
                                                        |
| 853 | - );  | 
                                                        |
| 854 | - }  | 
                                                        |
| 855 | -  | 
                                                        |
| 856 | -  | 
                                                        |
| 857 | -  | 
                                                        |
| 858 | -  | 
                                                        |
| 859 | - /**  | 
                                                        |
| 860 | - * This returns the corresponding registration message type slug to the given reg status. If there isn't a  | 
                                                        |
| 861 | - * match, then returns an empty string.  | 
                                                        |
| 862 | - *  | 
                                                        |
| 863 | - * @since 4.9.0  | 
                                                        |
| 864 | - * @param $reg_status  | 
                                                        |
| 865 | - * @return string  | 
                                                        |
| 866 | - */  | 
                                                        |
| 867 | - public static function convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 868 | -    { | 
                                                        |
| 869 | - $reg_status_array = self::reg_status_to_message_type_array();  | 
                                                        |
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';  | 
                                                        |
| 871 | - }  | 
                                                        |
| 872 | -  | 
                                                        |
| 873 | -  | 
                                                        |
| 874 | - /**  | 
                                                        |
| 875 | - * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).  | 
                                                        |
| 876 | - *  | 
                                                        |
| 877 | - * @since 4.9.0  | 
                                                        |
| 878 | - * @return array  | 
                                                        |
| 879 | - */  | 
                                                        |
| 880 | - public static function payment_status_to_message_type_array()  | 
                                                        |
| 881 | -    { | 
                                                        |
| 882 | - return (array) apply_filters(  | 
                                                        |
| 883 | - 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',  | 
                                                        |
| 884 | - array(  | 
                                                        |
| 885 | - EEM_Payment::status_id_approved => 'payment',  | 
                                                        |
| 886 | - EEM_Payment::status_id_pending => 'payment_pending',  | 
                                                        |
| 887 | - EEM_Payment::status_id_cancelled => 'payment_cancelled',  | 
                                                        |
| 888 | - EEM_Payment::status_id_declined => 'payment_declined',  | 
                                                        |
| 889 | - EEM_Payment::status_id_failed => 'payment_failed'  | 
                                                        |
| 890 | - )  | 
                                                        |
| 891 | - );  | 
                                                        |
| 892 | - }  | 
                                                        |
| 893 | -  | 
                                                        |
| 894 | -  | 
                                                        |
| 895 | -  | 
                                                        |
| 896 | -  | 
                                                        |
| 897 | - /**  | 
                                                        |
| 898 | - * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then  | 
                                                        |
| 899 | - * an empty string is returned  | 
                                                        |
| 900 | - *  | 
                                                        |
| 901 | - * @since 4.9.0  | 
                                                        |
| 902 | - * @param $payment_status  | 
                                                        |
| 903 | - * @return string  | 
                                                        |
| 904 | - */  | 
                                                        |
| 905 | - public static function convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 906 | -    { | 
                                                        |
| 907 | - $payment_status_array = self::payment_status_to_message_type_array();  | 
                                                        |
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';  | 
                                                        |
| 909 | - }  | 
                                                        |
| 910 | -  | 
                                                        |
| 911 | -  | 
                                                        |
| 912 | - /**  | 
                                                        |
| 913 | - * This is used to retrieve the template pack for the given name.  | 
                                                        |
| 914 | - *  | 
                                                        |
| 915 | - * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack.  | 
                                                        |
| 916 | - *  | 
                                                        |
| 917 | - * @return EE_Messages_Template_Pack  | 
                                                        |
| 918 | - */  | 
                                                        |
| 919 | - public static function get_template_pack($template_pack_name)  | 
                                                        |
| 920 | -    { | 
                                                        |
| 921 | -        if (! self::$_template_pack_collection instanceof EE_Object_Collection) { | 
                                                        |
| 922 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        |
| 923 | - }  | 
                                                        |
| 924 | -  | 
                                                        |
| 925 | - // first see if in collection already  | 
                                                        |
| 926 | - $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);  | 
                                                        |
| 927 | -  | 
                                                        |
| 928 | -        if ($template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 929 | - return $template_pack;  | 
                                                        |
| 930 | - }  | 
                                                        |
| 931 | -  | 
                                                        |
| 932 | - // nope...let's get it.  | 
                                                        |
| 933 | - // not set yet so let's attempt to get it.  | 
                                                        |
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 935 | - ' ',  | 
                                                        |
| 936 | - '_',  | 
                                                        |
| 937 | - ucwords(  | 
                                                        |
| 938 | -                str_replace('_', ' ', $template_pack_name) | 
                                                        |
| 939 | - )  | 
                                                        |
| 940 | - );  | 
                                                        |
| 941 | -        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { | 
                                                        |
| 942 | -            return self::get_template_pack('default'); | 
                                                        |
| 943 | -        } else { | 
                                                        |
| 944 | - $template_pack = new $pack_class_name();  | 
                                                        |
| 945 | - self::$_template_pack_collection->add($template_pack);  | 
                                                        |
| 946 | - return $template_pack;  | 
                                                        |
| 947 | - }  | 
                                                        |
| 948 | - }  | 
                                                        |
| 949 | -  | 
                                                        |
| 950 | -  | 
                                                        |
| 951 | -  | 
                                                        |
| 952 | -  | 
                                                        |
| 953 | - /**  | 
                                                        |
| 954 | - * Globs template packs installed in core and returns the template pack collection with all installed template packs  | 
                                                        |
| 955 | - * in it.  | 
                                                        |
| 956 | - *  | 
                                                        |
| 957 | - * @since 4.9.0  | 
                                                        |
| 958 | - *  | 
                                                        |
| 959 | - * @return EE_Messages_Template_Pack_Collection  | 
                                                        |
| 960 | - */  | 
                                                        |
| 961 | - public static function get_template_pack_collection()  | 
                                                        |
| 962 | -    { | 
                                                        |
| 963 | - $new_collection = false;  | 
                                                        |
| 964 | -        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { | 
                                                        |
| 965 | - self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        |
| 966 | - $new_collection = true;  | 
                                                        |
| 967 | - }  | 
                                                        |
| 968 | -  | 
                                                        |
| 969 | - // glob the defaults directory for messages  | 
                                                        |
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);  | 
                                                        |
| 971 | -        foreach ($templates as $template_path) { | 
                                                        |
| 972 | - // grab folder name  | 
                                                        |
| 973 | - $template = basename($template_path);  | 
                                                        |
| 974 | -  | 
                                                        |
| 975 | -            if (! $new_collection) { | 
                                                        |
| 976 | - // already have it?  | 
                                                        |
| 977 | -                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 978 | - continue;  | 
                                                        |
| 979 | - }  | 
                                                        |
| 980 | - }  | 
                                                        |
| 981 | -  | 
                                                        |
| 982 | - // setup classname.  | 
                                                        |
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 984 | - ' ',  | 
                                                        |
| 985 | - '_',  | 
                                                        |
| 986 | - ucwords(  | 
                                                        |
| 987 | - str_replace(  | 
                                                        |
| 988 | - '_',  | 
                                                        |
| 989 | - ' ',  | 
                                                        |
| 990 | - $template  | 
                                                        |
| 991 | - )  | 
                                                        |
| 992 | - )  | 
                                                        |
| 993 | - );  | 
                                                        |
| 994 | -            if (! class_exists($template_pack_class_name)) { | 
                                                        |
| 995 | - continue;  | 
                                                        |
| 996 | - }  | 
                                                        |
| 997 | - self::$_template_pack_collection->add(new $template_pack_class_name());  | 
                                                        |
| 998 | - }  | 
                                                        |
| 999 | -  | 
                                                        |
| 1000 | - /**  | 
                                                        |
| 1001 | - * Filter for plugins to add in any additional template packs  | 
                                                        |
| 1002 | - * Note the filter name here is for backward compat, this used to be found in EED_Messages.  | 
                                                        |
| 1003 | - */  | 
                                                        |
| 1004 | -        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); | 
                                                        |
| 1005 | -        foreach ((array) $additional_template_packs as $template_pack) { | 
                                                        |
| 1006 | - if (  | 
                                                        |
| 1007 | - self::$_template_pack_collection->get_by_name(  | 
                                                        |
| 1008 | - $template_pack->dbref  | 
                                                        |
| 1009 | - ) instanceof EE_Messages_Template_Pack  | 
                                                        |
| 1010 | -            ) { | 
                                                        |
| 1011 | - continue;  | 
                                                        |
| 1012 | - }  | 
                                                        |
| 1013 | - self::$_template_pack_collection->add($template_pack);  | 
                                                        |
| 1014 | - }  | 
                                                        |
| 1015 | - return self::$_template_pack_collection;  | 
                                                        |
| 1016 | - }  | 
                                                        |
| 1017 | -  | 
                                                        |
| 1018 | -  | 
                                                        |
| 1019 | - /**  | 
                                                        |
| 1020 | - * This is a wrapper for the protected _create_new_templates function  | 
                                                        |
| 1021 | - *  | 
                                                        |
| 1022 | - * @param string $messenger_name  | 
                                                        |
| 1023 | - * @param string $message_type_name message type that the templates are being created for  | 
                                                        |
| 1024 | - * @param int $GRP_ID  | 
                                                        |
| 1025 | - * @param bool $global  | 
                                                        |
| 1026 | - * @return array  | 
                                                        |
| 1027 | - * @throws EE_Error  | 
                                                        |
| 1028 | - * @throws ReflectionException  | 
                                                        |
| 1029 | - */  | 
                                                        |
| 1030 | - public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)  | 
                                                        |
| 1031 | -    { | 
                                                        |
| 1032 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 1033 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1034 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        |
| 1035 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        |
| 1036 | -        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { | 
                                                        |
| 1037 | - return array();  | 
                                                        |
| 1038 | - }  | 
                                                        |
| 1039 | - // whew made it this far! Okay, let's go ahead and create the templates then  | 
                                                        |
| 1040 | - return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);  | 
                                                        |
| 1041 | - }  | 
                                                        |
| 1042 | -  | 
                                                        |
| 1043 | -  | 
                                                        |
| 1044 | - /**  | 
                                                        |
| 1045 | - * @param EE_messenger $messenger  | 
                                                        |
| 1046 | - * @param EE_message_type $message_type  | 
                                                        |
| 1047 | - * @param $GRP_ID  | 
                                                        |
| 1048 | - * @param $global  | 
                                                        |
| 1049 | - * @return array|mixed  | 
                                                        |
| 1050 | - * @throws EE_Error  | 
                                                        |
| 1051 | - * @throws ReflectionException  | 
                                                        |
| 1052 | - */  | 
                                                        |
| 1053 | - protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)  | 
                                                        |
| 1054 | -    { | 
                                                        |
| 1055 | - // if we're creating a custom template then we don't need to use the defaults class  | 
                                                        |
| 1056 | -        if (! $global) { | 
                                                        |
| 1057 | - return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);  | 
                                                        |
| 1058 | - }  | 
                                                        |
| 1059 | - /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */  | 
                                                        |
| 1060 | - $Message_Template_Defaults = EE_Registry::factory(  | 
                                                        |
| 1061 | - 'EE_Messages_Template_Defaults',  | 
                                                        |
| 1062 | - array( $messenger, $message_type, $GRP_ID )  | 
                                                        |
| 1063 | - );  | 
                                                        |
| 1064 | - // generate templates  | 
                                                        |
| 1065 | - $success = $Message_Template_Defaults->create_new_templates();  | 
                                                        |
| 1066 | -  | 
                                                        |
| 1067 | - // if creating the template failed. Then we should deactivate the related message_type for the messenger because  | 
                                                        |
| 1068 | - // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation  | 
                                                        |
| 1069 | - // attempts.  | 
                                                        |
| 1070 | -        if (! $success) { | 
                                                        |
| 1071 | - /** @var EE_Message_Resource_Manager $message_resource_manager */  | 
                                                        |
| 1072 | -            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1073 | - $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);  | 
                                                        |
| 1074 | - }  | 
                                                        |
| 1075 | -  | 
                                                        |
| 1076 | - /**  | 
                                                        |
| 1077 | - * $success is in an array in the following format  | 
                                                        |
| 1078 | - * array(  | 
                                                        |
| 1079 | - * 'GRP_ID' => $new_grp_id,  | 
                                                        |
| 1080 | - * 'MTP_context' => $first_context_in_new_templates,  | 
                                                        |
| 1081 | - * )  | 
                                                        |
| 1082 | - */  | 
                                                        |
| 1083 | - return $success;  | 
                                                        |
| 1084 | - }  | 
                                                        |
| 1085 | -  | 
                                                        |
| 1086 | -  | 
                                                        |
| 1087 | - /**  | 
                                                        |
| 1088 | - * This creates a custom template using the incoming GRP_ID  | 
                                                        |
| 1089 | - *  | 
                                                        |
| 1090 | - * @param EE_messenger $messenger  | 
                                                        |
| 1091 | - * @param EE_message_type $message_type  | 
                                                        |
| 1092 | - * @param int $GRP_ID GRP_ID for the template_group being used as the base  | 
                                                        |
| 1093 | - * @return array $success This will be an array in the format:  | 
                                                        |
| 1094 | - * array(  | 
                                                        |
| 1095 | - * 'GRP_ID' => $new_grp_id,  | 
                                                        |
| 1096 | - * 'MTP_context' => $first_context_in_created_template  | 
                                                        |
| 1097 | - * )  | 
                                                        |
| 1098 | - * @throws EE_Error  | 
                                                        |
| 1099 | - * @throws ReflectionException  | 
                                                        |
| 1100 | - * @access private  | 
                                                        |
| 1101 | - */  | 
                                                        |
| 1102 | - private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)  | 
                                                        |
| 1103 | -    { | 
                                                        |
| 1104 | - // defaults  | 
                                                        |
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' );  | 
                                                        |
| 1106 | - // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.  | 
                                                        |
| 1107 | - $Message_Template_Group = empty($GRP_ID)  | 
                                                        |
| 1108 | - ? EEM_Message_Template_Group::instance()->get_one(  | 
                                                        |
| 1109 | - array(  | 
                                                        |
| 1110 | - array(  | 
                                                        |
| 1111 | - 'MTP_messenger' => $messenger->name,  | 
                                                        |
| 1112 | - 'MTP_message_type' => $message_type->name,  | 
                                                        |
| 1113 | - 'MTP_is_global' => true  | 
                                                        |
| 1114 | - )  | 
                                                        |
| 1115 | - )  | 
                                                        |
| 1116 | - )  | 
                                                        |
| 1117 | - : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 1118 | - // if we don't have a mtg at this point then we need to bail.  | 
                                                        |
| 1119 | -        if (! $Message_Template_Group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1120 | - EE_Error::add_error(  | 
                                                        |
| 1121 | - sprintf(  | 
                                                        |
| 1122 | - esc_html__(  | 
                                                        |
| 1123 | - 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.',  | 
                                                        |
| 1124 | - 'event_espresso'  | 
                                                        |
| 1125 | - ),  | 
                                                        |
| 1126 | - $GRP_ID  | 
                                                        |
| 1127 | - ),  | 
                                                        |
| 1128 | - __FILE__,  | 
                                                        |
| 1129 | - __FUNCTION__,  | 
                                                        |
| 1130 | - __LINE__  | 
                                                        |
| 1131 | - );  | 
                                                        |
| 1132 | - return $success;  | 
                                                        |
| 1133 | - }  | 
                                                        |
| 1134 | - // let's get all the related message_template objects for this group.  | 
                                                        |
| 1135 | - $message_templates = $Message_Template_Group->message_templates();  | 
                                                        |
| 1136 | - // now we have what we need to setup the new template  | 
                                                        |
| 1137 | - $new_mtg = clone $Message_Template_Group;  | 
                                                        |
| 1138 | -        $new_mtg->set('GRP_ID', 0); | 
                                                        |
| 1139 | -        $new_mtg->set('MTP_is_global', false); | 
                                                        |
| 1140 | -  | 
                                                        |
| 1141 | - /** @var RequestInterface $request */  | 
                                                        |
| 1142 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);  | 
                                                        |
| 1143 | -        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName') | 
                                                        |
| 1144 | -            ? $request->getRequestParam('templateName') | 
                                                        |
| 1145 | -            : esc_html__('New Custom Template', 'event_espresso'); | 
                                                        |
| 1146 | -        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') | 
                                                        |
| 1147 | -            ? $request->getRequestParam('templateDescription') | 
                                                        |
| 1148 | - : sprintf(  | 
                                                        |
| 1149 | - esc_html__(  | 
                                                        |
| 1150 | - 'This is a custom template that was created for the %s messenger and %s message type.',  | 
                                                        |
| 1151 | - 'event_espresso'  | 
                                                        |
| 1152 | - ),  | 
                                                        |
| 1153 | - $new_mtg->messenger_obj()->label['singular'],  | 
                                                        |
| 1154 | - $new_mtg->message_type_obj()->label['singular']  | 
                                                        |
| 1155 | - );  | 
                                                        |
| 1156 | -        $new_mtg->set('MTP_name', $template_name); | 
                                                        |
| 1157 | -        $new_mtg->set('MTP_description', $template_description); | 
                                                        |
| 1158 | - // remove ALL relations on this template group so they don't get saved!  | 
                                                        |
| 1159 | -        $new_mtg->_remove_relations('Message_Template'); | 
                                                        |
| 1160 | - $new_mtg->save();  | 
                                                        |
| 1161 | - $success['GRP_ID'] = $new_mtg->ID();  | 
                                                        |
| 1162 | - $success['template_name'] = $template_name;  | 
                                                        |
| 1163 | - // add new message templates and add relation to.  | 
                                                        |
| 1164 | -        foreach ($message_templates as $message_template) { | 
                                                        |
| 1165 | -            if (! $message_template instanceof EE_Message_Template) { | 
                                                        |
| 1166 | - continue;  | 
                                                        |
| 1167 | - }  | 
                                                        |
| 1168 | - $new_message_template = clone $message_template;  | 
                                                        |
| 1169 | -            $new_message_template->set('MTP_ID', 0); | 
                                                        |
| 1170 | -            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation | 
                                                        |
| 1171 | - $new_message_template->save();  | 
                                                        |
| 1172 | -            if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') { | 
                                                        |
| 1173 | -                $success['MTP_context'] = $new_message_template->get('MTP_context'); | 
                                                        |
| 1174 | - }  | 
                                                        |
| 1175 | - }  | 
                                                        |
| 1176 | - return $success;  | 
                                                        |
| 1177 | - }  | 
                                                        |
| 1178 | -  | 
                                                        |
| 1179 | -  | 
                                                        |
| 1180 | - /**  | 
                                                        |
| 1181 | - * message_type_has_active_templates_for_messenger  | 
                                                        |
| 1182 | - *  | 
                                                        |
| 1183 | - * @param EE_messenger $messenger  | 
                                                        |
| 1184 | - * @param EE_message_type $message_type  | 
                                                        |
| 1185 | - * @param bool $global  | 
                                                        |
| 1186 | - * @return bool  | 
                                                        |
| 1187 | - * @throws EE_Error  | 
                                                        |
| 1188 | - */  | 
                                                        |
| 1189 | - public static function message_type_has_active_templates_for_messenger(  | 
                                                        |
| 1190 | - EE_messenger $messenger,  | 
                                                        |
| 1191 | - EE_message_type $message_type,  | 
                                                        |
| 1192 | - $global = false  | 
                                                        |
| 1193 | -    ) { | 
                                                        |
| 1194 | - // is given message_type valid for given messenger (if this is not a global save)  | 
                                                        |
| 1195 | -        if ($global) { | 
                                                        |
| 1196 | - return true;  | 
                                                        |
| 1197 | - }  | 
                                                        |
| 1198 | - $active_templates = EEM_Message_Template_Group::instance()->count(  | 
                                                        |
| 1199 | - array(  | 
                                                        |
| 1200 | - array(  | 
                                                        |
| 1201 | - 'MTP_is_active' => true,  | 
                                                        |
| 1202 | - 'MTP_messenger' => $messenger->name,  | 
                                                        |
| 1203 | - 'MTP_message_type' => $message_type->name  | 
                                                        |
| 1204 | - )  | 
                                                        |
| 1205 | - )  | 
                                                        |
| 1206 | - );  | 
                                                        |
| 1207 | -        if ($active_templates > 0) { | 
                                                        |
| 1208 | - return true;  | 
                                                        |
| 1209 | - }  | 
                                                        |
| 1210 | - EE_Error::add_error(  | 
                                                        |
| 1211 | - sprintf(  | 
                                                        |
| 1212 | - esc_html__(  | 
                                                        |
| 1213 | - 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',  | 
                                                        |
| 1214 | - 'event_espresso'  | 
                                                        |
| 1215 | - ),  | 
                                                        |
| 1216 | - $message_type->name,  | 
                                                        |
| 1217 | - $messenger->name  | 
                                                        |
| 1218 | - ),  | 
                                                        |
| 1219 | - __FILE__,  | 
                                                        |
| 1220 | - __FUNCTION__,  | 
                                                        |
| 1221 | - __LINE__  | 
                                                        |
| 1222 | - );  | 
                                                        |
| 1223 | - return false;  | 
                                                        |
| 1224 | - }  | 
                                                        |
| 1225 | -  | 
                                                        |
| 1226 | -  | 
                                                        |
| 1227 | - /**  | 
                                                        |
| 1228 | - * get_fields  | 
                                                        |
| 1229 | - * This takes a given messenger and message type  | 
                                                        |
| 1230 | - * and returns all the template fields indexed by context with field type.  | 
                                                        |
| 1231 | - *  | 
                                                        |
| 1232 | - * @param string $messenger_name name of EE_messenger  | 
                                                        |
| 1233 | - * @param string $message_type_name name of EE_message_type  | 
                                                        |
| 1234 | - * @param string $current_context current context [optional]  | 
                                                        |
| 1235 | - * @return array  | 
                                                        |
| 1236 | - * @throws EE_Error  | 
                                                        |
| 1237 | - * @throws ReflectionException  | 
                                                        |
| 1238 | - */  | 
                                                        |
| 1239 | - public static function get_fields(  | 
                                                        |
| 1240 | - string $messenger_name,  | 
                                                        |
| 1241 | - string $message_type_name,  | 
                                                        |
| 1242 | - string $current_context = ''  | 
                                                        |
| 1243 | -    ): array { | 
                                                        |
| 1244 | - $template_fields = [];  | 
                                                        |
| 1245 | - /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 1246 | -        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1247 | - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        |
| 1248 | - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        |
| 1249 | -        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { | 
                                                        |
| 1250 | - return [];  | 
                                                        |
| 1251 | - }  | 
                                                        |
| 1252 | -  | 
                                                        |
| 1253 | - $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);  | 
                                                        |
| 1254 | -  | 
                                                        |
| 1255 | - // okay now let's assemble an array with the messenger template fields added to the message_type contexts.  | 
                                                        |
| 1256 | -        foreach ($message_type->get_contexts() as $context => $details) { | 
                                                        |
| 1257 | -            if ($current_context && $current_context !== $context) { | 
                                                        |
| 1258 | - continue;  | 
                                                        |
| 1259 | - }  | 
                                                        |
| 1260 | -            foreach ($messenger->get_template_fields() as $field => $value) { | 
                                                        |
| 1261 | -                if (in_array($field, $excluded_fields_for_messenger, true)) { | 
                                                        |
| 1262 | - continue;  | 
                                                        |
| 1263 | - }  | 
                                                        |
| 1264 | - $template_fields[ $context ][ $field ] = $value;  | 
                                                        |
| 1265 | - }  | 
                                                        |
| 1266 | - }  | 
                                                        |
| 1267 | -        if (empty($template_fields)) { | 
                                                        |
| 1268 | - EE_Error::add_error(  | 
                                                        |
| 1269 | -                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), | 
                                                        |
| 1270 | - __FILE__,  | 
                                                        |
| 1271 | - __FUNCTION__,  | 
                                                        |
| 1272 | - __LINE__  | 
                                                        |
| 1273 | - );  | 
                                                        |
| 1274 | - return [];  | 
                                                        |
| 1275 | - }  | 
                                                        |
| 1276 | - return $template_fields;  | 
                                                        |
| 1277 | - }  | 
                                                        |
| 830 | + }  | 
                                                        |
| 831 | +  | 
                                                        |
| 832 | +  | 
                                                        |
| 833 | +  | 
                                                        |
| 834 | +  | 
                                                        |
| 835 | +  | 
                                                        |
| 836 | + /**  | 
                                                        |
| 837 | + * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).  | 
                                                        |
| 838 | + *  | 
                                                        |
| 839 | + * @since 4.9.0  | 
                                                        |
| 840 | + * @return array  | 
                                                        |
| 841 | + */  | 
                                                        |
| 842 | + public static function reg_status_to_message_type_array()  | 
                                                        |
| 843 | +	{ | 
                                                        |
| 844 | + return (array) apply_filters(  | 
                                                        |
| 845 | + 'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',  | 
                                                        |
| 846 | + array(  | 
                                                        |
| 847 | + EEM_Registration::status_id_approved => 'registration',  | 
                                                        |
| 848 | + EEM_Registration::status_id_pending_payment => 'pending_approval',  | 
                                                        |
| 849 | + EEM_Registration::status_id_not_approved => 'not_approved_registration',  | 
                                                        |
| 850 | + EEM_Registration::status_id_cancelled => 'cancelled_registration',  | 
                                                        |
| 851 | + EEM_Registration::status_id_declined => 'declined_registration'  | 
                                                        |
| 852 | + )  | 
                                                        |
| 853 | + );  | 
                                                        |
| 854 | + }  | 
                                                        |
| 855 | +  | 
                                                        |
| 856 | +  | 
                                                        |
| 857 | +  | 
                                                        |
| 858 | +  | 
                                                        |
| 859 | + /**  | 
                                                        |
| 860 | + * This returns the corresponding registration message type slug to the given reg status. If there isn't a  | 
                                                        |
| 861 | + * match, then returns an empty string.  | 
                                                        |
| 862 | + *  | 
                                                        |
| 863 | + * @since 4.9.0  | 
                                                        |
| 864 | + * @param $reg_status  | 
                                                        |
| 865 | + * @return string  | 
                                                        |
| 866 | + */  | 
                                                        |
| 867 | + public static function convert_reg_status_to_message_type($reg_status)  | 
                                                        |
| 868 | +	{ | 
                                                        |
| 869 | + $reg_status_array = self::reg_status_to_message_type_array();  | 
                                                        |
| 870 | + return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';  | 
                                                        |
| 871 | + }  | 
                                                        |
| 872 | +  | 
                                                        |
| 873 | +  | 
                                                        |
| 874 | + /**  | 
                                                        |
| 875 | + * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).  | 
                                                        |
| 876 | + *  | 
                                                        |
| 877 | + * @since 4.9.0  | 
                                                        |
| 878 | + * @return array  | 
                                                        |
| 879 | + */  | 
                                                        |
| 880 | + public static function payment_status_to_message_type_array()  | 
                                                        |
| 881 | +	{ | 
                                                        |
| 882 | + return (array) apply_filters(  | 
                                                        |
| 883 | + 'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',  | 
                                                        |
| 884 | + array(  | 
                                                        |
| 885 | + EEM_Payment::status_id_approved => 'payment',  | 
                                                        |
| 886 | + EEM_Payment::status_id_pending => 'payment_pending',  | 
                                                        |
| 887 | + EEM_Payment::status_id_cancelled => 'payment_cancelled',  | 
                                                        |
| 888 | + EEM_Payment::status_id_declined => 'payment_declined',  | 
                                                        |
| 889 | + EEM_Payment::status_id_failed => 'payment_failed'  | 
                                                        |
| 890 | + )  | 
                                                        |
| 891 | + );  | 
                                                        |
| 892 | + }  | 
                                                        |
| 893 | +  | 
                                                        |
| 894 | +  | 
                                                        |
| 895 | +  | 
                                                        |
| 896 | +  | 
                                                        |
| 897 | + /**  | 
                                                        |
| 898 | + * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then  | 
                                                        |
| 899 | + * an empty string is returned  | 
                                                        |
| 900 | + *  | 
                                                        |
| 901 | + * @since 4.9.0  | 
                                                        |
| 902 | + * @param $payment_status  | 
                                                        |
| 903 | + * @return string  | 
                                                        |
| 904 | + */  | 
                                                        |
| 905 | + public static function convert_payment_status_to_message_type($payment_status)  | 
                                                        |
| 906 | +	{ | 
                                                        |
| 907 | + $payment_status_array = self::payment_status_to_message_type_array();  | 
                                                        |
| 908 | + return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';  | 
                                                        |
| 909 | + }  | 
                                                        |
| 910 | +  | 
                                                        |
| 911 | +  | 
                                                        |
| 912 | + /**  | 
                                                        |
| 913 | + * This is used to retrieve the template pack for the given name.  | 
                                                        |
| 914 | + *  | 
                                                        |
| 915 | + * @param string $template_pack_name should match the set `dbref` property value on the EE_Messages_Template_Pack.  | 
                                                        |
| 916 | + *  | 
                                                        |
| 917 | + * @return EE_Messages_Template_Pack  | 
                                                        |
| 918 | + */  | 
                                                        |
| 919 | + public static function get_template_pack($template_pack_name)  | 
                                                        |
| 920 | +	{ | 
                                                        |
| 921 | +		if (! self::$_template_pack_collection instanceof EE_Object_Collection) { | 
                                                        |
| 922 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        |
| 923 | + }  | 
                                                        |
| 924 | +  | 
                                                        |
| 925 | + // first see if in collection already  | 
                                                        |
| 926 | + $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);  | 
                                                        |
| 927 | +  | 
                                                        |
| 928 | +		if ($template_pack instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 929 | + return $template_pack;  | 
                                                        |
| 930 | + }  | 
                                                        |
| 931 | +  | 
                                                        |
| 932 | + // nope...let's get it.  | 
                                                        |
| 933 | + // not set yet so let's attempt to get it.  | 
                                                        |
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 935 | + ' ',  | 
                                                        |
| 936 | + '_',  | 
                                                        |
| 937 | + ucwords(  | 
                                                        |
| 938 | +				str_replace('_', ' ', $template_pack_name) | 
                                                        |
| 939 | + )  | 
                                                        |
| 940 | + );  | 
                                                        |
| 941 | +		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { | 
                                                        |
| 942 | +			return self::get_template_pack('default'); | 
                                                        |
| 943 | +		} else { | 
                                                        |
| 944 | + $template_pack = new $pack_class_name();  | 
                                                        |
| 945 | + self::$_template_pack_collection->add($template_pack);  | 
                                                        |
| 946 | + return $template_pack;  | 
                                                        |
| 947 | + }  | 
                                                        |
| 948 | + }  | 
                                                        |
| 949 | +  | 
                                                        |
| 950 | +  | 
                                                        |
| 951 | +  | 
                                                        |
| 952 | +  | 
                                                        |
| 953 | + /**  | 
                                                        |
| 954 | + * Globs template packs installed in core and returns the template pack collection with all installed template packs  | 
                                                        |
| 955 | + * in it.  | 
                                                        |
| 956 | + *  | 
                                                        |
| 957 | + * @since 4.9.0  | 
                                                        |
| 958 | + *  | 
                                                        |
| 959 | + * @return EE_Messages_Template_Pack_Collection  | 
                                                        |
| 960 | + */  | 
                                                        |
| 961 | + public static function get_template_pack_collection()  | 
                                                        |
| 962 | +	{ | 
                                                        |
| 963 | + $new_collection = false;  | 
                                                        |
| 964 | +		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { | 
                                                        |
| 965 | + self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        |
| 966 | + $new_collection = true;  | 
                                                        |
| 967 | + }  | 
                                                        |
| 968 | +  | 
                                                        |
| 969 | + // glob the defaults directory for messages  | 
                                                        |
| 970 | + $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);  | 
                                                        |
| 971 | +		foreach ($templates as $template_path) { | 
                                                        |
| 972 | + // grab folder name  | 
                                                        |
| 973 | + $template = basename($template_path);  | 
                                                        |
| 974 | +  | 
                                                        |
| 975 | +			if (! $new_collection) { | 
                                                        |
| 976 | + // already have it?  | 
                                                        |
| 977 | +				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { | 
                                                        |
| 978 | + continue;  | 
                                                        |
| 979 | + }  | 
                                                        |
| 980 | + }  | 
                                                        |
| 981 | +  | 
                                                        |
| 982 | + // setup classname.  | 
                                                        |
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 984 | + ' ',  | 
                                                        |
| 985 | + '_',  | 
                                                        |
| 986 | + ucwords(  | 
                                                        |
| 987 | + str_replace(  | 
                                                        |
| 988 | + '_',  | 
                                                        |
| 989 | + ' ',  | 
                                                        |
| 990 | + $template  | 
                                                        |
| 991 | + )  | 
                                                        |
| 992 | + )  | 
                                                        |
| 993 | + );  | 
                                                        |
| 994 | +			if (! class_exists($template_pack_class_name)) { | 
                                                        |
| 995 | + continue;  | 
                                                        |
| 996 | + }  | 
                                                        |
| 997 | + self::$_template_pack_collection->add(new $template_pack_class_name());  | 
                                                        |
| 998 | + }  | 
                                                        |
| 999 | +  | 
                                                        |
| 1000 | + /**  | 
                                                        |
| 1001 | + * Filter for plugins to add in any additional template packs  | 
                                                        |
| 1002 | + * Note the filter name here is for backward compat, this used to be found in EED_Messages.  | 
                                                        |
| 1003 | + */  | 
                                                        |
| 1004 | +		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array()); | 
                                                        |
| 1005 | +		foreach ((array) $additional_template_packs as $template_pack) { | 
                                                        |
| 1006 | + if (  | 
                                                        |
| 1007 | + self::$_template_pack_collection->get_by_name(  | 
                                                        |
| 1008 | + $template_pack->dbref  | 
                                                        |
| 1009 | + ) instanceof EE_Messages_Template_Pack  | 
                                                        |
| 1010 | +			) { | 
                                                        |
| 1011 | + continue;  | 
                                                        |
| 1012 | + }  | 
                                                        |
| 1013 | + self::$_template_pack_collection->add($template_pack);  | 
                                                        |
| 1014 | + }  | 
                                                        |
| 1015 | + return self::$_template_pack_collection;  | 
                                                        |
| 1016 | + }  | 
                                                        |
| 1017 | +  | 
                                                        |
| 1018 | +  | 
                                                        |
| 1019 | + /**  | 
                                                        |
| 1020 | + * This is a wrapper for the protected _create_new_templates function  | 
                                                        |
| 1021 | + *  | 
                                                        |
| 1022 | + * @param string $messenger_name  | 
                                                        |
| 1023 | + * @param string $message_type_name message type that the templates are being created for  | 
                                                        |
| 1024 | + * @param int $GRP_ID  | 
                                                        |
| 1025 | + * @param bool $global  | 
                                                        |
| 1026 | + * @return array  | 
                                                        |
| 1027 | + * @throws EE_Error  | 
                                                        |
| 1028 | + * @throws ReflectionException  | 
                                                        |
| 1029 | + */  | 
                                                        |
| 1030 | + public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)  | 
                                                        |
| 1031 | +	{ | 
                                                        |
| 1032 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 1033 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1034 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        |
| 1035 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        |
| 1036 | +		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { | 
                                                        |
| 1037 | + return array();  | 
                                                        |
| 1038 | + }  | 
                                                        |
| 1039 | + // whew made it this far! Okay, let's go ahead and create the templates then  | 
                                                        |
| 1040 | + return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);  | 
                                                        |
| 1041 | + }  | 
                                                        |
| 1042 | +  | 
                                                        |
| 1043 | +  | 
                                                        |
| 1044 | + /**  | 
                                                        |
| 1045 | + * @param EE_messenger $messenger  | 
                                                        |
| 1046 | + * @param EE_message_type $message_type  | 
                                                        |
| 1047 | + * @param $GRP_ID  | 
                                                        |
| 1048 | + * @param $global  | 
                                                        |
| 1049 | + * @return array|mixed  | 
                                                        |
| 1050 | + * @throws EE_Error  | 
                                                        |
| 1051 | + * @throws ReflectionException  | 
                                                        |
| 1052 | + */  | 
                                                        |
| 1053 | + protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)  | 
                                                        |
| 1054 | +	{ | 
                                                        |
| 1055 | + // if we're creating a custom template then we don't need to use the defaults class  | 
                                                        |
| 1056 | +		if (! $global) { | 
                                                        |
| 1057 | + return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);  | 
                                                        |
| 1058 | + }  | 
                                                        |
| 1059 | + /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */  | 
                                                        |
| 1060 | + $Message_Template_Defaults = EE_Registry::factory(  | 
                                                        |
| 1061 | + 'EE_Messages_Template_Defaults',  | 
                                                        |
| 1062 | + array( $messenger, $message_type, $GRP_ID )  | 
                                                        |
| 1063 | + );  | 
                                                        |
| 1064 | + // generate templates  | 
                                                        |
| 1065 | + $success = $Message_Template_Defaults->create_new_templates();  | 
                                                        |
| 1066 | +  | 
                                                        |
| 1067 | + // if creating the template failed. Then we should deactivate the related message_type for the messenger because  | 
                                                        |
| 1068 | + // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation  | 
                                                        |
| 1069 | + // attempts.  | 
                                                        |
| 1070 | +		if (! $success) { | 
                                                        |
| 1071 | + /** @var EE_Message_Resource_Manager $message_resource_manager */  | 
                                                        |
| 1072 | +			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1073 | + $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);  | 
                                                        |
| 1074 | + }  | 
                                                        |
| 1075 | +  | 
                                                        |
| 1076 | + /**  | 
                                                        |
| 1077 | + * $success is in an array in the following format  | 
                                                        |
| 1078 | + * array(  | 
                                                        |
| 1079 | + * 'GRP_ID' => $new_grp_id,  | 
                                                        |
| 1080 | + * 'MTP_context' => $first_context_in_new_templates,  | 
                                                        |
| 1081 | + * )  | 
                                                        |
| 1082 | + */  | 
                                                        |
| 1083 | + return $success;  | 
                                                        |
| 1084 | + }  | 
                                                        |
| 1085 | +  | 
                                                        |
| 1086 | +  | 
                                                        |
| 1087 | + /**  | 
                                                        |
| 1088 | + * This creates a custom template using the incoming GRP_ID  | 
                                                        |
| 1089 | + *  | 
                                                        |
| 1090 | + * @param EE_messenger $messenger  | 
                                                        |
| 1091 | + * @param EE_message_type $message_type  | 
                                                        |
| 1092 | + * @param int $GRP_ID GRP_ID for the template_group being used as the base  | 
                                                        |
| 1093 | + * @return array $success This will be an array in the format:  | 
                                                        |
| 1094 | + * array(  | 
                                                        |
| 1095 | + * 'GRP_ID' => $new_grp_id,  | 
                                                        |
| 1096 | + * 'MTP_context' => $first_context_in_created_template  | 
                                                        |
| 1097 | + * )  | 
                                                        |
| 1098 | + * @throws EE_Error  | 
                                                        |
| 1099 | + * @throws ReflectionException  | 
                                                        |
| 1100 | + * @access private  | 
                                                        |
| 1101 | + */  | 
                                                        |
| 1102 | + private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)  | 
                                                        |
| 1103 | +	{ | 
                                                        |
| 1104 | + // defaults  | 
                                                        |
| 1105 | + $success = array( 'GRP_ID' => null, 'MTP_context' => '' );  | 
                                                        |
| 1106 | + // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.  | 
                                                        |
| 1107 | + $Message_Template_Group = empty($GRP_ID)  | 
                                                        |
| 1108 | + ? EEM_Message_Template_Group::instance()->get_one(  | 
                                                        |
| 1109 | + array(  | 
                                                        |
| 1110 | + array(  | 
                                                        |
| 1111 | + 'MTP_messenger' => $messenger->name,  | 
                                                        |
| 1112 | + 'MTP_message_type' => $message_type->name,  | 
                                                        |
| 1113 | + 'MTP_is_global' => true  | 
                                                        |
| 1114 | + )  | 
                                                        |
| 1115 | + )  | 
                                                        |
| 1116 | + )  | 
                                                        |
| 1117 | + : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);  | 
                                                        |
| 1118 | + // if we don't have a mtg at this point then we need to bail.  | 
                                                        |
| 1119 | +		if (! $Message_Template_Group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1120 | + EE_Error::add_error(  | 
                                                        |
| 1121 | + sprintf(  | 
                                                        |
| 1122 | + esc_html__(  | 
                                                        |
| 1123 | + 'Something went wrong with generating the custom template from this group id: %s. This usually happens when there is no matching message template group in the db.',  | 
                                                        |
| 1124 | + 'event_espresso'  | 
                                                        |
| 1125 | + ),  | 
                                                        |
| 1126 | + $GRP_ID  | 
                                                        |
| 1127 | + ),  | 
                                                        |
| 1128 | + __FILE__,  | 
                                                        |
| 1129 | + __FUNCTION__,  | 
                                                        |
| 1130 | + __LINE__  | 
                                                        |
| 1131 | + );  | 
                                                        |
| 1132 | + return $success;  | 
                                                        |
| 1133 | + }  | 
                                                        |
| 1134 | + // let's get all the related message_template objects for this group.  | 
                                                        |
| 1135 | + $message_templates = $Message_Template_Group->message_templates();  | 
                                                        |
| 1136 | + // now we have what we need to setup the new template  | 
                                                        |
| 1137 | + $new_mtg = clone $Message_Template_Group;  | 
                                                        |
| 1138 | +		$new_mtg->set('GRP_ID', 0); | 
                                                        |
| 1139 | +		$new_mtg->set('MTP_is_global', false); | 
                                                        |
| 1140 | +  | 
                                                        |
| 1141 | + /** @var RequestInterface $request */  | 
                                                        |
| 1142 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);  | 
                                                        |
| 1143 | +		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName') | 
                                                        |
| 1144 | +			? $request->getRequestParam('templateName') | 
                                                        |
| 1145 | +			: esc_html__('New Custom Template', 'event_espresso'); | 
                                                        |
| 1146 | +		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription') | 
                                                        |
| 1147 | +			? $request->getRequestParam('templateDescription') | 
                                                        |
| 1148 | + : sprintf(  | 
                                                        |
| 1149 | + esc_html__(  | 
                                                        |
| 1150 | + 'This is a custom template that was created for the %s messenger and %s message type.',  | 
                                                        |
| 1151 | + 'event_espresso'  | 
                                                        |
| 1152 | + ),  | 
                                                        |
| 1153 | + $new_mtg->messenger_obj()->label['singular'],  | 
                                                        |
| 1154 | + $new_mtg->message_type_obj()->label['singular']  | 
                                                        |
| 1155 | + );  | 
                                                        |
| 1156 | +		$new_mtg->set('MTP_name', $template_name); | 
                                                        |
| 1157 | +		$new_mtg->set('MTP_description', $template_description); | 
                                                        |
| 1158 | + // remove ALL relations on this template group so they don't get saved!  | 
                                                        |
| 1159 | +		$new_mtg->_remove_relations('Message_Template'); | 
                                                        |
| 1160 | + $new_mtg->save();  | 
                                                        |
| 1161 | + $success['GRP_ID'] = $new_mtg->ID();  | 
                                                        |
| 1162 | + $success['template_name'] = $template_name;  | 
                                                        |
| 1163 | + // add new message templates and add relation to.  | 
                                                        |
| 1164 | +		foreach ($message_templates as $message_template) { | 
                                                        |
| 1165 | +			if (! $message_template instanceof EE_Message_Template) { | 
                                                        |
| 1166 | + continue;  | 
                                                        |
| 1167 | + }  | 
                                                        |
| 1168 | + $new_message_template = clone $message_template;  | 
                                                        |
| 1169 | +			$new_message_template->set('MTP_ID', 0); | 
                                                        |
| 1170 | +			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation | 
                                                        |
| 1171 | + $new_message_template->save();  | 
                                                        |
| 1172 | +			if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') { | 
                                                        |
| 1173 | +				$success['MTP_context'] = $new_message_template->get('MTP_context'); | 
                                                        |
| 1174 | + }  | 
                                                        |
| 1175 | + }  | 
                                                        |
| 1176 | + return $success;  | 
                                                        |
| 1177 | + }  | 
                                                        |
| 1178 | +  | 
                                                        |
| 1179 | +  | 
                                                        |
| 1180 | + /**  | 
                                                        |
| 1181 | + * message_type_has_active_templates_for_messenger  | 
                                                        |
| 1182 | + *  | 
                                                        |
| 1183 | + * @param EE_messenger $messenger  | 
                                                        |
| 1184 | + * @param EE_message_type $message_type  | 
                                                        |
| 1185 | + * @param bool $global  | 
                                                        |
| 1186 | + * @return bool  | 
                                                        |
| 1187 | + * @throws EE_Error  | 
                                                        |
| 1188 | + */  | 
                                                        |
| 1189 | + public static function message_type_has_active_templates_for_messenger(  | 
                                                        |
| 1190 | + EE_messenger $messenger,  | 
                                                        |
| 1191 | + EE_message_type $message_type,  | 
                                                        |
| 1192 | + $global = false  | 
                                                        |
| 1193 | +	) { | 
                                                        |
| 1194 | + // is given message_type valid for given messenger (if this is not a global save)  | 
                                                        |
| 1195 | +		if ($global) { | 
                                                        |
| 1196 | + return true;  | 
                                                        |
| 1197 | + }  | 
                                                        |
| 1198 | + $active_templates = EEM_Message_Template_Group::instance()->count(  | 
                                                        |
| 1199 | + array(  | 
                                                        |
| 1200 | + array(  | 
                                                        |
| 1201 | + 'MTP_is_active' => true,  | 
                                                        |
| 1202 | + 'MTP_messenger' => $messenger->name,  | 
                                                        |
| 1203 | + 'MTP_message_type' => $message_type->name  | 
                                                        |
| 1204 | + )  | 
                                                        |
| 1205 | + )  | 
                                                        |
| 1206 | + );  | 
                                                        |
| 1207 | +		if ($active_templates > 0) { | 
                                                        |
| 1208 | + return true;  | 
                                                        |
| 1209 | + }  | 
                                                        |
| 1210 | + EE_Error::add_error(  | 
                                                        |
| 1211 | + sprintf(  | 
                                                        |
| 1212 | + esc_html__(  | 
                                                        |
| 1213 | + 'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',  | 
                                                        |
| 1214 | + 'event_espresso'  | 
                                                        |
| 1215 | + ),  | 
                                                        |
| 1216 | + $message_type->name,  | 
                                                        |
| 1217 | + $messenger->name  | 
                                                        |
| 1218 | + ),  | 
                                                        |
| 1219 | + __FILE__,  | 
                                                        |
| 1220 | + __FUNCTION__,  | 
                                                        |
| 1221 | + __LINE__  | 
                                                        |
| 1222 | + );  | 
                                                        |
| 1223 | + return false;  | 
                                                        |
| 1224 | + }  | 
                                                        |
| 1225 | +  | 
                                                        |
| 1226 | +  | 
                                                        |
| 1227 | + /**  | 
                                                        |
| 1228 | + * get_fields  | 
                                                        |
| 1229 | + * This takes a given messenger and message type  | 
                                                        |
| 1230 | + * and returns all the template fields indexed by context with field type.  | 
                                                        |
| 1231 | + *  | 
                                                        |
| 1232 | + * @param string $messenger_name name of EE_messenger  | 
                                                        |
| 1233 | + * @param string $message_type_name name of EE_message_type  | 
                                                        |
| 1234 | + * @param string $current_context current context [optional]  | 
                                                        |
| 1235 | + * @return array  | 
                                                        |
| 1236 | + * @throws EE_Error  | 
                                                        |
| 1237 | + * @throws ReflectionException  | 
                                                        |
| 1238 | + */  | 
                                                        |
| 1239 | + public static function get_fields(  | 
                                                        |
| 1240 | + string $messenger_name,  | 
                                                        |
| 1241 | + string $message_type_name,  | 
                                                        |
| 1242 | + string $current_context = ''  | 
                                                        |
| 1243 | +	): array { | 
                                                        |
| 1244 | + $template_fields = [];  | 
                                                        |
| 1245 | + /** @type EE_Message_Resource_Manager $Message_Resource_Manager */  | 
                                                        |
| 1246 | +		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        |
| 1247 | + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        |
| 1248 | + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        |
| 1249 | +		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { | 
                                                        |
| 1250 | + return [];  | 
                                                        |
| 1251 | + }  | 
                                                        |
| 1252 | +  | 
                                                        |
| 1253 | + $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);  | 
                                                        |
| 1254 | +  | 
                                                        |
| 1255 | + // okay now let's assemble an array with the messenger template fields added to the message_type contexts.  | 
                                                        |
| 1256 | +		foreach ($message_type->get_contexts() as $context => $details) { | 
                                                        |
| 1257 | +			if ($current_context && $current_context !== $context) { | 
                                                        |
| 1258 | + continue;  | 
                                                        |
| 1259 | + }  | 
                                                        |
| 1260 | +			foreach ($messenger->get_template_fields() as $field => $value) { | 
                                                        |
| 1261 | +				if (in_array($field, $excluded_fields_for_messenger, true)) { | 
                                                        |
| 1262 | + continue;  | 
                                                        |
| 1263 | + }  | 
                                                        |
| 1264 | + $template_fields[ $context ][ $field ] = $value;  | 
                                                        |
| 1265 | + }  | 
                                                        |
| 1266 | + }  | 
                                                        |
| 1267 | +		if (empty($template_fields)) { | 
                                                        |
| 1268 | + EE_Error::add_error(  | 
                                                        |
| 1269 | +				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'), | 
                                                        |
| 1270 | + __FILE__,  | 
                                                        |
| 1271 | + __FUNCTION__,  | 
                                                        |
| 1272 | + __LINE__  | 
                                                        |
| 1273 | + );  | 
                                                        |
| 1274 | + return [];  | 
                                                        |
| 1275 | + }  | 
                                                        |
| 1276 | + return $template_fields;  | 
                                                        |
| 1277 | + }  | 
                                                        |
| 1278 | 1278 | }  | 
                                                        
@@ -95,7 +95,7 @@ discard block  | 
                                                    ||
| 95 | 95 | }  | 
                                                        
| 96 | 96 | $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);  | 
                                                        
| 97 | 97 | |
| 98 | -            if (! $new_message_template_group) { | 
                                                        |
| 98 | +            if ( ! $new_message_template_group) { | 
                                                        |
| 99 | 99 | continue;  | 
                                                        
| 100 | 100 | }  | 
                                                        
| 101 | 101 | $templates[] = $new_message_template_group;  | 
                                                        
@@ -130,7 +130,7 @@ discard block  | 
                                                    ||
| 130 | 130 | )  | 
                                                        
| 131 | 131 | )  | 
                                                        
| 132 | 132 | )  | 
                                                        
| 133 | - : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));  | 
                                                        |
| 133 | +            : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID))); | 
                                                        |
| 134 | 134 | |
| 135 | 135 | return $count > 0;  | 
                                                        
| 136 | 136 | }  | 
                                                        
@@ -147,14 +147,14 @@ discard block  | 
                                                    ||
| 147 | 147 | */  | 
                                                        
| 148 | 148 | public static function update_to_active($messenger_names, $message_type_names)  | 
                                                        
| 149 | 149 |      { | 
                                                        
| 150 | - $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );  | 
                                                        |
| 151 | - $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );  | 
                                                        |
| 150 | + $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names);  | 
                                                        |
| 151 | + $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names);  | 
                                                        |
| 152 | 152 | return EEM_Message_Template_Group::instance()->update(  | 
                                                        
| 153 | - array( 'MTP_is_active' => 1 ),  | 
                                                        |
| 153 | +            array('MTP_is_active' => 1), | 
                                                        |
| 154 | 154 | array(  | 
                                                        
| 155 | 155 | array(  | 
                                                        
| 156 | - 'MTP_messenger' => array( 'IN', $messenger_names ),  | 
                                                        |
| 157 | - 'MTP_message_type' => array( 'IN', $message_type_names )  | 
                                                        |
| 156 | +                    'MTP_messenger'     => array('IN', $messenger_names), | 
                                                        |
| 157 | +                    'MTP_message_type'  => array('IN', $message_type_names) | 
                                                        |
| 158 | 158 | )  | 
                                                        
| 159 | 159 | )  | 
                                                        
| 160 | 160 | );  | 
                                                        
@@ -242,13 +242,13 @@ discard block  | 
                                                    ||
| 242 | 242 | $messenger = $message_resource_manager->get_messenger($messenger);  | 
                                                        
| 243 | 243 | |
| 244 | 244 | // if messenger isn't a EE_messenger resource then bail.  | 
                                                        
| 245 | -        if (! $messenger instanceof EE_messenger) { | 
                                                        |
| 245 | +        if ( ! $messenger instanceof EE_messenger) { | 
                                                        |
| 246 | 246 | return array();  | 
                                                        
| 247 | 247 | }  | 
                                                        
| 248 | 248 | |
| 249 | 249 | // validate class for getting our list of shortcodes  | 
                                                        
| 250 | - $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';  | 
                                                        |
| 251 | -        if (! class_exists($classname)) { | 
                                                        |
| 250 | + $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator';  | 
                                                        |
| 251 | +        if ( ! class_exists($classname)) { | 
                                                        |
| 252 | 252 |              $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso'); | 
                                                        
| 253 | 253 | $msg[] = sprintf(  | 
                                                        
| 254 | 254 |                  esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'), | 
                                                        
@@ -264,44 +264,44 @@ discard block  | 
                                                    ||
| 264 | 264 | // let's make sure we're only getting the shortcode part of the validators  | 
                                                        
| 265 | 265 | $shortcodes = array();  | 
                                                        
| 266 | 266 |          foreach ($valid_shortcodes as $field => $validators) { | 
                                                        
| 267 | - $shortcodes[ $field ] = $validators['shortcodes'];  | 
                                                        |
| 267 | + $shortcodes[$field] = $validators['shortcodes'];  | 
                                                        |
| 268 | 268 | }  | 
                                                        
| 269 | 269 | $valid_shortcodes = $shortcodes;  | 
                                                        
| 270 | 270 | |
| 271 | 271 | // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.  | 
                                                        
| 272 | -        if (! empty($fields)) { | 
                                                        |
| 272 | +        if ( ! empty($fields)) { | 
                                                        |
| 273 | 273 | $specified_shortcodes = array();  | 
                                                        
| 274 | 274 |              foreach ($fields as $field) { | 
                                                        
| 275 | -                if (isset($valid_shortcodes[ $field ])) { | 
                                                        |
| 276 | - $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];  | 
                                                        |
| 275 | +                if (isset($valid_shortcodes[$field])) { | 
                                                        |
| 276 | + $specified_shortcodes[$field] = $valid_shortcodes[$field];  | 
                                                        |
| 277 | 277 | }  | 
                                                        
| 278 | 278 | }  | 
                                                        
| 279 | 279 | $valid_shortcodes = $specified_shortcodes;  | 
                                                        
| 280 | 280 | }  | 
                                                        
| 281 | 281 | |
| 282 | 282 | // if not merged then let's replace the fields with the localized fields  | 
                                                        
| 283 | -        if (! $merged) { | 
                                                        |
| 283 | +        if ( ! $merged) { | 
                                                        |
| 284 | 284 | // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.  | 
                                                        
| 285 | 285 | $field_settings = $messenger->get_template_fields();  | 
                                                        
| 286 | 286 | $localized = array();  | 
                                                        
| 287 | 287 |              foreach ($valid_shortcodes as $field => $shortcodes) { | 
                                                        
| 288 | 288 | // get localized field label  | 
                                                        
| 289 | -                if (isset($field_settings[ $field ])) { | 
                                                        |
| 289 | +                if (isset($field_settings[$field])) { | 
                                                        |
| 290 | 290 | // possible that this is used as a main field.  | 
                                                        
| 291 | -                    if (empty($field_settings[ $field ])) { | 
                                                        |
| 292 | -                        if (isset($field_settings['extra'][ $field ])) { | 
                                                        |
| 293 | - $_field = $field_settings['extra'][ $field ]['main']['label'];  | 
                                                        |
| 291 | +                    if (empty($field_settings[$field])) { | 
                                                        |
| 292 | +                        if (isset($field_settings['extra'][$field])) { | 
                                                        |
| 293 | + $_field = $field_settings['extra'][$field]['main']['label'];  | 
                                                        |
| 294 | 294 |                          } else { | 
                                                        
| 295 | 295 | $_field = $field;  | 
                                                        
| 296 | 296 | }  | 
                                                        
| 297 | 297 |                      } else { | 
                                                        
| 298 | - $_field = $field_settings[ $field ]['label'];  | 
                                                        |
| 298 | + $_field = $field_settings[$field]['label'];  | 
                                                        |
| 299 | 299 | }  | 
                                                        
| 300 | 300 |                  } elseif (isset($field_settings['extra'])) { | 
                                                        
| 301 | 301 | // loop through extra "main fields" and see if any of their children have our field  | 
                                                        
| 302 | 302 |                      foreach ($field_settings['extra'] as $fields) { | 
                                                        
| 303 | -                        if (isset($fields[ $field ])) { | 
                                                        |
| 304 | - $_field = $fields[ $field ]['label'];  | 
                                                        |
| 303 | +                        if (isset($fields[$field])) { | 
                                                        |
| 304 | + $_field = $fields[$field]['label'];  | 
                                                        |
| 305 | 305 |                          } else { | 
                                                        
| 306 | 306 | $_field = $field;  | 
                                                        
| 307 | 307 | }  | 
                                                        
@@ -310,7 +310,7 @@ discard block  | 
                                                    ||
| 310 | 310 | $_field = $field;  | 
                                                        
| 311 | 311 | }  | 
                                                        
| 312 | 312 |                  if (isset($_field)) { | 
                                                        
| 313 | - $localized[ (string) $_field ] = $shortcodes;  | 
                                                        |
| 313 | + $localized[(string) $_field] = $shortcodes;  | 
                                                        |
| 314 | 314 | }  | 
                                                        
| 315 | 315 | }  | 
                                                        
| 316 | 316 | $valid_shortcodes = $localized;  | 
                                                        
@@ -321,10 +321,10 @@ discard block  | 
                                                    ||
| 321 | 321 | $merged_codes = array();  | 
                                                        
| 322 | 322 |              foreach ($valid_shortcodes as $shortcode) { | 
                                                        
| 323 | 323 |                  foreach ($shortcode as $code => $label) { | 
                                                        
| 324 | -                    if (isset($merged_codes[ $code ])) { | 
                                                        |
| 324 | +                    if (isset($merged_codes[$code])) { | 
                                                        |
| 325 | 325 | continue;  | 
                                                        
| 326 | 326 |                      } else { | 
                                                        
| 327 | - $merged_codes[ $code ] = $label;  | 
                                                        |
| 327 | + $merged_codes[$code] = $label;  | 
                                                        |
| 328 | 328 | }  | 
                                                        
| 329 | 329 | }  | 
                                                        
| 330 | 330 | }  | 
                                                        
@@ -475,12 +475,12 @@ discard block  | 
                                                    ||
| 475 | 475 | $sending_messenger = ''  | 
                                                        
| 476 | 476 |      ) { | 
                                                        
| 477 | 477 | // first determine if the url can be to the EE_Message object.  | 
                                                        
| 478 | -        if (! $message_type->always_generate()) { | 
                                                        |
| 478 | +        if ( ! $message_type->always_generate()) { | 
                                                        |
| 479 | 479 | return EEH_MSG_Template::generate_browser_trigger($message);  | 
                                                        
| 480 | 480 | }  | 
                                                        
| 481 | 481 | |
| 482 | 482 | // if $registration object is not valid then exit early because there's nothing that can be generated.  | 
                                                        
| 483 | -        if (! $registration instanceof EE_Registration) { | 
                                                        |
| 483 | +        if ( ! $registration instanceof EE_Registration) { | 
                                                        |
| 484 | 484 | throw new EE_Error(  | 
                                                        
| 485 | 485 |                  esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso') | 
                                                        
| 486 | 486 | );  | 
                                                        
@@ -488,7 +488,7 @@ discard block  | 
                                                    ||
| 488 | 488 | |
| 489 | 489 | // validate given context  | 
                                                        
| 490 | 490 | $contexts = $message_type->get_contexts();  | 
                                                        
| 491 | -        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) { | 
                                                        |
| 491 | +        if ($message->context() !== '' && ! isset($contexts[$message->context()])) { | 
                                                        |
| 492 | 492 | throw new EE_Error(  | 
                                                        
| 493 | 493 | sprintf(  | 
                                                        
| 494 | 494 |                      esc_html__('The context %s is not a valid context for %s.', 'event_espresso'), | 
                                                        
@@ -499,11 +499,11 @@ discard block  | 
                                                    ||
| 499 | 499 | }  | 
                                                        
| 500 | 500 | |
| 501 | 501 | // valid sending messenger but only if sending messenger set. Otherwise generating messenger is used.  | 
                                                        
| 502 | -        if (! empty($sending_messenger)) { | 
                                                        |
| 502 | +        if ( ! empty($sending_messenger)) { | 
                                                        |
| 503 | 503 | $with_messengers = $message_type->with_messengers();  | 
                                                        
| 504 | 504 | if (  | 
                                                        
| 505 | - ! isset($with_messengers[ $message->messenger() ])  | 
                                                        |
| 506 | - || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])  | 
                                                        |
| 505 | + ! isset($with_messengers[$message->messenger()])  | 
                                                        |
| 506 | + || ! in_array($sending_messenger, $with_messengers[$message->messenger()])  | 
                                                        |
| 507 | 507 |              ) { | 
                                                        
| 508 | 508 | throw new EE_Error(  | 
                                                        
| 509 | 509 | sprintf(  | 
                                                        
@@ -636,7 +636,7 @@ discard block  | 
                                                    ||
| 636 | 636 | public static function get_message_action_icon($type)  | 
                                                        
| 637 | 637 |      { | 
                                                        
| 638 | 638 | $action_icons = self::get_message_action_icons();  | 
                                                        
| 639 | - return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];  | 
                                                        |
| 639 | + return isset($action_icons[$type]) ? $action_icons[$type] : [];  | 
                                                        |
| 640 | 640 | }  | 
                                                        
| 641 | 641 | |
| 642 | 642 | |
@@ -701,7 +701,7 @@ discard block  | 
                                                    ||
| 701 | 701 | public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())  | 
                                                        
| 702 | 702 |      { | 
                                                        
| 703 | 703 | $action_urls = self::get_message_action_urls($message, $query_params);  | 
                                                        
| 704 | - return isset($action_urls[ $type ]) ? $action_urls[ $type ] : '';  | 
                                                        |
| 704 | + return isset($action_urls[$type]) ? $action_urls[$type] : '';  | 
                                                        |
| 705 | 705 | }  | 
                                                        
| 706 | 706 | |
| 707 | 707 | |
@@ -722,7 +722,7 @@ discard block  | 
                                                    ||
| 722 | 722 |          EE_Registry::instance()->load_helper('URL'); | 
                                                        
| 723 | 723 | // if $message is not an instance of EE_Message then let's just do a dummy.  | 
                                                        
| 724 | 724 | $message = empty($message) ? EE_Message_Factory::create() : $message;  | 
                                                        
| 725 | - $action_urls = apply_filters(  | 
                                                        |
| 725 | + $action_urls = apply_filters(  | 
                                                        |
| 726 | 726 | 'FHEE__EEH_MSG_Template__get_message_action_url',  | 
                                                        
| 727 | 727 | array(  | 
                                                        
| 728 | 728 | 'view' => EEH_MSG_Template::generate_browser_trigger($message),  | 
                                                        
@@ -806,7 +806,7 @@ discard block  | 
                                                    ||
| 806 | 806 | $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);  | 
                                                        
| 807 | 807 | $icon_css = EEH_MSG_Template::get_message_action_icon($type);  | 
                                                        
| 808 | 808 | $label = $icon_css['label'] ?? null;  | 
                                                        
| 809 | - $label = $label ? 'aria-label="' . $label . '"' : '';  | 
                                                        |
| 809 | + $label = $label ? 'aria-label="'.$label.'"' : '';  | 
                                                        |
| 810 | 810 | $class = $label ? ' ee-aria-tooltip' : '';  | 
                                                        
| 811 | 811 | |
| 812 | 812 |          if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) { | 
                                                        
@@ -816,7 +816,7 @@ discard block  | 
                                                    ||
| 816 | 816 | $icon_css['css_class'] .= esc_attr(  | 
                                                        
| 817 | 817 | apply_filters(  | 
                                                        
| 818 | 818 | 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',  | 
                                                        
| 819 | - ' js-ee-message-action-link ee-message-action-link-' . $type,  | 
                                                        |
| 819 | + ' js-ee-message-action-link ee-message-action-link-'.$type,  | 
                                                        |
| 820 | 820 | $type,  | 
                                                        
| 821 | 821 | $message,  | 
                                                        
| 822 | 822 | $query_params  | 
                                                        
@@ -824,8 +824,8 @@ discard block  | 
                                                    ||
| 824 | 824 | );  | 
                                                        
| 825 | 825 | |
| 826 | 826 | return '  | 
                                                        
| 827 | - <a href="' . $url . '" ' . $label . ' class="button button--icon-only' . $class . '">  | 
                                                        |
| 828 | - <span class="' . esc_attr($icon_css['css_class']) . '"></span>  | 
                                                        |
| 827 | + <a href="' . $url.'" '.$label.' class="button button--icon-only'.$class.'">  | 
                                                        |
| 828 | + <span class="' . esc_attr($icon_css['css_class']).'"></span>  | 
                                                        |
| 829 | 829 | </a>';  | 
                                                        
| 830 | 830 | }  | 
                                                        
| 831 | 831 | |
@@ -867,7 +867,7 @@ discard block  | 
                                                    ||
| 867 | 867 | public static function convert_reg_status_to_message_type($reg_status)  | 
                                                        
| 868 | 868 |      { | 
                                                        
| 869 | 869 | $reg_status_array = self::reg_status_to_message_type_array();  | 
                                                        
| 870 | - return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';  | 
                                                        |
| 870 | + return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : '';  | 
                                                        |
| 871 | 871 | }  | 
                                                        
| 872 | 872 | |
| 873 | 873 | |
@@ -905,7 +905,7 @@ discard block  | 
                                                    ||
| 905 | 905 | public static function convert_payment_status_to_message_type($payment_status)  | 
                                                        
| 906 | 906 |      { | 
                                                        
| 907 | 907 | $payment_status_array = self::payment_status_to_message_type_array();  | 
                                                        
| 908 | - return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';  | 
                                                        |
| 908 | + return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : '';  | 
                                                        |
| 909 | 909 | }  | 
                                                        
| 910 | 910 | |
| 911 | 911 | |
@@ -918,7 +918,7 @@ discard block  | 
                                                    ||
| 918 | 918 | */  | 
                                                        
| 919 | 919 | public static function get_template_pack($template_pack_name)  | 
                                                        
| 920 | 920 |      { | 
                                                        
| 921 | -        if (! self::$_template_pack_collection instanceof EE_Object_Collection) { | 
                                                        |
| 921 | +        if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) { | 
                                                        |
| 922 | 922 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        
| 923 | 923 | }  | 
                                                        
| 924 | 924 | |
@@ -931,14 +931,14 @@ discard block  | 
                                                    ||
| 931 | 931 | |
| 932 | 932 | // nope...let's get it.  | 
                                                        
| 933 | 933 | // not set yet so let's attempt to get it.  | 
                                                        
| 934 | - $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 934 | + $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(  | 
                                                        |
| 935 | 935 | ' ',  | 
                                                        
| 936 | 936 | '_',  | 
                                                        
| 937 | 937 | ucwords(  | 
                                                        
| 938 | 938 |                  str_replace('_', ' ', $template_pack_name) | 
                                                        
| 939 | 939 | )  | 
                                                        
| 940 | 940 | );  | 
                                                        
| 941 | -        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') { | 
                                                        |
| 941 | +        if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') { | 
                                                        |
| 942 | 942 |              return self::get_template_pack('default'); | 
                                                        
| 943 | 943 |          } else { | 
                                                        
| 944 | 944 | $template_pack = new $pack_class_name();  | 
                                                        
@@ -961,18 +961,18 @@ discard block  | 
                                                    ||
| 961 | 961 | public static function get_template_pack_collection()  | 
                                                        
| 962 | 962 |      { | 
                                                        
| 963 | 963 | $new_collection = false;  | 
                                                        
| 964 | -        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { | 
                                                        |
| 964 | +        if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) { | 
                                                        |
| 965 | 965 | self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();  | 
                                                        
| 966 | 966 | $new_collection = true;  | 
                                                        
| 967 | 967 | }  | 
                                                        
| 968 | 968 | |
| 969 | 969 | // glob the defaults directory for messages  | 
                                                        
| 970 | - $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);  | 
                                                        |
| 970 | + $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR);  | 
                                                        |
| 971 | 971 |          foreach ($templates as $template_path) { | 
                                                        
| 972 | 972 | // grab folder name  | 
                                                        
| 973 | 973 | $template = basename($template_path);  | 
                                                        
| 974 | 974 | |
| 975 | -            if (! $new_collection) { | 
                                                        |
| 975 | +            if ( ! $new_collection) { | 
                                                        |
| 976 | 976 | // already have it?  | 
                                                        
| 977 | 977 |                  if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) { | 
                                                        
| 978 | 978 | continue;  | 
                                                        
@@ -980,7 +980,7 @@ discard block  | 
                                                    ||
| 980 | 980 | }  | 
                                                        
| 981 | 981 | |
| 982 | 982 | // setup classname.  | 
                                                        
| 983 | - $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(  | 
                                                        |
| 983 | + $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(  | 
                                                        |
| 984 | 984 | ' ',  | 
                                                        
| 985 | 985 | '_',  | 
                                                        
| 986 | 986 | ucwords(  | 
                                                        
@@ -991,7 +991,7 @@ discard block  | 
                                                    ||
| 991 | 991 | )  | 
                                                        
| 992 | 992 | )  | 
                                                        
| 993 | 993 | );  | 
                                                        
| 994 | -            if (! class_exists($template_pack_class_name)) { | 
                                                        |
| 994 | +            if ( ! class_exists($template_pack_class_name)) { | 
                                                        |
| 995 | 995 | continue;  | 
                                                        
| 996 | 996 | }  | 
                                                        
| 997 | 997 | self::$_template_pack_collection->add(new $template_pack_class_name());  | 
                                                        
@@ -1033,7 +1033,7 @@ discard block  | 
                                                    ||
| 1033 | 1033 |          $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        
| 1034 | 1034 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        
| 1035 | 1035 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        
| 1036 | -        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { | 
                                                        |
| 1036 | +        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) { | 
                                                        |
| 1037 | 1037 | return array();  | 
                                                        
| 1038 | 1038 | }  | 
                                                        
| 1039 | 1039 | // whew made it this far! Okay, let's go ahead and create the templates then  | 
                                                        
@@ -1053,13 +1053,13 @@ discard block  | 
                                                    ||
| 1053 | 1053 | protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)  | 
                                                        
| 1054 | 1054 |      { | 
                                                        
| 1055 | 1055 | // if we're creating a custom template then we don't need to use the defaults class  | 
                                                        
| 1056 | -        if (! $global) { | 
                                                        |
| 1056 | +        if ( ! $global) { | 
                                                        |
| 1057 | 1057 | return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);  | 
                                                        
| 1058 | 1058 | }  | 
                                                        
| 1059 | 1059 | /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */  | 
                                                        
| 1060 | 1060 | $Message_Template_Defaults = EE_Registry::factory(  | 
                                                        
| 1061 | 1061 | 'EE_Messages_Template_Defaults',  | 
                                                        
| 1062 | - array( $messenger, $message_type, $GRP_ID )  | 
                                                        |
| 1062 | + array($messenger, $message_type, $GRP_ID)  | 
                                                        |
| 1063 | 1063 | );  | 
                                                        
| 1064 | 1064 | // generate templates  | 
                                                        
| 1065 | 1065 | $success = $Message_Template_Defaults->create_new_templates();  | 
                                                        
@@ -1067,7 +1067,7 @@ discard block  | 
                                                    ||
| 1067 | 1067 | // if creating the template failed. Then we should deactivate the related message_type for the messenger because  | 
                                                        
| 1068 | 1068 | // its not active if it doesn't have a template. Note this is only happening for GLOBAL template creation  | 
                                                        
| 1069 | 1069 | // attempts.  | 
                                                        
| 1070 | -        if (! $success) { | 
                                                        |
| 1070 | +        if ( ! $success) { | 
                                                        |
| 1071 | 1071 | /** @var EE_Message_Resource_Manager $message_resource_manager */  | 
                                                        
| 1072 | 1072 |              $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        
| 1073 | 1073 | $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);  | 
                                                        
@@ -1102,7 +1102,7 @@ discard block  | 
                                                    ||
| 1102 | 1102 | private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)  | 
                                                        
| 1103 | 1103 |      { | 
                                                        
| 1104 | 1104 | // defaults  | 
                                                        
| 1105 | - $success = array( 'GRP_ID' => null, 'MTP_context' => '' );  | 
                                                        |
| 1105 | +        $success = array('GRP_ID' => null, 'MTP_context' => ''); | 
                                                        |
| 1106 | 1106 | // get the template group to use as a template from the db. If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.  | 
                                                        
| 1107 | 1107 | $Message_Template_Group = empty($GRP_ID)  | 
                                                        
| 1108 | 1108 | ? EEM_Message_Template_Group::instance()->get_one(  | 
                                                        
@@ -1116,7 +1116,7 @@ discard block  | 
                                                    ||
| 1116 | 1116 | )  | 
                                                        
| 1117 | 1117 | : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);  | 
                                                        
| 1118 | 1118 | // if we don't have a mtg at this point then we need to bail.  | 
                                                        
| 1119 | -        if (! $Message_Template_Group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1119 | +        if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) { | 
                                                        |
| 1120 | 1120 | EE_Error::add_error(  | 
                                                        
| 1121 | 1121 | sprintf(  | 
                                                        
| 1122 | 1122 | esc_html__(  | 
                                                        
@@ -1162,7 +1162,7 @@ discard block  | 
                                                    ||
| 1162 | 1162 | $success['template_name'] = $template_name;  | 
                                                        
| 1163 | 1163 | // add new message templates and add relation to.  | 
                                                        
| 1164 | 1164 |          foreach ($message_templates as $message_template) { | 
                                                        
| 1165 | -            if (! $message_template instanceof EE_Message_Template) { | 
                                                        |
| 1165 | +            if ( ! $message_template instanceof EE_Message_Template) { | 
                                                        |
| 1166 | 1166 | continue;  | 
                                                        
| 1167 | 1167 | }  | 
                                                        
| 1168 | 1168 | $new_message_template = clone $message_template;  | 
                                                        
@@ -1246,7 +1246,7 @@ discard block  | 
                                                    ||
| 1246 | 1246 |          $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); | 
                                                        
| 1247 | 1247 | $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);  | 
                                                        
| 1248 | 1248 | $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);  | 
                                                        
| 1249 | -        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { | 
                                                        |
| 1249 | +        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { | 
                                                        |
| 1250 | 1250 | return [];  | 
                                                        
| 1251 | 1251 | }  | 
                                                        
| 1252 | 1252 | |
@@ -1261,7 +1261,7 @@ discard block  | 
                                                    ||
| 1261 | 1261 |                  if (in_array($field, $excluded_fields_for_messenger, true)) { | 
                                                        
| 1262 | 1262 | continue;  | 
                                                        
| 1263 | 1263 | }  | 
                                                        
| 1264 | - $template_fields[ $context ][ $field ] = $value;  | 
                                                        |
| 1264 | + $template_fields[$context][$field] = $value;  | 
                                                        |
| 1265 | 1265 | }  | 
                                                        
| 1266 | 1266 | }  | 
                                                        
| 1267 | 1267 |          if (empty($template_fields)) { |