Completed
Branch BUG-10375-migrations-not-repor... (1e9646)
by
unknown
62:53 queued 49:42
created
modules/ical/EED_Ical.module.php 3 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
 	public static function set_hooks() {
34 34
 		// create download buttons
35 35
 		add_filter(
36
-		    'FHEE__espresso_list_of_event_dates__datetime_html',
37
-            array( 'EED_Ical', 'generate_add_to_iCal_button' ),
38
-            10,
39
-            2
40
-        );
36
+			'FHEE__espresso_list_of_event_dates__datetime_html',
37
+			array( 'EED_Ical', 'generate_add_to_iCal_button' ),
38
+			10,
39
+			2
40
+		);
41 41
 		 // process ics download request
42 42
 		EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' );
43 43
 	}
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
 
67 67
 
68 68
 
69
-    /**
70
-     *    generate_add_to_iCal_button
71
-     *
72
-     * @access    public
73
-     * @param $html
74
-     * @param $datetime
75
-     * @return    string
76
-     * @throws \EE_Error
77
-     */
69
+	/**
70
+	 *    generate_add_to_iCal_button
71
+	 *
72
+	 * @access    public
73
+	 * @param $html
74
+	 * @param $datetime
75
+	 * @return    string
76
+	 * @throws \EE_Error
77
+	 */
78 78
 	public static function generate_add_to_iCal_button( $html, $datetime ) {
79 79
 		// first verify a proper datetime object has been received
80 80
 		if ( $datetime instanceof EE_Datetime ) {
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 					$html .= '</form>';
94 94
 					break;
95 95
 				// buttons are just links that have been styled to appear as buttons,
96
-                // but may not be blend with a theme as well as submit buttons
96
+				// but may not be blend with a theme as well as submit buttons
97 97
 				case 'button' :
98 98
 					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99 99
 					$html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 
115 115
 
116 116
 
117
-    /**
118
-     *    download_ics_file
119
-     *
120
-     * @access    public
121
-     * @return    void
122
-     * @throws \EE_Error
123
-     */
117
+	/**
118
+	 *    download_ics_file
119
+	 *
120
+	 * @access    public
121
+	 * @return    void
122
+	 * @throws \EE_Error
123
+	 */
124 124
 	public static function download_ics_file() {
125 125
 		if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) {
126 126
 			$DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' ));
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 			//Escape special chars within the description
229 229
 			$description = EED_Ical::_escape_ICal_data( $description );
230 230
 
231
-		    //Remove line breaks and output in iCal format
232
-		    $description = str_replace( array( "\r\n", "\n"), '\n', $description );
231
+			//Remove line breaks and output in iCal format
232
+			$description = str_replace( array( "\r\n", "\n"), '\n', $description );
233 233
 
234 234
 		return $description;
235 235
 	}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,6 @@
 block discarded – undo
1
-<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3
+}
2 4
 
3 5
 /**
4 6
  * EED_Ical Class
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	 * @return EED_Ical|EED_Module
20 20
 	 */
21 21
 	public static function instance() {
22
-		return parent::get_instance( __CLASS__ );
22
+		return parent::get_instance(__CLASS__);
23 23
 	}
24 24
 
25 25
 
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 		// create download buttons
35 35
 		add_filter(
36 36
 		    'FHEE__espresso_list_of_event_dates__datetime_html',
37
-            array( 'EED_Ical', 'generate_add_to_iCal_button' ),
37
+            array('EED_Ical', 'generate_add_to_iCal_button'),
38 38
             10,
39 39
             2
40 40
         );
41 41
 		 // process ics download request
42
-		EE_Config::register_route( 'download_ics_file', 'EED_Ical', 'download_ics_file' );
42
+		EE_Config::register_route('download_ics_file', 'EED_Ical', 'download_ics_file');
43 43
 	}
44 44
 
45 45
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @param    WP $WP
63 63
 	 * @return    void
64 64
 	 */
65
-	public function run( $WP ) {}
65
+	public function run($WP) {}
66 66
 
67 67
 
68 68
 
@@ -75,35 +75,35 @@  discard block
 block discarded – undo
75 75
      * @return    string
76 76
      * @throws \EE_Error
77 77
      */
78
-	public static function generate_add_to_iCal_button( $html, $datetime ) {
78
+	public static function generate_add_to_iCal_button($html, $datetime) {
79 79
 		// first verify a proper datetime object has been received
80
-		if ( $datetime instanceof EE_Datetime ) {
80
+		if ($datetime instanceof EE_Datetime) {
81 81
 			// set whether a link or submit button is shown
82
-			$iCal_type = apply_filters( 'FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit' );
82
+			$iCal_type = apply_filters('FHEE__EED_Ical__generate_add_to_iCal_button__iCal_type', 'submit');
83 83
 			// generate a link to the route we registered in set_hooks()
84
-			$URL = add_query_arg( array( 'ee' => 'download_ics_file', 'ics_id' => $datetime->ID() ), site_url() );
84
+			$URL = add_query_arg(array('ee' => 'download_ics_file', 'ics_id' => $datetime->ID()), site_url());
85 85
 			// what type ?
86
-			switch ( $iCal_type ) {
86
+			switch ($iCal_type) {
87 87
 				// submit buttons appear as buttons and are very compatible with a theme's style
88 88
 				case 'submit' :
89
-					$html .= '<form id="download-iCal-frm-' . $datetime->ID();
90
-					$html .= '" class="download-iCal-frm" action="' . $URL . '" method="post" >';
89
+					$html .= '<form id="download-iCal-frm-'.$datetime->ID();
90
+					$html .= '" class="download-iCal-frm" action="'.$URL.'" method="post" >';
91 91
 					$html .= '<input type="submit" class="ee-ical-sbmt" value="&#xf145;" title="';
92
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '"/>';
92
+					$html .= __('Add to iCal Calendar', 'event_espresso').'"/>';
93 93
 					$html .= '</form>';
94 94
 					break;
95 95
 				// buttons are just links that have been styled to appear as buttons,
96 96
                 // but may not be blend with a theme as well as submit buttons
97 97
 				case 'button' :
98
-					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="' . $URL;
99
-					$html .= '" title="' . __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
98
+					$html .= '<a class="ee-ical-btn small ee-button ee-roundish" href="'.$URL;
99
+					$html .= '" title="'.__('Add to iCal Calendar', 'event_espresso').'">';
100 100
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
101 101
 					$html .= '</a>';
102 102
 					break;
103 103
 				// links are just links that use the calendar dashicon
104 104
 				case 'icon' :
105
-					$html .= '<a class="ee-ical-lnk" href="' . $URL . '" title="';
106
-					$html .= __( 'Add to iCal Calendar', 'event_espresso' ) . '">';
105
+					$html .= '<a class="ee-ical-lnk" href="'.$URL.'" title="';
106
+					$html .= __('Add to iCal Calendar', 'event_espresso').'">';
107 107
 					$html .= ' <span class="dashicons dashicons-calendar"></span>';
108 108
 					$html .= '</a>';
109 109
 					break;
@@ -122,29 +122,29 @@  discard block
 block discarded – undo
122 122
      * @throws \EE_Error
123 123
      */
124 124
 	public static function download_ics_file() {
125
-		if ( EE_Registry::instance()->REQ->is_set( 'ics_id' )) {
126
-			$DTT_ID = absint( EE_Registry::instance()->REQ->get( 'ics_id' ));
127
-			$datetime = EE_Registry::instance()->load_model( 'Datetime' )->get_one_by_ID( $DTT_ID );
128
-			if ( $datetime instanceof EE_Datetime ) {
125
+		if (EE_Registry::instance()->REQ->is_set('ics_id')) {
126
+			$DTT_ID = absint(EE_Registry::instance()->REQ->get('ics_id'));
127
+			$datetime = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($DTT_ID);
128
+			if ($datetime instanceof EE_Datetime) {
129 129
 				// get related event, venues, and event categories
130 130
 				$event = $datetime->event();
131 131
 				// get related category Term object and it's name
132 132
 				$category = $event->first_event_category();
133
-				if ( $category instanceof EE_Term ) {
133
+				if ($category instanceof EE_Term) {
134 134
 					$category = $category->name();
135 135
 				}
136 136
 				$location = '';
137 137
 				// get first related venue and convert to CSV string
138
-				$venue = $event->venues(array( 'limit'=>1 ));
139
-				if ( is_array( $venue ) && ! empty( $venue )) {
140
-					$venue = array_shift( $venue );
141
-					if ( $venue instanceof EE_Venue ) {
142
-						$location = espresso_venue_raw_address( 'inline', $venue->ID(), FALSE );
138
+				$venue = $event->venues(array('limit'=>1));
139
+				if (is_array($venue) && ! empty($venue)) {
140
+					$venue = array_shift($venue);
141
+					if ($venue instanceof EE_Venue) {
142
+						$location = espresso_venue_raw_address('inline', $venue->ID(), FALSE);
143 143
 					}
144 144
 				}
145 145
 
146 146
 				//Generate filename
147
-				$filename = $event->slug() . '-' . $datetime->start_date( 'Y-m-d' ) . '.ics';
147
+				$filename = $event->slug().'-'.$datetime->start_date('Y-m-d').'.ics';
148 148
 
149 149
 				//Check the datetime status has not been cancelled and set the ics value accordingly
150 150
 				$status = $datetime->get_active_status();
@@ -153,62 +153,62 @@  discard block
 block discarded – undo
153 153
 				// Create array of ics details, escape strings, convert timestamps to ics format, etc
154 154
 				$ics_data = array(
155 155
 					'ORGANIZER_NAME' => EE_Registry::instance()->CFG->organization->name,
156
-					'UID' => md5( $event->name() . $event->ID() . $datetime->ID() ),
156
+					'UID' => md5($event->name().$event->ID().$datetime->ID()),
157 157
 					'ORGANIZER' => EE_Registry::instance()->CFG->organization->email,
158
-					'DTSTAMP' => date( EED_Ical::iCal_datetime_format ),
158
+					'DTSTAMP' => date(EED_Ical::iCal_datetime_format),
159 159
 					'LOCATION' => $location,
160 160
 					'SUMMARY' => $event->name(),
161
-					'DESCRIPTION' => wp_strip_all_tags( $event->description() ),
161
+					'DESCRIPTION' => wp_strip_all_tags($event->description()),
162 162
 					'STATUS' => $status,
163 163
 					'CATEGORIES' => $category,
164
-					'URL;VALUE=URI' => get_permalink( $event->ID() ),
165
-					'DTSTART' => date( EED_Ical::iCal_datetime_format, $datetime->start() ),
166
-					'DTEND' => date( EED_Ical::iCal_datetime_format, $datetime->end() ),
164
+					'URL;VALUE=URI' => get_permalink($event->ID()),
165
+					'DTSTART' => date(EED_Ical::iCal_datetime_format, $datetime->start()),
166
+					'DTEND' => date(EED_Ical::iCal_datetime_format, $datetime->end()),
167 167
 				);
168 168
 
169 169
 				//Filter the values used within the ics output.
170 170
 				//NOTE - all values within ics_data will be escaped automatically.
171
-				$ics_data = apply_filters( 'FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime );
171
+				$ics_data = apply_filters('FHEE__EED_Ical__download_ics_file_ics_data', $ics_data, $datetime);
172 172
 
173 173
 				//Escape all ics data
174
-				foreach( $ics_data as $key => $value ) {
174
+				foreach ($ics_data as $key => $value) {
175 175
 					//Description is escaped differently from all all values
176
-					if( $key === 'DESCRIPTION' ) {
177
-						$ics_data[$key] = EED_Ical::_escape_ICal_description( wp_strip_all_tags( $value ) );
176
+					if ($key === 'DESCRIPTION') {
177
+						$ics_data[$key] = EED_Ical::_escape_ICal_description(wp_strip_all_tags($value));
178 178
 					} else {
179
-						$ics_data[$key] = EED_Ical::_escape_ICal_data( $value );
179
+						$ics_data[$key] = EED_Ical::_escape_ICal_data($value);
180 180
 					}
181 181
 				}
182 182
 
183 183
 				//Pull the organizer name from ics_data and remove it from the array.
184
-				$organizer_name = isset( $ics_data['ORGANIZER_NAME'] ) ? $ics_data['ORGANIZER_NAME'] : '';
185
-				unset( $ics_data['ORGANIZER_NAME'] );
184
+				$organizer_name = isset($ics_data['ORGANIZER_NAME']) ? $ics_data['ORGANIZER_NAME'] : '';
185
+				unset($ics_data['ORGANIZER_NAME']);
186 186
 
187 187
 				// set headers
188
-				header( 'Content-type: text/calendar; charset=utf-8' );
189
-				header( 'Content-Disposition: attachment; filename="' . $filename . '"' );
190
-				header( 'Cache-Control: private, max-age=0, must-revalidate' );
191
-				header( 'Pragma: public' );
192
-				header( 'Content-Type: application/octet-stream' );
193
-				header( 'Content-Type: application/force-download' );
194
-				header( 'Cache-Control: no-cache, must-revalidate' );
195
-				header( 'Content-Transfer-Encoding: binary' );
196
-				header( 'Expires: Sat, 26 Jul 1997 05:00:00 GMT' ); // past date
197
-				ini_set( 'zlib.output_compression', '0' );
188
+				header('Content-type: text/calendar; charset=utf-8');
189
+				header('Content-Disposition: attachment; filename="'.$filename.'"');
190
+				header('Cache-Control: private, max-age=0, must-revalidate');
191
+				header('Pragma: public');
192
+				header('Content-Type: application/octet-stream');
193
+				header('Content-Type: application/force-download');
194
+				header('Cache-Control: no-cache, must-revalidate');
195
+				header('Content-Transfer-Encoding: binary');
196
+				header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // past date
197
+				ini_set('zlib.output_compression', '0');
198 198
 				// echo the output
199
-				echo "BEGIN:VCALENDAR" . PHP_EOL;
200
-				echo "VERSION:2.0" . PHP_EOL;
201
-				echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN" . PHP_EOL;
202
-				echo "CALSCALE:GREGORIAN" . PHP_EOL;
203
-				echo "BEGIN:VEVENT" . PHP_EOL;
199
+				echo "BEGIN:VCALENDAR".PHP_EOL;
200
+				echo "VERSION:2.0".PHP_EOL;
201
+				echo "PRODID:-//{$organizer_name}//NONSGML PDA Calendar Version 1.0//EN".PHP_EOL;
202
+				echo "CALSCALE:GREGORIAN".PHP_EOL;
203
+				echo "BEGIN:VEVENT".PHP_EOL;
204 204
 				
205 205
 				//Output all remaining values from ics_data.
206
-				foreach( $ics_data as $key => $value ) {
207
-					echo $key . ':' . $value . PHP_EOL;
206
+				foreach ($ics_data as $key => $value) {
207
+					echo $key.':'.$value.PHP_EOL;
208 208
 				}
209 209
 
210
-				echo "END:VEVENT" . PHP_EOL;
211
-				echo "END:VCALENDAR" . PHP_EOL;
210
+				echo "END:VEVENT".PHP_EOL;
211
+				echo "END:VCALENDAR".PHP_EOL;
212 212
 			}
213 213
 		}
214 214
 		die();
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 *  	@param	string $string
224 224
 	 *  	@return	string
225 225
 	 */
226
-	private static function _escape_ICal_data( $string = '' ) {
227
-		return preg_replace( '/([\,;])/', '\\\$1', $string );
226
+	private static function _escape_ICal_data($string = '') {
227
+		return preg_replace('/([\,;])/', '\\\$1', $string);
228 228
 	}
229 229
 
230 230
 	/**
@@ -234,13 +234,13 @@  discard block
 block discarded – undo
234 234
 	 *  	@param	string $description
235 235
 	 *  	@return	string
236 236
 	 */
237
-	private static function _escape_ICal_description( $description = '' ) {
237
+	private static function _escape_ICal_description($description = '') {
238 238
 
239 239
 			//Escape special chars within the description
240
-			$description = EED_Ical::_escape_ICal_data( $description );
240
+			$description = EED_Ical::_escape_ICal_data($description);
241 241
 
242 242
 		    //Remove line breaks and output in iCal format
243
-		    $description = str_replace( array( "\r\n", "\n"), '\n', $description );
243
+		    $description = str_replace(array("\r\n", "\n"), '\n', $description);
244 244
 
245 245
 		return $description;
246 246
 	}
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 2 patches
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
         $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88 88
         $this->_admin_base_path = EE_MSG_ADMIN;
89 89
         
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
90
+        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state'] : array();
91 91
         
92 92
         $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93 93
         $this->_load_message_resource_manager();
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
             array('none_selected' => __('Show All Messengers', 'event_espresso')),
220 220
             $messenger_options
221 221
         );
222
-        $input             = new EE_Select_Input(
222
+        $input = new EE_Select_Input(
223 223
             $messenger_options,
224 224
             array(
225 225
                 'html_name'  => 'ee_messenger_filter_by',
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             array('none_selected' => __('Show All Message Types', 'event_espresso')),
258 258
             $message_type_options
259 259
         );
260
-        $input                = new EE_Select_Input(
260
+        $input = new EE_Select_Input(
261 261
             $message_type_options,
262 262
             array(
263 263
                 'html_name'  => 'ee_message_type_filter_by',
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             array('none_selected' => __('Show all Contexts', 'event_espresso')),
296 296
             $context_options
297 297
         );
298
-        $input           = new EE_Select_Input(
298
+        $input = new EE_Select_Input(
299 299
             $context_options,
300 300
             array(
301 301
                 'html_name'  => 'ee_context_filter_by',
@@ -676,47 +676,47 @@  discard block
 block discarded – undo
676 676
     
677 677
     public function messages_help_tab()
678 678
     {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
679
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_help_tab.template.php');
680 680
     }
681 681
     
682 682
     
683 683
     public function messengers_help_tab()
684 684
     {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
685
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messenger_help_tab.template.php');
686 686
     }
687 687
     
688 688
     
689 689
     public function message_types_help_tab()
690 690
     {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
691
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_type_help_tab.template.php');
692 692
     }
693 693
     
694 694
     
695 695
     public function messages_overview_help_tab()
696 696
     {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
697
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_overview_help_tab.template.php');
698 698
     }
699 699
     
700 700
     
701 701
     public function message_templates_help_tab()
702 702
     {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
703
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_message_templates_help_tab.template.php');
704 704
     }
705 705
     
706 706
     
707 707
     public function edit_message_template_help_tab()
708 708
     {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
709
+        $args['img1'] = '<img src="'.EE_MSG_ASSETS_URL.'images/editor.png'.'" alt="'.esc_attr__('Editor Title',
710
+                'event_espresso').'" />';
711
+        $args['img2'] = '<img src="'.EE_MSG_ASSETS_URL.'images/switch-context.png'.'" alt="'.esc_attr__('Context Switcher and Preview',
712
+                'event_espresso').'" />';
713
+        $args['img3'] = '<img class="left" src="'.EE_MSG_ASSETS_URL.'images/form-fields.png'.'" alt="'.esc_attr__('Message Template Form Fields',
714
+                'event_espresso').'" />';
715
+        $args['img4'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/shortcodes-metabox.png'.'" alt="'.esc_attr__('Shortcodes Metabox',
716
+                'event_espresso').'" />';
717
+        $args['img5'] = '<img class="right" src="'.EE_MSG_ASSETS_URL.'images/publish-meta-box.png'.'" alt="'.esc_attr__('Publish Metabox',
718
+                'event_espresso').'" />';
719
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_templates_editor_help_tab.template.php',
720 720
             $args);
721 721
     }
722 722
     
@@ -725,37 +725,37 @@  discard block
 block discarded – undo
725 725
     {
726 726
         $this->_set_shortcodes();
727 727
         $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
728
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_shortcodes_help_tab.template.php',
729 729
             $args);
730 730
     }
731 731
     
732 732
     
733 733
     public function preview_message_help_tab()
734 734
     {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
735
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_preview_help_tab.template.php');
736 736
     }
737 737
     
738 738
     
739 739
     public function settings_help_tab()
740 740
     {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
741
+        $args['img1'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'" alt="'.esc_attr__('Active Email Tab',
742
+                'event_espresso').'" />';
743
+        $args['img2'] = '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'.'" alt="'.esc_attr__('Inactive Email Tab',
744
+                'event_espresso').'" />';
745 745
         $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746 746
         $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
747
+        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'ee_msg_messages_settings_help_tab.template.php', $args);
748 748
     }
749 749
     
750 750
     
751 751
     public function load_scripts_styles()
752 752
     {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
753
+        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL.'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754 754
         wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
756
+        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL.'ee-messages-settings.js',
757 757
             array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
758
+        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL.'ee_message_admin_list_table.js',
759 759
             array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760 760
     }
761 761
     
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
         
788 788
         $this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
790
+        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
791 791
             __('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.',
792 792
                 'event_espresso'),
793 793
             $this->_message_template_group->messenger_obj()->label['singular'],
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
         EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797 797
             'event_espresso');
798 798
         
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
799
+        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL.'ee_message_editor.js', array('jquery'),
800 800
             EVENT_ESPRESSO_VERSION);
801 801
         
802 802
         wp_enqueue_script('ee_admin_js');
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
     
828 828
     public function load_scripts_styles_settings()
829 829
     {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
830
+        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL.'ee_message_settings.css', array(),
831 831
             EVENT_ESPRESSO_VERSION);
832 832
         wp_enqueue_style('ee-text-links');
833 833
         wp_enqueue_style('ee-message-settings');
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
             }
894 894
             $status_bulk_actions = $common_bulk_actions;
895 895
             //unset bulk actions not applying to status
896
-            if (! empty($status_bulk_actions)) {
896
+            if ( ! empty($status_bulk_actions)) {
897 897
                 switch ($status) {
898 898
                     case EEM_Message::status_idle:
899 899
                     case EEM_Message::status_resend:
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             }
919 919
 
920 920
             //skip adding messenger executing status to views because it will be included with the Failed view.
921
-            if ( $status === EEM_Message::status_messenger_executing ) {
921
+            if ($status === EEM_Message::status_messenger_executing) {
922 922
                 continue;
923 923
             }
924 924
             
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
         $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945 945
         $this->_template_args['per_column']        = 6;
946 946
         $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
947
+        $this->_template_args['before_list_table'] = '<h3>'.EEM_Message::instance()->get_pretty_label_for_results().'</h3>';
948 948
         $this->display_admin_list_table_page_with_no_sidebar();
949 949
     }
950 950
     
@@ -968,37 +968,37 @@  discard block
 block discarded – undo
968 968
         /** @type array $status_items status legend setup */
969 969
         $status_items = array(
970 970
             'sent_status'       => array(
971
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
971
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_sent,
972 972
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973 973
             ),
974 974
             'idle_status'       => array(
975
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
975
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_idle,
976 976
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977 977
             ),
978 978
             'failed_status'     => array(
979
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
979
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_failed,
980 980
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981 981
             ),
982 982
             'messenger_executing_status' => array(
983
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
983
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_messenger_executing,
984 984
                 'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985 985
             ),
986 986
             'resend_status'     => array(
987
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
987
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_resend,
988 988
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989 989
             ),
990 990
             'incomplete_status' => array(
991
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
991
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_incomplete,
992 992
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993 993
             ),
994 994
             'retry_status'      => array(
995
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
995
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_retry,
996 996
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997 997
             )
998 998
         );
999 999
         if (EEM_Message::debug()) {
1000 1000
             $status_items['debug_only_status'] = array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Message::status_debug_only,
1002 1002
                 'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003 1003
             );
1004 1004
         }
@@ -1010,10 +1010,10 @@  discard block
 block discarded – undo
1010 1010
     protected function _custom_mtps_preview()
1011 1011
     {
1012 1012
         $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
-                'event_espresso') . '" />';
1015
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1016
-                'event_espresso') . '</strong>';
1013
+        $this->_template_args['preview_img']  = '<img src="'.EE_MSG_ASSETS_URL.'images/custom_mtps_preview.png" alt="'.esc_attr__('Preview Custom Message Templates screenshot',
1014
+                'event_espresso').'" />';
1015
+        $this->_template_args['preview_text'] = '<strong>'.__('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.',
1016
+                'event_espresso').'</strong>';
1017 1017
         $this->display_admin_caf_preview_page('custom_message_types', false);
1018 1018
     }
1019 1019
     
@@ -1261,7 +1261,7 @@  discard block
 block discarded – undo
1261 1261
                             //let's verify if we need this extra field via the shortcodes parameter.
1262 1262
                             $continue = false;
1263 1263
                             if (isset($extra_array['shortcodes_required'])) {
1264
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1264
+                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1265 1265
                                     if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266 1266
                                         $continue = true;
1267 1267
                                     }
@@ -1271,9 +1271,9 @@  discard block
 block discarded – undo
1271 1271
                                 }
1272 1272
                             }
1273 1273
                             
1274
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1274
+                            $field_id                                = $reference_field.'-'.$extra_field.'-content';
1275 1275
                             $template_form_fields[$field_id]         = $extra_array;
1276
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1276
+                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields['.$reference_field.'][content]['.$extra_field.']';
1277 1277
                             $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1278 1278
                             
1279 1279
                             $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
                                                                                 is_array($validators[$extra_field])
1284 1284
                                                                                 && isset($validators[$extra_field]['msg'])
1285 1285
                                                                             )
1286
-                                ? 'validate-error ' . $css_class
1286
+                                ? 'validate-error '.$css_class
1287 1287
                                 : $css_class;
1288 1288
                             
1289 1289
                             $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
@@ -1311,11 +1311,11 @@  discard block
 block discarded – undo
1311 1311
                                 
1312 1312
                             }/**/
1313 1313
                         }
1314
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
-                        $templatefield_templatename_id = $reference_field . '-name';
1314
+                        $templatefield_MTP_id          = $reference_field.'-MTP_ID';
1315
+                        $templatefield_templatename_id = $reference_field.'-name';
1316 1316
                         
1317 1317
                         $template_form_fields[$templatefield_MTP_id] = array(
1318
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1318
+                            'name'       => 'MTP_template_fields['.$reference_field.'][MTP_ID]',
1319 1319
                             'label'      => null,
1320 1320
                             'input'      => 'hidden',
1321 1321
                             'type'       => 'int',
@@ -1328,7 +1328,7 @@  discard block
 block discarded – undo
1328 1328
                         );
1329 1329
                         
1330 1330
                         $template_form_fields[$templatefield_templatename_id] = array(
1331
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1331
+                            'name'       => 'MTP_template_fields['.$reference_field.'][name]',
1332 1332
                             'label'      => null,
1333 1333
                             'input'      => 'hidden',
1334 1334
                             'type'       => 'string',
@@ -1342,9 +1342,9 @@  discard block
 block discarded – undo
1342 1342
                     }
1343 1343
                     continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344 1344
                 } else {
1345
-                    $field_id                                 = $template_field . '-content';
1345
+                    $field_id                                 = $template_field.'-content';
1346 1346
                     $template_form_fields[$field_id]          = $field_setup_array;
1347
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1347
+                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields['.$template_field.'][content]';
1348 1348
                     $message_template                         = isset($message_templates[$context][$template_field])
1349 1349
                         ? $message_templates[$context][$template_field]
1350 1350
                         : null;
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
                     $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366 1366
                                                                     && in_array($template_field, $v_fields)
1367 1367
                                                                     && isset($validators[$template_field]['msg'])
1368
-                        ? 'validate-error ' . $css_class
1368
+                        ? 'validate-error '.$css_class
1369 1369
                         : $css_class;
1370 1370
                     
1371 1371
                     //shortcode selector
@@ -1376,12 +1376,12 @@  discard block
 block discarded – undo
1376 1376
                 
1377 1377
                 //k took care of content field(s) now let's take care of others.
1378 1378
                 
1379
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
-                $templatefield_field_templatename_id = $template_field . '-name';
1379
+                $templatefield_MTP_id                = $template_field.'-MTP_ID';
1380
+                $templatefield_field_templatename_id = $template_field.'-name';
1381 1381
                 
1382 1382
                 //foreach template field there are actually two form fields created
1383 1383
                 $template_form_fields[$templatefield_MTP_id] = array(
1384
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1384
+                    'name'       => 'MTP_template_fields['.$template_field.'][MTP_ID]',
1385 1385
                     'label'      => null,
1386 1386
                     'input'      => 'hidden',
1387 1387
                     'type'       => 'int',
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                 );
1395 1395
                 
1396 1396
                 $template_form_fields[$templatefield_field_templatename_id] = array(
1397
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1397
+                    'name'       => 'MTP_template_fields['.$template_field.'][name]',
1398 1398
                     'label'      => null,
1399 1399
                     'input'      => 'hidden',
1400 1400
                     'type'       => 'string',
@@ -1512,7 +1512,7 @@  discard block
 block discarded – undo
1512 1512
                 'format'     => '%d',
1513 1513
                 'db-col'     => 'MTP_deleted'
1514 1514
             );
1515
-            $sidebar_form_fields['ee-msg-author']  = array(
1515
+            $sidebar_form_fields['ee-msg-author'] = array(
1516 1516
                 'name'       => 'MTP_user_id',
1517 1517
                 'label'      => __('Author', 'event_espresso'),
1518 1518
                 'input'      => 'hidden',
@@ -1531,17 +1531,17 @@  discard block
 block discarded – undo
1531 1531
                 'value' => $action
1532 1532
             );
1533 1533
             
1534
-            $sidebar_form_fields['ee-msg-id']        = array(
1534
+            $sidebar_form_fields['ee-msg-id'] = array(
1535 1535
                 'name'  => 'id',
1536 1536
                 'input' => 'hidden',
1537 1537
                 'type'  => 'int',
1538 1538
                 'value' => $GRP_ID
1539 1539
             );
1540 1540
             $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
-                'name'  => $action . '_nonce',
1541
+                'name'  => $action.'_nonce',
1542 1542
                 'input' => 'hidden',
1543 1543
                 'type'  => 'string',
1544
-                'value' => wp_create_nonce($action . '_nonce')
1544
+                'value' => wp_create_nonce($action.'_nonce')
1545 1545
             );
1546 1546
             
1547 1547
             if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
@@ -1573,7 +1573,7 @@  discard block
 block discarded – undo
1573 1573
         );
1574 1574
         
1575 1575
         //add preview button
1576
-        $preview_url    = parent::add_query_args_and_nonce(
1576
+        $preview_url = parent::add_query_args_and_nonce(
1577 1577
             array(
1578 1578
                 'message_type' => $message_template_group->message_type(),
1579 1579
                 'messenger'    => $message_template_group->messenger(),
@@ -1583,8 +1583,8 @@  discard block
 block discarded – undo
1583 1583
             ),
1584 1584
             $this->_admin_base_url
1585 1585
         );
1586
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
-                'event_espresso') . '</a>';
1586
+        $preview_button = '<a href="'.$preview_url.'" class="button-secondary messages-preview-button">'.__('Preview',
1587
+                'event_espresso').'</a>';
1588 1588
         
1589 1589
         
1590 1590
         //setup context switcher
@@ -1612,8 +1612,8 @@  discard block
 block discarded – undo
1612 1612
         $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1613 1613
         
1614 1614
         $this->_template_path = $this->_template_args['GRP_ID']
1615
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1615
+            ? EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_edit_meta_box.template.php'
1616
+            : EE_MSG_TEMPLATE_PATH.'ee_msg_details_main_add_meta_box.template.php';
1617 1617
         
1618 1618
         //send along EE_Message_Template_Group object for further template use.
1619 1619
         $this->_template_args['MTP'] = $message_template_group;
@@ -1648,7 +1648,7 @@  discard block
 block discarded – undo
1648 1648
     
1649 1649
     public function _add_form_element_before()
1650 1650
     {
1651
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1651
+        return '<form method="post" action="'.$this->_template_args["edit_message_template_form_url"].'" id="ee-msg-edit-frm">';
1652 1652
     }
1653 1653
     
1654 1654
     public function _add_form_element_after()
@@ -1843,14 +1843,14 @@  discard block
 block discarded – undo
1843 1843
         }
1844 1844
         
1845 1845
         //let's add a button to go back to the edit view
1846
-        $query_args             = array(
1846
+        $query_args = array(
1847 1847
             'id'      => $this->_req_data['GRP_ID'],
1848 1848
             'context' => $this->_req_data['context'],
1849 1849
             'action'  => 'edit_message_template'
1850 1850
         );
1851 1851
         $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
-                'event_espresso') . '</a>';
1852
+        $preview_button         = '<a href="'.$go_back_url.'" class="button-secondary messages-preview-go-back-button">'.__('Go Back to Edit',
1853
+                'event_espresso').'</a>';
1854 1854
         $message_types          = $this->get_installed_message_types();
1855 1855
         $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856 1856
         $active_messenger_label = $active_messenger instanceof EE_messenger
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
         );
1865 1865
         //setup display of preview.
1866 1866
         $this->_admin_page_title                    = $preview_title;
1867
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1867
+        $this->_template_args['admin_page_content'] = $preview_button.'<br />'.stripslashes($preview);
1868 1868
         $this->_template_args['data']['force_json'] = true;
1869 1869
         
1870 1870
         return '';
@@ -1946,7 +1946,7 @@  discard block
 block discarded – undo
1946 1946
         }
1947 1947
         
1948 1948
         //setup variation select values for the currently selected template.
1949
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1949
+        $variations = $this->_message_template_group->get_template_pack()->get_variations(
1950 1950
             $this->_message_template_group->messenger(),
1951 1951
             $this->_message_template_group->message_type()
1952 1952
         );
@@ -1960,12 +1960,12 @@  discard block
 block discarded – undo
1960 1960
         
1961 1961
         $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962 1962
         
1963
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1963
+        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
1964 1964
             'MTP_template_pack',
1965 1965
             $tp_select_values,
1966 1966
             $this->_message_template_group->get_template_pack_name()
1967 1967
         );
1968
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1968
+        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
1969 1969
             'MTP_template_variation',
1970 1970
             $variations_select_values,
1971 1971
             $this->_message_template_group->get_template_pack_variation()
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
         $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976 1976
         $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977 1977
         
1978
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1978
+        $template = EE_MSG_TEMPLATE_PATH.'template_pack_and_variations_metabox.template.php';
1979 1979
         
1980 1980
         EEH_Template::display_template($template, $template_args);
1981 1981
     }
@@ -2004,7 +2004,7 @@  discard block
 block discarded – undo
2004 2004
         if ( ! empty($fields)) {
2005 2005
             //yup there be fields
2006 2006
             foreach ($fields as $field => $config) {
2007
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2007
+                $field_id = $this->_message_template_group->messenger().'_'.$field;
2008 2008
                 $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009 2009
                 $default  = isset($config['default']) ? $config['default'] : '';
2010 2010
                 $default  = isset($config['value']) ? $config['value'] : $default;
@@ -2019,7 +2019,7 @@  discard block
 block discarded – undo
2019 2019
                     : $fix;
2020 2020
                 
2021 2021
                 $template_form_fields[$field_id] = array(
2022
-                    'name'       => 'test_settings_fld[' . $field . ']',
2022
+                    'name'       => 'test_settings_fld['.$field.']',
2023 2023
                     'label'      => $config['label'],
2024 2024
                     'input'      => $config['input'],
2025 2025
                     'type'       => $config['type'],
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
         }
2050 2050
         
2051 2051
         //and button
2052
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2052
+        $test_settings_html .= '<p>'.__('Need to reset this message type and start over?', 'event_espresso').'</p>';
2053 2053
         $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054 2054
         $test_settings_html .= $this->get_action_link_or_button(
2055 2055
             'reset_to_default',
@@ -2080,7 +2080,7 @@  discard block
 block discarded – undo
2080 2080
             'linked_input_id' => $linked_input_id
2081 2081
         );
2082 2082
         
2083
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2083
+        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH.'shortcode_selector_skeleton.template.php',
2084 2084
             $template_args, true);
2085 2085
     }
2086 2086
     
@@ -2098,7 +2098,7 @@  discard block
 block discarded – undo
2098 2098
         //$messenger = $this->_message_template_group->messenger_obj();
2099 2099
         //now let's set the content depending on the status of the shortcodes array
2100 2100
         if (empty($shortcodes)) {
2101
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2101
+            $content = '<p>'.__('There are no valid shortcodes available', 'event_espresso').'</p>';
2102 2102
             echo $content;
2103 2103
         } else {
2104 2104
             //$alt = 0;
@@ -2215,7 +2215,7 @@  discard block
 block discarded – undo
2215 2215
                     <?php
2216 2216
                 }
2217 2217
                 //setup nonce_url
2218
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2218
+                wp_nonce_field($args['action'].'_nonce', $args['action'].'_nonce', false);
2219 2219
                 ?>
2220 2220
                 <select name="context">
2221 2221
                     <?php
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
             : '';
2314 2314
         $context      = ucwords(str_replace('_', ' ', $context_slug));
2315 2315
         
2316
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2316
+        $item_desc = $messenger_label && $message_type_label ? $messenger_label.' '.$message_type_label.' '.$context.' ' : '';
2317 2317
         $item_desc .= 'Message Template';
2318 2318
         $query_args  = array();
2319 2319
         $edit_array  = array();
@@ -2682,8 +2682,8 @@  discard block
 block discarded – undo
2682 2682
      */
2683 2683
     protected function _learn_more_about_message_templates_link()
2684 2684
     {
2685
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2686
-            'event_espresso') . '</a>';
2685
+        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'.__('learn more about how message templates works',
2686
+            'event_espresso').'</a>';
2687 2687
     }
2688 2688
     
2689 2689
     
@@ -2759,10 +2759,10 @@  discard block
 block discarded – undo
2759 2759
                 
2760 2760
                 $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2761 2761
                     'label'    => ucwords($message_type->label['singular']),
2762
-                    'class'    => 'message-type-' . $a_or_i,
2763
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2764
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2765
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2762
+                    'class'    => 'message-type-'.$a_or_i,
2763
+                    'slug_id'  => $message_type->name.'-messagetype-'.$messenger->name,
2764
+                    'mt_nonce' => wp_create_nonce($message_type->name.'_nonce'),
2765
+                    'href'     => 'espresso_'.$message_type->name.'_message_type_settings',
2766 2766
                     'title'    => $a_or_i == 'active'
2767 2767
                         ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2768 2768
                         : __('Drag this message type to the messenger to activate', 'event_espresso'),
@@ -2798,9 +2798,9 @@  discard block
 block discarded – undo
2798 2798
             $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2799 2799
             
2800 2800
             foreach ($fields as $fldname => $fldprops) {
2801
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2801
+                $field_id                       = $messenger->name.'-'.$message_type->name.'-'.$fldname;
2802 2802
                 $template_form_field[$field_id] = array(
2803
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2803
+                    'name'       => 'message_type_settings['.$fldname.']',
2804 2804
                     'label'      => $fldprops['label'],
2805 2805
                     'input'      => $fldprops['field_type'],
2806 2806
                     'type'       => $fldprops['value_type'],
@@ -2841,7 +2841,7 @@  discard block
 block discarded – undo
2841 2841
         $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2842 2842
         
2843 2843
         
2844
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2844
+        $template = EE_MSG_TEMPLATE_PATH.'ee_msg_mt_settings_content.template.php';
2845 2845
         $content  = EEH_Template::display_template($template, $settings_template_args, true);
2846 2846
         
2847 2847
         return $content;
@@ -2871,11 +2871,11 @@  discard block
 block discarded – undo
2871 2871
                 $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2872 2872
                     ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2873 2873
                     : '';
2874
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2874
+                $m_boxes[$messenger.'_a_box']         = sprintf(
2875 2875
                     __('%s Settings', 'event_espresso'),
2876 2876
                     $tab_array['label']
2877 2877
                 );
2878
-                $m_template_args[$messenger . '_a_box'] = array(
2878
+                $m_template_args[$messenger.'_a_box'] = array(
2879 2879
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2880 2880
                     'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2881 2881
                         ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
@@ -2889,8 +2889,8 @@  discard block
 block discarded – undo
2889 2889
                 // message type meta boxes
2890 2890
                 // (which is really just the inactive container for each messenger
2891 2891
                 // showing inactive message types for that messenger)
2892
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2893
-                $mt_template_args[$messenger . '_i_box'] = array(
2892
+                $mt_boxes[$messenger.'_i_box']         = __('Inactive Message Types', 'event_espresso');
2893
+                $mt_template_args[$messenger.'_i_box'] = array(
2894 2894
                     'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2895 2895
                     'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2896 2896
                         ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
@@ -2906,14 +2906,14 @@  discard block
 block discarded – undo
2906 2906
         
2907 2907
         
2908 2908
         //register messenger metaboxes
2909
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2909
+        $m_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_mt_meta_box.template.php';
2910 2910
         foreach ($m_boxes as $box => $label) {
2911 2911
             $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2912 2912
             $msgr          = str_replace('_a_box', '', $box);
2913 2913
             add_meta_box(
2914
-                'espresso_' . $msgr . '_settings',
2914
+                'espresso_'.$msgr.'_settings',
2915 2915
                 $label,
2916
-                function ($post, $metabox) {
2916
+                function($post, $metabox) {
2917 2917
                     echo EEH_Template::display_template($metabox["args"]["template_path"],
2918 2918
                         $metabox["args"]["template_args"], true);
2919 2919
                 },
@@ -2925,17 +2925,17 @@  discard block
 block discarded – undo
2925 2925
         }
2926 2926
         
2927 2927
         //register message type metaboxes
2928
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2928
+        $mt_template_path = EE_MSG_TEMPLATE_PATH.'ee_msg_details_messenger_meta_box.template.php';
2929 2929
         foreach ($mt_boxes as $box => $label) {
2930 2930
             $callback_args = array(
2931 2931
                 'template_path' => $mt_template_path,
2932 2932
                 'template_args' => $mt_template_args[$box]
2933 2933
             );
2934
-            $mt            = str_replace('_i_box', '', $box);
2934
+            $mt = str_replace('_i_box', '', $box);
2935 2935
             add_meta_box(
2936
-                'espresso_' . $mt . '_inactive_mts',
2936
+                'espresso_'.$mt.'_inactive_mts',
2937 2937
                 $label,
2938
-                function ($post, $metabox) {
2938
+                function($post, $metabox) {
2939 2939
                     echo EEH_Template::display_template($metabox["args"]["template_path"],
2940 2940
                         $metabox["args"]["template_args"], true);
2941 2941
                 },
@@ -3037,7 +3037,7 @@  discard block
 block discarded – undo
3037 3037
             if ($form->is_valid()) {
3038 3038
                 $valid_data = $form->valid_data();
3039 3039
                 foreach ($valid_data as $property => $value) {
3040
-                    $setter = 'set_' . $property;
3040
+                    $setter = 'set_'.$property;
3041 3041
                     if (method_exists($network_config, $setter)) {
3042 3042
                         $network_config->{$setter}($value);
3043 3043
                     } else if (
@@ -3066,8 +3066,8 @@  discard block
 block discarded – undo
3066 3066
      */
3067 3067
     protected function _get_mt_tabs($tab_array)
3068 3068
     {
3069
-        $tab_array = (array)$tab_array;
3070
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3069
+        $tab_array = (array) $tab_array;
3070
+        $template  = EE_MSG_TEMPLATE_PATH.'ee_msg_details_mt_settings_tab_item.template.php';
3071 3071
         $tabs      = '';
3072 3072
         
3073 3073
         foreach ($tab_array as $tab) {
@@ -3100,9 +3100,9 @@  discard block
 block discarded – undo
3100 3100
             $existing_settings = $messenger->get_existing_admin_settings();
3101 3101
             
3102 3102
             foreach ($fields as $fldname => $fldprops) {
3103
-                $field_id                       = $messenger->name . '-' . $fldname;
3103
+                $field_id                       = $messenger->name.'-'.$fldname;
3104 3104
                 $template_form_field[$field_id] = array(
3105
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3105
+                    'name'       => 'messenger_settings['.$field_id.']',
3106 3106
                     'label'      => $fldprops['label'],
3107 3107
                     'input'      => $fldprops['field_type'],
3108 3108
                     'type'       => $fldprops['value_type'],
@@ -3137,7 +3137,7 @@  discard block
 block discarded – undo
3137 3137
         //make sure any active message types that are existing are included in the hidden fields
3138 3138
         if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3139 3139
             foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3140
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3140
+                $settings_template_args['hidden_fields']['messenger_settings[message_types]['.$mt.']'] = array(
3141 3141
                     'type'  => 'hidden',
3142 3142
                     'value' => $mt
3143 3143
                 );
@@ -3147,7 +3147,7 @@  discard block
 block discarded – undo
3147 3147
             $settings_template_args['hidden_fields'],
3148 3148
             'array'
3149 3149
         );
3150
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3150
+        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3151 3151
         
3152 3152
         $settings_template_args['messenger']           = $messenger->name;
3153 3153
         $settings_template_args['description']         = $messenger->description;
@@ -3164,9 +3164,9 @@  discard block
 block discarded – undo
3164 3164
         
3165 3165
         
3166 3166
         $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3167
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3167
+        $settings_template_args['nonce']         = wp_create_nonce('activate_'.$messenger->name.'_toggle_nonce');
3168 3168
         $settings_template_args['on_off_status'] = $active ? true : false;
3169
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3169
+        $template                                = EE_MSG_TEMPLATE_PATH.'ee_msg_m_settings_content.template.php';
3170 3170
         $content                                 = EEH_Template::display_template($template, $settings_template_args,
3171 3171
             true);
3172 3172
         
@@ -3194,7 +3194,7 @@  discard block
 block discarded – undo
3194 3194
         
3195 3195
         //do a nonce check here since we're not arriving via a normal route
3196 3196
         $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3197
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3197
+        $nonce_ref = 'activate_'.$this->_req_data['messenger'].'_toggle_nonce';
3198 3198
         
3199 3199
         $this->_verify_nonce($nonce, $nonce_ref);
3200 3200
         
@@ -3296,7 +3296,7 @@  discard block
 block discarded – undo
3296 3296
         
3297 3297
         //do a nonce check here since we're not arriving via a normal route
3298 3298
         $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3299
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3299
+        $nonce_ref = $this->_req_data['message_type'].'_nonce';
3300 3300
         
3301 3301
         $this->_verify_nonce($nonce, $nonce_ref);
3302 3302
         
Please login to merge, or discard this patch.
Indentation   +3620 added lines, -3620 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('NO direct script access allowed');
2
+	exit('NO direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -17,2213 +17,2213 @@  discard block
 block discarded – undo
17 17
 class Messages_Admin_Page extends EE_Admin_Page
18 18
 {
19 19
     
20
-    /**
21
-     * @type EE_Message_Resource_Manager $_message_resource_manager
22
-     */
23
-    protected $_message_resource_manager;
24
-    
25
-    /**
26
-     * @type string $_active_message_type_name
27
-     */
28
-    protected $_active_message_type_name = '';
29
-    
30
-    /**
31
-     * @type EE_messenger $_active_messenger
32
-     */
33
-    protected $_active_messenger;
34
-    protected $_activate_state;
35
-    protected $_activate_meta_box_type;
36
-    protected $_current_message_meta_box;
37
-    protected $_current_message_meta_box_object;
38
-    protected $_context_switcher;
39
-    protected $_shortcodes = array();
40
-    protected $_active_messengers = array();
41
-    protected $_active_message_types = array();
42
-    
43
-    /**
44
-     * @var EE_Message_Template_Group $_message_template_group
45
-     */
46
-    protected $_message_template_group;
47
-    protected $_m_mt_settings = array();
48
-    
49
-    
50
-    /**
51
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
-     * IF there is no group then it gets automatically set to the Default template pack.
53
-     *
54
-     * @since 4.5.0
55
-     *
56
-     * @var EE_Messages_Template_Pack
57
-     */
58
-    protected $_template_pack;
59
-    
60
-    
61
-    /**
62
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
-     * group is.  If there is no group then it automatically gets set to default.
64
-     *
65
-     * @since 4.5.0
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_variation;
70
-    
71
-    
72
-    /**
73
-     * @param bool $routing
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        //make sure messages autoloader is running
78
-        EED_Messages::set_autoloaders();
79
-        parent::__construct($routing);
80
-    }
81
-    
82
-    
83
-    protected function _init_page_props()
84
-    {
85
-        $this->page_slug        = EE_MSG_PG_SLUG;
86
-        $this->page_label       = __('Messages Settings', 'event_espresso');
87
-        $this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
-        $this->_admin_base_path = EE_MSG_ADMIN;
89
-        
90
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
-        
92
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
-        $this->_load_message_resource_manager();
94
-    }
95
-    
96
-    
97
-    /**
98
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
-     *
100
-     *
101
-     * @throws EE_Error
102
-     */
103
-    protected function _load_message_resource_manager()
104
-    {
105
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
-    }
107
-    
108
-    
109
-    /**
110
-     * @deprecated 4.9.9.rc.014
111
-     * @return array
112
-     */
113
-    public function get_messengers_for_list_table()
114
-    {
115
-        EE_Error::doing_it_wrong(
116
-            __METHOD__,
117
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
20
+	/**
21
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
22
+	 */
23
+	protected $_message_resource_manager;
24
+    
25
+	/**
26
+	 * @type string $_active_message_type_name
27
+	 */
28
+	protected $_active_message_type_name = '';
29
+    
30
+	/**
31
+	 * @type EE_messenger $_active_messenger
32
+	 */
33
+	protected $_active_messenger;
34
+	protected $_activate_state;
35
+	protected $_activate_meta_box_type;
36
+	protected $_current_message_meta_box;
37
+	protected $_current_message_meta_box_object;
38
+	protected $_context_switcher;
39
+	protected $_shortcodes = array();
40
+	protected $_active_messengers = array();
41
+	protected $_active_message_types = array();
42
+    
43
+	/**
44
+	 * @var EE_Message_Template_Group $_message_template_group
45
+	 */
46
+	protected $_message_template_group;
47
+	protected $_m_mt_settings = array();
48
+    
49
+    
50
+	/**
51
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
52
+	 * IF there is no group then it gets automatically set to the Default template pack.
53
+	 *
54
+	 * @since 4.5.0
55
+	 *
56
+	 * @var EE_Messages_Template_Pack
57
+	 */
58
+	protected $_template_pack;
59
+    
60
+    
61
+	/**
62
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
63
+	 * group is.  If there is no group then it automatically gets set to default.
64
+	 *
65
+	 * @since 4.5.0
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_variation;
70
+    
71
+    
72
+	/**
73
+	 * @param bool $routing
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		//make sure messages autoloader is running
78
+		EED_Messages::set_autoloaders();
79
+		parent::__construct($routing);
80
+	}
81
+    
82
+    
83
+	protected function _init_page_props()
84
+	{
85
+		$this->page_slug        = EE_MSG_PG_SLUG;
86
+		$this->page_label       = __('Messages Settings', 'event_espresso');
87
+		$this->_admin_base_url  = EE_MSG_ADMIN_URL;
88
+		$this->_admin_base_path = EE_MSG_ADMIN;
89
+        
90
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array)$this->_req_data['activate_state'] : array();
91
+        
92
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
93
+		$this->_load_message_resource_manager();
94
+	}
95
+    
96
+    
97
+	/**
98
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
99
+	 *
100
+	 *
101
+	 * @throws EE_Error
102
+	 */
103
+	protected function _load_message_resource_manager()
104
+	{
105
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
106
+	}
107
+    
108
+    
109
+	/**
110
+	 * @deprecated 4.9.9.rc.014
111
+	 * @return array
112
+	 */
113
+	public function get_messengers_for_list_table()
114
+	{
115
+		EE_Error::doing_it_wrong(
116
+			__METHOD__,
117
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
118 118
 			values for use in creating a messenger filter dropdown which is now generated differently via
119 119
 			 Messages_Admin_Page::get_messengers_select_input', 'event_espresso'),
120
-            '4.9.9.rc.014'
121
-        );
122
-        
123
-        $m_values          = array();
124
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
-        //setup messengers for selects
126
-        $i = 1;
127
-        foreach ($active_messengers as $active_messenger) {
128
-            if ($active_messenger instanceof EE_Message) {
129
-                $m_values[$i]['id']   = $active_messenger->messenger();
130
-                $m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
-                $i++;
132
-            }
133
-        }
134
-        
135
-        return $m_values;
136
-    }
137
-    
138
-    
139
-    /**
140
-     * @deprecated 4.9.9.rc.014
141
-     * @return array
142
-     */
143
-    public function get_message_types_for_list_table()
144
-    {
145
-        EE_Error::doing_it_wrong(
146
-            __METHOD__,
147
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
120
+			'4.9.9.rc.014'
121
+		);
122
+        
123
+		$m_values          = array();
124
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
125
+		//setup messengers for selects
126
+		$i = 1;
127
+		foreach ($active_messengers as $active_messenger) {
128
+			if ($active_messenger instanceof EE_Message) {
129
+				$m_values[$i]['id']   = $active_messenger->messenger();
130
+				$m_values[$i]['text'] = ucwords($active_messenger->messenger_label());
131
+				$i++;
132
+			}
133
+		}
134
+        
135
+		return $m_values;
136
+	}
137
+    
138
+    
139
+	/**
140
+	 * @deprecated 4.9.9.rc.014
141
+	 * @return array
142
+	 */
143
+	public function get_message_types_for_list_table()
144
+	{
145
+		EE_Error::doing_it_wrong(
146
+			__METHOD__,
147
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
148 148
 			values for use in creating a message type filter dropdown which is now generated differently via
149 149
 			 Messages_Admin_Page::get_message_types_select_input', 'event_espresso'),
150
-            '4.9.9.rc.014'
151
-        );
152
-        
153
-        $mt_values       = array();
154
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
-        $i               = 1;
156
-        foreach ($active_messages as $active_message) {
157
-            if ($active_message instanceof EE_Message) {
158
-                $mt_values[$i]['id']   = $active_message->message_type();
159
-                $mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
-                $i++;
161
-            }
162
-        }
163
-        
164
-        return $mt_values;
165
-    }
166
-    
167
-    
168
-    /**
169
-     * @deprecated 4.9.9.rc.014
170
-     * @return array
171
-     */
172
-    public function get_contexts_for_message_types_for_list_table()
173
-    {
174
-        EE_Error::doing_it_wrong(
175
-            __METHOD__,
176
-            __('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
150
+			'4.9.9.rc.014'
151
+		);
152
+        
153
+		$mt_values       = array();
154
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
155
+		$i               = 1;
156
+		foreach ($active_messages as $active_message) {
157
+			if ($active_message instanceof EE_Message) {
158
+				$mt_values[$i]['id']   = $active_message->message_type();
159
+				$mt_values[$i]['text'] = ucwords($active_message->message_type_label());
160
+				$i++;
161
+			}
162
+		}
163
+        
164
+		return $mt_values;
165
+	}
166
+    
167
+    
168
+	/**
169
+	 * @deprecated 4.9.9.rc.014
170
+	 * @return array
171
+	 */
172
+	public function get_contexts_for_message_types_for_list_table()
173
+	{
174
+		EE_Error::doing_it_wrong(
175
+			__METHOD__,
176
+			__('This method is no longer in use.  There is no replacement for it. The method was used to generate a set of
177 177
 			values for use in creating a message type context filter dropdown which is now generated differently via
178 178
 			 Messages_Admin_Page::get_contexts_for_message_types_select_input', 'event_espresso'),
179
-            '4.9.9.rc.014'
180
-        );
181
-        
182
-        $contexts                = array();
183
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
-        foreach ($active_message_contexts as $active_message) {
185
-            if ($active_message instanceof EE_Message) {
186
-                $message_type = $active_message->message_type_object();
187
-                if ($message_type instanceof EE_message_type) {
188
-                    $message_type_contexts = $message_type->get_contexts();
189
-                    foreach ($message_type_contexts as $context => $context_details) {
190
-                        $contexts[$context] = $context_details['label'];
191
-                    }
192
-                }
193
-            }
194
-        }
195
-        
196
-        return $contexts;
197
-    }
198
-    
199
-    
200
-    /**
201
-     * Generate select input with provided messenger options array.
202
-     *
203
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
-     *                                 labels.
205
-     *
206
-     * @return string
207
-     */
208
-    public function get_messengers_select_input($messenger_options)
209
-    {
210
-        //if empty or just one value then just return an empty string
211
-        if (empty($messenger_options)
212
-            || ! is_array($messenger_options)
213
-            || count($messenger_options) === 1
214
-        ) {
215
-            return '';
216
-        }
217
-        //merge in default
218
-        $messenger_options = array_merge(
219
-            array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
-            $messenger_options
221
-        );
222
-        $input             = new EE_Select_Input(
223
-            $messenger_options,
224
-            array(
225
-                'html_name'  => 'ee_messenger_filter_by',
226
-                'html_id'    => 'ee_messenger_filter_by',
227
-                'html_class' => 'wide',
228
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
-                    : 'none_selected'
231
-            )
232
-        );
233
-        
234
-        return $input->get_html_for_input();
235
-    }
236
-    
237
-    
238
-    /**
239
-     * Generate select input with provided message type options array.
240
-     *
241
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
-     *                                    message type labels
243
-     *
244
-     * @return string
245
-     */
246
-    public function get_message_types_select_input($message_type_options)
247
-    {
248
-        //if empty or count of options is 1 then just return an empty string
249
-        if (empty($message_type_options)
250
-            || ! is_array($message_type_options)
251
-            || count($message_type_options) === 1
252
-        ) {
253
-            return '';
254
-        }
255
-        //merge in default
256
-        $message_type_options = array_merge(
257
-            array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
-            $message_type_options
259
-        );
260
-        $input                = new EE_Select_Input(
261
-            $message_type_options,
262
-            array(
263
-                'html_name'  => 'ee_message_type_filter_by',
264
-                'html_id'    => 'ee_message_type_filter_by',
265
-                'html_class' => 'wide',
266
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
-                    : 'none_selected',
269
-            )
270
-        );
271
-        
272
-        return $input->get_html_for_input();
273
-    }
274
-    
275
-    
276
-    /**
277
-     * Generate select input with provide message type contexts array.
278
-     *
279
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
-     *                               context label.
281
-     *
282
-     * @return string
283
-     */
284
-    public function get_contexts_for_message_types_select_input($context_options)
285
-    {
286
-        //if empty or count of options is one then just return empty string
287
-        if (empty($context_options)
288
-            || ! is_array($context_options)
289
-            || count($context_options) === 1
290
-        ) {
291
-            return '';
292
-        }
293
-        //merge in default
294
-        $context_options = array_merge(
295
-            array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
-            $context_options
297
-        );
298
-        $input           = new EE_Select_Input(
299
-            $context_options,
300
-            array(
301
-                'html_name'  => 'ee_context_filter_by',
302
-                'html_id'    => 'ee_context_filter_by',
303
-                'html_class' => 'wide',
304
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
305
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
306
-                    : 'none_selected',
307
-            )
308
-        );
309
-        
310
-        return $input->get_html_for_input();
311
-    }
312
-    
313
-    
314
-    protected function _ajax_hooks()
315
-    {
316
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
-    }
322
-    
323
-    
324
-    protected function _define_page_props()
325
-    {
326
-        $this->_admin_page_title = $this->page_label;
327
-        $this->_labels           = array(
328
-            'buttons'    => array(
329
-                'add'    => __('Add New Message Template', 'event_espresso'),
330
-                'edit'   => __('Edit Message Template', 'event_espresso'),
331
-                'delete' => __('Delete Message Template', 'event_espresso')
332
-            ),
333
-            'publishbox' => __('Update Actions', 'event_espresso')
334
-        );
335
-    }
336
-    
337
-    
338
-    /**
339
-     *        an array for storing key => value pairs of request actions and their corresponding methods
340
-     * @access protected
341
-     * @return void
342
-     */
343
-    protected function _set_page_routes()
344
-    {
345
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
-            ? $this->_req_data['GRP_ID']
347
-            : 0;
348
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
-            ? $this->_req_data['id']
350
-            : $grp_id;
351
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
-            ? $this->_req_data['MSG_ID']
353
-            : 0;
354
-        
355
-        $this->_page_routes = array(
356
-            'default'                          => array(
357
-                'func'       => '_message_queue_list_table',
358
-                'capability' => 'ee_read_global_messages'
359
-            ),
360
-            'global_mtps'                      => array(
361
-                'func'       => '_ee_default_messages_overview_list_table',
362
-                'capability' => 'ee_read_global_messages'
363
-            ),
364
-            'custom_mtps'                      => array(
365
-                'func'       => '_custom_mtps_preview',
366
-                'capability' => 'ee_read_messages'
367
-            ),
368
-            'add_new_message_template'         => array(
369
-                'func'       => '_add_message_template',
370
-                'capability' => 'ee_edit_messages',
371
-                'noheader'   => true
372
-            ),
373
-            'edit_message_template'            => array(
374
-                'func'       => '_edit_message_template',
375
-                'capability' => 'ee_edit_message',
376
-                'obj_id'     => $grp_id
377
-            ),
378
-            'preview_message'                  => array(
379
-                'func'               => '_preview_message',
380
-                'capability'         => 'ee_read_message',
381
-                'obj_id'             => $grp_id,
382
-                'noheader'           => true,
383
-                'headers_sent_route' => 'display_preview_message'
384
-            ),
385
-            'display_preview_message'          => array(
386
-                'func'       => '_display_preview_message',
387
-                'capability' => 'ee_read_message',
388
-                'obj_id'     => $grp_id
389
-            ),
390
-            'insert_message_template'          => array(
391
-                'func'       => '_insert_or_update_message_template',
392
-                'capability' => 'ee_edit_messages',
393
-                'args'       => array('new_template' => true),
394
-                'noheader'   => true
395
-            ),
396
-            'update_message_template'          => array(
397
-                'func'       => '_insert_or_update_message_template',
398
-                'capability' => 'ee_edit_message',
399
-                'obj_id'     => $grp_id,
400
-                'args'       => array('new_template' => false),
401
-                'noheader'   => true
402
-            ),
403
-            'trash_message_template'           => array(
404
-                'func'       => '_trash_or_restore_message_template',
405
-                'capability' => 'ee_delete_message',
406
-                'obj_id'     => $grp_id,
407
-                'args'       => array('trash' => true, 'all' => true),
408
-                'noheader'   => true
409
-            ),
410
-            'trash_message_template_context'   => array(
411
-                'func'       => '_trash_or_restore_message_template',
412
-                'capability' => 'ee_delete_message',
413
-                'obj_id'     => $grp_id,
414
-                'args'       => array('trash' => true),
415
-                'noheader'   => true
416
-            ),
417
-            'restore_message_template'         => array(
418
-                'func'       => '_trash_or_restore_message_template',
419
-                'capability' => 'ee_delete_message',
420
-                'obj_id'     => $grp_id,
421
-                'args'       => array('trash' => false, 'all' => true),
422
-                'noheader'   => true
423
-            ),
424
-            'restore_message_template_context' => array(
425
-                'func'       => '_trash_or_restore_message_template',
426
-                'capability' => 'ee_delete_message',
427
-                'obj_id'     => $grp_id,
428
-                'args'       => array('trash' => false),
429
-                'noheader'   => true
430
-            ),
431
-            'delete_message_template'          => array(
432
-                'func'       => '_delete_message_template',
433
-                'capability' => 'ee_delete_message',
434
-                'obj_id'     => $grp_id,
435
-                'noheader'   => true
436
-            ),
437
-            'reset_to_default'                 => array(
438
-                'func'       => '_reset_to_default_template',
439
-                'capability' => 'ee_edit_message',
440
-                'obj_id'     => $grp_id,
441
-                'noheader'   => true
442
-            ),
443
-            'settings'                         => array(
444
-                'func'       => '_settings',
445
-                'capability' => 'manage_options'
446
-            ),
447
-            'update_global_settings'           => array(
448
-                'func'       => '_update_global_settings',
449
-                'capability' => 'manage_options',
450
-                'noheader'   => true
451
-            ),
452
-            'generate_now'                     => array(
453
-                'func'       => '_generate_now',
454
-                'capability' => 'ee_send_message',
455
-                'noheader'   => true
456
-            ),
457
-            'generate_and_send_now'            => array(
458
-                'func'       => '_generate_and_send_now',
459
-                'capability' => 'ee_send_message',
460
-                'noheader'   => true
461
-            ),
462
-            'queue_for_resending'              => array(
463
-                'func'       => '_queue_for_resending',
464
-                'capability' => 'ee_send_message',
465
-                'noheader'   => true
466
-            ),
467
-            'send_now'                         => array(
468
-                'func'       => '_send_now',
469
-                'capability' => 'ee_send_message',
470
-                'noheader'   => true
471
-            ),
472
-            'delete_ee_message'                => array(
473
-                'func'       => '_delete_ee_messages',
474
-                'capability' => 'ee_delete_message',
475
-                'noheader'   => true
476
-            ),
477
-            'delete_ee_messages'               => array(
478
-                'func'       => '_delete_ee_messages',
479
-                'capability' => 'ee_delete_messages',
480
-                'noheader'   => true,
481
-                'obj_id'     => $msg_id
482
-            )
483
-        );
484
-    }
485
-    
486
-    
487
-    protected function _set_page_config()
488
-    {
489
-        $this->_page_config = array(
490
-            'default'                  => array(
491
-                'nav'           => array(
492
-                    'label' => __('Message Activity', 'event_espresso'),
493
-                    'order' => 10
494
-                ),
495
-                'list_table'    => 'EE_Message_List_Table',
496
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
-                'require_nonce' => false
498
-            ),
499
-            'global_mtps'              => array(
500
-                'nav'           => array(
501
-                    'label' => __('Default Message Templates', 'event_espresso'),
502
-                    'order' => 20
503
-                ),
504
-                'list_table'    => 'Messages_Template_List_Table',
505
-                'help_tabs'     => array(
506
-                    'messages_overview_help_tab'                                => array(
507
-                        'title'    => __('Messages Overview', 'event_espresso'),
508
-                        'filename' => 'messages_overview'
509
-                    ),
510
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
511
-                        'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
-                        'filename' => 'messages_overview_table_column_headings'
513
-                    ),
514
-                    'messages_overview_messages_filters_help_tab'               => array(
515
-                        'title'    => __('Message Filters', 'event_espresso'),
516
-                        'filename' => 'messages_overview_filters'
517
-                    ),
518
-                    'messages_overview_messages_views_help_tab'                 => array(
519
-                        'title'    => __('Message Views', 'event_espresso'),
520
-                        'filename' => 'messages_overview_views'
521
-                    ),
522
-                    'message_overview_message_types_help_tab'                   => array(
523
-                        'title'    => __('Message Types', 'event_espresso'),
524
-                        'filename' => 'messages_overview_types'
525
-                    ),
526
-                    'messages_overview_messengers_help_tab'                     => array(
527
-                        'title'    => __('Messengers', 'event_espresso'),
528
-                        'filename' => 'messages_overview_messengers',
529
-                    ),
530
-                    'messages_overview_other_help_tab'                          => array(
531
-                        'title'    => __('Messages Other', 'event_espresso'),
532
-                        'filename' => 'messages_overview_other',
533
-                    ),
534
-                ),
535
-                'help_tour'     => array('Messages_Overview_Help_Tour'),
536
-                'require_nonce' => false
537
-            ),
538
-            'custom_mtps'              => array(
539
-                'nav'           => array(
540
-                    'label' => __('Custom Message Templates', 'event_espresso'),
541
-                    'order' => 30
542
-                ),
543
-                'help_tabs'     => array(),
544
-                'help_tour'     => array(),
545
-                'require_nonce' => false
546
-            ),
547
-            'add_new_message_template' => array(
548
-                'nav'           => array(
549
-                    'label'      => __('Add New Message Templates', 'event_espresso'),
550
-                    'order'      => 5,
551
-                    'persistent' => false
552
-                ),
553
-                'require_nonce' => false
554
-            ),
555
-            'edit_message_template'    => array(
556
-                'labels'        => array(
557
-                    'buttons'    => array(
558
-                        'reset' => __('Reset Templates'),
559
-                    ),
560
-                    'publishbox' => __('Update Actions', 'event_espresso')
561
-                ),
562
-                'nav'           => array(
563
-                    'label'      => __('Edit Message Templates', 'event_espresso'),
564
-                    'order'      => 5,
565
-                    'persistent' => false,
566
-                    'url'        => ''
567
-                ),
568
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
-                'has_metaboxes' => true,
570
-                'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
-                'help_tabs'     => array(
572
-                    'edit_message_template'       => array(
573
-                        'title'    => __('Message Template Editor', 'event_espresso'),
574
-                        'callback' => 'edit_message_template_help_tab'
575
-                    ),
576
-                    'message_templates_help_tab'  => array(
577
-                        'title'    => __('Message Templates', 'event_espresso'),
578
-                        'filename' => 'messages_templates'
579
-                    ),
580
-                    'message_template_shortcodes' => array(
581
-                        'title'    => __('Message Shortcodes', 'event_espresso'),
582
-                        'callback' => 'message_template_shortcodes_help_tab'
583
-                    ),
584
-                    'message_preview_help_tab'    => array(
585
-                        'title'    => __('Message Preview', 'event_espresso'),
586
-                        'filename' => 'messages_preview'
587
-                    ),
588
-                ),
589
-                'require_nonce' => false
590
-            ),
591
-            'display_preview_message'  => array(
592
-                'nav'           => array(
593
-                    'label'      => __('Message Preview', 'event_espresso'),
594
-                    'order'      => 5,
595
-                    'url'        => '',
596
-                    'persistent' => false
597
-                ),
598
-                'help_tabs'     => array(
599
-                    'preview_message' => array(
600
-                        'title'    => __('About Previews', 'event_espresso'),
601
-                        'callback' => 'preview_message_help_tab'
602
-                    )
603
-                ),
604
-                'require_nonce' => false
605
-            ),
606
-            'settings'                 => array(
607
-                'nav'           => array(
608
-                    'label' => __('Settings', 'event_espresso'),
609
-                    'order' => 40
610
-                ),
611
-                'metaboxes'     => array('_messages_settings_metaboxes'),
612
-                'help_tabs'     => array(
613
-                    'messages_settings_help_tab'               => array(
614
-                        'title'    => __('Messages Settings', 'event_espresso'),
615
-                        'filename' => 'messages_settings'
616
-                    ),
617
-                    'messages_settings_message_types_help_tab' => array(
618
-                        'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
-                        'filename' => 'messages_settings_message_types'
620
-                    ),
621
-                    'messages_settings_messengers_help_tab'    => array(
622
-                        'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
-                        'filename' => 'messages_settings_messengers'
624
-                    ),
625
-                ),
626
-                'help_tour'     => array('Messages_Settings_Help_Tour'),
627
-                'require_nonce' => false
628
-            )
629
-        );
630
-    }
631
-    
632
-    
633
-    protected function _add_screen_options()
634
-    {
635
-        //todo
636
-    }
637
-    
638
-    
639
-    protected function _add_screen_options_global_mtps()
640
-    {
641
-        /**
642
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
644
-         */
645
-        $page_title              = $this->_admin_page_title;
646
-        $this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
-        $this->_per_page_screen_option();
648
-        $this->_admin_page_title = $page_title;
649
-    }
650
-    
651
-    
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_admin_page_title = __('Message Activity', 'event_espresso');
655
-        $this->_per_page_screen_option();
656
-    }
657
-    
658
-    
659
-    //none of the below group are currently used for Messages
660
-    protected function _add_feature_pointers()
661
-    {
662
-    }
663
-    
664
-    public function admin_init()
665
-    {
666
-    }
667
-    
668
-    public function admin_notices()
669
-    {
670
-    }
671
-    
672
-    public function admin_footer_scripts()
673
-    {
674
-    }
675
-    
676
-    
677
-    public function messages_help_tab()
678
-    {
679
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
-    }
681
-    
682
-    
683
-    public function messengers_help_tab()
684
-    {
685
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
-    }
687
-    
688
-    
689
-    public function message_types_help_tab()
690
-    {
691
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
-    }
693
-    
694
-    
695
-    public function messages_overview_help_tab()
696
-    {
697
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
-    }
699
-    
700
-    
701
-    public function message_templates_help_tab()
702
-    {
703
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
-    }
705
-    
706
-    
707
-    public function edit_message_template_help_tab()
708
-    {
709
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
-                'event_espresso') . '" />';
711
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
-                'event_espresso') . '" />';
713
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
-                'event_espresso') . '" />';
715
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
-                'event_espresso') . '" />';
717
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
-                'event_espresso') . '" />';
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
-            $args);
721
-    }
722
-    
723
-    
724
-    public function message_template_shortcodes_help_tab()
725
-    {
726
-        $this->_set_shortcodes();
727
-        $args['shortcodes'] = $this->_shortcodes;
728
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
-            $args);
730
-    }
179
+			'4.9.9.rc.014'
180
+		);
181
+        
182
+		$contexts                = array();
183
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
184
+		foreach ($active_message_contexts as $active_message) {
185
+			if ($active_message instanceof EE_Message) {
186
+				$message_type = $active_message->message_type_object();
187
+				if ($message_type instanceof EE_message_type) {
188
+					$message_type_contexts = $message_type->get_contexts();
189
+					foreach ($message_type_contexts as $context => $context_details) {
190
+						$contexts[$context] = $context_details['label'];
191
+					}
192
+				}
193
+			}
194
+		}
195
+        
196
+		return $contexts;
197
+	}
198
+    
199
+    
200
+	/**
201
+	 * Generate select input with provided messenger options array.
202
+	 *
203
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
204
+	 *                                 labels.
205
+	 *
206
+	 * @return string
207
+	 */
208
+	public function get_messengers_select_input($messenger_options)
209
+	{
210
+		//if empty or just one value then just return an empty string
211
+		if (empty($messenger_options)
212
+			|| ! is_array($messenger_options)
213
+			|| count($messenger_options) === 1
214
+		) {
215
+			return '';
216
+		}
217
+		//merge in default
218
+		$messenger_options = array_merge(
219
+			array('none_selected' => __('Show All Messengers', 'event_espresso')),
220
+			$messenger_options
221
+		);
222
+		$input             = new EE_Select_Input(
223
+			$messenger_options,
224
+			array(
225
+				'html_name'  => 'ee_messenger_filter_by',
226
+				'html_id'    => 'ee_messenger_filter_by',
227
+				'html_class' => 'wide',
228
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
229
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
230
+					: 'none_selected'
231
+			)
232
+		);
233
+        
234
+		return $input->get_html_for_input();
235
+	}
236
+    
237
+    
238
+	/**
239
+	 * Generate select input with provided message type options array.
240
+	 *
241
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
242
+	 *                                    message type labels
243
+	 *
244
+	 * @return string
245
+	 */
246
+	public function get_message_types_select_input($message_type_options)
247
+	{
248
+		//if empty or count of options is 1 then just return an empty string
249
+		if (empty($message_type_options)
250
+			|| ! is_array($message_type_options)
251
+			|| count($message_type_options) === 1
252
+		) {
253
+			return '';
254
+		}
255
+		//merge in default
256
+		$message_type_options = array_merge(
257
+			array('none_selected' => __('Show All Message Types', 'event_espresso')),
258
+			$message_type_options
259
+		);
260
+		$input                = new EE_Select_Input(
261
+			$message_type_options,
262
+			array(
263
+				'html_name'  => 'ee_message_type_filter_by',
264
+				'html_id'    => 'ee_message_type_filter_by',
265
+				'html_class' => 'wide',
266
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
267
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
268
+					: 'none_selected',
269
+			)
270
+		);
271
+        
272
+		return $input->get_html_for_input();
273
+	}
274
+    
275
+    
276
+	/**
277
+	 * Generate select input with provide message type contexts array.
278
+	 *
279
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
280
+	 *                               context label.
281
+	 *
282
+	 * @return string
283
+	 */
284
+	public function get_contexts_for_message_types_select_input($context_options)
285
+	{
286
+		//if empty or count of options is one then just return empty string
287
+		if (empty($context_options)
288
+			|| ! is_array($context_options)
289
+			|| count($context_options) === 1
290
+		) {
291
+			return '';
292
+		}
293
+		//merge in default
294
+		$context_options = array_merge(
295
+			array('none_selected' => __('Show all Contexts', 'event_espresso')),
296
+			$context_options
297
+		);
298
+		$input           = new EE_Select_Input(
299
+			$context_options,
300
+			array(
301
+				'html_name'  => 'ee_context_filter_by',
302
+				'html_id'    => 'ee_context_filter_by',
303
+				'html_class' => 'wide',
304
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
305
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
306
+					: 'none_selected',
307
+			)
308
+		);
309
+        
310
+		return $input->get_html_for_input();
311
+	}
312
+    
313
+    
314
+	protected function _ajax_hooks()
315
+	{
316
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
317
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
318
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
319
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
320
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
321
+	}
322
+    
323
+    
324
+	protected function _define_page_props()
325
+	{
326
+		$this->_admin_page_title = $this->page_label;
327
+		$this->_labels           = array(
328
+			'buttons'    => array(
329
+				'add'    => __('Add New Message Template', 'event_espresso'),
330
+				'edit'   => __('Edit Message Template', 'event_espresso'),
331
+				'delete' => __('Delete Message Template', 'event_espresso')
332
+			),
333
+			'publishbox' => __('Update Actions', 'event_espresso')
334
+		);
335
+	}
336
+    
337
+    
338
+	/**
339
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
340
+	 * @access protected
341
+	 * @return void
342
+	 */
343
+	protected function _set_page_routes()
344
+	{
345
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
346
+			? $this->_req_data['GRP_ID']
347
+			: 0;
348
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
349
+			? $this->_req_data['id']
350
+			: $grp_id;
351
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
352
+			? $this->_req_data['MSG_ID']
353
+			: 0;
354
+        
355
+		$this->_page_routes = array(
356
+			'default'                          => array(
357
+				'func'       => '_message_queue_list_table',
358
+				'capability' => 'ee_read_global_messages'
359
+			),
360
+			'global_mtps'                      => array(
361
+				'func'       => '_ee_default_messages_overview_list_table',
362
+				'capability' => 'ee_read_global_messages'
363
+			),
364
+			'custom_mtps'                      => array(
365
+				'func'       => '_custom_mtps_preview',
366
+				'capability' => 'ee_read_messages'
367
+			),
368
+			'add_new_message_template'         => array(
369
+				'func'       => '_add_message_template',
370
+				'capability' => 'ee_edit_messages',
371
+				'noheader'   => true
372
+			),
373
+			'edit_message_template'            => array(
374
+				'func'       => '_edit_message_template',
375
+				'capability' => 'ee_edit_message',
376
+				'obj_id'     => $grp_id
377
+			),
378
+			'preview_message'                  => array(
379
+				'func'               => '_preview_message',
380
+				'capability'         => 'ee_read_message',
381
+				'obj_id'             => $grp_id,
382
+				'noheader'           => true,
383
+				'headers_sent_route' => 'display_preview_message'
384
+			),
385
+			'display_preview_message'          => array(
386
+				'func'       => '_display_preview_message',
387
+				'capability' => 'ee_read_message',
388
+				'obj_id'     => $grp_id
389
+			),
390
+			'insert_message_template'          => array(
391
+				'func'       => '_insert_or_update_message_template',
392
+				'capability' => 'ee_edit_messages',
393
+				'args'       => array('new_template' => true),
394
+				'noheader'   => true
395
+			),
396
+			'update_message_template'          => array(
397
+				'func'       => '_insert_or_update_message_template',
398
+				'capability' => 'ee_edit_message',
399
+				'obj_id'     => $grp_id,
400
+				'args'       => array('new_template' => false),
401
+				'noheader'   => true
402
+			),
403
+			'trash_message_template'           => array(
404
+				'func'       => '_trash_or_restore_message_template',
405
+				'capability' => 'ee_delete_message',
406
+				'obj_id'     => $grp_id,
407
+				'args'       => array('trash' => true, 'all' => true),
408
+				'noheader'   => true
409
+			),
410
+			'trash_message_template_context'   => array(
411
+				'func'       => '_trash_or_restore_message_template',
412
+				'capability' => 'ee_delete_message',
413
+				'obj_id'     => $grp_id,
414
+				'args'       => array('trash' => true),
415
+				'noheader'   => true
416
+			),
417
+			'restore_message_template'         => array(
418
+				'func'       => '_trash_or_restore_message_template',
419
+				'capability' => 'ee_delete_message',
420
+				'obj_id'     => $grp_id,
421
+				'args'       => array('trash' => false, 'all' => true),
422
+				'noheader'   => true
423
+			),
424
+			'restore_message_template_context' => array(
425
+				'func'       => '_trash_or_restore_message_template',
426
+				'capability' => 'ee_delete_message',
427
+				'obj_id'     => $grp_id,
428
+				'args'       => array('trash' => false),
429
+				'noheader'   => true
430
+			),
431
+			'delete_message_template'          => array(
432
+				'func'       => '_delete_message_template',
433
+				'capability' => 'ee_delete_message',
434
+				'obj_id'     => $grp_id,
435
+				'noheader'   => true
436
+			),
437
+			'reset_to_default'                 => array(
438
+				'func'       => '_reset_to_default_template',
439
+				'capability' => 'ee_edit_message',
440
+				'obj_id'     => $grp_id,
441
+				'noheader'   => true
442
+			),
443
+			'settings'                         => array(
444
+				'func'       => '_settings',
445
+				'capability' => 'manage_options'
446
+			),
447
+			'update_global_settings'           => array(
448
+				'func'       => '_update_global_settings',
449
+				'capability' => 'manage_options',
450
+				'noheader'   => true
451
+			),
452
+			'generate_now'                     => array(
453
+				'func'       => '_generate_now',
454
+				'capability' => 'ee_send_message',
455
+				'noheader'   => true
456
+			),
457
+			'generate_and_send_now'            => array(
458
+				'func'       => '_generate_and_send_now',
459
+				'capability' => 'ee_send_message',
460
+				'noheader'   => true
461
+			),
462
+			'queue_for_resending'              => array(
463
+				'func'       => '_queue_for_resending',
464
+				'capability' => 'ee_send_message',
465
+				'noheader'   => true
466
+			),
467
+			'send_now'                         => array(
468
+				'func'       => '_send_now',
469
+				'capability' => 'ee_send_message',
470
+				'noheader'   => true
471
+			),
472
+			'delete_ee_message'                => array(
473
+				'func'       => '_delete_ee_messages',
474
+				'capability' => 'ee_delete_message',
475
+				'noheader'   => true
476
+			),
477
+			'delete_ee_messages'               => array(
478
+				'func'       => '_delete_ee_messages',
479
+				'capability' => 'ee_delete_messages',
480
+				'noheader'   => true,
481
+				'obj_id'     => $msg_id
482
+			)
483
+		);
484
+	}
485
+    
486
+    
487
+	protected function _set_page_config()
488
+	{
489
+		$this->_page_config = array(
490
+			'default'                  => array(
491
+				'nav'           => array(
492
+					'label' => __('Message Activity', 'event_espresso'),
493
+					'order' => 10
494
+				),
495
+				'list_table'    => 'EE_Message_List_Table',
496
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
497
+				'require_nonce' => false
498
+			),
499
+			'global_mtps'              => array(
500
+				'nav'           => array(
501
+					'label' => __('Default Message Templates', 'event_espresso'),
502
+					'order' => 20
503
+				),
504
+				'list_table'    => 'Messages_Template_List_Table',
505
+				'help_tabs'     => array(
506
+					'messages_overview_help_tab'                                => array(
507
+						'title'    => __('Messages Overview', 'event_espresso'),
508
+						'filename' => 'messages_overview'
509
+					),
510
+					'messages_overview_messages_table_column_headings_help_tab' => array(
511
+						'title'    => __('Messages Table Column Headings', 'event_espresso'),
512
+						'filename' => 'messages_overview_table_column_headings'
513
+					),
514
+					'messages_overview_messages_filters_help_tab'               => array(
515
+						'title'    => __('Message Filters', 'event_espresso'),
516
+						'filename' => 'messages_overview_filters'
517
+					),
518
+					'messages_overview_messages_views_help_tab'                 => array(
519
+						'title'    => __('Message Views', 'event_espresso'),
520
+						'filename' => 'messages_overview_views'
521
+					),
522
+					'message_overview_message_types_help_tab'                   => array(
523
+						'title'    => __('Message Types', 'event_espresso'),
524
+						'filename' => 'messages_overview_types'
525
+					),
526
+					'messages_overview_messengers_help_tab'                     => array(
527
+						'title'    => __('Messengers', 'event_espresso'),
528
+						'filename' => 'messages_overview_messengers',
529
+					),
530
+					'messages_overview_other_help_tab'                          => array(
531
+						'title'    => __('Messages Other', 'event_espresso'),
532
+						'filename' => 'messages_overview_other',
533
+					),
534
+				),
535
+				'help_tour'     => array('Messages_Overview_Help_Tour'),
536
+				'require_nonce' => false
537
+			),
538
+			'custom_mtps'              => array(
539
+				'nav'           => array(
540
+					'label' => __('Custom Message Templates', 'event_espresso'),
541
+					'order' => 30
542
+				),
543
+				'help_tabs'     => array(),
544
+				'help_tour'     => array(),
545
+				'require_nonce' => false
546
+			),
547
+			'add_new_message_template' => array(
548
+				'nav'           => array(
549
+					'label'      => __('Add New Message Templates', 'event_espresso'),
550
+					'order'      => 5,
551
+					'persistent' => false
552
+				),
553
+				'require_nonce' => false
554
+			),
555
+			'edit_message_template'    => array(
556
+				'labels'        => array(
557
+					'buttons'    => array(
558
+						'reset' => __('Reset Templates'),
559
+					),
560
+					'publishbox' => __('Update Actions', 'event_espresso')
561
+				),
562
+				'nav'           => array(
563
+					'label'      => __('Edit Message Templates', 'event_espresso'),
564
+					'order'      => 5,
565
+					'persistent' => false,
566
+					'url'        => ''
567
+				),
568
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
569
+				'has_metaboxes' => true,
570
+				'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
571
+				'help_tabs'     => array(
572
+					'edit_message_template'       => array(
573
+						'title'    => __('Message Template Editor', 'event_espresso'),
574
+						'callback' => 'edit_message_template_help_tab'
575
+					),
576
+					'message_templates_help_tab'  => array(
577
+						'title'    => __('Message Templates', 'event_espresso'),
578
+						'filename' => 'messages_templates'
579
+					),
580
+					'message_template_shortcodes' => array(
581
+						'title'    => __('Message Shortcodes', 'event_espresso'),
582
+						'callback' => 'message_template_shortcodes_help_tab'
583
+					),
584
+					'message_preview_help_tab'    => array(
585
+						'title'    => __('Message Preview', 'event_espresso'),
586
+						'filename' => 'messages_preview'
587
+					),
588
+				),
589
+				'require_nonce' => false
590
+			),
591
+			'display_preview_message'  => array(
592
+				'nav'           => array(
593
+					'label'      => __('Message Preview', 'event_espresso'),
594
+					'order'      => 5,
595
+					'url'        => '',
596
+					'persistent' => false
597
+				),
598
+				'help_tabs'     => array(
599
+					'preview_message' => array(
600
+						'title'    => __('About Previews', 'event_espresso'),
601
+						'callback' => 'preview_message_help_tab'
602
+					)
603
+				),
604
+				'require_nonce' => false
605
+			),
606
+			'settings'                 => array(
607
+				'nav'           => array(
608
+					'label' => __('Settings', 'event_espresso'),
609
+					'order' => 40
610
+				),
611
+				'metaboxes'     => array('_messages_settings_metaboxes'),
612
+				'help_tabs'     => array(
613
+					'messages_settings_help_tab'               => array(
614
+						'title'    => __('Messages Settings', 'event_espresso'),
615
+						'filename' => 'messages_settings'
616
+					),
617
+					'messages_settings_message_types_help_tab' => array(
618
+						'title'    => __('Activating / Deactivating Message Types', 'event_espresso'),
619
+						'filename' => 'messages_settings_message_types'
620
+					),
621
+					'messages_settings_messengers_help_tab'    => array(
622
+						'title'    => __('Activating / Deactivating Messengers', 'event_espresso'),
623
+						'filename' => 'messages_settings_messengers'
624
+					),
625
+				),
626
+				'help_tour'     => array('Messages_Settings_Help_Tour'),
627
+				'require_nonce' => false
628
+			)
629
+		);
630
+	}
631
+    
632
+    
633
+	protected function _add_screen_options()
634
+	{
635
+		//todo
636
+	}
637
+    
638
+    
639
+	protected function _add_screen_options_global_mtps()
640
+	{
641
+		/**
642
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
643
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
644
+		 */
645
+		$page_title              = $this->_admin_page_title;
646
+		$this->_admin_page_title = __('Global Message Templates', 'event_espresso');
647
+		$this->_per_page_screen_option();
648
+		$this->_admin_page_title = $page_title;
649
+	}
650
+    
651
+    
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_admin_page_title = __('Message Activity', 'event_espresso');
655
+		$this->_per_page_screen_option();
656
+	}
657
+    
658
+    
659
+	//none of the below group are currently used for Messages
660
+	protected function _add_feature_pointers()
661
+	{
662
+	}
663
+    
664
+	public function admin_init()
665
+	{
666
+	}
667
+    
668
+	public function admin_notices()
669
+	{
670
+	}
671
+    
672
+	public function admin_footer_scripts()
673
+	{
674
+	}
675
+    
676
+    
677
+	public function messages_help_tab()
678
+	{
679
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
680
+	}
681
+    
682
+    
683
+	public function messengers_help_tab()
684
+	{
685
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
686
+	}
687
+    
688
+    
689
+	public function message_types_help_tab()
690
+	{
691
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
692
+	}
693
+    
694
+    
695
+	public function messages_overview_help_tab()
696
+	{
697
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
698
+	}
699
+    
700
+    
701
+	public function message_templates_help_tab()
702
+	{
703
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
704
+	}
705
+    
706
+    
707
+	public function edit_message_template_help_tab()
708
+	{
709
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="' . esc_attr__('Editor Title',
710
+				'event_espresso') . '" />';
711
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="' . esc_attr__('Context Switcher and Preview',
712
+				'event_espresso') . '" />';
713
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="' . esc_attr__('Message Template Form Fields',
714
+				'event_espresso') . '" />';
715
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="' . esc_attr__('Shortcodes Metabox',
716
+				'event_espresso') . '" />';
717
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="' . esc_attr__('Publish Metabox',
718
+				'event_espresso') . '" />';
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
720
+			$args);
721
+	}
722
+    
723
+    
724
+	public function message_template_shortcodes_help_tab()
725
+	{
726
+		$this->_set_shortcodes();
727
+		$args['shortcodes'] = $this->_shortcodes;
728
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
729
+			$args);
730
+	}
731 731
     
732 732
     
733
-    public function preview_message_help_tab()
734
-    {
735
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
-    }
733
+	public function preview_message_help_tab()
734
+	{
735
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
736
+	}
737 737
     
738
-    
739
-    public function settings_help_tab()
740
-    {
741
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
-                'event_espresso') . '" />';
743
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
-                'event_espresso') . '" />';
745
-        $args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
-        $args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
-    }
738
+    
739
+	public function settings_help_tab()
740
+	{
741
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '" alt="' . esc_attr__('Active Email Tab',
742
+				'event_espresso') . '" />';
743
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' . '" alt="' . esc_attr__('Inactive Email Tab',
744
+				'event_espresso') . '" />';
745
+		$args['img3'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked"><label for="ee-on-off-toggle-on"></label>';
746
+		$args['img4'] = '<div class="switch"><input id="ee-on-off-toggle-on" class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox"><label for="ee-on-off-toggle-on"></label>';
747
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
748
+	}
749 749
     
750 750
     
751
-    public function load_scripts_styles()
752
-    {
753
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
-        wp_enqueue_style('espresso_ee_msg');
751
+	public function load_scripts_styles()
752
+	{
753
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
754
+		wp_enqueue_style('espresso_ee_msg');
755 755
         
756
-        wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
-            array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
-        wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
-            array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
-    }
756
+		wp_register_script('ee-messages-settings', EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
757
+			array('jquery-ui-droppable', 'ee-serialize-full-array'), EVENT_ESPRESSO_VERSION, true);
758
+		wp_register_script('ee-msg-list-table-js', EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
759
+			array('ee-dialog'), EVENT_ESPRESSO_VERSION);
760
+	}
761 761
     
762 762
     
763
-    public function load_scripts_styles_default()
764
-    {
765
-        wp_enqueue_script('ee-msg-list-table-js');
766
-    }
763
+	public function load_scripts_styles_default()
764
+	{
765
+		wp_enqueue_script('ee-msg-list-table-js');
766
+	}
767 767
     
768 768
     
769
-    public function wp_editor_css($mce_css)
770
-    {
771
-        //if we're on the edit_message_template route
772
-        if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
-            $message_type_name = $this->_active_message_type_name;
769
+	public function wp_editor_css($mce_css)
770
+	{
771
+		//if we're on the edit_message_template route
772
+		if ($this->_req_action == 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
773
+			$message_type_name = $this->_active_message_type_name;
774 774
             
775
-            //we're going to REPLACE the existing mce css
776
-            //we need to get the css file location from the active messenger
777
-            $mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
-                'wpeditor', $this->_variation);
779
-        }
775
+			//we're going to REPLACE the existing mce css
776
+			//we need to get the css file location from the active messenger
777
+			$mce_css = $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true,
778
+				'wpeditor', $this->_variation);
779
+		}
780 780
         
781
-        return $mce_css;
782
-    }
783
-    
784
-    
785
-    public function load_scripts_styles_edit_message_template()
786
-    {
787
-        
788
-        $this->_set_shortcodes();
781
+		return $mce_css;
782
+	}
783
+    
784
+    
785
+	public function load_scripts_styles_edit_message_template()
786
+	{
787
+        
788
+		$this->_set_shortcodes();
789 789
         
790
-        EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
-            __('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.',
792
-                'event_espresso'),
793
-            $this->_message_template_group->messenger_obj()->label['singular'],
794
-            $this->_message_template_group->message_type_obj()->label['singular']
795
-        );
796
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
-            'event_espresso');
798
-        
799
-        wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
-            EVENT_ESPRESSO_VERSION);
801
-        
802
-        wp_enqueue_script('ee_admin_js');
803
-        wp_enqueue_script('ee_msgs_edit_js');
804
-        
805
-        //add in special css for tiny_mce
806
-        add_filter('mce_css', array($this, 'wp_editor_css'));
807
-    }
808
-    
809
-    
810
-    public function load_scripts_styles_display_preview_message()
811
-    {
812
-        
813
-        $this->_set_message_template_group();
814
-        
815
-        if (isset($this->_req_data['messenger'])) {
816
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
-        }
818
-        
819
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
-        
821
-        
822
-        wp_enqueue_style('espresso_preview_css',
823
-            $this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
-                $this->_variation));
825
-    }
826
-    
827
-    
828
-    public function load_scripts_styles_settings()
829
-    {
830
-        wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
-            EVENT_ESPRESSO_VERSION);
832
-        wp_enqueue_style('ee-text-links');
833
-        wp_enqueue_style('ee-message-settings');
834
-        
835
-        wp_enqueue_script('ee-messages-settings');
836
-    }
837
-    
838
-    
839
-    /**
840
-     * set views array for List Table
841
-     */
842
-    public function _set_list_table_views_global_mtps()
843
-    {
844
-        $this->_views = array(
845
-            'in_use' => array(
846
-                'slug'        => 'in_use',
847
-                'label'       => __('In Use', 'event_espresso'),
848
-                'count'       => 0,
849
-                'bulk_action' => array(
850
-                    'trash_message_template' => __('Move to Trash', 'event_espresso')
851
-                )
852
-            )
853
-        );
854
-    }
855
-    
856
-    
857
-    /**
858
-     * set views array for message queue list table
859
-     */
860
-    public function _set_list_table_views_default()
861
-    {
862
-        EE_Registry::instance()->load_helper('Template');
863
-        
864
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
-            'message_list_table_bulk_actions')
866
-            ? array(
867
-                'generate_now'          => __('Generate Now', 'event_espresso'),
868
-                'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
-                'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
-                'send_now'              => __('Send Now', 'event_espresso')
871
-            )
872
-            : array();
873
-        
874
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
-            'message_list_table_bulk_actions')
876
-            ? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
-            : array();
878
-        
879
-        
880
-        $this->_views = array(
881
-            'all' => array(
882
-                'slug'        => 'all',
883
-                'label'       => __('All', 'event_espresso'),
884
-                'count'       => 0,
885
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
-            )
887
-        );
888
-        
889
-        
890
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
891
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
-                continue;
893
-            }
894
-            $status_bulk_actions = $common_bulk_actions;
895
-            //unset bulk actions not applying to status
896
-            if (! empty($status_bulk_actions)) {
897
-                switch ($status) {
898
-                    case EEM_Message::status_idle:
899
-                    case EEM_Message::status_resend:
900
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
-                        break;
790
+		EE_Registry::$i18n_js_strings['confirm_default_reset']        = sprintf(
791
+			__('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.',
792
+				'event_espresso'),
793
+			$this->_message_template_group->messenger_obj()->label['singular'],
794
+			$this->_message_template_group->message_type_obj()->label['singular']
795
+		);
796
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = __('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?',
797
+			'event_espresso');
798
+        
799
+		wp_register_script('ee_msgs_edit_js', EE_MSG_ASSETS_URL . 'ee_message_editor.js', array('jquery'),
800
+			EVENT_ESPRESSO_VERSION);
801
+        
802
+		wp_enqueue_script('ee_admin_js');
803
+		wp_enqueue_script('ee_msgs_edit_js');
804
+        
805
+		//add in special css for tiny_mce
806
+		add_filter('mce_css', array($this, 'wp_editor_css'));
807
+	}
808
+    
809
+    
810
+	public function load_scripts_styles_display_preview_message()
811
+	{
812
+        
813
+		$this->_set_message_template_group();
814
+        
815
+		if (isset($this->_req_data['messenger'])) {
816
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
817
+		}
818
+        
819
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
820
+        
821
+        
822
+		wp_enqueue_style('espresso_preview_css',
823
+			$this->_active_messenger->get_variation($this->_template_pack, $message_type_name, true, 'preview',
824
+				$this->_variation));
825
+	}
826
+    
827
+    
828
+	public function load_scripts_styles_settings()
829
+	{
830
+		wp_register_style('ee-message-settings', EE_MSG_ASSETS_URL . 'ee_message_settings.css', array(),
831
+			EVENT_ESPRESSO_VERSION);
832
+		wp_enqueue_style('ee-text-links');
833
+		wp_enqueue_style('ee-message-settings');
834
+        
835
+		wp_enqueue_script('ee-messages-settings');
836
+	}
837
+    
838
+    
839
+	/**
840
+	 * set views array for List Table
841
+	 */
842
+	public function _set_list_table_views_global_mtps()
843
+	{
844
+		$this->_views = array(
845
+			'in_use' => array(
846
+				'slug'        => 'in_use',
847
+				'label'       => __('In Use', 'event_espresso'),
848
+				'count'       => 0,
849
+				'bulk_action' => array(
850
+					'trash_message_template' => __('Move to Trash', 'event_espresso')
851
+				)
852
+			)
853
+		);
854
+	}
855
+    
856
+    
857
+	/**
858
+	 * set views array for message queue list table
859
+	 */
860
+	public function _set_list_table_views_default()
861
+	{
862
+		EE_Registry::instance()->load_helper('Template');
863
+        
864
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can('ee_send_message',
865
+			'message_list_table_bulk_actions')
866
+			? array(
867
+				'generate_now'          => __('Generate Now', 'event_espresso'),
868
+				'generate_and_send_now' => __('Generate and Send Now', 'event_espresso'),
869
+				'queue_for_resending'   => __('Queue for Resending', 'event_espresso'),
870
+				'send_now'              => __('Send Now', 'event_espresso')
871
+			)
872
+			: array();
873
+        
874
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can('ee_delete_messages',
875
+			'message_list_table_bulk_actions')
876
+			? array('delete_ee_messages' => __('Delete Messages', 'event_espresso'))
877
+			: array();
878
+        
879
+        
880
+		$this->_views = array(
881
+			'all' => array(
882
+				'slug'        => 'all',
883
+				'label'       => __('All', 'event_espresso'),
884
+				'count'       => 0,
885
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action)
886
+			)
887
+		);
888
+        
889
+        
890
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
891
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
892
+				continue;
893
+			}
894
+			$status_bulk_actions = $common_bulk_actions;
895
+			//unset bulk actions not applying to status
896
+			if (! empty($status_bulk_actions)) {
897
+				switch ($status) {
898
+					case EEM_Message::status_idle:
899
+					case EEM_Message::status_resend:
900
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
901
+						break;
902 902
                     
903
-                    case EEM_Message::status_failed:
904
-                    case EEM_Message::status_debug_only:
905
-                    case EEM_Message::status_messenger_executing:
906
-                        $status_bulk_actions = array();
907
-                        break;
903
+					case EEM_Message::status_failed:
904
+					case EEM_Message::status_debug_only:
905
+					case EEM_Message::status_messenger_executing:
906
+						$status_bulk_actions = array();
907
+						break;
908 908
                     
909
-                    case EEM_Message::status_incomplete:
910
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
911
-                        break;
909
+					case EEM_Message::status_incomplete:
910
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
911
+						break;
912 912
                     
913
-                    case EEM_Message::status_retry:
914
-                    case EEM_Message::status_sent:
915
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
916
-                        break;
917
-                }
918
-            }
913
+					case EEM_Message::status_retry:
914
+					case EEM_Message::status_sent:
915
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
916
+						break;
917
+				}
918
+			}
919 919
 
920
-            //skip adding messenger executing status to views because it will be included with the Failed view.
921
-            if ( $status === EEM_Message::status_messenger_executing ) {
922
-                continue;
923
-            }
920
+			//skip adding messenger executing status to views because it will be included with the Failed view.
921
+			if ( $status === EEM_Message::status_messenger_executing ) {
922
+				continue;
923
+			}
924 924
             
925
-            $this->_views[strtolower($status)] = array(
926
-                'slug'        => strtolower($status),
927
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
928
-                'count'       => 0,
929
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
930
-            );
931
-        }
932
-    }
933
-    
934
-    
935
-    protected function _ee_default_messages_overview_list_table()
936
-    {
937
-        $this->_admin_page_title = __('Default Message Templates', 'event_espresso');
938
-        $this->display_admin_list_table_page_with_no_sidebar();
939
-    }
940
-    
941
-    
942
-    protected function _message_queue_list_table()
943
-    {
944
-        $this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945
-        $this->_template_args['per_column']        = 6;
946
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
-        $this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
948
-        $this->display_admin_list_table_page_with_no_sidebar();
949
-    }
950
-    
951
-    
952
-    protected function _message_legend_items()
953
-    {
954
-        
955
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
956
-        $action_items       = array();
957
-        
958
-        foreach ($action_css_classes as $action_item => $action_details) {
959
-            if ($action_item === 'see_notifications_for') {
960
-                continue;
961
-            }
962
-            $action_items[$action_item] = array(
963
-                'class' => $action_details['css_class'],
964
-                'desc'  => $action_details['label']
965
-            );
966
-        }
967
-        
968
-        /** @type array $status_items status legend setup */
969
-        $status_items = array(
970
-            'sent_status'       => array(
971
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
972
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973
-            ),
974
-            'idle_status'       => array(
975
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
976
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977
-            ),
978
-            'failed_status'     => array(
979
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
980
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981
-            ),
982
-            'messenger_executing_status' => array(
983
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
984
-                'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985
-            ),
986
-            'resend_status'     => array(
987
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
988
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989
-            ),
990
-            'incomplete_status' => array(
991
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
992
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993
-            ),
994
-            'retry_status'      => array(
995
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
996
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997
-            )
998
-        );
999
-        if (EEM_Message::debug()) {
1000
-            $status_items['debug_only_status'] = array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1002
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003
-            );
1004
-        }
1005
-        
1006
-        return array_merge($action_items, $status_items);
1007
-    }
1008
-    
1009
-    
1010
-    protected function _custom_mtps_preview()
1011
-    {
1012
-        $this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
-        $this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
-                'event_espresso') . '" />';
1015
-        $this->_template_args['preview_text'] = '<strong>' . __('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.',
1016
-                'event_espresso') . '</strong>';
1017
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1018
-    }
1019
-    
1020
-    
1021
-    /**
1022
-     * get_message_templates
1023
-     * This gets all the message templates for listing on the overview list.
1024
-     *
1025
-     * @access public
1026
-     *
1027
-     * @param int    $perpage the amount of templates groups to show per page
1028
-     * @param string $type    the current _view we're getting templates for
1029
-     * @param bool   $count   return count?
1030
-     * @param bool   $all     disregard any paging info (get all data);
1031
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1032
-     *
1033
-     * @return array
1034
-     */
1035
-    public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1036
-    {
1037
-        
1038
-        $MTP = EEM_Message_Template_Group::instance();
1039
-        
1040
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1041
-        $orderby                    = $this->_req_data['orderby'];
1042
-        
1043
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1044
-        
1045
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1046
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1047
-        
1048
-        $offset = ($current_page - 1) * $per_page;
1049
-        $limit  = $all ? null : array($offset, $per_page);
1050
-        
1051
-        
1052
-        //options will match what is in the _views array property
1053
-        switch ($type) {
925
+			$this->_views[strtolower($status)] = array(
926
+				'slug'        => strtolower($status),
927
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
928
+				'count'       => 0,
929
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action)
930
+			);
931
+		}
932
+	}
933
+    
934
+    
935
+	protected function _ee_default_messages_overview_list_table()
936
+	{
937
+		$this->_admin_page_title = __('Default Message Templates', 'event_espresso');
938
+		$this->display_admin_list_table_page_with_no_sidebar();
939
+	}
940
+    
941
+    
942
+	protected function _message_queue_list_table()
943
+	{
944
+		$this->_search_btn_label                   = __('Message Activity', 'event_espresso');
945
+		$this->_template_args['per_column']        = 6;
946
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_message_legend_items());
947
+		$this->_template_args['before_list_table'] = '<h3>' . EEM_Message::instance()->get_pretty_label_for_results() . '</h3>';
948
+		$this->display_admin_list_table_page_with_no_sidebar();
949
+	}
950
+    
951
+    
952
+	protected function _message_legend_items()
953
+	{
954
+        
955
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
956
+		$action_items       = array();
957
+        
958
+		foreach ($action_css_classes as $action_item => $action_details) {
959
+			if ($action_item === 'see_notifications_for') {
960
+				continue;
961
+			}
962
+			$action_items[$action_item] = array(
963
+				'class' => $action_details['css_class'],
964
+				'desc'  => $action_details['label']
965
+			);
966
+		}
967
+        
968
+		/** @type array $status_items status legend setup */
969
+		$status_items = array(
970
+			'sent_status'       => array(
971
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
972
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence')
973
+			),
974
+			'idle_status'       => array(
975
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
976
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence')
977
+			),
978
+			'failed_status'     => array(
979
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
980
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence')
981
+			),
982
+			'messenger_executing_status' => array(
983
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
984
+				'desc' => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence')
985
+			),
986
+			'resend_status'     => array(
987
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
988
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence')
989
+			),
990
+			'incomplete_status' => array(
991
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
992
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence')
993
+			),
994
+			'retry_status'      => array(
995
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
996
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence')
997
+			)
998
+		);
999
+		if (EEM_Message::debug()) {
1000
+			$status_items['debug_only_status'] = array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1002
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence')
1003
+			);
1004
+		}
1005
+        
1006
+		return array_merge($action_items, $status_items);
1007
+	}
1008
+    
1009
+    
1010
+	protected function _custom_mtps_preview()
1011
+	{
1012
+		$this->_admin_page_title              = __('Custom Message Templates (Preview)', 'event_espresso');
1013
+		$this->_template_args['preview_img']  = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png" alt="' . esc_attr__('Preview Custom Message Templates screenshot',
1014
+				'event_espresso') . '" />';
1015
+		$this->_template_args['preview_text'] = '<strong>' . __('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.',
1016
+				'event_espresso') . '</strong>';
1017
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1018
+	}
1019
+    
1020
+    
1021
+	/**
1022
+	 * get_message_templates
1023
+	 * This gets all the message templates for listing on the overview list.
1024
+	 *
1025
+	 * @access public
1026
+	 *
1027
+	 * @param int    $perpage the amount of templates groups to show per page
1028
+	 * @param string $type    the current _view we're getting templates for
1029
+	 * @param bool   $count   return count?
1030
+	 * @param bool   $all     disregard any paging info (get all data);
1031
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1032
+	 *
1033
+	 * @return array
1034
+	 */
1035
+	public function get_message_templates($perpage = 10, $type = 'in_use', $count = false, $all = false, $global = true)
1036
+	{
1037
+        
1038
+		$MTP = EEM_Message_Template_Group::instance();
1039
+        
1040
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1041
+		$orderby                    = $this->_req_data['orderby'];
1042
+        
1043
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
1044
+        
1045
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
1046
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $perpage;
1047
+        
1048
+		$offset = ($current_page - 1) * $per_page;
1049
+		$limit  = $all ? null : array($offset, $per_page);
1050
+        
1051
+        
1052
+		//options will match what is in the _views array property
1053
+		switch ($type) {
1054 1054
             
1055
-            case 'in_use':
1056
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1057
-                break;
1055
+			case 'in_use':
1056
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1057
+				break;
1058 1058
             
1059
-            default:
1060
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1059
+			default:
1060
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1061 1061
             
1062
-        }
1063
-        
1064
-        return $templates;
1065
-    }
1066
-    
1067
-    
1068
-    /**
1069
-     * filters etc might need a list of installed message_types
1070
-     * @return array an array of message type objects
1071
-     */
1072
-    public function get_installed_message_types()
1073
-    {
1074
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1075
-        $installed               = array();
1076
-        
1077
-        foreach ($installed_message_types as $message_type) {
1078
-            $installed[$message_type->name] = $message_type;
1079
-        }
1080
-        
1081
-        return $installed;
1082
-    }
1083
-    
1084
-    
1085
-    /**
1086
-     * _add_message_template
1087
-     *
1088
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1089
-     *
1090
-     * @param string $message_type
1091
-     * @param string $messenger
1092
-     * @param string $GRP_ID
1093
-     *
1094
-     * @throws EE_error
1095
-     */
1096
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1097
-    {
1098
-        //set values override any request data
1099
-        $message_type = ! empty($message_type) ? $message_type : '';
1100
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1101
-        
1102
-        $messenger = ! empty($messenger) ? $messenger : '';
1103
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1104
-        
1105
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1106
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1107
-        
1108
-        //we need messenger and message type.  They should be coming from the event editor. If not here then return error
1109
-        if (empty($message_type) || empty($messenger)) {
1110
-            throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1111
-                'event_espresso'));
1112
-        }
1113
-        
1114
-        //we need the GRP_ID for the template being used as the base for the new template
1115
-        if (empty($GRP_ID)) {
1116
-            throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1117
-                'event_espresso'));
1118
-        }
1119
-        
1120
-        //let's just make sure the template gets generated!
1121
-        
1122
-        //we need to reassign some variables for what the insert is expecting
1123
-        $this->_req_data['MTP_messenger']    = $messenger;
1124
-        $this->_req_data['MTP_message_type'] = $message_type;
1125
-        $this->_req_data['GRP_ID']           = $GRP_ID;
1126
-        $this->_insert_or_update_message_template(true);
1127
-    }
1128
-    
1129
-    
1130
-    /**
1131
-     * public wrapper for the _add_message_template method
1132
-     *
1133
-     * @param string $message_type     message type slug
1134
-     * @param string $messenger        messenger slug
1135
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1136
-     *                                 off of.
1137
-     */
1138
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1139
-    {
1140
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1141
-    }
1142
-    
1143
-    
1144
-    /**
1145
-     * _edit_message_template
1146
-     *
1147
-     * @access protected
1148
-     * @return void
1149
-     */
1150
-    protected function _edit_message_template()
1151
-    {
1152
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1153
-        $template_fields = '';
1154
-        $sidebar_fields  = '';
1155
-        //we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1156
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1157
-        
1158
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1159
-            ? absint($this->_req_data['id'])
1160
-            : false;
1161
-        
1162
-        $this->_set_shortcodes(); //this also sets the _message_template property.
1163
-        $message_template_group = $this->_message_template_group;
1164
-        $c_label                = $message_template_group->context_label();
1165
-        $c_config               = $message_template_group->contexts_config();
1166
-        
1167
-        reset($c_config);
1168
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1169
-            ? strtolower($this->_req_data['context'])
1170
-            : key($c_config);
1171
-        
1172
-        
1173
-        if (empty($GRP_ID)) {
1174
-            $action = 'insert_message_template';
1175
-            //$button_both = false;
1176
-            //$button_text = array( __( 'Save','event_espresso') );
1177
-            //$button_actions = array('something_different');
1178
-            //$referrer = false;
1179
-            $edit_message_template_form_url = add_query_arg(
1180
-                array('action' => $action, 'noheader' => true),
1181
-                EE_MSG_ADMIN_URL
1182
-            );
1183
-        } else {
1184
-            $action = 'update_message_template';
1185
-            //$button_both = true;
1186
-            //$button_text = array();
1187
-            //$button_actions = array();
1188
-            //$referrer = $this->_admin_base_url;
1189
-            $edit_message_template_form_url = add_query_arg(
1190
-                array('action' => $action, 'noheader' => true),
1191
-                EE_MSG_ADMIN_URL
1192
-            );
1193
-        }
1194
-        
1195
-        //set active messenger for this view
1196
-        $this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1197
-            $message_template_group->messenger()
1198
-        );
1199
-        $this->_active_message_type_name = $message_template_group->message_type();
1200
-        
1201
-        
1202
-        //Do we have any validation errors?
1203
-        $validators = $this->_get_transient();
1204
-        $v_fields   = ! empty($validators) ? array_keys($validators) : array();
1205
-        
1206
-        
1207
-        //we need to assemble the title from Various details
1208
-        $context_label = sprintf(
1209
-            __('(%s %s)', 'event_espresso'),
1210
-            $c_config[$context]['label'],
1211
-            ucwords($c_label['label'])
1212
-        );
1213
-        
1214
-        $title = sprintf(
1215
-            __(' %s %s Template %s', 'event_espresso'),
1216
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1217
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1218
-            $context_label
1219
-        );
1220
-        
1221
-        $this->_template_args['GRP_ID']           = $GRP_ID;
1222
-        $this->_template_args['message_template'] = $message_template_group;
1223
-        $this->_template_args['is_extra_fields']  = false;
1224
-        
1225
-        
1226
-        //let's get EEH_MSG_Template so we can get template form fields
1227
-        $template_field_structure = EEH_MSG_Template::get_fields(
1228
-            $message_template_group->messenger(),
1229
-            $message_template_group->message_type()
1230
-        );
1231
-        
1232
-        if ( ! $template_field_structure) {
1233
-            $template_field_structure = false;
1234
-            $template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1235
-                'event_espresso');
1236
-        }
1237
-        
1238
-        
1239
-        $message_templates = $message_template_group->context_templates();
1240
-        
1241
-        
1242
-        //if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1243
-        if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1244
-            foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1245
-                unset($template_field_structure[$context][$reference_field]);
1246
-            }
1247
-        }
1248
-        
1249
-        //let's loop through the template_field_structure and actually assemble the input fields!
1250
-        if ( ! empty($template_field_structure)) {
1251
-            foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1252
-                //if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1253
-                if ($template_field == 'extra') {
1254
-                    $this->_template_args['is_extra_fields'] = true;
1255
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1256
-                        $message_template = $message_templates[$context][$reference_field];
1257
-                        $content          = $message_template instanceof EE_Message_Template
1258
-                            ? $message_template->get('MTP_content')
1259
-                            : '';
1260
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1261
-                            //let's verify if we need this extra field via the shortcodes parameter.
1262
-                            $continue = false;
1263
-                            if (isset($extra_array['shortcodes_required'])) {
1264
-                                foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1265
-                                    if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266
-                                        $continue = true;
1267
-                                    }
1268
-                                }
1269
-                                if ($continue) {
1270
-                                    continue;
1271
-                                }
1272
-                            }
1062
+		}
1063
+        
1064
+		return $templates;
1065
+	}
1066
+    
1067
+    
1068
+	/**
1069
+	 * filters etc might need a list of installed message_types
1070
+	 * @return array an array of message type objects
1071
+	 */
1072
+	public function get_installed_message_types()
1073
+	{
1074
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1075
+		$installed               = array();
1076
+        
1077
+		foreach ($installed_message_types as $message_type) {
1078
+			$installed[$message_type->name] = $message_type;
1079
+		}
1080
+        
1081
+		return $installed;
1082
+	}
1083
+    
1084
+    
1085
+	/**
1086
+	 * _add_message_template
1087
+	 *
1088
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1089
+	 *
1090
+	 * @param string $message_type
1091
+	 * @param string $messenger
1092
+	 * @param string $GRP_ID
1093
+	 *
1094
+	 * @throws EE_error
1095
+	 */
1096
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1097
+	{
1098
+		//set values override any request data
1099
+		$message_type = ! empty($message_type) ? $message_type : '';
1100
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type']) ? $this->_req_data['message_type'] : $message_type;
1101
+        
1102
+		$messenger = ! empty($messenger) ? $messenger : '';
1103
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger']) ? $this->_req_data['messenger'] : $messenger;
1104
+        
1105
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1106
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1107
+        
1108
+		//we need messenger and message type.  They should be coming from the event editor. If not here then return error
1109
+		if (empty($message_type) || empty($messenger)) {
1110
+			throw new EE_error(__('Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1111
+				'event_espresso'));
1112
+		}
1113
+        
1114
+		//we need the GRP_ID for the template being used as the base for the new template
1115
+		if (empty($GRP_ID)) {
1116
+			throw new EE_Error(__('In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1117
+				'event_espresso'));
1118
+		}
1119
+        
1120
+		//let's just make sure the template gets generated!
1121
+        
1122
+		//we need to reassign some variables for what the insert is expecting
1123
+		$this->_req_data['MTP_messenger']    = $messenger;
1124
+		$this->_req_data['MTP_message_type'] = $message_type;
1125
+		$this->_req_data['GRP_ID']           = $GRP_ID;
1126
+		$this->_insert_or_update_message_template(true);
1127
+	}
1128
+    
1129
+    
1130
+	/**
1131
+	 * public wrapper for the _add_message_template method
1132
+	 *
1133
+	 * @param string $message_type     message type slug
1134
+	 * @param string $messenger        messenger slug
1135
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1136
+	 *                                 off of.
1137
+	 */
1138
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1139
+	{
1140
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1141
+	}
1142
+    
1143
+    
1144
+	/**
1145
+	 * _edit_message_template
1146
+	 *
1147
+	 * @access protected
1148
+	 * @return void
1149
+	 */
1150
+	protected function _edit_message_template()
1151
+	{
1152
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1153
+		$template_fields = '';
1154
+		$sidebar_fields  = '';
1155
+		//we filter the tinyMCE settings to remove the validation since message templates by their nature will not have valid html in the templates.
1156
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1157
+        
1158
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1159
+			? absint($this->_req_data['id'])
1160
+			: false;
1161
+        
1162
+		$this->_set_shortcodes(); //this also sets the _message_template property.
1163
+		$message_template_group = $this->_message_template_group;
1164
+		$c_label                = $message_template_group->context_label();
1165
+		$c_config               = $message_template_group->contexts_config();
1166
+        
1167
+		reset($c_config);
1168
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1169
+			? strtolower($this->_req_data['context'])
1170
+			: key($c_config);
1171
+        
1172
+        
1173
+		if (empty($GRP_ID)) {
1174
+			$action = 'insert_message_template';
1175
+			//$button_both = false;
1176
+			//$button_text = array( __( 'Save','event_espresso') );
1177
+			//$button_actions = array('something_different');
1178
+			//$referrer = false;
1179
+			$edit_message_template_form_url = add_query_arg(
1180
+				array('action' => $action, 'noheader' => true),
1181
+				EE_MSG_ADMIN_URL
1182
+			);
1183
+		} else {
1184
+			$action = 'update_message_template';
1185
+			//$button_both = true;
1186
+			//$button_text = array();
1187
+			//$button_actions = array();
1188
+			//$referrer = $this->_admin_base_url;
1189
+			$edit_message_template_form_url = add_query_arg(
1190
+				array('action' => $action, 'noheader' => true),
1191
+				EE_MSG_ADMIN_URL
1192
+			);
1193
+		}
1194
+        
1195
+		//set active messenger for this view
1196
+		$this->_active_messenger         = $this->_message_resource_manager->get_active_messenger(
1197
+			$message_template_group->messenger()
1198
+		);
1199
+		$this->_active_message_type_name = $message_template_group->message_type();
1200
+        
1201
+        
1202
+		//Do we have any validation errors?
1203
+		$validators = $this->_get_transient();
1204
+		$v_fields   = ! empty($validators) ? array_keys($validators) : array();
1205
+        
1206
+        
1207
+		//we need to assemble the title from Various details
1208
+		$context_label = sprintf(
1209
+			__('(%s %s)', 'event_espresso'),
1210
+			$c_config[$context]['label'],
1211
+			ucwords($c_label['label'])
1212
+		);
1213
+        
1214
+		$title = sprintf(
1215
+			__(' %s %s Template %s', 'event_espresso'),
1216
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1217
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1218
+			$context_label
1219
+		);
1220
+        
1221
+		$this->_template_args['GRP_ID']           = $GRP_ID;
1222
+		$this->_template_args['message_template'] = $message_template_group;
1223
+		$this->_template_args['is_extra_fields']  = false;
1224
+        
1225
+        
1226
+		//let's get EEH_MSG_Template so we can get template form fields
1227
+		$template_field_structure = EEH_MSG_Template::get_fields(
1228
+			$message_template_group->messenger(),
1229
+			$message_template_group->message_type()
1230
+		);
1231
+        
1232
+		if ( ! $template_field_structure) {
1233
+			$template_field_structure = false;
1234
+			$template_fields          = __('There was an error in assembling the fields for this display (you should see an error message)',
1235
+				'event_espresso');
1236
+		}
1237
+        
1238
+        
1239
+		$message_templates = $message_template_group->context_templates();
1240
+        
1241
+        
1242
+		//if we have the extra key.. then we need to remove the content index from the template_field_structure as it will get handled in the "extra" array.
1243
+		if (is_array($template_field_structure[$context]) && isset($template_field_structure[$context]['extra'])) {
1244
+			foreach ($template_field_structure[$context]['extra'] as $reference_field => $new_fields) {
1245
+				unset($template_field_structure[$context][$reference_field]);
1246
+			}
1247
+		}
1248
+        
1249
+		//let's loop through the template_field_structure and actually assemble the input fields!
1250
+		if ( ! empty($template_field_structure)) {
1251
+			foreach ($template_field_structure[$context] as $template_field => $field_setup_array) {
1252
+				//if this is an 'extra' template field then we need to remove any existing fields that are keyed up in the extra array and reset them.
1253
+				if ($template_field == 'extra') {
1254
+					$this->_template_args['is_extra_fields'] = true;
1255
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1256
+						$message_template = $message_templates[$context][$reference_field];
1257
+						$content          = $message_template instanceof EE_Message_Template
1258
+							? $message_template->get('MTP_content')
1259
+							: '';
1260
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1261
+							//let's verify if we need this extra field via the shortcodes parameter.
1262
+							$continue = false;
1263
+							if (isset($extra_array['shortcodes_required'])) {
1264
+								foreach ((array)$extra_array['shortcodes_required'] as $shortcode) {
1265
+									if ( ! array_key_exists($shortcode, $this->_shortcodes)) {
1266
+										$continue = true;
1267
+									}
1268
+								}
1269
+								if ($continue) {
1270
+									continue;
1271
+								}
1272
+							}
1273 1273
                             
1274
-                            $field_id                                = $reference_field . '-' . $extra_field . '-content';
1275
-                            $template_form_fields[$field_id]         = $extra_array;
1276
-                            $template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1277
-                            $css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1274
+							$field_id                                = $reference_field . '-' . $extra_field . '-content';
1275
+							$template_form_fields[$field_id]         = $extra_array;
1276
+							$template_form_fields[$field_id]['name'] = 'MTP_template_fields[' . $reference_field . '][content][' . $extra_field . ']';
1277
+							$css_class                               = isset($extra_array['css_class']) ? $extra_array['css_class'] : '';
1278 1278
                             
1279
-                            $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1280
-                                                                            && in_array($extra_field, $v_fields)
1281
-                                                                            &&
1282
-                                                                            (
1283
-                                                                                is_array($validators[$extra_field])
1284
-                                                                                && isset($validators[$extra_field]['msg'])
1285
-                                                                            )
1286
-                                ? 'validate-error ' . $css_class
1287
-                                : $css_class;
1279
+							$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1280
+																			&& in_array($extra_field, $v_fields)
1281
+																			&&
1282
+																			(
1283
+																				is_array($validators[$extra_field])
1284
+																				&& isset($validators[$extra_field]['msg'])
1285
+																			)
1286
+								? 'validate-error ' . $css_class
1287
+								: $css_class;
1288 1288
                             
1289
-                            $template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1290
-                                ? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1291
-                                : '';
1289
+							$template_form_fields[$field_id]['value'] = ! empty($message_templates) && isset($content[$extra_field])
1290
+								? stripslashes(html_entity_decode($content[$extra_field], ENT_QUOTES, "UTF-8"))
1291
+								: '';
1292 1292
                             
1293
-                            //do we have a validation error?  if we do then let's use that value instead
1294
-                            $template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1293
+							//do we have a validation error?  if we do then let's use that value instead
1294
+							$template_form_fields[$field_id]['value'] = isset($validators[$extra_field]) ? $validators[$extra_field]['value'] : $template_form_fields[$field_id]['value'];
1295 1295
                             
1296 1296
                             
1297
-                            $template_form_fields[$field_id]['db-col'] = 'MTP_content';
1297
+							$template_form_fields[$field_id]['db-col'] = 'MTP_content';
1298 1298
                             
1299
-                            //shortcode selector
1300
-                            $field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1301
-                            $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1302
-                                $field_name_to_use,
1303
-                                $field_id
1304
-                            );
1299
+							//shortcode selector
1300
+							$field_name_to_use                                 = $extra_field == 'main' ? 'content' : $extra_field;
1301
+							$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1302
+								$field_name_to_use,
1303
+								$field_id
1304
+							);
1305 1305
                             
1306
-                            if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1307
-                                //we want to decode the entities
1308
-                                $template_form_fields[$field_id]['value'] = stripslashes(
1309
-                                    html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1310
-                                );
1306
+							if (isset($extra_array['input']) && $extra_array['input'] == 'wp_editor') {
1307
+								//we want to decode the entities
1308
+								$template_form_fields[$field_id]['value'] = stripslashes(
1309
+									html_entity_decode($template_form_fields[$field_id]['value'], ENT_QUOTES, "UTF-8")
1310
+								);
1311 1311
                                 
1312
-                            }/**/
1313
-                        }
1314
-                        $templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
-                        $templatefield_templatename_id = $reference_field . '-name';
1312
+							}/**/
1313
+						}
1314
+						$templatefield_MTP_id          = $reference_field . '-MTP_ID';
1315
+						$templatefield_templatename_id = $reference_field . '-name';
1316 1316
                         
1317
-                        $template_form_fields[$templatefield_MTP_id] = array(
1318
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1319
-                            'label'      => null,
1320
-                            'input'      => 'hidden',
1321
-                            'type'       => 'int',
1322
-                            'required'   => false,
1323
-                            'validation' => false,
1324
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1325
-                            'css_class'  => '',
1326
-                            'format'     => '%d',
1327
-                            'db-col'     => 'MTP_ID'
1328
-                        );
1317
+						$template_form_fields[$templatefield_MTP_id] = array(
1318
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1319
+							'label'      => null,
1320
+							'input'      => 'hidden',
1321
+							'type'       => 'int',
1322
+							'required'   => false,
1323
+							'validation' => false,
1324
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1325
+							'css_class'  => '',
1326
+							'format'     => '%d',
1327
+							'db-col'     => 'MTP_ID'
1328
+						);
1329 1329
                         
1330
-                        $template_form_fields[$templatefield_templatename_id] = array(
1331
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1332
-                            'label'      => null,
1333
-                            'input'      => 'hidden',
1334
-                            'type'       => 'string',
1335
-                            'required'   => false,
1336
-                            'validation' => true,
1337
-                            'value'      => $reference_field,
1338
-                            'css_class'  => '',
1339
-                            'format'     => '%s',
1340
-                            'db-col'     => 'MTP_template_field'
1341
-                        );
1342
-                    }
1343
-                    continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344
-                } else {
1345
-                    $field_id                                 = $template_field . '-content';
1346
-                    $template_form_fields[$field_id]          = $field_setup_array;
1347
-                    $template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1348
-                    $message_template                         = isset($message_templates[$context][$template_field])
1349
-                        ? $message_templates[$context][$template_field]
1350
-                        : null;
1351
-                    $template_form_fields[$field_id]['value'] = ! empty($message_templates)
1352
-                                                                && is_array($message_templates[$context])
1353
-                                                                && $message_template instanceof EE_Message_Template
1354
-                        ? $message_template->get('MTP_content')
1355
-                        : '';
1330
+						$template_form_fields[$templatefield_templatename_id] = array(
1331
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1332
+							'label'      => null,
1333
+							'input'      => 'hidden',
1334
+							'type'       => 'string',
1335
+							'required'   => false,
1336
+							'validation' => true,
1337
+							'value'      => $reference_field,
1338
+							'css_class'  => '',
1339
+							'format'     => '%s',
1340
+							'db-col'     => 'MTP_template_field'
1341
+						);
1342
+					}
1343
+					continue; //skip the next stuff, we got the necessary fields here for this dataset.
1344
+				} else {
1345
+					$field_id                                 = $template_field . '-content';
1346
+					$template_form_fields[$field_id]          = $field_setup_array;
1347
+					$template_form_fields[$field_id]['name']  = 'MTP_template_fields[' . $template_field . '][content]';
1348
+					$message_template                         = isset($message_templates[$context][$template_field])
1349
+						? $message_templates[$context][$template_field]
1350
+						: null;
1351
+					$template_form_fields[$field_id]['value'] = ! empty($message_templates)
1352
+																&& is_array($message_templates[$context])
1353
+																&& $message_template instanceof EE_Message_Template
1354
+						? $message_template->get('MTP_content')
1355
+						: '';
1356 1356
                     
1357
-                    //do we have a validator error for this field?  if we do then we'll use that value instead
1358
-                    $template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1359
-                        ? $validators[$template_field]['value']
1360
-                        : $template_form_fields[$field_id]['value'];
1357
+					//do we have a validator error for this field?  if we do then we'll use that value instead
1358
+					$template_form_fields[$field_id]['value'] = isset($validators[$template_field])
1359
+						? $validators[$template_field]['value']
1360
+						: $template_form_fields[$field_id]['value'];
1361 1361
                     
1362 1362
                     
1363
-                    $template_form_fields[$field_id]['db-col']    = 'MTP_content';
1364
-                    $css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1365
-                    $template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366
-                                                                    && in_array($template_field, $v_fields)
1367
-                                                                    && isset($validators[$template_field]['msg'])
1368
-                        ? 'validate-error ' . $css_class
1369
-                        : $css_class;
1363
+					$template_form_fields[$field_id]['db-col']    = 'MTP_content';
1364
+					$css_class                                    = isset($field_setup_array['css_class']) ? $field_setup_array['css_class'] : '';
1365
+					$template_form_fields[$field_id]['css_class'] = ! empty($v_fields)
1366
+																	&& in_array($template_field, $v_fields)
1367
+																	&& isset($validators[$template_field]['msg'])
1368
+						? 'validate-error ' . $css_class
1369
+						: $css_class;
1370 1370
                     
1371
-                    //shortcode selector
1372
-                    $template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1373
-                        $template_field, $field_id
1374
-                    );
1375
-                }
1371
+					//shortcode selector
1372
+					$template_form_fields[$field_id]['append_content'] = $this->_get_shortcode_selector(
1373
+						$template_field, $field_id
1374
+					);
1375
+				}
1376 1376
                 
1377
-                //k took care of content field(s) now let's take care of others.
1377
+				//k took care of content field(s) now let's take care of others.
1378 1378
                 
1379
-                $templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
-                $templatefield_field_templatename_id = $template_field . '-name';
1379
+				$templatefield_MTP_id                = $template_field . '-MTP_ID';
1380
+				$templatefield_field_templatename_id = $template_field . '-name';
1381 1381
                 
1382
-                //foreach template field there are actually two form fields created
1383
-                $template_form_fields[$templatefield_MTP_id] = array(
1384
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1385
-                    'label'      => null,
1386
-                    'input'      => 'hidden',
1387
-                    'type'       => 'int',
1388
-                    'required'   => false,
1389
-                    'validation' => true,
1390
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1391
-                    'css_class'  => '',
1392
-                    'format'     => '%d',
1393
-                    'db-col'     => 'MTP_ID'
1394
-                );
1382
+				//foreach template field there are actually two form fields created
1383
+				$template_form_fields[$templatefield_MTP_id] = array(
1384
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1385
+					'label'      => null,
1386
+					'input'      => 'hidden',
1387
+					'type'       => 'int',
1388
+					'required'   => false,
1389
+					'validation' => true,
1390
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1391
+					'css_class'  => '',
1392
+					'format'     => '%d',
1393
+					'db-col'     => 'MTP_ID'
1394
+				);
1395 1395
                 
1396
-                $template_form_fields[$templatefield_field_templatename_id] = array(
1397
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1398
-                    'label'      => null,
1399
-                    'input'      => 'hidden',
1400
-                    'type'       => 'string',
1401
-                    'required'   => false,
1402
-                    'validation' => true,
1403
-                    'value'      => $template_field,
1404
-                    'css_class'  => '',
1405
-                    'format'     => '%s',
1406
-                    'db-col'     => 'MTP_template_field'
1407
-                );
1396
+				$template_form_fields[$templatefield_field_templatename_id] = array(
1397
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1398
+					'label'      => null,
1399
+					'input'      => 'hidden',
1400
+					'type'       => 'string',
1401
+					'required'   => false,
1402
+					'validation' => true,
1403
+					'value'      => $template_field,
1404
+					'css_class'  => '',
1405
+					'format'     => '%s',
1406
+					'db-col'     => 'MTP_template_field'
1407
+				);
1408 1408
                 
1409
-            }
1409
+			}
1410 1410
             
1411
-            //add other fields
1412
-            $template_form_fields['ee-msg-current-context'] = array(
1413
-                'name'       => 'MTP_context',
1414
-                'label'      => null,
1415
-                'input'      => 'hidden',
1416
-                'type'       => 'string',
1417
-                'required'   => false,
1418
-                'validation' => true,
1419
-                'value'      => $context,
1420
-                'css_class'  => '',
1421
-                'format'     => '%s',
1422
-                'db-col'     => 'MTP_context'
1423
-            );
1411
+			//add other fields
1412
+			$template_form_fields['ee-msg-current-context'] = array(
1413
+				'name'       => 'MTP_context',
1414
+				'label'      => null,
1415
+				'input'      => 'hidden',
1416
+				'type'       => 'string',
1417
+				'required'   => false,
1418
+				'validation' => true,
1419
+				'value'      => $context,
1420
+				'css_class'  => '',
1421
+				'format'     => '%s',
1422
+				'db-col'     => 'MTP_context'
1423
+			);
1424 1424
             
1425
-            $template_form_fields['ee-msg-grp-id'] = array(
1426
-                'name'       => 'GRP_ID',
1427
-                'label'      => null,
1428
-                'input'      => 'hidden',
1429
-                'type'       => 'int',
1430
-                'required'   => false,
1431
-                'validation' => true,
1432
-                'value'      => $GRP_ID,
1433
-                'css_class'  => '',
1434
-                'format'     => '%d',
1435
-                'db-col'     => 'GRP_ID'
1436
-            );
1425
+			$template_form_fields['ee-msg-grp-id'] = array(
1426
+				'name'       => 'GRP_ID',
1427
+				'label'      => null,
1428
+				'input'      => 'hidden',
1429
+				'type'       => 'int',
1430
+				'required'   => false,
1431
+				'validation' => true,
1432
+				'value'      => $GRP_ID,
1433
+				'css_class'  => '',
1434
+				'format'     => '%d',
1435
+				'db-col'     => 'GRP_ID'
1436
+			);
1437 1437
             
1438
-            $template_form_fields['ee-msg-messenger'] = array(
1439
-                'name'       => 'MTP_messenger',
1440
-                'label'      => null,
1441
-                'input'      => 'hidden',
1442
-                'type'       => 'string',
1443
-                'required'   => false,
1444
-                'validation' => true,
1445
-                'value'      => $message_template_group->messenger(),
1446
-                'css_class'  => '',
1447
-                'format'     => '%s',
1448
-                'db-col'     => 'MTP_messenger'
1449
-            );
1438
+			$template_form_fields['ee-msg-messenger'] = array(
1439
+				'name'       => 'MTP_messenger',
1440
+				'label'      => null,
1441
+				'input'      => 'hidden',
1442
+				'type'       => 'string',
1443
+				'required'   => false,
1444
+				'validation' => true,
1445
+				'value'      => $message_template_group->messenger(),
1446
+				'css_class'  => '',
1447
+				'format'     => '%s',
1448
+				'db-col'     => 'MTP_messenger'
1449
+			);
1450 1450
             
1451
-            $template_form_fields['ee-msg-message-type'] = array(
1452
-                'name'       => 'MTP_message_type',
1453
-                'label'      => null,
1454
-                'input'      => 'hidden',
1455
-                'type'       => 'string',
1456
-                'required'   => false,
1457
-                'validation' => true,
1458
-                'value'      => $message_template_group->message_type(),
1459
-                'css_class'  => '',
1460
-                'format'     => '%s',
1461
-                'db-col'     => 'MTP_message_type'
1462
-            );
1451
+			$template_form_fields['ee-msg-message-type'] = array(
1452
+				'name'       => 'MTP_message_type',
1453
+				'label'      => null,
1454
+				'input'      => 'hidden',
1455
+				'type'       => 'string',
1456
+				'required'   => false,
1457
+				'validation' => true,
1458
+				'value'      => $message_template_group->message_type(),
1459
+				'css_class'  => '',
1460
+				'format'     => '%s',
1461
+				'db-col'     => 'MTP_message_type'
1462
+			);
1463 1463
             
1464
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1465
-                'name'       => 'MTP_is_global',
1466
-                'label'      => __('Global Template', 'event_espresso'),
1467
-                'input'      => 'hidden',
1468
-                'type'       => 'int',
1469
-                'required'   => false,
1470
-                'validation' => true,
1471
-                'value'      => $message_template_group->get('MTP_is_global'),
1472
-                'css_class'  => '',
1473
-                'format'     => '%d',
1474
-                'db-col'     => 'MTP_is_global'
1475
-            );
1464
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1465
+				'name'       => 'MTP_is_global',
1466
+				'label'      => __('Global Template', 'event_espresso'),
1467
+				'input'      => 'hidden',
1468
+				'type'       => 'int',
1469
+				'required'   => false,
1470
+				'validation' => true,
1471
+				'value'      => $message_template_group->get('MTP_is_global'),
1472
+				'css_class'  => '',
1473
+				'format'     => '%d',
1474
+				'db-col'     => 'MTP_is_global'
1475
+			);
1476 1476
             
1477
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1478
-                'name'       => 'MTP_is_override',
1479
-                'label'      => __('Override all custom', 'event_espresso'),
1480
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1481
-                'type'       => 'int',
1482
-                'required'   => false,
1483
-                'validation' => true,
1484
-                'value'      => $message_template_group->get('MTP_is_override'),
1485
-                'css_class'  => '',
1486
-                'format'     => '%d',
1487
-                'db-col'     => 'MTP_is_override'
1488
-            );
1477
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1478
+				'name'       => 'MTP_is_override',
1479
+				'label'      => __('Override all custom', 'event_espresso'),
1480
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1481
+				'type'       => 'int',
1482
+				'required'   => false,
1483
+				'validation' => true,
1484
+				'value'      => $message_template_group->get('MTP_is_override'),
1485
+				'css_class'  => '',
1486
+				'format'     => '%d',
1487
+				'db-col'     => 'MTP_is_override'
1488
+			);
1489 1489
             
1490
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1491
-                'name'       => 'MTP_is_active',
1492
-                'label'      => __('Active Template', 'event_espresso'),
1493
-                'input'      => 'hidden',
1494
-                'type'       => 'int',
1495
-                'required'   => false,
1496
-                'validation' => true,
1497
-                'value'      => $message_template_group->is_active(),
1498
-                'css_class'  => '',
1499
-                'format'     => '%d',
1500
-                'db-col'     => 'MTP_is_active'
1501
-            );
1490
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1491
+				'name'       => 'MTP_is_active',
1492
+				'label'      => __('Active Template', 'event_espresso'),
1493
+				'input'      => 'hidden',
1494
+				'type'       => 'int',
1495
+				'required'   => false,
1496
+				'validation' => true,
1497
+				'value'      => $message_template_group->is_active(),
1498
+				'css_class'  => '',
1499
+				'format'     => '%d',
1500
+				'db-col'     => 'MTP_is_active'
1501
+			);
1502 1502
             
1503
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1504
-                'name'       => 'MTP_deleted',
1505
-                'label'      => null,
1506
-                'input'      => 'hidden',
1507
-                'type'       => 'int',
1508
-                'required'   => false,
1509
-                'validation' => true,
1510
-                'value'      => $message_template_group->get('MTP_deleted'),
1511
-                'css_class'  => '',
1512
-                'format'     => '%d',
1513
-                'db-col'     => 'MTP_deleted'
1514
-            );
1515
-            $sidebar_form_fields['ee-msg-author']  = array(
1516
-                'name'       => 'MTP_user_id',
1517
-                'label'      => __('Author', 'event_espresso'),
1518
-                'input'      => 'hidden',
1519
-                'type'       => 'int',
1520
-                'required'   => false,
1521
-                'validation' => false,
1522
-                'value'      => $message_template_group->user(),
1523
-                'format'     => '%d',
1524
-                'db-col'     => 'MTP_user_id'
1525
-            );
1503
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1504
+				'name'       => 'MTP_deleted',
1505
+				'label'      => null,
1506
+				'input'      => 'hidden',
1507
+				'type'       => 'int',
1508
+				'required'   => false,
1509
+				'validation' => true,
1510
+				'value'      => $message_template_group->get('MTP_deleted'),
1511
+				'css_class'  => '',
1512
+				'format'     => '%d',
1513
+				'db-col'     => 'MTP_deleted'
1514
+			);
1515
+			$sidebar_form_fields['ee-msg-author']  = array(
1516
+				'name'       => 'MTP_user_id',
1517
+				'label'      => __('Author', 'event_espresso'),
1518
+				'input'      => 'hidden',
1519
+				'type'       => 'int',
1520
+				'required'   => false,
1521
+				'validation' => false,
1522
+				'value'      => $message_template_group->user(),
1523
+				'format'     => '%d',
1524
+				'db-col'     => 'MTP_user_id'
1525
+			);
1526 1526
             
1527
-            $sidebar_form_fields['ee-msg-route'] = array(
1528
-                'name'  => 'action',
1529
-                'input' => 'hidden',
1530
-                'type'  => 'string',
1531
-                'value' => $action
1532
-            );
1527
+			$sidebar_form_fields['ee-msg-route'] = array(
1528
+				'name'  => 'action',
1529
+				'input' => 'hidden',
1530
+				'type'  => 'string',
1531
+				'value' => $action
1532
+			);
1533 1533
             
1534
-            $sidebar_form_fields['ee-msg-id']        = array(
1535
-                'name'  => 'id',
1536
-                'input' => 'hidden',
1537
-                'type'  => 'int',
1538
-                'value' => $GRP_ID
1539
-            );
1540
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
-                'name'  => $action . '_nonce',
1542
-                'input' => 'hidden',
1543
-                'type'  => 'string',
1544
-                'value' => wp_create_nonce($action . '_nonce')
1545
-            );
1534
+			$sidebar_form_fields['ee-msg-id']        = array(
1535
+				'name'  => 'id',
1536
+				'input' => 'hidden',
1537
+				'type'  => 'int',
1538
+				'value' => $GRP_ID
1539
+			);
1540
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1541
+				'name'  => $action . '_nonce',
1542
+				'input' => 'hidden',
1543
+				'type'  => 'string',
1544
+				'value' => wp_create_nonce($action . '_nonce')
1545
+			);
1546 1546
             
1547
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1548
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1549
-                    'name'  => 'template_switch',
1550
-                    'input' => 'hidden',
1551
-                    'type'  => 'int',
1552
-                    'value' => 1
1553
-                );
1554
-            }
1547
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1548
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1549
+					'name'  => 'template_switch',
1550
+					'input' => 'hidden',
1551
+					'type'  => 'int',
1552
+					'value' => 1
1553
+				);
1554
+			}
1555 1555
             
1556 1556
             
1557
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1558
-            $sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1557
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1558
+			$sidebar_fields  = $this->_generate_admin_form_fields($sidebar_form_fields);
1559 1559
             
1560 1560
             
1561
-        } //end if ( !empty($template_field_structure) )
1561
+		} //end if ( !empty($template_field_structure) )
1562 1562
         
1563
-        //set extra content for publish box
1564
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1565
-        $this->_set_publish_post_box_vars(
1566
-            'id',
1567
-            $GRP_ID,
1568
-            false,
1569
-            add_query_arg(
1570
-                array('action' => 'global_mtps'),
1571
-                $this->_admin_base_url
1572
-            )
1573
-        );
1574
-        
1575
-        //add preview button
1576
-        $preview_url    = parent::add_query_args_and_nonce(
1577
-            array(
1578
-                'message_type' => $message_template_group->message_type(),
1579
-                'messenger'    => $message_template_group->messenger(),
1580
-                'context'      => $context,
1581
-                'GRP_ID'       => $GRP_ID,
1582
-                'action'       => 'preview_message'
1583
-            ),
1584
-            $this->_admin_base_url
1585
-        );
1586
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
-                'event_espresso') . '</a>';
1588
-        
1589
-        
1590
-        //setup context switcher
1591
-        $context_switcher_args = array(
1592
-            'page'    => 'espresso_messages',
1593
-            'action'  => 'edit_message_template',
1594
-            'id'      => $GRP_ID,
1595
-            'context' => $context,
1596
-            'extra'   => $preview_button
1597
-        );
1598
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1599
-        
1600
-        
1601
-        //main box
1602
-        $this->_template_args['template_fields']                         = $template_fields;
1603
-        $this->_template_args['sidebar_box_id']                          = 'details';
1604
-        $this->_template_args['action']                                  = $action;
1605
-        $this->_template_args['context']                                 = $context;
1606
-        $this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1607
-        $this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1608
-        
1609
-        
1610
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1611
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1612
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1613
-        
1614
-        $this->_template_path = $this->_template_args['GRP_ID']
1615
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1617
-        
1618
-        //send along EE_Message_Template_Group object for further template use.
1619
-        $this->_template_args['MTP'] = $message_template_group;
1620
-        
1621
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1622
-            $this->_template_args, true);
1623
-        
1624
-        
1625
-        //finally, let's set the admin_page title
1626
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1627
-        
1628
-        
1629
-        //we need to take care of setting the shortcodes property for use elsewhere.
1630
-        $this->_set_shortcodes();
1631
-        
1632
-        
1633
-        //final template wrapper
1634
-        $this->display_admin_page_with_sidebar();
1635
-    }
1636
-    
1637
-    
1638
-    public function filter_tinymce_init($mceInit, $editor_id)
1639
-    {
1640
-        return $mceInit;
1641
-    }
1642
-    
1643
-    
1644
-    public function add_context_switcher()
1645
-    {
1646
-        return $this->_context_switcher;
1647
-    }
1648
-    
1649
-    public function _add_form_element_before()
1650
-    {
1651
-        return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1652
-    }
1653
-    
1654
-    public function _add_form_element_after()
1655
-    {
1656
-        return '</form>';
1657
-    }
1658
-    
1659
-    
1660
-    /**
1661
-     * This executes switching the template pack for a message template.
1662
-     *
1663
-     * @since 4.5.0
1664
-     *
1665
-     */
1666
-    public function switch_template_pack()
1667
-    {
1668
-        $GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1669
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1670
-        
1671
-        //verify we have needed values.
1672
-        if (empty($GRP_ID) || empty($template_pack)) {
1673
-            $this->_template_args['error'] = true;
1674
-            EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1675
-                __FILE__, __FUNCTION__, __LINE__);
1676
-        } else {
1677
-            //get template, set the new template_pack and then reset to default
1678
-            /** @type EE_Message_Template_Group $message_template_group */
1679
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1563
+		//set extra content for publish box
1564
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1565
+		$this->_set_publish_post_box_vars(
1566
+			'id',
1567
+			$GRP_ID,
1568
+			false,
1569
+			add_query_arg(
1570
+				array('action' => 'global_mtps'),
1571
+				$this->_admin_base_url
1572
+			)
1573
+		);
1574
+        
1575
+		//add preview button
1576
+		$preview_url    = parent::add_query_args_and_nonce(
1577
+			array(
1578
+				'message_type' => $message_template_group->message_type(),
1579
+				'messenger'    => $message_template_group->messenger(),
1580
+				'context'      => $context,
1581
+				'GRP_ID'       => $GRP_ID,
1582
+				'action'       => 'preview_message'
1583
+			),
1584
+			$this->_admin_base_url
1585
+		);
1586
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">' . __('Preview',
1587
+				'event_espresso') . '</a>';
1588
+        
1589
+        
1590
+		//setup context switcher
1591
+		$context_switcher_args = array(
1592
+			'page'    => 'espresso_messages',
1593
+			'action'  => 'edit_message_template',
1594
+			'id'      => $GRP_ID,
1595
+			'context' => $context,
1596
+			'extra'   => $preview_button
1597
+		);
1598
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1599
+        
1600
+        
1601
+		//main box
1602
+		$this->_template_args['template_fields']                         = $template_fields;
1603
+		$this->_template_args['sidebar_box_id']                          = 'details';
1604
+		$this->_template_args['action']                                  = $action;
1605
+		$this->_template_args['context']                                 = $context;
1606
+		$this->_template_args['edit_message_template_form_url']          = $edit_message_template_form_url;
1607
+		$this->_template_args['learn_more_about_message_templates_link'] = $this->_learn_more_about_message_templates_link();
1608
+        
1609
+        
1610
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1611
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1612
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1613
+        
1614
+		$this->_template_path = $this->_template_args['GRP_ID']
1615
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1616
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1617
+        
1618
+		//send along EE_Message_Template_Group object for further template use.
1619
+		$this->_template_args['MTP'] = $message_template_group;
1620
+        
1621
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($this->_template_path,
1622
+			$this->_template_args, true);
1623
+        
1624
+        
1625
+		//finally, let's set the admin_page title
1626
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1627
+        
1628
+        
1629
+		//we need to take care of setting the shortcodes property for use elsewhere.
1630
+		$this->_set_shortcodes();
1631
+        
1632
+        
1633
+		//final template wrapper
1634
+		$this->display_admin_page_with_sidebar();
1635
+	}
1636
+    
1637
+    
1638
+	public function filter_tinymce_init($mceInit, $editor_id)
1639
+	{
1640
+		return $mceInit;
1641
+	}
1642
+    
1643
+    
1644
+	public function add_context_switcher()
1645
+	{
1646
+		return $this->_context_switcher;
1647
+	}
1648
+    
1649
+	public function _add_form_element_before()
1650
+	{
1651
+		return '<form method="post" action="' . $this->_template_args["edit_message_template_form_url"] . '" id="ee-msg-edit-frm">';
1652
+	}
1653
+    
1654
+	public function _add_form_element_after()
1655
+	{
1656
+		return '</form>';
1657
+	}
1658
+    
1659
+    
1660
+	/**
1661
+	 * This executes switching the template pack for a message template.
1662
+	 *
1663
+	 * @since 4.5.0
1664
+	 *
1665
+	 */
1666
+	public function switch_template_pack()
1667
+	{
1668
+		$GRP_ID        = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1669
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1670
+        
1671
+		//verify we have needed values.
1672
+		if (empty($GRP_ID) || empty($template_pack)) {
1673
+			$this->_template_args['error'] = true;
1674
+			EE_Error::add_error(__('The required date for switching templates is not available.', 'event_espresso'),
1675
+				__FILE__, __FUNCTION__, __LINE__);
1676
+		} else {
1677
+			//get template, set the new template_pack and then reset to default
1678
+			/** @type EE_Message_Template_Group $message_template_group */
1679
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1680 1680
             
1681
-            $message_template_group->set_template_pack_name($template_pack);
1682
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1683
-            $this->_req_data['mt']   = $message_template_group->message_type();
1681
+			$message_template_group->set_template_pack_name($template_pack);
1682
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1683
+			$this->_req_data['mt']   = $message_template_group->message_type();
1684 1684
             
1685
-            $query_args = $this->_reset_to_default_template();
1685
+			$query_args = $this->_reset_to_default_template();
1686 1686
             
1687
-            if (empty($query_args['id'])) {
1688
-                EE_Error::add_error(
1689
-                    __(
1690
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1691
-                        'event_espresso'
1692
-                    ),
1693
-                    __FILE__, __FUNCTION__, __LINE__
1694
-                );
1695
-                $this->_template_args['error'] = true;
1696
-            } else {
1697
-                $template_label       = $message_template_group->get_template_pack()->label;
1698
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1699
-                EE_Error::add_success(
1700
-                    sprintf(
1701
-                        __(
1702
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1703
-                            'event_espresso'
1704
-                        ),
1705
-                        $template_label,
1706
-                        $template_pack_labels->template_pack
1707
-                    )
1708
-                );
1709
-                //generate the redirect url for js.
1710
-                $url                                          = self::add_query_args_and_nonce($query_args,
1711
-                    $this->_admin_base_url);
1712
-                $this->_template_args['data']['redirect_url'] = $url;
1713
-                $this->_template_args['success']              = true;
1714
-            }
1687
+			if (empty($query_args['id'])) {
1688
+				EE_Error::add_error(
1689
+					__(
1690
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1691
+						'event_espresso'
1692
+					),
1693
+					__FILE__, __FUNCTION__, __LINE__
1694
+				);
1695
+				$this->_template_args['error'] = true;
1696
+			} else {
1697
+				$template_label       = $message_template_group->get_template_pack()->label;
1698
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
1699
+				EE_Error::add_success(
1700
+					sprintf(
1701
+						__(
1702
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
1703
+							'event_espresso'
1704
+						),
1705
+						$template_label,
1706
+						$template_pack_labels->template_pack
1707
+					)
1708
+				);
1709
+				//generate the redirect url for js.
1710
+				$url                                          = self::add_query_args_and_nonce($query_args,
1711
+					$this->_admin_base_url);
1712
+				$this->_template_args['data']['redirect_url'] = $url;
1713
+				$this->_template_args['success']              = true;
1714
+			}
1715 1715
             
1716
-            $this->_return_json();
1716
+			$this->_return_json();
1717 1717
             
1718
-        }
1719
-    }
1720
-    
1721
-    
1722
-    /**
1723
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1724
-     * they want.
1725
-     *
1726
-     * @access protected
1727
-     * @return array|null
1728
-     */
1729
-    protected function _reset_to_default_template()
1730
-    {
1731
-        
1732
-        $templates = array();
1733
-        $GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1734
-        //we need to make sure we've got the info we need.
1735
-        if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1736
-            EE_Error::add_error(
1737
-                __(
1738
-                    '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.',
1739
-                    'event_espresso'
1740
-                ),
1741
-                __FILE__, __FUNCTION__, __LINE__
1742
-            );
1743
-        }
1744
-        
1745
-        // all templates will be reset to whatever the defaults are
1746
-        // for the global template matching the messenger and message type.
1747
-        $success = ! empty($GRP_ID) ? true : false;
1748
-        
1749
-        if ($success) {
1718
+		}
1719
+	}
1720
+    
1721
+    
1722
+	/**
1723
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
1724
+	 * they want.
1725
+	 *
1726
+	 * @access protected
1727
+	 * @return array|null
1728
+	 */
1729
+	protected function _reset_to_default_template()
1730
+	{
1731
+        
1732
+		$templates = array();
1733
+		$GRP_ID    = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1734
+		//we need to make sure we've got the info we need.
1735
+		if ( ! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
1736
+			EE_Error::add_error(
1737
+				__(
1738
+					'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.',
1739
+					'event_espresso'
1740
+				),
1741
+				__FILE__, __FUNCTION__, __LINE__
1742
+			);
1743
+		}
1744
+        
1745
+		// all templates will be reset to whatever the defaults are
1746
+		// for the global template matching the messenger and message type.
1747
+		$success = ! empty($GRP_ID) ? true : false;
1748
+        
1749
+		if ($success) {
1750 1750
             
1751
-            //let's first determine if the incoming template is a global template,
1752
-            // if it isn't then we need to get the global template matching messenger and message type.
1753
-            //$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1751
+			//let's first determine if the incoming template is a global template,
1752
+			// if it isn't then we need to get the global template matching messenger and message type.
1753
+			//$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
1754 1754
             
1755 1755
             
1756
-            //note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1757
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
1756
+			//note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
1757
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
1758 1758
             
1759
-            if ($success) {
1760
-                // if successfully deleted, lets generate the new ones.
1761
-                // Note. We set GLOBAL to true, because resets on ANY template
1762
-                // will use the related global template defaults for regeneration.
1763
-                // This means that if a custom template is reset it resets to whatever the related global template is.
1764
-                // HOWEVER, we DO keep the template pack and template variation set
1765
-                // for the current custom template when resetting.
1766
-                $templates = $this->_generate_new_templates(
1767
-                    $this->_req_data['msgr'],
1768
-                    $this->_req_data['mt'],
1769
-                    $GRP_ID,
1770
-                    true
1771
-                );
1772
-            }
1759
+			if ($success) {
1760
+				// if successfully deleted, lets generate the new ones.
1761
+				// Note. We set GLOBAL to true, because resets on ANY template
1762
+				// will use the related global template defaults for regeneration.
1763
+				// This means that if a custom template is reset it resets to whatever the related global template is.
1764
+				// HOWEVER, we DO keep the template pack and template variation set
1765
+				// for the current custom template when resetting.
1766
+				$templates = $this->_generate_new_templates(
1767
+					$this->_req_data['msgr'],
1768
+					$this->_req_data['mt'],
1769
+					$GRP_ID,
1770
+					true
1771
+				);
1772
+			}
1773 1773
             
1774
-        }
1775
-        
1776
-        //any error messages?
1777
-        if ( ! $success) {
1778
-            EE_Error::add_error(
1779
-                __('Something went wrong with deleting existing templates. Unable to reset to default',
1780
-                    'event_espresso'),
1781
-                __FILE__, __FUNCTION__, __LINE__
1782
-            );
1783
-        }
1784
-        
1785
-        //all good, let's add a success message!
1786
-        if ($success && ! empty($templates)) {
1787
-            $templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1788
-            EE_Error::overwrite_success();
1789
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1790
-        }
1791
-        
1792
-        
1793
-        $query_args = array(
1794
-            'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1795
-            'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1796
-            'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1797
-        );
1798
-        
1799
-        //if called via ajax then we return query args otherwise redirect
1800
-        if (defined('DOING_AJAX') && DOING_AJAX) {
1801
-            return $query_args;
1802
-        } else {
1803
-            $this->_redirect_after_action(false, '', '', $query_args, true);
1774
+		}
1775
+        
1776
+		//any error messages?
1777
+		if ( ! $success) {
1778
+			EE_Error::add_error(
1779
+				__('Something went wrong with deleting existing templates. Unable to reset to default',
1780
+					'event_espresso'),
1781
+				__FILE__, __FUNCTION__, __LINE__
1782
+			);
1783
+		}
1784
+        
1785
+		//all good, let's add a success message!
1786
+		if ($success && ! empty($templates)) {
1787
+			$templates = $templates[0]; //the info for the template we generated is the first element in the returned array.
1788
+			EE_Error::overwrite_success();
1789
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
1790
+		}
1791
+        
1792
+        
1793
+		$query_args = array(
1794
+			'id'      => isset($templates['GRP_ID']) ? $templates['GRP_ID'] : null,
1795
+			'context' => isset($templates['MTP_context']) ? $templates['MTP_context'] : null,
1796
+			'action'  => isset($templates['GRP_ID']) ? 'edit_message_template' : 'global_mtps'
1797
+		);
1798
+        
1799
+		//if called via ajax then we return query args otherwise redirect
1800
+		if (defined('DOING_AJAX') && DOING_AJAX) {
1801
+			return $query_args;
1802
+		} else {
1803
+			$this->_redirect_after_action(false, '', '', $query_args, true);
1804 1804
             
1805
-            return null;
1806
-        }
1807
-    }
1808
-    
1809
-    
1810
-    /**
1811
-     * Retrieve and set the message preview for display.
1812
-     *
1813
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1814
-     *
1815
-     * @return string
1816
-     */
1817
-    public function _preview_message($send = false)
1818
-    {
1819
-        //first make sure we've got the necessary parameters
1820
-        if (
1821
-        ! isset(
1822
-            $this->_req_data['message_type'],
1823
-            $this->_req_data['messenger'],
1824
-            $this->_req_data['messenger'],
1825
-            $this->_req_data['GRP_ID']
1826
-        )
1827
-        ) {
1828
-            EE_Error::add_error(
1829
-                __('Missing necessary parameters for displaying preview', 'event_espresso'),
1830
-                __FILE__, __FUNCTION__, __LINE__
1831
-            );
1832
-        }
1833
-        
1834
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1835
-        
1836
-        
1837
-        //get the preview!
1838
-        $preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1839
-            $this->_req_data['messenger'], $send);
1840
-        
1841
-        if ($send) {
1842
-            return $preview;
1843
-        }
1844
-        
1845
-        //let's add a button to go back to the edit view
1846
-        $query_args             = array(
1847
-            'id'      => $this->_req_data['GRP_ID'],
1848
-            'context' => $this->_req_data['context'],
1849
-            'action'  => 'edit_message_template'
1850
-        );
1851
-        $go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
-        $preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
-                'event_espresso') . '</a>';
1854
-        $message_types          = $this->get_installed_message_types();
1855
-        $active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856
-        $active_messenger_label = $active_messenger instanceof EE_messenger
1857
-            ? ucwords($active_messenger->label['singular'])
1858
-            : esc_html__('Unknown Messenger', 'event_espresso');
1859
-        //let's provide a helpful title for context
1860
-        $preview_title = sprintf(
1861
-            __('Viewing Preview for %s %s Message Template', 'event_espresso'),
1862
-            $active_messenger_label,
1863
-            ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1864
-        );
1865
-        //setup display of preview.
1866
-        $this->_admin_page_title                    = $preview_title;
1867
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1868
-        $this->_template_args['data']['force_json'] = true;
1869
-        
1870
-        return '';
1871
-    }
1872
-    
1873
-    
1874
-    /**
1875
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1876
-     * gets called automatically.
1877
-     *
1878
-     * @since 4.5.0
1879
-     *
1880
-     * @return string
1881
-     */
1882
-    protected function _display_preview_message()
1883
-    {
1884
-        $this->display_admin_page_with_no_sidebar();
1885
-    }
1886
-    
1887
-    
1888
-    /**
1889
-     * registers metaboxes that should show up on the "edit_message_template" page
1890
-     *
1891
-     * @access protected
1892
-     * @return void
1893
-     */
1894
-    protected function _register_edit_meta_boxes()
1895
-    {
1896
-        add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1897
-            array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1898
-        add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1899
-            $this->_current_screen->id, 'side', 'high');
1900
-        add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1901
-            $this->_current_screen->id, 'side', 'high');
1902
-    }
1903
-    
1904
-    
1905
-    /**
1906
-     * metabox content for all template pack and variation selection.
1907
-     *
1908
-     * @since 4.5.0
1909
-     *
1910
-     * @return string
1911
-     */
1912
-    public function template_pack_meta_box()
1913
-    {
1914
-        $this->_set_message_template_group();
1915
-        
1916
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
1917
-        
1918
-        $tp_select_values = array();
1919
-        
1920
-        foreach ($tp_collection as $tp) {
1921
-            //only include template packs that support this messenger and message type!
1922
-            $supports = $tp->get_supports();
1923
-            if (
1924
-                ! isset($supports[$this->_message_template_group->messenger()])
1925
-                || ! in_array(
1926
-                    $this->_message_template_group->message_type(),
1927
-                    $supports[$this->_message_template_group->messenger()]
1928
-                )
1929
-            ) {
1930
-                //not supported
1931
-                continue;
1932
-            }
1805
+			return null;
1806
+		}
1807
+	}
1808
+    
1809
+    
1810
+	/**
1811
+	 * Retrieve and set the message preview for display.
1812
+	 *
1813
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
1814
+	 *
1815
+	 * @return string
1816
+	 */
1817
+	public function _preview_message($send = false)
1818
+	{
1819
+		//first make sure we've got the necessary parameters
1820
+		if (
1821
+		! isset(
1822
+			$this->_req_data['message_type'],
1823
+			$this->_req_data['messenger'],
1824
+			$this->_req_data['messenger'],
1825
+			$this->_req_data['GRP_ID']
1826
+		)
1827
+		) {
1828
+			EE_Error::add_error(
1829
+				__('Missing necessary parameters for displaying preview', 'event_espresso'),
1830
+				__FILE__, __FUNCTION__, __LINE__
1831
+			);
1832
+		}
1833
+        
1834
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
1835
+        
1836
+        
1837
+		//get the preview!
1838
+		$preview = EED_Messages::preview_message($this->_req_data['message_type'], $this->_req_data['context'],
1839
+			$this->_req_data['messenger'], $send);
1840
+        
1841
+		if ($send) {
1842
+			return $preview;
1843
+		}
1844
+        
1845
+		//let's add a button to go back to the edit view
1846
+		$query_args             = array(
1847
+			'id'      => $this->_req_data['GRP_ID'],
1848
+			'context' => $this->_req_data['context'],
1849
+			'action'  => 'edit_message_template'
1850
+		);
1851
+		$go_back_url            = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
1852
+		$preview_button         = '<a href="' . $go_back_url . '" class="button-secondary messages-preview-go-back-button">' . __('Go Back to Edit',
1853
+				'event_espresso') . '</a>';
1854
+		$message_types          = $this->get_installed_message_types();
1855
+		$active_messenger       = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
1856
+		$active_messenger_label = $active_messenger instanceof EE_messenger
1857
+			? ucwords($active_messenger->label['singular'])
1858
+			: esc_html__('Unknown Messenger', 'event_espresso');
1859
+		//let's provide a helpful title for context
1860
+		$preview_title = sprintf(
1861
+			__('Viewing Preview for %s %s Message Template', 'event_espresso'),
1862
+			$active_messenger_label,
1863
+			ucwords($message_types[$this->_req_data['message_type']]->label['singular'])
1864
+		);
1865
+		//setup display of preview.
1866
+		$this->_admin_page_title                    = $preview_title;
1867
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . stripslashes($preview);
1868
+		$this->_template_args['data']['force_json'] = true;
1869
+        
1870
+		return '';
1871
+	}
1872
+    
1873
+    
1874
+	/**
1875
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
1876
+	 * gets called automatically.
1877
+	 *
1878
+	 * @since 4.5.0
1879
+	 *
1880
+	 * @return string
1881
+	 */
1882
+	protected function _display_preview_message()
1883
+	{
1884
+		$this->display_admin_page_with_no_sidebar();
1885
+	}
1886
+    
1887
+    
1888
+	/**
1889
+	 * registers metaboxes that should show up on the "edit_message_template" page
1890
+	 *
1891
+	 * @access protected
1892
+	 * @return void
1893
+	 */
1894
+	protected function _register_edit_meta_boxes()
1895
+	{
1896
+		add_meta_box('mtp_valid_shortcodes', __('Valid Shortcodes', 'event_espresso'),
1897
+			array($this, 'shortcode_meta_box'), $this->_current_screen->id, 'side', 'default');
1898
+		add_meta_box('mtp_extra_actions', __('Extra Actions', 'event_espresso'), array($this, 'extra_actions_meta_box'),
1899
+			$this->_current_screen->id, 'side', 'high');
1900
+		add_meta_box('mtp_templates', __('Template Styles', 'event_espresso'), array($this, 'template_pack_meta_box'),
1901
+			$this->_current_screen->id, 'side', 'high');
1902
+	}
1903
+    
1904
+    
1905
+	/**
1906
+	 * metabox content for all template pack and variation selection.
1907
+	 *
1908
+	 * @since 4.5.0
1909
+	 *
1910
+	 * @return string
1911
+	 */
1912
+	public function template_pack_meta_box()
1913
+	{
1914
+		$this->_set_message_template_group();
1915
+        
1916
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
1917
+        
1918
+		$tp_select_values = array();
1919
+        
1920
+		foreach ($tp_collection as $tp) {
1921
+			//only include template packs that support this messenger and message type!
1922
+			$supports = $tp->get_supports();
1923
+			if (
1924
+				! isset($supports[$this->_message_template_group->messenger()])
1925
+				|| ! in_array(
1926
+					$this->_message_template_group->message_type(),
1927
+					$supports[$this->_message_template_group->messenger()]
1928
+				)
1929
+			) {
1930
+				//not supported
1931
+				continue;
1932
+			}
1933 1933
             
1934
-            $tp_select_values[] = array(
1935
-                'text' => $tp->label,
1936
-                'id'   => $tp->dbref
1937
-            );
1938
-        }
1939
-        
1940
-        //if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1941
-        if (empty($tp_select_values)) {
1942
-            $tp_select_values[] = array(
1943
-                'text' => __('Default', 'event_espresso'),
1944
-                'id'   => 'default'
1945
-            );
1946
-        }
1947
-        
1948
-        //setup variation select values for the currently selected template.
1949
-        $variations               = $this->_message_template_group->get_template_pack()->get_variations(
1950
-            $this->_message_template_group->messenger(),
1951
-            $this->_message_template_group->message_type()
1952
-        );
1953
-        $variations_select_values = array();
1954
-        foreach ($variations as $variation => $label) {
1955
-            $variations_select_values[] = array(
1956
-                'text' => $label,
1957
-                'id'   => $variation
1958
-            );
1959
-        }
1960
-        
1961
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962
-        
1963
-        $template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1964
-            'MTP_template_pack',
1965
-            $tp_select_values,
1966
-            $this->_message_template_group->get_template_pack_name()
1967
-        );
1968
-        $template_args['variations_selector']            = EEH_Form_Fields::select_input(
1969
-            'MTP_template_variation',
1970
-            $variations_select_values,
1971
-            $this->_message_template_group->get_template_pack_variation()
1972
-        );
1973
-        $template_args['template_pack_label']            = $template_pack_labels->template_pack;
1974
-        $template_args['template_variation_label']       = $template_pack_labels->template_variation;
1975
-        $template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977
-        
1978
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1979
-        
1980
-        EEH_Template::display_template($template, $template_args);
1981
-    }
1982
-    
1983
-    
1984
-    /**
1985
-     * This meta box holds any extra actions related to Message Templates
1986
-     * For now, this includes Resetting templates to defaults and sending a test email.
1987
-     *
1988
-     * @access  public
1989
-     * @return void
1990
-     * @throws \EE_Error
1991
-     */
1992
-    public function extra_actions_meta_box()
1993
-    {
1994
-        $template_form_fields = array();
1995
-        
1996
-        $extra_args = array(
1997
-            'msgr'   => $this->_message_template_group->messenger(),
1998
-            'mt'     => $this->_message_template_group->message_type(),
1999
-            'GRP_ID' => $this->_message_template_group->GRP_ID()
2000
-        );
2001
-        //first we need to see if there are any fields
2002
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2003
-        
2004
-        if ( ! empty($fields)) {
2005
-            //yup there be fields
2006
-            foreach ($fields as $field => $config) {
2007
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2008
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009
-                $default  = isset($config['default']) ? $config['default'] : '';
2010
-                $default  = isset($config['value']) ? $config['value'] : $default;
1934
+			$tp_select_values[] = array(
1935
+				'text' => $tp->label,
1936
+				'id'   => $tp->dbref
1937
+			);
1938
+		}
1939
+        
1940
+		//if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by the default template pack.  This still allows for the odd template pack to override.
1941
+		if (empty($tp_select_values)) {
1942
+			$tp_select_values[] = array(
1943
+				'text' => __('Default', 'event_espresso'),
1944
+				'id'   => 'default'
1945
+			);
1946
+		}
1947
+        
1948
+		//setup variation select values for the currently selected template.
1949
+		$variations               = $this->_message_template_group->get_template_pack()->get_variations(
1950
+			$this->_message_template_group->messenger(),
1951
+			$this->_message_template_group->message_type()
1952
+		);
1953
+		$variations_select_values = array();
1954
+		foreach ($variations as $variation => $label) {
1955
+			$variations_select_values[] = array(
1956
+				'text' => $label,
1957
+				'id'   => $variation
1958
+			);
1959
+		}
1960
+        
1961
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
1962
+        
1963
+		$template_args['template_packs_selector']        = EEH_Form_Fields::select_input(
1964
+			'MTP_template_pack',
1965
+			$tp_select_values,
1966
+			$this->_message_template_group->get_template_pack_name()
1967
+		);
1968
+		$template_args['variations_selector']            = EEH_Form_Fields::select_input(
1969
+			'MTP_template_variation',
1970
+			$variations_select_values,
1971
+			$this->_message_template_group->get_template_pack_variation()
1972
+		);
1973
+		$template_args['template_pack_label']            = $template_pack_labels->template_pack;
1974
+		$template_args['template_variation_label']       = $template_pack_labels->template_variation;
1975
+		$template_args['template_pack_description']      = $template_pack_labels->template_pack_description;
1976
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
1977
+        
1978
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
1979
+        
1980
+		EEH_Template::display_template($template, $template_args);
1981
+	}
1982
+    
1983
+    
1984
+	/**
1985
+	 * This meta box holds any extra actions related to Message Templates
1986
+	 * For now, this includes Resetting templates to defaults and sending a test email.
1987
+	 *
1988
+	 * @access  public
1989
+	 * @return void
1990
+	 * @throws \EE_Error
1991
+	 */
1992
+	public function extra_actions_meta_box()
1993
+	{
1994
+		$template_form_fields = array();
1995
+        
1996
+		$extra_args = array(
1997
+			'msgr'   => $this->_message_template_group->messenger(),
1998
+			'mt'     => $this->_message_template_group->message_type(),
1999
+			'GRP_ID' => $this->_message_template_group->GRP_ID()
2000
+		);
2001
+		//first we need to see if there are any fields
2002
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2003
+        
2004
+		if ( ! empty($fields)) {
2005
+			//yup there be fields
2006
+			foreach ($fields as $field => $config) {
2007
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2008
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2009
+				$default  = isset($config['default']) ? $config['default'] : '';
2010
+				$default  = isset($config['value']) ? $config['value'] : $default;
2011 2011
                 
2012
-                // if type is hidden and the value is empty
2013
-                // something may have gone wrong so let's correct with the defaults
2014
-                $fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2015
-                    ? $default
2016
-                    : '';
2017
-                $existing[$field] = isset($existing[$field]) && empty($fix)
2018
-                    ? $existing[$field]
2019
-                    : $fix;
2012
+				// if type is hidden and the value is empty
2013
+				// something may have gone wrong so let's correct with the defaults
2014
+				$fix              = $config['input'] === 'hidden' && isset($existing[$field]) && empty($existing[$field])
2015
+					? $default
2016
+					: '';
2017
+				$existing[$field] = isset($existing[$field]) && empty($fix)
2018
+					? $existing[$field]
2019
+					: $fix;
2020 2020
                 
2021
-                $template_form_fields[$field_id] = array(
2022
-                    'name'       => 'test_settings_fld[' . $field . ']',
2023
-                    'label'      => $config['label'],
2024
-                    'input'      => $config['input'],
2025
-                    'type'       => $config['type'],
2026
-                    'required'   => $config['required'],
2027
-                    'validation' => $config['validation'],
2028
-                    'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2029
-                    'css_class'  => $config['css_class'],
2030
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2031
-                    'default'    => $default,
2032
-                    'format'     => $config['format']
2033
-                );
2034
-            }
2035
-        }
2036
-        
2037
-        $test_settings_fields = ! empty($template_form_fields)
2038
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2039
-            : '';
2040
-        
2041
-        $test_settings_html = '';
2042
-        //print out $test_settings_fields
2043
-        if ( ! empty($test_settings_fields)) {
2044
-            echo $test_settings_fields;
2045
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2046
-            $test_settings_html .= 'name="test_button" value="';
2047
-            $test_settings_html .= __('Test Send', 'event_espresso');
2048
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2049
-        }
2050
-        
2051
-        //and button
2052
-        $test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2053
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054
-        $test_settings_html .= $this->get_action_link_or_button(
2055
-            'reset_to_default',
2056
-            'reset',
2057
-            $extra_args,
2058
-            'button-primary reset-default-button'
2059
-        );
2060
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2061
-        echo $test_settings_html;
2062
-    }
2063
-    
2064
-    
2065
-    /**
2066
-     * This returns the shortcode selector skeleton for a given context and field.
2067
-     *
2068
-     * @since 4.9.rc.000
2069
-     *
2070
-     * @param string $field           The name of the field retrieving shortcodes for.
2071
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2072
-     *
2073
-     * @return string
2074
-     */
2075
-    protected function _get_shortcode_selector($field, $linked_input_id)
2076
-    {
2077
-        $template_args = array(
2078
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2079
-            'fieldname'       => $field,
2080
-            'linked_input_id' => $linked_input_id
2081
-        );
2082
-        
2083
-        return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2084
-            $template_args, true);
2085
-    }
2086
-    
2087
-    
2088
-    /**
2089
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2090
-     * page)
2091
-     *
2092
-     * @access public
2093
-     * @return void
2094
-     */
2095
-    public function shortcode_meta_box()
2096
-    {
2097
-        $shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2098
-        //$messenger = $this->_message_template_group->messenger_obj();
2099
-        //now let's set the content depending on the status of the shortcodes array
2100
-        if (empty($shortcodes)) {
2101
-            $content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2102
-            echo $content;
2103
-        } else {
2104
-            //$alt = 0;
2105
-            ?>
2021
+				$template_form_fields[$field_id] = array(
2022
+					'name'       => 'test_settings_fld[' . $field . ']',
2023
+					'label'      => $config['label'],
2024
+					'input'      => $config['input'],
2025
+					'type'       => $config['type'],
2026
+					'required'   => $config['required'],
2027
+					'validation' => $config['validation'],
2028
+					'value'      => isset($existing[$field]) ? $existing[$field] : $default,
2029
+					'css_class'  => $config['css_class'],
2030
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2031
+					'default'    => $default,
2032
+					'format'     => $config['format']
2033
+				);
2034
+			}
2035
+		}
2036
+        
2037
+		$test_settings_fields = ! empty($template_form_fields)
2038
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2039
+			: '';
2040
+        
2041
+		$test_settings_html = '';
2042
+		//print out $test_settings_fields
2043
+		if ( ! empty($test_settings_fields)) {
2044
+			echo $test_settings_fields;
2045
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2046
+			$test_settings_html .= 'name="test_button" value="';
2047
+			$test_settings_html .= __('Test Send', 'event_espresso');
2048
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2049
+		}
2050
+        
2051
+		//and button
2052
+		$test_settings_html .= '<p>' . __('Need to reset this message type and start over?', 'event_espresso') . '</p>';
2053
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2054
+		$test_settings_html .= $this->get_action_link_or_button(
2055
+			'reset_to_default',
2056
+			'reset',
2057
+			$extra_args,
2058
+			'button-primary reset-default-button'
2059
+		);
2060
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2061
+		echo $test_settings_html;
2062
+	}
2063
+    
2064
+    
2065
+	/**
2066
+	 * This returns the shortcode selector skeleton for a given context and field.
2067
+	 *
2068
+	 * @since 4.9.rc.000
2069
+	 *
2070
+	 * @param string $field           The name of the field retrieving shortcodes for.
2071
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2072
+	 *
2073
+	 * @return string
2074
+	 */
2075
+	protected function _get_shortcode_selector($field, $linked_input_id)
2076
+	{
2077
+		$template_args = array(
2078
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2079
+			'fieldname'       => $field,
2080
+			'linked_input_id' => $linked_input_id
2081
+		);
2082
+        
2083
+		return EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2084
+			$template_args, true);
2085
+	}
2086
+    
2087
+    
2088
+	/**
2089
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2090
+	 * page)
2091
+	 *
2092
+	 * @access public
2093
+	 * @return void
2094
+	 */
2095
+	public function shortcode_meta_box()
2096
+	{
2097
+		$shortcodes = $this->_get_shortcodes(array(), false); //just make sure shortcodes property is set
2098
+		//$messenger = $this->_message_template_group->messenger_obj();
2099
+		//now let's set the content depending on the status of the shortcodes array
2100
+		if (empty($shortcodes)) {
2101
+			$content = '<p>' . __('There are no valid shortcodes available', 'event_espresso') . '</p>';
2102
+			echo $content;
2103
+		} else {
2104
+			//$alt = 0;
2105
+			?>
2106 2106
             <div
2107 2107
                 style="float:right; margin-top:10px"><?php echo $this->_get_help_tab_link('message_template_shortcodes'); ?></div>
2108 2108
             <p class="small-text"><?php printf(__('You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2109
-                    'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2109
+					'event_espresso'), '<span class="dashicons dashicons-menu"></span>'); ?></p>
2110 2110
             <?php
2111
-        }
2112
-        
2113
-        
2114
-    }
2115
-    
2116
-    
2117
-    /**
2118
-     * used to set the $_shortcodes property for when its needed elsewhere.
2119
-     *
2120
-     * @access protected
2121
-     * @return void
2122
-     */
2123
-    protected function _set_shortcodes()
2124
-    {
2125
-        
2126
-        //no need to run this if the property is already set
2127
-        if ( ! empty($this->_shortcodes)) {
2128
-            return;
2129
-        }
2130
-        
2131
-        $this->_shortcodes = $this->_get_shortcodes();
2132
-    }
2133
-    
2134
-    
2135
-    /**
2136
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2137
-     * property)
2138
-     *
2139
-     * @access  protected
2140
-     *
2141
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2142
-     *                         for. Defaults to all (for the given context)
2143
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2144
-     *
2145
-     * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2146
-     *                        true just an array of shortcode/label pairs.
2147
-     */
2148
-    protected function _get_shortcodes($fields = array(), $merged = true)
2149
-    {
2150
-        $this->_set_message_template_group();
2151
-        
2152
-        //we need the messenger and message template to retrieve the valid shortcodes array.
2153
-        $GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2154
-        $context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2155
-        
2156
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2157
-    }
2158
-    
2159
-    
2160
-    /**
2161
-     * This sets the _message_template property (containing the called message_template object)
2162
-     *
2163
-     * @access protected
2164
-     * @return  void
2165
-     */
2166
-    protected function _set_message_template_group()
2167
-    {
2168
-        
2169
-        if ( ! empty($this->_message_template_group)) {
2170
-            return;
2171
-        } //get out if this is already set.
2172
-        
2173
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2174
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2175
-        
2176
-        //let's get the message templates
2177
-        $MTP = EEM_Message_Template_Group::instance();
2178
-        
2179
-        if (empty($GRP_ID)) {
2180
-            $this->_message_template_group = $MTP->create_default_object();
2181
-        } else {
2182
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2183
-        }
2184
-        
2185
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2186
-        $this->_variation     = $this->_message_template_group->get_template_pack_variation();
2187
-        
2188
-    }
2189
-    
2190
-    
2191
-    /**
2192
-     * sets up a context switcher for edit forms
2193
-     *
2194
-     * @access  protected
2195
-     *
2196
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2197
-     * @param array                      $args                  various things the context switcher needs.
2198
-     *
2199
-     */
2200
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2201
-    {
2202
-        $context_details = $template_group_object->contexts_config();
2203
-        $context_label   = $template_group_object->context_label();
2204
-        ob_start();
2205
-        ?>
2111
+		}
2112
+        
2113
+        
2114
+	}
2115
+    
2116
+    
2117
+	/**
2118
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2119
+	 *
2120
+	 * @access protected
2121
+	 * @return void
2122
+	 */
2123
+	protected function _set_shortcodes()
2124
+	{
2125
+        
2126
+		//no need to run this if the property is already set
2127
+		if ( ! empty($this->_shortcodes)) {
2128
+			return;
2129
+		}
2130
+        
2131
+		$this->_shortcodes = $this->_get_shortcodes();
2132
+	}
2133
+    
2134
+    
2135
+	/**
2136
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2137
+	 * property)
2138
+	 *
2139
+	 * @access  protected
2140
+	 *
2141
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2142
+	 *                         for. Defaults to all (for the given context)
2143
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2144
+	 *
2145
+	 * @return array          Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2146
+	 *                        true just an array of shortcode/label pairs.
2147
+	 */
2148
+	protected function _get_shortcodes($fields = array(), $merged = true)
2149
+	{
2150
+		$this->_set_message_template_group();
2151
+        
2152
+		//we need the messenger and message template to retrieve the valid shortcodes array.
2153
+		$GRP_ID  = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id']) : false;
2154
+		$context = isset($this->_req_data['context']) ? $this->_req_data['context'] : key($this->_message_template_group->contexts_config());
2155
+        
2156
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2157
+	}
2158
+    
2159
+    
2160
+	/**
2161
+	 * This sets the _message_template property (containing the called message_template object)
2162
+	 *
2163
+	 * @access protected
2164
+	 * @return  void
2165
+	 */
2166
+	protected function _set_message_template_group()
2167
+	{
2168
+        
2169
+		if ( ! empty($this->_message_template_group)) {
2170
+			return;
2171
+		} //get out if this is already set.
2172
+        
2173
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2174
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2175
+        
2176
+		//let's get the message templates
2177
+		$MTP = EEM_Message_Template_Group::instance();
2178
+        
2179
+		if (empty($GRP_ID)) {
2180
+			$this->_message_template_group = $MTP->create_default_object();
2181
+		} else {
2182
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2183
+		}
2184
+        
2185
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2186
+		$this->_variation     = $this->_message_template_group->get_template_pack_variation();
2187
+        
2188
+	}
2189
+    
2190
+    
2191
+	/**
2192
+	 * sets up a context switcher for edit forms
2193
+	 *
2194
+	 * @access  protected
2195
+	 *
2196
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2197
+	 * @param array                      $args                  various things the context switcher needs.
2198
+	 *
2199
+	 */
2200
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2201
+	{
2202
+		$context_details = $template_group_object->contexts_config();
2203
+		$context_label   = $template_group_object->context_label();
2204
+		ob_start();
2205
+		?>
2206 2206
         <div class="ee-msg-switcher-container">
2207 2207
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2208 2208
                 <?php
2209
-                foreach ($args as $name => $value) {
2210
-                    if ($name == 'context' || empty($value) || $name == 'extra') {
2211
-                        continue;
2212
-                    }
2213
-                    ?>
2209
+				foreach ($args as $name => $value) {
2210
+					if ($name == 'context' || empty($value) || $name == 'extra') {
2211
+						continue;
2212
+					}
2213
+					?>
2214 2214
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2215 2215
                     <?php
2216
-                }
2217
-                //setup nonce_url
2218
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2219
-                ?>
2216
+				}
2217
+				//setup nonce_url
2218
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2219
+				?>
2220 2220
                 <select name="context">
2221 2221
                     <?php
2222
-                    $context_templates = $template_group_object->context_templates();
2223
-                    if (is_array($context_templates)) :
2224
-                        foreach ($context_templates as $context => $template_fields) :
2225
-                            $checked = ($context == $args['context']) ? 'selected="selected"' : '';
2226
-                            ?>
2222
+					$context_templates = $template_group_object->context_templates();
2223
+					if (is_array($context_templates)) :
2224
+						foreach ($context_templates as $context => $template_fields) :
2225
+							$checked = ($context == $args['context']) ? 'selected="selected"' : '';
2226
+							?>
2227 2227
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2228 2228
                                 <?php echo $context_details[$context]['label']; ?>
2229 2229
                             </option>
@@ -2236,1560 +2236,1560 @@  discard block
 block discarded – undo
2236 2236
             <?php echo $args['extra']; ?>
2237 2237
         </div> <!-- end .ee-msg-switcher-container -->
2238 2238
         <?php
2239
-        $output = ob_get_contents();
2240
-        ob_clean();
2241
-        $this->_context_switcher = $output;
2242
-    }
2243
-    
2244
-    
2245
-    /**
2246
-     * utility for sanitizing new values coming in.
2247
-     * Note: this is only used when updating a context.
2248
-     *
2249
-     * @access protected
2250
-     *
2251
-     * @param int $index This helps us know which template field to select from the request array.
2252
-     *
2253
-     * @return array
2254
-     */
2255
-    protected function _set_message_template_column_values($index)
2256
-    {
2257
-        if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2258
-            foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2259
-                $this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2260
-            }
2261
-        } /*else {
2239
+		$output = ob_get_contents();
2240
+		ob_clean();
2241
+		$this->_context_switcher = $output;
2242
+	}
2243
+    
2244
+    
2245
+	/**
2246
+	 * utility for sanitizing new values coming in.
2247
+	 * Note: this is only used when updating a context.
2248
+	 *
2249
+	 * @access protected
2250
+	 *
2251
+	 * @param int $index This helps us know which template field to select from the request array.
2252
+	 *
2253
+	 * @return array
2254
+	 */
2255
+	protected function _set_message_template_column_values($index)
2256
+	{
2257
+		if (is_array($this->_req_data['MTP_template_fields'][$index]['content'])) {
2258
+			foreach ($this->_req_data['MTP_template_fields'][$index]['content'] as $field => $value) {
2259
+				$this->_req_data['MTP_template_fields'][$index]['content'][$field] = $value;
2260
+			}
2261
+		} /*else {
2262 2262
 			$this->_req_data['MTP_template_fields'][$index]['content'] = $this->_req_data['MTP_template_fields'][$index]['content'];
2263 2263
 		}*/
2264 2264
         
2265 2265
         
2266
-        $set_column_values = array(
2267
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2268
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2269
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2270
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2271
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2272
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2273
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2274
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2275
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2276
-                ? absint($this->_req_data['MTP_is_global'])
2277
-                : 0,
2278
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2279
-                ? absint($this->_req_data['MTP_is_override'])
2280
-                : 0,
2281
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2282
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2283
-        );
2284
-        
2285
-        
2286
-        return $set_column_values;
2287
-    }
2288
-    
2289
-    
2290
-    protected function _insert_or_update_message_template($new = false)
2291
-    {
2292
-        
2293
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2294
-        $success  = 0;
2295
-        $override = false;
2296
-        
2297
-        //setup notices description
2298
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2299
-        
2300
-        //need the message type and messenger objects to be able to use the labels for the notices
2301
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2302
-        $messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2303
-        
2304
-        $message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2305
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2306
-        
2307
-        $message_type_label = $message_type_object instanceof EE_message_type
2308
-            ? ucwords($message_type_object->label['singular'])
2309
-            : '';
2310
-        
2311
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2312
-            ? $this->_req_data['MTP_context']
2313
-            : '';
2314
-        $context      = ucwords(str_replace('_', ' ', $context_slug));
2315
-        
2316
-        $item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2317
-        $item_desc .= 'Message Template';
2318
-        $query_args  = array();
2319
-        $edit_array  = array();
2320
-        $action_desc = '';
2321
-        
2322
-        //if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2323
-        if ($new) {
2324
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2325
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2326
-                if (empty($edit_array)) {
2327
-                    $success = 0;
2328
-                } else {
2329
-                    $success    = 1;
2330
-                    $edit_array = $edit_array[0];
2331
-                    $query_args = array(
2332
-                        'id'      => $edit_array['GRP_ID'],
2333
-                        'context' => $edit_array['MTP_context'],
2334
-                        'action'  => 'edit_message_template'
2335
-                    );
2336
-                }
2337
-            }
2338
-            $action_desc = 'created';
2339
-        } else {
2340
-            $MTPG = EEM_Message_Template_Group::instance();
2341
-            $MTP  = EEM_Message_Template::instance();
2266
+		$set_column_values = array(
2267
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][$index]['MTP_ID']),
2268
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2269
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2270
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2271
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2272
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][$index]['name']),
2273
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2274
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][$index]['content'],
2275
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2276
+				? absint($this->_req_data['MTP_is_global'])
2277
+				: 0,
2278
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2279
+				? absint($this->_req_data['MTP_is_override'])
2280
+				: 0,
2281
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2282
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active'])
2283
+		);
2284
+        
2285
+        
2286
+		return $set_column_values;
2287
+	}
2288
+    
2289
+    
2290
+	protected function _insert_or_update_message_template($new = false)
2291
+	{
2292
+        
2293
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2294
+		$success  = 0;
2295
+		$override = false;
2296
+        
2297
+		//setup notices description
2298
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2299
+        
2300
+		//need the message type and messenger objects to be able to use the labels for the notices
2301
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2302
+		$messenger_label  = $messenger_object instanceof EE_messenger ? ucwords($messenger_object->label['singular']) : '';
2303
+        
2304
+		$message_type_slug   = ! empty($this->_req_data['MTP_message_type']) ? $this->_req_data['MTP_message_type'] : '';
2305
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2306
+        
2307
+		$message_type_label = $message_type_object instanceof EE_message_type
2308
+			? ucwords($message_type_object->label['singular'])
2309
+			: '';
2310
+        
2311
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2312
+			? $this->_req_data['MTP_context']
2313
+			: '';
2314
+		$context      = ucwords(str_replace('_', ' ', $context_slug));
2315
+        
2316
+		$item_desc = $messenger_label && $message_type_label ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' ' : '';
2317
+		$item_desc .= 'Message Template';
2318
+		$query_args  = array();
2319
+		$edit_array  = array();
2320
+		$action_desc = '';
2321
+        
2322
+		//if this is "new" then we need to generate the default contexts for the selected messenger/message_type for user to edit.
2323
+		if ($new) {
2324
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2325
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2326
+				if (empty($edit_array)) {
2327
+					$success = 0;
2328
+				} else {
2329
+					$success    = 1;
2330
+					$edit_array = $edit_array[0];
2331
+					$query_args = array(
2332
+						'id'      => $edit_array['GRP_ID'],
2333
+						'context' => $edit_array['MTP_context'],
2334
+						'action'  => 'edit_message_template'
2335
+					);
2336
+				}
2337
+			}
2338
+			$action_desc = 'created';
2339
+		} else {
2340
+			$MTPG = EEM_Message_Template_Group::instance();
2341
+			$MTP  = EEM_Message_Template::instance();
2342 2342
             
2343 2343
             
2344
-            //run update for each template field in displayed context
2345
-            if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2346
-                EE_Error::add_error(
2347
-                    __('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2348
-                        'event_espresso'),
2349
-                    __FILE__, __FUNCTION__, __LINE__
2350
-                );
2351
-                $success = 0;
2344
+			//run update for each template field in displayed context
2345
+			if ( ! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2346
+				EE_Error::add_error(
2347
+					__('There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2348
+						'event_espresso'),
2349
+					__FILE__, __FUNCTION__, __LINE__
2350
+				);
2351
+				$success = 0;
2352 2352
                 
2353
-            } else {
2354
-                //first validate all fields!
2355
-                $validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2356
-                    $message_type_slug);
2353
+			} else {
2354
+				//first validate all fields!
2355
+				$validates = $MTPG->validate($this->_req_data['MTP_template_fields'], $context_slug, $messenger_slug,
2356
+					$message_type_slug);
2357 2357
                 
2358
-                //if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2359
-                if (is_array($validates) && ! empty($validates)) {
2360
-                    //add the transient so when the form loads we know which fields to highlight
2361
-                    $this->_add_transient('edit_message_template', $validates);
2358
+				//if $validate returned error messages (i.e. is_array()) then we need to process them and setup an appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.  WE need to make sure there is no actual error messages in validates.
2359
+				if (is_array($validates) && ! empty($validates)) {
2360
+					//add the transient so when the form loads we know which fields to highlight
2361
+					$this->_add_transient('edit_message_template', $validates);
2362 2362
                     
2363
-                    $success = 0;
2363
+					$success = 0;
2364 2364
                     
2365
-                    //setup notices
2366
-                    foreach ($validates as $field => $error) {
2367
-                        if (isset($error['msg'])) {
2368
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2369
-                        }
2370
-                    }
2365
+					//setup notices
2366
+					foreach ($validates as $field => $error) {
2367
+						if (isset($error['msg'])) {
2368
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2369
+						}
2370
+					}
2371 2371
                     
2372
-                } else {
2373
-                    $set_column_values = array();
2374
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2375
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2372
+				} else {
2373
+					$set_column_values = array();
2374
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2375
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2376 2376
                         
2377
-                        $where_cols_n_values = array(
2378
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2379
-                        );
2377
+						$where_cols_n_values = array(
2378
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][$template_field]['MTP_ID']
2379
+						);
2380 2380
                         
2381
-                        $message_template_fields = array(
2382
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2383
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2384
-                            'MTP_context'        => $set_column_values['MTP_context'],
2385
-                            'MTP_content'        => $set_column_values['MTP_content']
2386
-                        );
2387
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2388
-                            if ($updated === false) {
2389
-                                EE_Error::add_error(
2390
-                                    sprintf(
2391
-                                        __('%s field was NOT updated for some reason', 'event_espresso'),
2392
-                                        $template_field
2393
-                                    ),
2394
-                                    __FILE__, __FUNCTION__, __LINE__
2395
-                                );
2396
-                            } else {
2397
-                                $success = 1;
2398
-                            }
2399
-                        }
2400
-                        $action_desc = 'updated';
2401
-                    }
2381
+						$message_template_fields = array(
2382
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2383
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2384
+							'MTP_context'        => $set_column_values['MTP_context'],
2385
+							'MTP_content'        => $set_column_values['MTP_content']
2386
+						);
2387
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2388
+							if ($updated === false) {
2389
+								EE_Error::add_error(
2390
+									sprintf(
2391
+										__('%s field was NOT updated for some reason', 'event_espresso'),
2392
+										$template_field
2393
+									),
2394
+									__FILE__, __FUNCTION__, __LINE__
2395
+								);
2396
+							} else {
2397
+								$success = 1;
2398
+							}
2399
+						}
2400
+						$action_desc = 'updated';
2401
+					}
2402 2402
                     
2403
-                    //we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2404
-                    $mtpg_fields = array(
2405
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2406
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2407
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2408
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2409
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2410
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2411
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2412
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2413
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2414
-                            : '',
2415
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2416
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2417
-                            : ''
2418
-                    );
2403
+					//we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2404
+					$mtpg_fields = array(
2405
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2406
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2407
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2408
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2409
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2410
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2411
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2412
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2413
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2414
+							: '',
2415
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2416
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2417
+							: ''
2418
+					);
2419 2419
                     
2420
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2421
-                    $updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2420
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2421
+					$updated    = $MTPG->update($mtpg_fields, array($mtpg_where));
2422 2422
                     
2423
-                    if ($updated === false) {
2424
-                        EE_Error::add_error(
2425
-                            sprintf(
2426
-                                __('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2427
-                                $set_column_values['GRP_ID']
2428
-                            ),
2429
-                            __FILE__, __FUNCTION__, __LINE__
2430
-                        );
2431
-                    } else {
2432
-                        //k now we need to ensure the template_pack and template_variation fields are set.
2433
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2434
-                            ? $this->_req_data['MTP_template_pack']
2435
-                            : 'default';
2423
+					if ($updated === false) {
2424
+						EE_Error::add_error(
2425
+							sprintf(
2426
+								__('The Message Template Group (%d) was NOT updated for some reason', 'event_espresso'),
2427
+								$set_column_values['GRP_ID']
2428
+							),
2429
+							__FILE__, __FUNCTION__, __LINE__
2430
+						);
2431
+					} else {
2432
+						//k now we need to ensure the template_pack and template_variation fields are set.
2433
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2434
+							? $this->_req_data['MTP_template_pack']
2435
+							: 'default';
2436 2436
                         
2437
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2438
-                            ? $this->_req_data['MTP_template_variation']
2439
-                            : 'default';
2437
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2438
+							? $this->_req_data['MTP_template_variation']
2439
+							: 'default';
2440 2440
                         
2441
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2442
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2443
-                            $mtpg_obj->set_template_pack_name($template_pack);
2444
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2445
-                        }
2446
-                        $success = 1;
2447
-                    }
2448
-                }
2449
-            }
2441
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2442
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2443
+							$mtpg_obj->set_template_pack_name($template_pack);
2444
+							$mtpg_obj->set_template_pack_variation($template_variation);
2445
+						}
2446
+						$success = 1;
2447
+					}
2448
+				}
2449
+			}
2450 2450
             
2451
-        }
2452
-        
2453
-        //we return things differently if doing ajax
2454
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2455
-            $this->_template_args['success'] = $success;
2456
-            $this->_template_args['error']   = ! $success ? true : false;
2457
-            $this->_template_args['content'] = '';
2458
-            $this->_template_args['data']    = array(
2459
-                'grpID'        => $edit_array['GRP_ID'],
2460
-                'templateName' => $edit_array['template_name']
2461
-            );
2462
-            if ($success) {
2463
-                EE_Error::overwrite_success();
2464
-                EE_Error::add_success(__('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.',
2465
-                    'event_espresso'));
2466
-            }
2451
+		}
2452
+        
2453
+		//we return things differently if doing ajax
2454
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2455
+			$this->_template_args['success'] = $success;
2456
+			$this->_template_args['error']   = ! $success ? true : false;
2457
+			$this->_template_args['content'] = '';
2458
+			$this->_template_args['data']    = array(
2459
+				'grpID'        => $edit_array['GRP_ID'],
2460
+				'templateName' => $edit_array['template_name']
2461
+			);
2462
+			if ($success) {
2463
+				EE_Error::overwrite_success();
2464
+				EE_Error::add_success(__('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.',
2465
+					'event_espresso'));
2466
+			}
2467 2467
             
2468
-            $this->_return_json();
2469
-        }
2470
-        
2471
-        
2472
-        //was a test send triggered?
2473
-        if (isset($this->_req_data['test_button'])) {
2474
-            EE_Error::overwrite_success();
2475
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2476
-            $override = true;
2477
-        }
2478
-        
2479
-        if (empty($query_args)) {
2480
-            $query_args = array(
2481
-                'id'      => $this->_req_data['GRP_ID'],
2482
-                'context' => $context_slug,
2483
-                'action'  => 'edit_message_template'
2484
-            );
2485
-        }
2486
-        
2487
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2488
-    }
2489
-    
2490
-    
2491
-    /**
2492
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
2493
-     *
2494
-     * @param  string $context      what context being tested
2495
-     * @param  string $messenger    messenger being tested
2496
-     * @param  string $message_type message type being tested
2497
-     *
2498
-     */
2499
-    protected function _do_test_send($context, $messenger, $message_type)
2500
-    {
2501
-        //set things up for preview
2502
-        $this->_req_data['messenger']    = $messenger;
2503
-        $this->_req_data['message_type'] = $message_type;
2504
-        $this->_req_data['context']      = $context;
2505
-        $this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2506
-        $active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2507
-        
2508
-        //let's save any existing fields that might be required by the messenger
2509
-        if (
2510
-            isset($this->_req_data['test_settings_fld'])
2511
-            && $active_messenger instanceof EE_messenger
2512
-            && apply_filters(
2513
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2514
-                true,
2515
-                $this->_req_data['test_settings_fld'],
2516
-                $active_messenger
2517
-            )
2518
-        ) {
2519
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2520
-        }
2521
-        
2522
-        $success = $this->_preview_message(true);
2523
-        
2524
-        if ($success) {
2525
-            EE_Error::add_success(__('Test message sent', 'event_espresso'));
2526
-        } else {
2527
-            EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2528
-                __LINE__);
2529
-        }
2530
-    }
2531
-    
2532
-    
2533
-    /**
2534
-     * _generate_new_templates
2535
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2536
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2537
-     * for the event.
2538
-     *
2539
-     *
2540
-     * @param  string $messenger     the messenger we are generating templates for
2541
-     * @param array   $message_types array of message types that the templates are generated for.
2542
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2543
-     *                               indicate the message_template_group being used as the base.
2544
-     *
2545
-     * @param bool    $global
2546
-     *
2547
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
2548
-     *                               encountering problems.
2549
-     * @throws \EE_Error
2550
-     */
2551
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2552
-    {
2553
-        
2554
-        //if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2555
-        if (empty($message_types)) {
2556
-            return true;
2557
-        }
2558
-        
2559
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2560
-    }
2561
-    
2562
-    
2563
-    /**
2564
-     * [_trash_or_restore_message_template]
2565
-     *
2566
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2567
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2568
-     *                        an individual context (FALSE).
2569
-     *
2570
-     * @return void
2571
-     */
2572
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
2573
-    {
2574
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2575
-        $MTP = EEM_Message_Template_Group::instance();
2576
-        
2577
-        $success = 1;
2578
-        
2579
-        //incoming GRP_IDs
2580
-        if ($all) {
2581
-            //Checkboxes
2582
-            if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2583
-                //if array has more than one element then success message should be plural.
2584
-                //todo: what about nonce?
2585
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2468
+			$this->_return_json();
2469
+		}
2470
+        
2471
+        
2472
+		//was a test send triggered?
2473
+		if (isset($this->_req_data['test_button'])) {
2474
+			EE_Error::overwrite_success();
2475
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2476
+			$override = true;
2477
+		}
2478
+        
2479
+		if (empty($query_args)) {
2480
+			$query_args = array(
2481
+				'id'      => $this->_req_data['GRP_ID'],
2482
+				'context' => $context_slug,
2483
+				'action'  => 'edit_message_template'
2484
+			);
2485
+		}
2486
+        
2487
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
2488
+	}
2489
+    
2490
+    
2491
+	/**
2492
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
2493
+	 *
2494
+	 * @param  string $context      what context being tested
2495
+	 * @param  string $messenger    messenger being tested
2496
+	 * @param  string $message_type message type being tested
2497
+	 *
2498
+	 */
2499
+	protected function _do_test_send($context, $messenger, $message_type)
2500
+	{
2501
+		//set things up for preview
2502
+		$this->_req_data['messenger']    = $messenger;
2503
+		$this->_req_data['message_type'] = $message_type;
2504
+		$this->_req_data['context']      = $context;
2505
+		$this->_req_data['GRP_ID']       = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
2506
+		$active_messenger                = $this->_message_resource_manager->get_active_messenger($messenger);
2507
+        
2508
+		//let's save any existing fields that might be required by the messenger
2509
+		if (
2510
+			isset($this->_req_data['test_settings_fld'])
2511
+			&& $active_messenger instanceof EE_messenger
2512
+			&& apply_filters(
2513
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
2514
+				true,
2515
+				$this->_req_data['test_settings_fld'],
2516
+				$active_messenger
2517
+			)
2518
+		) {
2519
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
2520
+		}
2521
+        
2522
+		$success = $this->_preview_message(true);
2523
+        
2524
+		if ($success) {
2525
+			EE_Error::add_success(__('Test message sent', 'event_espresso'));
2526
+		} else {
2527
+			EE_Error::add_error(__('The test message was not sent', 'event_espresso'), __FILE__, __FUNCTION__,
2528
+				__LINE__);
2529
+		}
2530
+	}
2531
+    
2532
+    
2533
+	/**
2534
+	 * _generate_new_templates
2535
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
2536
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
2537
+	 * for the event.
2538
+	 *
2539
+	 *
2540
+	 * @param  string $messenger     the messenger we are generating templates for
2541
+	 * @param array   $message_types array of message types that the templates are generated for.
2542
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
2543
+	 *                               indicate the message_template_group being used as the base.
2544
+	 *
2545
+	 * @param bool    $global
2546
+	 *
2547
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
2548
+	 *                               encountering problems.
2549
+	 * @throws \EE_Error
2550
+	 */
2551
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
2552
+	{
2553
+        
2554
+		//if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we just don't generate any templates.
2555
+		if (empty($message_types)) {
2556
+			return true;
2557
+		}
2558
+        
2559
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
2560
+	}
2561
+    
2562
+    
2563
+	/**
2564
+	 * [_trash_or_restore_message_template]
2565
+	 *
2566
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
2567
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
2568
+	 *                        an individual context (FALSE).
2569
+	 *
2570
+	 * @return void
2571
+	 */
2572
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
2573
+	{
2574
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2575
+		$MTP = EEM_Message_Template_Group::instance();
2576
+        
2577
+		$success = 1;
2578
+        
2579
+		//incoming GRP_IDs
2580
+		if ($all) {
2581
+			//Checkboxes
2582
+			if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2583
+				//if array has more than one element then success message should be plural.
2584
+				//todo: what about nonce?
2585
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2586 2586
                 
2587
-                //cycle through checkboxes
2588
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2589
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2590
-                    if ( ! $trashed_or_restored) {
2591
-                        $success = 0;
2592
-                    }
2593
-                }
2594
-            } else {
2595
-                //grab single GRP_ID and handle
2596
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2597
-                if ( ! empty($GRP_ID)) {
2598
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
-                    if ( ! $trashed_or_restored) {
2600
-                        $success = 0;
2601
-                    }
2602
-                } else {
2603
-                    $success = 0;
2604
-                }
2605
-            }
2587
+				//cycle through checkboxes
2588
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2589
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2590
+					if ( ! $trashed_or_restored) {
2591
+						$success = 0;
2592
+					}
2593
+				}
2594
+			} else {
2595
+				//grab single GRP_ID and handle
2596
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
2597
+				if ( ! empty($GRP_ID)) {
2598
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
2599
+					if ( ! $trashed_or_restored) {
2600
+						$success = 0;
2601
+					}
2602
+				} else {
2603
+					$success = 0;
2604
+				}
2605
+			}
2606 2606
             
2607
-        }
2607
+		}
2608 2608
         
2609
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2609
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2610 2610
         
2611
-        $action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2611
+		$action_desc = ! empty($this->_req_data['template_switch']) ? __('switched') : $action_desc;
2612 2612
         
2613
-        $item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2614
-            'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2613
+		$item_desc = $all ? _n('Message Template Group', 'Message Template Groups', $success,
2614
+			'event_espresso') : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
2615 2615
         
2616
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2617
-            'event_espresso') : $item_desc;
2616
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n('template', 'templates', $success,
2617
+			'event_espresso') : $item_desc;
2618 2618
         
2619
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
2619
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
2620 2620
         
2621
-    }
2621
+	}
2622 2622
     
2623 2623
     
2624
-    /**
2625
-     * [_delete_message_template]
2626
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2627
-     * @return void
2628
-     */
2629
-    protected function _delete_message_template()
2630
-    {
2631
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2624
+	/**
2625
+	 * [_delete_message_template]
2626
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
2627
+	 * @return void
2628
+	 */
2629
+	protected function _delete_message_template()
2630
+	{
2631
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2632 2632
         
2633
-        //checkboxes
2634
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2635
-            //if array has more than one element then success message should be plural
2636
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2633
+		//checkboxes
2634
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2635
+			//if array has more than one element then success message should be plural
2636
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2637 2637
             
2638
-            //cycle through bulk action checkboxes
2639
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2640
-                $success = $this->_delete_mtp_permanently($GRP_ID);
2641
-            }
2642
-        } else {
2643
-            //grab single grp_id and delete
2644
-            $GRP_ID  = absint($this->_req_data['id']);
2645
-            $success = $this->_delete_mtp_permanently($GRP_ID);
2646
-        }
2647
-        
2648
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2649
-        
2650
-    }
2651
-    
2652
-    
2653
-    /**
2654
-     * helper for permanently deleting a mtP group and all related message_templates
2655
-     *
2656
-     * @param  int  $GRP_ID        The group being deleted
2657
-     * @param  bool $include_group whether to delete the Message Template Group as well.
2658
-     *
2659
-     * @return bool        boolean to indicate the success of the deletes or not.
2660
-     */
2661
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2662
-    {
2663
-        $success = 1;
2664
-        $MTPG    = EEM_Message_Template_Group::instance();
2665
-        //first let's GET this group
2666
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
2667
-        //then delete permanently all the related Message Templates
2668
-        $deleted = $MTG->delete_related_permanently('Message_Template');
2669
-        
2670
-        if ($deleted === 0) {
2671
-            $success = 0;
2672
-        }
2673
-        
2674
-        //now delete permanently this particular group
2675
-        
2676
-        if ($include_group && ! $MTG->delete_permanently()) {
2677
-            $success = 0;
2678
-        }
2679
-        
2680
-        return $success;
2681
-    }
2682
-    
2683
-    
2684
-    /**
2685
-     *    _learn_more_about_message_templates_link
2686
-     * @access protected
2687
-     * @return string
2688
-     */
2689
-    protected function _learn_more_about_message_templates_link()
2690
-    {
2691
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2692
-            'event_espresso') . '</a>';
2693
-    }
2694
-    
2695
-    
2696
-    /**
2697
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2698
-     * ajax and other routes.
2699
-     * @return void
2700
-     */
2701
-    protected function _settings()
2702
-    {
2703
-        
2704
-        
2705
-        $this->_set_m_mt_settings();
2706
-        
2707
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2708
-        
2709
-        //let's setup the messenger tabs
2710
-        $this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2711
-            'messenger_links', '|', $selected_messenger);
2712
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2713
-        $this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2714
-        
2715
-        $this->display_admin_page_with_sidebar();
2716
-        
2717
-    }
2718
-    
2719
-    
2720
-    /**
2721
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2722
-     *
2723
-     * @access protected
2724
-     * @return void
2725
-     */
2726
-    protected function _set_m_mt_settings()
2727
-    {
2728
-        //first if this is already set then lets get out no need to regenerate data.
2729
-        if ( ! empty($this->_m_mt_settings)) {
2730
-            return;
2731
-        }
2732
-        
2733
-        //$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2734
-        
2735
-        //get all installed messengers and message_types
2736
-        /** @type EE_messenger[] $messengers */
2737
-        $messengers = $this->_message_resource_manager->installed_messengers();
2738
-        /** @type EE_message_type[] $message_types */
2739
-        $message_types = $this->_message_resource_manager->installed_message_types();
2740
-        
2741
-        
2742
-        //assemble the array for the _tab_text_links helper
2743
-        
2744
-        foreach ($messengers as $messenger) {
2745
-            $this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2746
-                'label' => ucwords($messenger->label['singular']),
2747
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2748
-                'href'  => $messenger->name,
2749
-                'title' => __('Modify this Messenger', 'event_espresso'),
2750
-                'slug'  => $messenger->name,
2751
-                'obj'   => $messenger
2752
-            );
2638
+			//cycle through bulk action checkboxes
2639
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
2640
+				$success = $this->_delete_mtp_permanently($GRP_ID);
2641
+			}
2642
+		} else {
2643
+			//grab single grp_id and delete
2644
+			$GRP_ID  = absint($this->_req_data['id']);
2645
+			$success = $this->_delete_mtp_permanently($GRP_ID);
2646
+		}
2647
+        
2648
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
2649
+        
2650
+	}
2651
+    
2652
+    
2653
+	/**
2654
+	 * helper for permanently deleting a mtP group and all related message_templates
2655
+	 *
2656
+	 * @param  int  $GRP_ID        The group being deleted
2657
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
2658
+	 *
2659
+	 * @return bool        boolean to indicate the success of the deletes or not.
2660
+	 */
2661
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
2662
+	{
2663
+		$success = 1;
2664
+		$MTPG    = EEM_Message_Template_Group::instance();
2665
+		//first let's GET this group
2666
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
2667
+		//then delete permanently all the related Message Templates
2668
+		$deleted = $MTG->delete_related_permanently('Message_Template');
2669
+        
2670
+		if ($deleted === 0) {
2671
+			$success = 0;
2672
+		}
2673
+        
2674
+		//now delete permanently this particular group
2675
+        
2676
+		if ($include_group && ! $MTG->delete_permanently()) {
2677
+			$success = 0;
2678
+		}
2679
+        
2680
+		return $success;
2681
+	}
2682
+    
2683
+    
2684
+	/**
2685
+	 *    _learn_more_about_message_templates_link
2686
+	 * @access protected
2687
+	 * @return string
2688
+	 */
2689
+	protected function _learn_more_about_message_templates_link()
2690
+	{
2691
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . __('learn more about how message templates works',
2692
+			'event_espresso') . '</a>';
2693
+	}
2694
+    
2695
+    
2696
+	/**
2697
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
2698
+	 * ajax and other routes.
2699
+	 * @return void
2700
+	 */
2701
+	protected function _settings()
2702
+	{
2703
+        
2704
+        
2705
+		$this->_set_m_mt_settings();
2706
+        
2707
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2708
+        
2709
+		//let's setup the messenger tabs
2710
+		$this->_template_args['admin_page_header']         = EEH_Tabbed_Content::tab_text_links($this->_m_mt_settings['messenger_tabs'],
2711
+			'messenger_links', '|', $selected_messenger);
2712
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
2713
+		$this->_template_args['after_admin_page_content']  = '</div><!-- end .ui-widget -->';
2714
+        
2715
+		$this->display_admin_page_with_sidebar();
2716
+        
2717
+	}
2718
+    
2719
+    
2720
+	/**
2721
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
2722
+	 *
2723
+	 * @access protected
2724
+	 * @return void
2725
+	 */
2726
+	protected function _set_m_mt_settings()
2727
+	{
2728
+		//first if this is already set then lets get out no need to regenerate data.
2729
+		if ( ! empty($this->_m_mt_settings)) {
2730
+			return;
2731
+		}
2732
+        
2733
+		//$selected_messenger = isset( $this->_req_data['selected_messenger'] ) ? $this->_req_data['selected_messenger'] : 'email';
2734
+        
2735
+		//get all installed messengers and message_types
2736
+		/** @type EE_messenger[] $messengers */
2737
+		$messengers = $this->_message_resource_manager->installed_messengers();
2738
+		/** @type EE_message_type[] $message_types */
2739
+		$message_types = $this->_message_resource_manager->installed_message_types();
2740
+        
2741
+        
2742
+		//assemble the array for the _tab_text_links helper
2743
+        
2744
+		foreach ($messengers as $messenger) {
2745
+			$this->_m_mt_settings['messenger_tabs'][$messenger->name] = array(
2746
+				'label' => ucwords($messenger->label['singular']),
2747
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name) ? 'messenger-active' : '',
2748
+				'href'  => $messenger->name,
2749
+				'title' => __('Modify this Messenger', 'event_espresso'),
2750
+				'slug'  => $messenger->name,
2751
+				'obj'   => $messenger
2752
+			);
2753 2753
             
2754 2754
             
2755
-            $message_types_for_messenger = $messenger->get_valid_message_types();
2755
+			$message_types_for_messenger = $messenger->get_valid_message_types();
2756 2756
             
2757
-            foreach ($message_types as $message_type) {
2758
-                //first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2759
-                if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2760
-                    continue;
2761
-                }
2757
+			foreach ($message_types as $message_type) {
2758
+				//first we need to verify that this message type is valid with this messenger. Cause if it isn't then it shouldn't show in either the inactive OR active metabox.
2759
+				if ( ! in_array($message_type->name, $message_types_for_messenger)) {
2760
+					continue;
2761
+				}
2762 2762
                 
2763
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2764
-                    $message_type->name) ? 'active' : 'inactive';
2763
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger($messenger->name,
2764
+					$message_type->name) ? 'active' : 'inactive';
2765 2765
                 
2766
-                $this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2767
-                    'label'    => ucwords($message_type->label['singular']),
2768
-                    'class'    => 'message-type-' . $a_or_i,
2769
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2770
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2771
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2772
-                    'title'    => $a_or_i == 'active'
2773
-                        ? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2774
-                        : __('Drag this message type to the messenger to activate', 'event_espresso'),
2775
-                    'content'  => $a_or_i == 'active'
2776
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
2777
-                        : $this->_message_type_settings_content($message_type, $messenger),
2778
-                    'slug'     => $message_type->name,
2779
-                    'active'   => $a_or_i == 'active' ? true : false,
2780
-                    'obj'      => $message_type
2781
-                );
2782
-            }
2783
-        }
2784
-    }
2785
-    
2786
-    
2787
-    /**
2788
-     * This just prepares the content for the message type settings
2789
-     *
2790
-     * @param  object  $message_type The message type object
2791
-     * @param  object  $messenger    The messenger object
2792
-     * @param  boolean $active       Whether the message type is active or not
2793
-     *
2794
-     * @return string                html output for the content
2795
-     */
2796
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
2797
-    {
2798
-        //get message type fields
2799
-        $fields                                         = $message_type->get_admin_settings_fields();
2800
-        $settings_template_args['template_form_fields'] = '';
2801
-        
2802
-        if ( ! empty($fields) && $active) {
2766
+				$this->_m_mt_settings['message_type_tabs'][$messenger->name][$a_or_i][$message_type->name] = array(
2767
+					'label'    => ucwords($message_type->label['singular']),
2768
+					'class'    => 'message-type-' . $a_or_i,
2769
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
2770
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
2771
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
2772
+					'title'    => $a_or_i == 'active'
2773
+						? __('Drag this message type to the Inactive window to deactivate', 'event_espresso')
2774
+						: __('Drag this message type to the messenger to activate', 'event_espresso'),
2775
+					'content'  => $a_or_i == 'active'
2776
+						? $this->_message_type_settings_content($message_type, $messenger, true)
2777
+						: $this->_message_type_settings_content($message_type, $messenger),
2778
+					'slug'     => $message_type->name,
2779
+					'active'   => $a_or_i == 'active' ? true : false,
2780
+					'obj'      => $message_type
2781
+				);
2782
+			}
2783
+		}
2784
+	}
2785
+    
2786
+    
2787
+	/**
2788
+	 * This just prepares the content for the message type settings
2789
+	 *
2790
+	 * @param  object  $message_type The message type object
2791
+	 * @param  object  $messenger    The messenger object
2792
+	 * @param  boolean $active       Whether the message type is active or not
2793
+	 *
2794
+	 * @return string                html output for the content
2795
+	 */
2796
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
2797
+	{
2798
+		//get message type fields
2799
+		$fields                                         = $message_type->get_admin_settings_fields();
2800
+		$settings_template_args['template_form_fields'] = '';
2801
+        
2802
+		if ( ! empty($fields) && $active) {
2803 2803
             
2804
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2804
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
2805 2805
             
2806
-            foreach ($fields as $fldname => $fldprops) {
2807
-                $field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2808
-                $template_form_field[$field_id] = array(
2809
-                    'name'       => 'message_type_settings[' . $fldname . ']',
2810
-                    'label'      => $fldprops['label'],
2811
-                    'input'      => $fldprops['field_type'],
2812
-                    'type'       => $fldprops['value_type'],
2813
-                    'required'   => $fldprops['required'],
2814
-                    'validation' => $fldprops['validation'],
2815
-                    'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2816
-                    'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2817
-                    'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2818
-                    'css_class'  => 'no-drag',
2819
-                    'format'     => $fldprops['format']
2820
-                );
2821
-            }
2806
+			foreach ($fields as $fldname => $fldprops) {
2807
+				$field_id                       = $messenger->name . '-' . $message_type->name . '-' . $fldname;
2808
+				$template_form_field[$field_id] = array(
2809
+					'name'       => 'message_type_settings[' . $fldname . ']',
2810
+					'label'      => $fldprops['label'],
2811
+					'input'      => $fldprops['field_type'],
2812
+					'type'       => $fldprops['value_type'],
2813
+					'required'   => $fldprops['required'],
2814
+					'validation' => $fldprops['validation'],
2815
+					'value'      => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2816
+					'options'    => isset($fldprops['options']) ? $fldprops['options'] : array(),
2817
+					'default'    => isset($existing_settings[$fldname]) ? $existing_settings[$fldname] : $fldprops['default'],
2818
+					'css_class'  => 'no-drag',
2819
+					'format'     => $fldprops['format']
2820
+				);
2821
+			}
2822 2822
             
2823 2823
             
2824
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2825
-                'string', 'ee_mt_activate_form') : '';
2826
-        }
2827
-        
2828
-        $settings_template_args['description'] = $message_type->description;
2829
-        //we also need some hidden fields
2830
-        $settings_template_args['hidden_fields'] = array(
2831
-            'message_type_settings[messenger]'    => array(
2832
-                'type'  => 'hidden',
2833
-                'value' => $messenger->name
2834
-            ),
2835
-            'message_type_settings[message_type]' => array(
2836
-                'type'  => 'hidden',
2837
-                'value' => $message_type->name
2838
-            ),
2839
-            'type'                                => array(
2840
-                'type'  => 'hidden',
2841
-                'value' => 'message_type'
2842
-            )
2843
-        );
2844
-        
2845
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2846
-            'array');
2847
-        $settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2848
-        
2849
-        
2850
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2851
-        $content  = EEH_Template::display_template($template, $settings_template_args, true);
2852
-        
2853
-        return $content;
2854
-    }
2855
-    
2856
-    
2857
-    /**
2858
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
2859
-     *
2860
-     * @access protected
2861
-     * @return void
2862
-     */
2863
-    protected function _messages_settings_metaboxes()
2864
-    {
2865
-        $this->_set_m_mt_settings();
2866
-        $m_boxes         = $mt_boxes = array();
2867
-        $m_template_args = $mt_template_args = array();
2868
-        
2869
-        $selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2870
-        
2871
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
2872
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2873
-                $hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2874
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2875
-                //messenger meta boxes
2876
-                $active                                 = $selected_messenger == $messenger ? true : false;
2877
-                $active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2878
-                    ? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2879
-                    : '';
2880
-                $m_boxes[$messenger . '_a_box']         = sprintf(
2881
-                    __('%s Settings', 'event_espresso'),
2882
-                    $tab_array['label']
2883
-                );
2884
-                $m_template_args[$messenger . '_a_box'] = array(
2885
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2886
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2888
-                        : '',
2889
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2890
-                    'hidden'                 => $active ? '' : ' hidden',
2891
-                    'hide_on_message'        => $hide_on_message,
2892
-                    'messenger'              => $messenger,
2893
-                    'active'                 => $active
2894
-                );
2895
-                // message type meta boxes
2896
-                // (which is really just the inactive container for each messenger
2897
-                // showing inactive message types for that messenger)
2898
-                $mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
-                $mt_template_args[$messenger . '_i_box'] = array(
2900
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2901
-                    'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2902
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2903
-                        : '',
2904
-                    'hidden'                 => $active ? '' : ' hidden',
2905
-                    'hide_on_message'        => $hide_on_message,
2906
-                    'hide_off_message'       => $hide_off_message,
2907
-                    'messenger'              => $messenger,
2908
-                    'active'                 => $active
2909
-                );
2910
-            }
2911
-        }
2912
-        
2913
-        
2914
-        //register messenger metaboxes
2915
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2916
-        foreach ($m_boxes as $box => $label) {
2917
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2918
-            $msgr          = str_replace('_a_box', '', $box);
2919
-            add_meta_box(
2920
-                'espresso_' . $msgr . '_settings',
2921
-                $label,
2922
-                function ($post, $metabox) {
2923
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2924
-                        $metabox["args"]["template_args"], true);
2925
-                },
2926
-                $this->_current_screen->id,
2927
-                'normal',
2928
-                'high',
2929
-                $callback_args
2930
-            );
2931
-        }
2932
-        
2933
-        //register message type metaboxes
2934
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2935
-        foreach ($mt_boxes as $box => $label) {
2936
-            $callback_args = array(
2937
-                'template_path' => $mt_template_path,
2938
-                'template_args' => $mt_template_args[$box]
2939
-            );
2940
-            $mt            = str_replace('_i_box', '', $box);
2941
-            add_meta_box(
2942
-                'espresso_' . $mt . '_inactive_mts',
2943
-                $label,
2944
-                function ($post, $metabox) {
2945
-                    echo EEH_Template::display_template($metabox["args"]["template_path"],
2946
-                        $metabox["args"]["template_args"], true);
2947
-                },
2948
-                $this->_current_screen->id,
2949
-                'side',
2950
-                'high',
2951
-                $callback_args
2952
-            );
2953
-        }
2954
-        
2955
-        //register metabox for global messages settings but only when on the main site.  On single site installs this will
2956
-        //always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2957
-        if (is_main_site()) {
2958
-            add_meta_box(
2959
-                'espresso_global_message_settings',
2960
-                __('Global Message Settings', 'event_espresso'),
2961
-                array($this, 'global_messages_settings_metabox_content'),
2962
-                $this->_current_screen->id,
2963
-                'normal',
2964
-                'low',
2965
-                array()
2966
-            );
2967
-        }
2968
-        
2969
-    }
2970
-    
2971
-    
2972
-    /**
2973
-     *  This generates the content for the global messages settings metabox.
2974
-     * @return string
2975
-     */
2976
-    public function global_messages_settings_metabox_content()
2977
-    {
2978
-        $form = $this->_generate_global_settings_form();
2979
-        echo $form->form_open(
2980
-                $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2981
-                'POST'
2982
-            )
2983
-             . $form->get_html()
2984
-             . $form->form_close();
2985
-    }
2986
-    
2987
-    
2988
-    /**
2989
-     * This generates and returns the form object for the global messages settings.
2990
-     * @return EE_Form_Section_Proper
2991
-     */
2992
-    protected function _generate_global_settings_form()
2993
-    {
2994
-        EE_Registry::instance()->load_helper('HTML');
2995
-        /** @var EE_Network_Core_Config $network_config */
2996
-        $network_config = EE_Registry::instance()->NET_CFG->core;
2997
-        
2998
-        return new EE_Form_Section_Proper(
2999
-            array(
3000
-                'name'            => 'global_messages_settings',
3001
-                'html_id'         => 'global_messages_settings',
3002
-                'html_class'      => 'form-table',
3003
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3004
-                'subsections'     => apply_filters(
3005
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3006
-                    array(
3007
-                        'do_messages_on_same_request' => new EE_Select_Input(
3008
-                            array(
3009
-                                true  => __("On the same request", "event_espresso"),
3010
-                                false => __("On a separate request", "event_espresso")
3011
-                            ),
3012
-                            array(
3013
-                                'default'         => $network_config->do_messages_on_same_request,
3014
-                                'html_label_text' => __('Generate and send all messages:', 'event_espresso'),
3015
-                                'html_help_text'  => __('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.',
3016
-                                    'event_espresso'),
3017
-                            )
3018
-                        ),
3019
-                        'update_settings'             => new EE_Submit_Input(
3020
-                            array(
3021
-                                'default'         => __('Update', 'event_espresso'),
3022
-                                'html_label_text' => '&nbsp'
3023
-                            )
3024
-                        )
3025
-                    )
3026
-                )
3027
-            )
3028
-        );
3029
-    }
3030
-    
3031
-    
3032
-    /**
3033
-     * This handles updating the global settings set on the admin page.
3034
-     * @throws \EE_Error
3035
-     */
3036
-    protected function _update_global_settings()
3037
-    {
3038
-        /** @var EE_Network_Core_Config $network_config */
3039
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3040
-        $form           = $this->_generate_global_settings_form();
3041
-        if ($form->was_submitted()) {
3042
-            $form->receive_form_submission();
3043
-            if ($form->is_valid()) {
3044
-                $valid_data = $form->valid_data();
3045
-                foreach ($valid_data as $property => $value) {
3046
-                    $setter = 'set_' . $property;
3047
-                    if (method_exists($network_config, $setter)) {
3048
-                        $network_config->{$setter}($value);
3049
-                    } else if (
3050
-                        property_exists($network_config, $property)
3051
-                        && $network_config->{$property} !== $value
3052
-                    ) {
3053
-                        $network_config->{$property} = $value;
3054
-                    }
3055
-                }
3056
-                //only update if the form submission was valid!
3057
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3058
-                EE_Error::overwrite_success();
3059
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3060
-            }
3061
-        }
3062
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3063
-    }
3064
-    
3065
-    
3066
-    /**
3067
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3068
-     *
3069
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3070
-     *
3071
-     * @return string            html formatted tabs
3072
-     */
3073
-    protected function _get_mt_tabs($tab_array)
3074
-    {
3075
-        $tab_array = (array)$tab_array;
3076
-        $template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3077
-        $tabs      = '';
3078
-        
3079
-        foreach ($tab_array as $tab) {
3080
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3081
-        }
3082
-        
3083
-        return $tabs;
3084
-    }
3085
-    
3086
-    
3087
-    /**
3088
-     * This prepares the content of the messenger meta box admin settings
3089
-     *
3090
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3091
-     *
3092
-     * @return string            html formatted content
3093
-     */
3094
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3095
-    {
3096
-        
3097
-        $fields                                         = $messenger->get_admin_settings_fields();
3098
-        $settings_template_args['template_form_fields'] = '';
3099
-        
3100
-        //is $messenger active?
3101
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3102
-        
3103
-        
3104
-        if ( ! empty($fields)) {
2824
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field) ? $this->_generate_admin_form_fields($template_form_field,
2825
+				'string', 'ee_mt_activate_form') : '';
2826
+		}
2827
+        
2828
+		$settings_template_args['description'] = $message_type->description;
2829
+		//we also need some hidden fields
2830
+		$settings_template_args['hidden_fields'] = array(
2831
+			'message_type_settings[messenger]'    => array(
2832
+				'type'  => 'hidden',
2833
+				'value' => $messenger->name
2834
+			),
2835
+			'message_type_settings[message_type]' => array(
2836
+				'type'  => 'hidden',
2837
+				'value' => $message_type->name
2838
+			),
2839
+			'type'                                => array(
2840
+				'type'  => 'hidden',
2841
+				'value' => 'message_type'
2842
+			)
2843
+		);
2844
+        
2845
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields($settings_template_args['hidden_fields'],
2846
+			'array');
2847
+		$settings_template_args['show_form']     = empty($settings_template_args['template_form_fields']) ? ' hidden' : '';
2848
+        
2849
+        
2850
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
2851
+		$content  = EEH_Template::display_template($template, $settings_template_args, true);
2852
+        
2853
+		return $content;
2854
+	}
2855
+    
2856
+    
2857
+	/**
2858
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
2859
+	 *
2860
+	 * @access protected
2861
+	 * @return void
2862
+	 */
2863
+	protected function _messages_settings_metaboxes()
2864
+	{
2865
+		$this->_set_m_mt_settings();
2866
+		$m_boxes         = $mt_boxes = array();
2867
+		$m_template_args = $mt_template_args = array();
2868
+        
2869
+		$selected_messenger = isset($this->_req_data['selected_messenger']) ? $this->_req_data['selected_messenger'] : 'email';
2870
+        
2871
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
2872
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
2873
+				$hide_on_message  = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
2874
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
2875
+				//messenger meta boxes
2876
+				$active                                 = $selected_messenger == $messenger ? true : false;
2877
+				$active_mt_tabs                         = isset($this->_m_mt_settings['message_type_tabs'][$messenger]['active'])
2878
+					? $this->_m_mt_settings['message_type_tabs'][$messenger]['active']
2879
+					: '';
2880
+				$m_boxes[$messenger . '_a_box']         = sprintf(
2881
+					__('%s Settings', 'event_espresso'),
2882
+					$tab_array['label']
2883
+				);
2884
+				$m_template_args[$messenger . '_a_box'] = array(
2885
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2886
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2887
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2888
+						: '',
2889
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
2890
+					'hidden'                 => $active ? '' : ' hidden',
2891
+					'hide_on_message'        => $hide_on_message,
2892
+					'messenger'              => $messenger,
2893
+					'active'                 => $active
2894
+				);
2895
+				// message type meta boxes
2896
+				// (which is really just the inactive container for each messenger
2897
+				// showing inactive message types for that messenger)
2898
+				$mt_boxes[$messenger . '_i_box']         = __('Inactive Message Types', 'event_espresso');
2899
+				$mt_template_args[$messenger . '_i_box'] = array(
2900
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
2901
+					'inactive_message_types' => isset($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2902
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][$messenger]['inactive'])
2903
+						: '',
2904
+					'hidden'                 => $active ? '' : ' hidden',
2905
+					'hide_on_message'        => $hide_on_message,
2906
+					'hide_off_message'       => $hide_off_message,
2907
+					'messenger'              => $messenger,
2908
+					'active'                 => $active
2909
+				);
2910
+			}
2911
+		}
2912
+        
2913
+        
2914
+		//register messenger metaboxes
2915
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
2916
+		foreach ($m_boxes as $box => $label) {
2917
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[$box]);
2918
+			$msgr          = str_replace('_a_box', '', $box);
2919
+			add_meta_box(
2920
+				'espresso_' . $msgr . '_settings',
2921
+				$label,
2922
+				function ($post, $metabox) {
2923
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2924
+						$metabox["args"]["template_args"], true);
2925
+				},
2926
+				$this->_current_screen->id,
2927
+				'normal',
2928
+				'high',
2929
+				$callback_args
2930
+			);
2931
+		}
2932
+        
2933
+		//register message type metaboxes
2934
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
2935
+		foreach ($mt_boxes as $box => $label) {
2936
+			$callback_args = array(
2937
+				'template_path' => $mt_template_path,
2938
+				'template_args' => $mt_template_args[$box]
2939
+			);
2940
+			$mt            = str_replace('_i_box', '', $box);
2941
+			add_meta_box(
2942
+				'espresso_' . $mt . '_inactive_mts',
2943
+				$label,
2944
+				function ($post, $metabox) {
2945
+					echo EEH_Template::display_template($metabox["args"]["template_path"],
2946
+						$metabox["args"]["template_args"], true);
2947
+				},
2948
+				$this->_current_screen->id,
2949
+				'side',
2950
+				'high',
2951
+				$callback_args
2952
+			);
2953
+		}
2954
+        
2955
+		//register metabox for global messages settings but only when on the main site.  On single site installs this will
2956
+		//always result in the metabox showing, on multisite installs the metabox will only show on the main site.
2957
+		if (is_main_site()) {
2958
+			add_meta_box(
2959
+				'espresso_global_message_settings',
2960
+				__('Global Message Settings', 'event_espresso'),
2961
+				array($this, 'global_messages_settings_metabox_content'),
2962
+				$this->_current_screen->id,
2963
+				'normal',
2964
+				'low',
2965
+				array()
2966
+			);
2967
+		}
2968
+        
2969
+	}
2970
+    
2971
+    
2972
+	/**
2973
+	 *  This generates the content for the global messages settings metabox.
2974
+	 * @return string
2975
+	 */
2976
+	public function global_messages_settings_metabox_content()
2977
+	{
2978
+		$form = $this->_generate_global_settings_form();
2979
+		echo $form->form_open(
2980
+				$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
2981
+				'POST'
2982
+			)
2983
+			 . $form->get_html()
2984
+			 . $form->form_close();
2985
+	}
2986
+    
2987
+    
2988
+	/**
2989
+	 * This generates and returns the form object for the global messages settings.
2990
+	 * @return EE_Form_Section_Proper
2991
+	 */
2992
+	protected function _generate_global_settings_form()
2993
+	{
2994
+		EE_Registry::instance()->load_helper('HTML');
2995
+		/** @var EE_Network_Core_Config $network_config */
2996
+		$network_config = EE_Registry::instance()->NET_CFG->core;
2997
+        
2998
+		return new EE_Form_Section_Proper(
2999
+			array(
3000
+				'name'            => 'global_messages_settings',
3001
+				'html_id'         => 'global_messages_settings',
3002
+				'html_class'      => 'form-table',
3003
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3004
+				'subsections'     => apply_filters(
3005
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3006
+					array(
3007
+						'do_messages_on_same_request' => new EE_Select_Input(
3008
+							array(
3009
+								true  => __("On the same request", "event_espresso"),
3010
+								false => __("On a separate request", "event_espresso")
3011
+							),
3012
+							array(
3013
+								'default'         => $network_config->do_messages_on_same_request,
3014
+								'html_label_text' => __('Generate and send all messages:', 'event_espresso'),
3015
+								'html_help_text'  => __('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.',
3016
+									'event_espresso'),
3017
+							)
3018
+						),
3019
+						'update_settings'             => new EE_Submit_Input(
3020
+							array(
3021
+								'default'         => __('Update', 'event_espresso'),
3022
+								'html_label_text' => '&nbsp'
3023
+							)
3024
+						)
3025
+					)
3026
+				)
3027
+			)
3028
+		);
3029
+	}
3030
+    
3031
+    
3032
+	/**
3033
+	 * This handles updating the global settings set on the admin page.
3034
+	 * @throws \EE_Error
3035
+	 */
3036
+	protected function _update_global_settings()
3037
+	{
3038
+		/** @var EE_Network_Core_Config $network_config */
3039
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3040
+		$form           = $this->_generate_global_settings_form();
3041
+		if ($form->was_submitted()) {
3042
+			$form->receive_form_submission();
3043
+			if ($form->is_valid()) {
3044
+				$valid_data = $form->valid_data();
3045
+				foreach ($valid_data as $property => $value) {
3046
+					$setter = 'set_' . $property;
3047
+					if (method_exists($network_config, $setter)) {
3048
+						$network_config->{$setter}($value);
3049
+					} else if (
3050
+						property_exists($network_config, $property)
3051
+						&& $network_config->{$property} !== $value
3052
+					) {
3053
+						$network_config->{$property} = $value;
3054
+					}
3055
+				}
3056
+				//only update if the form submission was valid!
3057
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3058
+				EE_Error::overwrite_success();
3059
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3060
+			}
3061
+		}
3062
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3063
+	}
3064
+    
3065
+    
3066
+	/**
3067
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3068
+	 *
3069
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3070
+	 *
3071
+	 * @return string            html formatted tabs
3072
+	 */
3073
+	protected function _get_mt_tabs($tab_array)
3074
+	{
3075
+		$tab_array = (array)$tab_array;
3076
+		$template  = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3077
+		$tabs      = '';
3078
+        
3079
+		foreach ($tab_array as $tab) {
3080
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3081
+		}
3082
+        
3083
+		return $tabs;
3084
+	}
3085
+    
3086
+    
3087
+	/**
3088
+	 * This prepares the content of the messenger meta box admin settings
3089
+	 *
3090
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3091
+	 *
3092
+	 * @return string            html formatted content
3093
+	 */
3094
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3095
+	{
3096
+        
3097
+		$fields                                         = $messenger->get_admin_settings_fields();
3098
+		$settings_template_args['template_form_fields'] = '';
3099
+        
3100
+		//is $messenger active?
3101
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3102
+        
3103
+        
3104
+		if ( ! empty($fields)) {
3105 3105
             
3106
-            $existing_settings = $messenger->get_existing_admin_settings();
3106
+			$existing_settings = $messenger->get_existing_admin_settings();
3107 3107
             
3108
-            foreach ($fields as $fldname => $fldprops) {
3109
-                $field_id                       = $messenger->name . '-' . $fldname;
3110
-                $template_form_field[$field_id] = array(
3111
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3112
-                    'label'      => $fldprops['label'],
3113
-                    'input'      => $fldprops['field_type'],
3114
-                    'type'       => $fldprops['value_type'],
3115
-                    'required'   => $fldprops['required'],
3116
-                    'validation' => $fldprops['validation'],
3117
-                    'value'      => isset($existing_settings[$field_id])
3118
-                        ? $existing_settings[$field_id]
3119
-                        : $fldprops['default'],
3120
-                    'css_class'  => '',
3121
-                    'format'     => $fldprops['format']
3122
-                );
3123
-            }
3108
+			foreach ($fields as $fldname => $fldprops) {
3109
+				$field_id                       = $messenger->name . '-' . $fldname;
3110
+				$template_form_field[$field_id] = array(
3111
+					'name'       => 'messenger_settings[' . $field_id . ']',
3112
+					'label'      => $fldprops['label'],
3113
+					'input'      => $fldprops['field_type'],
3114
+					'type'       => $fldprops['value_type'],
3115
+					'required'   => $fldprops['required'],
3116
+					'validation' => $fldprops['validation'],
3117
+					'value'      => isset($existing_settings[$field_id])
3118
+						? $existing_settings[$field_id]
3119
+						: $fldprops['default'],
3120
+					'css_class'  => '',
3121
+					'format'     => $fldprops['format']
3122
+				);
3123
+			}
3124 3124
             
3125 3125
             
3126
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3127
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3128
-                : '';
3129
-        }
3130
-        
3131
-        //we also need some hidden fields
3132
-        $settings_template_args['hidden_fields'] = array(
3133
-            'messenger_settings[messenger]' => array(
3134
-                'type'  => 'hidden',
3135
-                'value' => $messenger->name
3136
-            ),
3137
-            'type'                          => array(
3138
-                'type'  => 'hidden',
3139
-                'value' => 'messenger'
3140
-            )
3141
-        );
3142
-        
3143
-        //make sure any active message types that are existing are included in the hidden fields
3144
-        if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3145
-            foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3146
-                $settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3147
-                    'type'  => 'hidden',
3148
-                    'value' => $mt
3149
-                );
3150
-            }
3151
-        }
3152
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3153
-            $settings_template_args['hidden_fields'],
3154
-            'array'
3155
-        );
3156
-        $active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3157
-        
3158
-        $settings_template_args['messenger']           = $messenger->name;
3159
-        $settings_template_args['description']         = $messenger->description;
3160
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3161
-        
3162
-        
3163
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3164
-            ? $settings_template_args['show_hide_edit_form']
3165
-            : ' hidden';
3166
-        
3167
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3168
-            ? ' hidden'
3169
-            : $settings_template_args['show_hide_edit_form'];
3170
-        
3171
-        
3172
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3173
-        $settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3174
-        $settings_template_args['on_off_status'] = $active ? true : false;
3175
-        $template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3176
-        $content                                 = EEH_Template::display_template($template, $settings_template_args,
3177
-            true);
3178
-        
3179
-        return $content;
3180
-    }
3181
-    
3182
-    
3183
-    /**
3184
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3185
-     */
3186
-    public function activate_messenger_toggle()
3187
-    {
3188
-        $success = true;
3189
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3190
-        //let's check that we have required data
3191
-        if ( ! isset($this->_req_data['messenger'])) {
3192
-            EE_Error::add_error(
3193
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3194
-                __FILE__,
3195
-                __FUNCTION__,
3196
-                __LINE__
3197
-            );
3198
-            $success = false;
3199
-        }
3200
-        
3201
-        //do a nonce check here since we're not arriving via a normal route
3202
-        $nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3203
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3204
-        
3205
-        $this->_verify_nonce($nonce, $nonce_ref);
3206
-        
3207
-        
3208
-        if ( ! isset($this->_req_data['status'])) {
3209
-            EE_Error::add_error(
3210
-                __(
3211
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3212
-                    'event_espresso'
3213
-                ),
3214
-                __FILE__,
3215
-                __FUNCTION__,
3216
-                __LINE__
3217
-            );
3218
-            $success = false;
3219
-        }
3220
-        
3221
-        //do check to verify we have a valid status.
3222
-        $status = $this->_req_data['status'];
3223
-        
3224
-        if ($status != 'off' && $status != 'on') {
3225
-            EE_Error::add_error(
3226
-                sprintf(
3227
-                    __('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3228
-                    $this->_req_data['status']
3229
-                ),
3230
-                __FILE__,
3231
-                __FUNCTION__,
3232
-                __LINE__
3233
-            );
3234
-            $success = false;
3235
-        }
3236
-        
3237
-        if ($success) {
3238
-            //made it here?  Stop dawdling then!!
3239
-            $success = $status == 'off'
3240
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3241
-                : $this->_activate_messenger($this->_req_data['messenger']);
3242
-        }
3243
-        
3244
-        $this->_template_args['success'] = $success;
3245
-        
3246
-        //no special instructions so let's just do the json return (which should automatically do all the special stuff).
3247
-        $this->_return_json();
3248
-        
3249
-    }
3250
-    
3251
-    
3252
-    /**
3253
-     * used by ajax from the messages settings page to activate|deactivate a message type
3254
-     *
3255
-     */
3256
-    public function activate_mt_toggle()
3257
-    {
3258
-        $success = true;
3259
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3260
-        
3261
-        //let's make sure we have the necessary data
3262
-        if ( ! isset($this->_req_data['message_type'])) {
3263
-            EE_Error::add_error(
3264
-                __('Message Type name needed to toggle activation. None given', 'event_espresso'),
3265
-                __FILE__, __FUNCTION__, __LINE__
3266
-            );
3267
-            $success = false;
3268
-        }
3269
-        
3270
-        if ( ! isset($this->_req_data['messenger'])) {
3271
-            EE_Error::add_error(
3272
-                __('Messenger name needed to toggle activation. None given', 'event_espresso'),
3273
-                __FILE__, __FUNCTION__, __LINE__
3274
-            );
3275
-            $success = false;
3276
-        }
3277
-        
3278
-        if ( ! isset($this->_req_data['status'])) {
3279
-            EE_Error::add_error(
3280
-                __('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3281
-                    'event_espresso'),
3282
-                __FILE__, __FUNCTION__, __LINE__
3283
-            );
3284
-            $success = false;
3285
-        }
3286
-        
3287
-        
3288
-        //do check to verify we have a valid status.
3289
-        $status = $this->_req_data['status'];
3290
-        
3291
-        if ($status != 'activate' && $status != 'deactivate') {
3292
-            EE_Error::add_error(
3293
-                sprintf(
3294
-                    __('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3295
-                    $this->_req_data['status']
3296
-                ),
3297
-                __FILE__, __FUNCTION__, __LINE__
3298
-            );
3299
-            $success = false;
3300
-        }
3301
-        
3302
-        
3303
-        //do a nonce check here since we're not arriving via a normal route
3304
-        $nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3305
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3306
-        
3307
-        $this->_verify_nonce($nonce, $nonce_ref);
3308
-        
3309
-        if ($success) {
3310
-            //made it here? um, what are you waiting for then?
3311
-            $success = $status == 'deactivate'
3312
-                ? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3313
-                    $this->_req_data['message_type'])
3314
-                : $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3315
-                    $this->_req_data['message_type']);
3316
-        }
3317
-        
3318
-        $this->_template_args['success'] = $success;
3319
-        $this->_return_json();
3320
-    }
3321
-    
3322
-    
3323
-    /**
3324
-     * Takes care of processing activating a messenger and preparing the appropriate response.
3325
-     *
3326
-     * @param string $messenger_name The name of the messenger being activated
3327
-     *
3328
-     * @return bool
3329
-     */
3330
-    protected function _activate_messenger($messenger_name)
3331
-    {
3332
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3333
-        $active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3334
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3335
-        
3336
-        //ensure is active
3337
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3338
-        
3339
-        //set response_data for reload
3340
-        foreach ($message_types_to_activate as $message_type_name) {
3341
-            /** @var EE_message_type $message_type */
3342
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3343
-            if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3344
-                    $message_type_name)
3345
-                && $message_type instanceof EE_message_type
3346
-            ) {
3347
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
3348
-                if ($message_type->get_admin_settings_fields()) {
3349
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
3350
-                }
3351
-            }
3352
-        }
3353
-        
3354
-        //add success message for activating messenger
3355
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3356
-        
3357
-    }
3358
-    
3359
-    
3360
-    /**
3361
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
3362
-     *
3363
-     * @param string $messenger_name The name of the messenger being activated
3364
-     *
3365
-     * @return bool
3366
-     */
3367
-    protected function _deactivate_messenger($messenger_name)
3368
-    {
3369
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3370
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3371
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
3372
-        
3373
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3374
-    }
3375
-    
3376
-    
3377
-    /**
3378
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3379
-     *
3380
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
3381
-     * @param string $message_type_name The name of the message type being activated for the messenger
3382
-     *
3383
-     * @return bool
3384
-     */
3385
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3386
-    {
3387
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3388
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3389
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3390
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3391
-        
3392
-        //ensure is active
3393
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3394
-        
3395
-        //set response for load
3396
-        if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3397
-            $message_type_name)
3398
-        ) {
3399
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
3400
-            if ($message_type_to_activate->get_admin_settings_fields()) {
3401
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
3402
-            }
3403
-        }
3404
-        
3405
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3406
-            $message_type_to_activate);
3407
-    }
3408
-    
3409
-    
3410
-    /**
3411
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3412
-     *
3413
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3414
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
3415
-     *
3416
-     * @return bool
3417
-     */
3418
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3419
-    {
3420
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3425
-        
3426
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3427
-            $message_type_to_deactivate);
3428
-    }
3429
-    
3430
-    
3431
-    /**
3432
-     * This just initializes the defaults for activating messenger and message type responses.
3433
-     */
3434
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
3435
-    {
3436
-        $this->_template_args['data']['active_mts'] = array();
3437
-        $this->_template_args['data']['mt_reload']  = array();
3438
-    }
3439
-    
3440
-    
3441
-    /**
3442
-     * Setup appropriate response for activating a messenger and/or message types
3443
-     *
3444
-     * @param EE_messenger         $messenger
3445
-     * @param EE_message_type|null $message_type
3446
-     *
3447
-     * @return bool
3448
-     * @throws EE_Error
3449
-     */
3450
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
3451
-        $messenger,
3452
-        EE_Message_Type $message_type = null
3453
-    ) {
3454
-        //if $messenger isn't a valid messenger object then get out.
3455
-        if ( ! $messenger instanceof EE_Messenger) {
3456
-            EE_Error::add_error(
3457
-                __('The messenger being activated is not a valid messenger', 'event_espresso'),
3458
-                __FILE__,
3459
-                __FUNCTION__,
3460
-                __LINE__
3461
-            );
3126
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3127
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3128
+				: '';
3129
+		}
3130
+        
3131
+		//we also need some hidden fields
3132
+		$settings_template_args['hidden_fields'] = array(
3133
+			'messenger_settings[messenger]' => array(
3134
+				'type'  => 'hidden',
3135
+				'value' => $messenger->name
3136
+			),
3137
+			'type'                          => array(
3138
+				'type'  => 'hidden',
3139
+				'value' => 'messenger'
3140
+			)
3141
+		);
3142
+        
3143
+		//make sure any active message types that are existing are included in the hidden fields
3144
+		if (isset($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'])) {
3145
+			foreach ($this->_m_mt_settings['message_type_tabs'][$messenger->name]['active'] as $mt => $values) {
3146
+				$settings_template_args['hidden_fields']['messenger_settings[message_types][' . $mt . ']'] = array(
3147
+					'type'  => 'hidden',
3148
+					'value' => $mt
3149
+				);
3150
+			}
3151
+		}
3152
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3153
+			$settings_template_args['hidden_fields'],
3154
+			'array'
3155
+		);
3156
+		$active                                  = $this->_message_resource_manager->is_messenger_active($messenger->name);
3157
+        
3158
+		$settings_template_args['messenger']           = $messenger->name;
3159
+		$settings_template_args['description']         = $messenger->description;
3160
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3161
+        
3162
+        
3163
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active($messenger->name)
3164
+			? $settings_template_args['show_hide_edit_form']
3165
+			: ' hidden';
3166
+        
3167
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3168
+			? ' hidden'
3169
+			: $settings_template_args['show_hide_edit_form'];
3170
+        
3171
+        
3172
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3173
+		$settings_template_args['nonce']         = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3174
+		$settings_template_args['on_off_status'] = $active ? true : false;
3175
+		$template                                = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3176
+		$content                                 = EEH_Template::display_template($template, $settings_template_args,
3177
+			true);
3178
+        
3179
+		return $content;
3180
+	}
3181
+    
3182
+    
3183
+	/**
3184
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3185
+	 */
3186
+	public function activate_messenger_toggle()
3187
+	{
3188
+		$success = true;
3189
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3190
+		//let's check that we have required data
3191
+		if ( ! isset($this->_req_data['messenger'])) {
3192
+			EE_Error::add_error(
3193
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3194
+				__FILE__,
3195
+				__FUNCTION__,
3196
+				__LINE__
3197
+			);
3198
+			$success = false;
3199
+		}
3200
+        
3201
+		//do a nonce check here since we're not arriving via a normal route
3202
+		$nonce     = isset($this->_req_data['activate_nonce']) ? sanitize_text_field($this->_req_data['activate_nonce']) : '';
3203
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3204
+        
3205
+		$this->_verify_nonce($nonce, $nonce_ref);
3206
+        
3207
+        
3208
+		if ( ! isset($this->_req_data['status'])) {
3209
+			EE_Error::add_error(
3210
+				__(
3211
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3212
+					'event_espresso'
3213
+				),
3214
+				__FILE__,
3215
+				__FUNCTION__,
3216
+				__LINE__
3217
+			);
3218
+			$success = false;
3219
+		}
3220
+        
3221
+		//do check to verify we have a valid status.
3222
+		$status = $this->_req_data['status'];
3223
+        
3224
+		if ($status != 'off' && $status != 'on') {
3225
+			EE_Error::add_error(
3226
+				sprintf(
3227
+					__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3228
+					$this->_req_data['status']
3229
+				),
3230
+				__FILE__,
3231
+				__FUNCTION__,
3232
+				__LINE__
3233
+			);
3234
+			$success = false;
3235
+		}
3236
+        
3237
+		if ($success) {
3238
+			//made it here?  Stop dawdling then!!
3239
+			$success = $status == 'off'
3240
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3241
+				: $this->_activate_messenger($this->_req_data['messenger']);
3242
+		}
3243
+        
3244
+		$this->_template_args['success'] = $success;
3245
+        
3246
+		//no special instructions so let's just do the json return (which should automatically do all the special stuff).
3247
+		$this->_return_json();
3248
+        
3249
+	}
3250
+    
3251
+    
3252
+	/**
3253
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3254
+	 *
3255
+	 */
3256
+	public function activate_mt_toggle()
3257
+	{
3258
+		$success = true;
3259
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3260
+        
3261
+		//let's make sure we have the necessary data
3262
+		if ( ! isset($this->_req_data['message_type'])) {
3263
+			EE_Error::add_error(
3264
+				__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3265
+				__FILE__, __FUNCTION__, __LINE__
3266
+			);
3267
+			$success = false;
3268
+		}
3269
+        
3270
+		if ( ! isset($this->_req_data['messenger'])) {
3271
+			EE_Error::add_error(
3272
+				__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3273
+				__FILE__, __FUNCTION__, __LINE__
3274
+			);
3275
+			$success = false;
3276
+		}
3277
+        
3278
+		if ( ! isset($this->_req_data['status'])) {
3279
+			EE_Error::add_error(
3280
+				__('Messenger status needed to know whether activation or deactivation is happening. No status is given',
3281
+					'event_espresso'),
3282
+				__FILE__, __FUNCTION__, __LINE__
3283
+			);
3284
+			$success = false;
3285
+		}
3286
+        
3287
+        
3288
+		//do check to verify we have a valid status.
3289
+		$status = $this->_req_data['status'];
3290
+        
3291
+		if ($status != 'activate' && $status != 'deactivate') {
3292
+			EE_Error::add_error(
3293
+				sprintf(
3294
+					__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3295
+					$this->_req_data['status']
3296
+				),
3297
+				__FILE__, __FUNCTION__, __LINE__
3298
+			);
3299
+			$success = false;
3300
+		}
3301
+        
3302
+        
3303
+		//do a nonce check here since we're not arriving via a normal route
3304
+		$nonce     = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3305
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3306
+        
3307
+		$this->_verify_nonce($nonce, $nonce_ref);
3308
+        
3309
+		if ($success) {
3310
+			//made it here? um, what are you waiting for then?
3311
+			$success = $status == 'deactivate'
3312
+				? $this->_deactivate_message_type_for_messenger($this->_req_data['messenger'],
3313
+					$this->_req_data['message_type'])
3314
+				: $this->_activate_message_type_for_messenger($this->_req_data['messenger'],
3315
+					$this->_req_data['message_type']);
3316
+		}
3317
+        
3318
+		$this->_template_args['success'] = $success;
3319
+		$this->_return_json();
3320
+	}
3321
+    
3322
+    
3323
+	/**
3324
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
3325
+	 *
3326
+	 * @param string $messenger_name The name of the messenger being activated
3327
+	 *
3328
+	 * @return bool
3329
+	 */
3330
+	protected function _activate_messenger($messenger_name)
3331
+	{
3332
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3333
+		$active_messenger          = $this->_message_resource_manager->get_messenger($messenger_name);
3334
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger ? $active_messenger->get_default_message_types() : array();
3335
+        
3336
+		//ensure is active
3337
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
3338
+        
3339
+		//set response_data for reload
3340
+		foreach ($message_types_to_activate as $message_type_name) {
3341
+			/** @var EE_message_type $message_type */
3342
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
3343
+			if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3344
+					$message_type_name)
3345
+				&& $message_type instanceof EE_message_type
3346
+			) {
3347
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
3348
+				if ($message_type->get_admin_settings_fields()) {
3349
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
3350
+				}
3351
+			}
3352
+		}
3353
+        
3354
+		//add success message for activating messenger
3355
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
3356
+        
3357
+	}
3358
+    
3359
+    
3360
+	/**
3361
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
3362
+	 *
3363
+	 * @param string $messenger_name The name of the messenger being activated
3364
+	 *
3365
+	 * @return bool
3366
+	 */
3367
+	protected function _deactivate_messenger($messenger_name)
3368
+	{
3369
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3370
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3371
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
3372
+        
3373
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
3374
+	}
3375
+    
3376
+    
3377
+	/**
3378
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
3379
+	 *
3380
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
3381
+	 * @param string $message_type_name The name of the message type being activated for the messenger
3382
+	 *
3383
+	 * @return bool
3384
+	 */
3385
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
3386
+	{
3387
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3388
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3389
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3390
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
3391
+        
3392
+		//ensure is active
3393
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
3394
+        
3395
+		//set response for load
3396
+		if ($this->_message_resource_manager->is_message_type_active_for_messenger($messenger_name,
3397
+			$message_type_name)
3398
+		) {
3399
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
3400
+			if ($message_type_to_activate->get_admin_settings_fields()) {
3401
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
3402
+			}
3403
+		}
3404
+        
3405
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger,
3406
+			$message_type_to_activate);
3407
+	}
3408
+    
3409
+    
3410
+	/**
3411
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
3412
+	 *
3413
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
3414
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
3415
+	 *
3416
+	 * @return bool
3417
+	 */
3418
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
3419
+	{
3420
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
3421
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
3422
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
3423
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
3424
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
3425
+        
3426
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger,
3427
+			$message_type_to_deactivate);
3428
+	}
3429
+    
3430
+    
3431
+	/**
3432
+	 * This just initializes the defaults for activating messenger and message type responses.
3433
+	 */
3434
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
3435
+	{
3436
+		$this->_template_args['data']['active_mts'] = array();
3437
+		$this->_template_args['data']['mt_reload']  = array();
3438
+	}
3439
+    
3440
+    
3441
+	/**
3442
+	 * Setup appropriate response for activating a messenger and/or message types
3443
+	 *
3444
+	 * @param EE_messenger         $messenger
3445
+	 * @param EE_message_type|null $message_type
3446
+	 *
3447
+	 * @return bool
3448
+	 * @throws EE_Error
3449
+	 */
3450
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
3451
+		$messenger,
3452
+		EE_Message_Type $message_type = null
3453
+	) {
3454
+		//if $messenger isn't a valid messenger object then get out.
3455
+		if ( ! $messenger instanceof EE_Messenger) {
3456
+			EE_Error::add_error(
3457
+				__('The messenger being activated is not a valid messenger', 'event_espresso'),
3458
+				__FILE__,
3459
+				__FUNCTION__,
3460
+				__LINE__
3461
+			);
3462 3462
             
3463
-            return false;
3464
-        }
3465
-        //activated
3466
-        if ($this->_template_args['data']['active_mts']) {
3467
-            EE_Error::overwrite_success();
3468
-            //activated a message type with the messenger
3469
-            if ($message_type instanceof EE_message_type) {
3470
-                EE_Error::add_success(
3471
-                    sprintf(
3472
-                        __('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3473
-                        ucwords($message_type->label['singular']),
3474
-                        ucwords($messenger->label['singular'])
3475
-                    )
3476
-                );
3463
+			return false;
3464
+		}
3465
+		//activated
3466
+		if ($this->_template_args['data']['active_mts']) {
3467
+			EE_Error::overwrite_success();
3468
+			//activated a message type with the messenger
3469
+			if ($message_type instanceof EE_message_type) {
3470
+				EE_Error::add_success(
3471
+					sprintf(
3472
+						__('%s message type has been successfully activated with the %s messenger', 'event_espresso'),
3473
+						ucwords($message_type->label['singular']),
3474
+						ucwords($messenger->label['singular'])
3475
+					)
3476
+				);
3477 3477
                 
3478
-                //if message type was invoice then let's make sure we activate the invoice payment method.
3479
-                if ($message_type->name == 'invoice') {
3480
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
3481
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3482
-                    if ($pm instanceof EE_Payment_Method) {
3483
-                        EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
3484
-                            'event_espresso'));
3485
-                    }
3486
-                }
3487
-                //just toggles the entire messenger
3488
-            } else {
3489
-                EE_Error::add_success(
3490
-                    sprintf(
3491
-                        __('%s messenger has been successfully activated', 'event_espresso'),
3492
-                        ucwords($messenger->label['singular'])
3493
-                    )
3494
-                );
3495
-            }
3478
+				//if message type was invoice then let's make sure we activate the invoice payment method.
3479
+				if ($message_type->name == 'invoice') {
3480
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
3481
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
3482
+					if ($pm instanceof EE_Payment_Method) {
3483
+						EE_Error::add_attention(__('Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
3484
+							'event_espresso'));
3485
+					}
3486
+				}
3487
+				//just toggles the entire messenger
3488
+			} else {
3489
+				EE_Error::add_success(
3490
+					sprintf(
3491
+						__('%s messenger has been successfully activated', 'event_espresso'),
3492
+						ucwords($messenger->label['singular'])
3493
+					)
3494
+				);
3495
+			}
3496 3496
             
3497
-            return true;
3497
+			return true;
3498 3498
             
3499
-            //possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3500
-            //message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3501
-            //in which case we just give a success message for the messenger being successfully activated.
3502
-        } else {
3503
-            if ( ! $messenger->get_default_message_types()) {
3504
-                //messenger doesn't have any default message types so still a success.
3505
-                EE_Error::add_success(
3506
-                    sprintf(
3507
-                        __('%s messenger was successfully activated.', 'event_espresso'),
3508
-                        ucwords($messenger->label['singular'])
3509
-                    )
3510
-                );
3499
+			//possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
3500
+			//message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
3501
+			//in which case we just give a success message for the messenger being successfully activated.
3502
+		} else {
3503
+			if ( ! $messenger->get_default_message_types()) {
3504
+				//messenger doesn't have any default message types so still a success.
3505
+				EE_Error::add_success(
3506
+					sprintf(
3507
+						__('%s messenger was successfully activated.', 'event_espresso'),
3508
+						ucwords($messenger->label['singular'])
3509
+					)
3510
+				);
3511 3511
                 
3512
-                return true;
3513
-            } else {
3514
-                EE_Error::add_error(
3515
-                    $message_type instanceof EE_message_type
3516
-                        ? sprintf(
3517
-                        __('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3518
-                        ucwords($message_type->label['singular']),
3519
-                        ucwords($messenger->label['singular'])
3520
-                    )
3521
-                        : sprintf(
3522
-                        __('%s messenger was not successfully activated', 'event_espresso'),
3523
-                        ucwords($messenger->label['singular'])
3524
-                    ),
3525
-                    __FILE__,
3526
-                    __FUNCTION__,
3527
-                    __LINE__
3528
-                );
3512
+				return true;
3513
+			} else {
3514
+				EE_Error::add_error(
3515
+					$message_type instanceof EE_message_type
3516
+						? sprintf(
3517
+						__('%s message type was not successfully activated with the %s messenger', 'event_espresso'),
3518
+						ucwords($message_type->label['singular']),
3519
+						ucwords($messenger->label['singular'])
3520
+					)
3521
+						: sprintf(
3522
+						__('%s messenger was not successfully activated', 'event_espresso'),
3523
+						ucwords($messenger->label['singular'])
3524
+					),
3525
+					__FILE__,
3526
+					__FUNCTION__,
3527
+					__LINE__
3528
+				);
3529 3529
                 
3530
-                return false;
3531
-            }
3532
-        }
3533
-    }
3534
-    
3535
-    
3536
-    /**
3537
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
3538
-     *
3539
-     * @param EE_messenger         $messenger
3540
-     * @param EE_message_type|null $message_type
3541
-     *
3542
-     * @return bool
3543
-     */
3544
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3545
-        $messenger,
3546
-        EE_message_type $message_type = null
3547
-    ) {
3548
-        EE_Error::overwrite_success();
3549
-        
3550
-        //if $messenger isn't a valid messenger object then get out.
3551
-        if ( ! $messenger instanceof EE_Messenger) {
3552
-            EE_Error::add_error(
3553
-                __('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3554
-                __FILE__,
3555
-                __FUNCTION__,
3556
-                __LINE__
3557
-            );
3530
+				return false;
3531
+			}
3532
+		}
3533
+	}
3534
+    
3535
+    
3536
+	/**
3537
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
3538
+	 *
3539
+	 * @param EE_messenger         $messenger
3540
+	 * @param EE_message_type|null $message_type
3541
+	 *
3542
+	 * @return bool
3543
+	 */
3544
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
3545
+		$messenger,
3546
+		EE_message_type $message_type = null
3547
+	) {
3548
+		EE_Error::overwrite_success();
3549
+        
3550
+		//if $messenger isn't a valid messenger object then get out.
3551
+		if ( ! $messenger instanceof EE_Messenger) {
3552
+			EE_Error::add_error(
3553
+				__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
3554
+				__FILE__,
3555
+				__FUNCTION__,
3556
+				__LINE__
3557
+			);
3558 3558
             
3559
-            return false;
3560
-        }
3561
-        
3562
-        if ($message_type instanceof EE_message_type) {
3563
-            $message_type_name = $message_type->name;
3564
-            EE_Error::add_success(
3565
-                sprintf(
3566
-                    __('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3567
-                    ucwords($message_type->label['singular']),
3568
-                    ucwords($messenger->label['singular'])
3569
-                )
3570
-            );
3571
-        } else {
3572
-            $message_type_name = '';
3573
-            EE_Error::add_success(
3574
-                sprintf(
3575
-                    __('%s messenger has been successfully deactivated.', 'event_espresso'),
3576
-                    ucwords($messenger->label['singular'])
3577
-                )
3578
-            );
3579
-        }
3580
-        
3581
-        //if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3582
-        if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3583
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
3584
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3585
-            if ($count_updated > 0) {
3586
-                $msg = $message_type_name == 'invoice'
3587
-                    ? __('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.',
3588
-                        'event_espresso')
3589
-                    : __('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.',
3590
-                        'event_espresso');
3591
-                EE_Error::add_attention($msg);
3592
-            }
3593
-        }
3594
-        
3595
-        return true;
3596
-    }
3597
-    
3598
-    
3599
-    /**
3600
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3601
-     */
3602
-    public function update_mt_form()
3603
-    {
3604
-        if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3605
-            EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3606
-                __LINE__);
3607
-            $this->_return_json();
3608
-        }
3609
-        
3610
-        $message_types = $this->get_installed_message_types();
3611
-        
3612
-        $message_type = $message_types[$this->_req_data['message_type']];
3613
-        $messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3614
-        
3615
-        $content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3616
-        $this->_template_args['success'] = true;
3617
-        $this->_template_args['content'] = $content;
3618
-        $this->_return_json();
3619
-    }
3620
-    
3621
-    
3622
-    /**
3623
-     * this handles saving the settings for a messenger or message type
3624
-     *
3625
-     */
3626
-    public function save_settings()
3627
-    {
3628
-        if ( ! isset($this->_req_data['type'])) {
3629
-            EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3630
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3631
-            $this->_template_args['error'] = true;
3632
-            $this->_return_json();
3633
-        }
3634
-        
3635
-        
3636
-        if ($this->_req_data['type'] == 'messenger') {
3637
-            $settings  = $this->_req_data['messenger_settings']; //this should be an array.
3638
-            $messenger = $settings['messenger'];
3639
-            //let's setup the settings data
3640
-            foreach ($settings as $key => $value) {
3641
-                switch ($key) {
3642
-                    case 'messenger' :
3643
-                        unset($settings['messenger']);
3644
-                        break;
3645
-                    case 'message_types' :
3646
-                        unset($settings['message_types']);
3647
-                        break;
3648
-                    default :
3649
-                        $settings[$key] = $value;
3650
-                        break;
3651
-                }
3652
-            }
3653
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3654
-        } else if ($this->_req_data['type'] == 'message_type') {
3655
-            $settings     = $this->_req_data['message_type_settings'];
3656
-            $messenger    = $settings['messenger'];
3657
-            $message_type = $settings['message_type'];
3559
+			return false;
3560
+		}
3561
+        
3562
+		if ($message_type instanceof EE_message_type) {
3563
+			$message_type_name = $message_type->name;
3564
+			EE_Error::add_success(
3565
+				sprintf(
3566
+					__('%s message type has been successfully deactivated for the %s messenger.', 'event_espresso'),
3567
+					ucwords($message_type->label['singular']),
3568
+					ucwords($messenger->label['singular'])
3569
+				)
3570
+			);
3571
+		} else {
3572
+			$message_type_name = '';
3573
+			EE_Error::add_success(
3574
+				sprintf(
3575
+					__('%s messenger has been successfully deactivated.', 'event_espresso'),
3576
+					ucwords($messenger->label['singular'])
3577
+				)
3578
+			);
3579
+		}
3580
+        
3581
+		//if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
3582
+		if ($messenger->name == 'html' || $message_type_name == 'invoice') {
3583
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
3584
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
3585
+			if ($count_updated > 0) {
3586
+				$msg = $message_type_name == 'invoice'
3587
+					? __('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.',
3588
+						'event_espresso')
3589
+					: __('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.',
3590
+						'event_espresso');
3591
+				EE_Error::add_attention($msg);
3592
+			}
3593
+		}
3594
+        
3595
+		return true;
3596
+	}
3597
+    
3598
+    
3599
+	/**
3600
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
3601
+	 */
3602
+	public function update_mt_form()
3603
+	{
3604
+		if ( ! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
3605
+			EE_Error::add_error(__('Require message type or messenger to send an updated form'), __FILE__, __FUNCTION__,
3606
+				__LINE__);
3607
+			$this->_return_json();
3608
+		}
3609
+        
3610
+		$message_types = $this->get_installed_message_types();
3611
+        
3612
+		$message_type = $message_types[$this->_req_data['message_type']];
3613
+		$messenger    = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
3614
+        
3615
+		$content                         = $this->_message_type_settings_content($message_type, $messenger, true);
3616
+		$this->_template_args['success'] = true;
3617
+		$this->_template_args['content'] = $content;
3618
+		$this->_return_json();
3619
+	}
3620
+    
3621
+    
3622
+	/**
3623
+	 * this handles saving the settings for a messenger or message type
3624
+	 *
3625
+	 */
3626
+	public function save_settings()
3627
+	{
3628
+		if ( ! isset($this->_req_data['type'])) {
3629
+			EE_Error::add_error(__('Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
3630
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3631
+			$this->_template_args['error'] = true;
3632
+			$this->_return_json();
3633
+		}
3634
+        
3635
+        
3636
+		if ($this->_req_data['type'] == 'messenger') {
3637
+			$settings  = $this->_req_data['messenger_settings']; //this should be an array.
3638
+			$messenger = $settings['messenger'];
3639
+			//let's setup the settings data
3640
+			foreach ($settings as $key => $value) {
3641
+				switch ($key) {
3642
+					case 'messenger' :
3643
+						unset($settings['messenger']);
3644
+						break;
3645
+					case 'message_types' :
3646
+						unset($settings['message_types']);
3647
+						break;
3648
+					default :
3649
+						$settings[$key] = $value;
3650
+						break;
3651
+				}
3652
+			}
3653
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
3654
+		} else if ($this->_req_data['type'] == 'message_type') {
3655
+			$settings     = $this->_req_data['message_type_settings'];
3656
+			$messenger    = $settings['messenger'];
3657
+			$message_type = $settings['message_type'];
3658 3658
             
3659
-            foreach ($settings as $key => $value) {
3660
-                switch ($key) {
3661
-                    case 'messenger' :
3662
-                        unset($settings['messenger']);
3663
-                        break;
3664
-                    case 'message_type' :
3665
-                        unset($settings['message_type']);
3666
-                        break;
3667
-                    default :
3668
-                        $settings[$key] = $value;
3669
-                        break;
3670
-                }
3671
-            }
3659
+			foreach ($settings as $key => $value) {
3660
+				switch ($key) {
3661
+					case 'messenger' :
3662
+						unset($settings['messenger']);
3663
+						break;
3664
+					case 'message_type' :
3665
+						unset($settings['message_type']);
3666
+						break;
3667
+					default :
3668
+						$settings[$key] = $value;
3669
+						break;
3670
+				}
3671
+			}
3672 3672
             
3673
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3674
-        }
3675
-        
3676
-        //okay we should have the data all setup.  Now we just update!
3677
-        $success = $this->_message_resource_manager->update_active_messengers_option();
3678
-        
3679
-        if ($success) {
3680
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
3681
-        } else {
3682
-            EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3683
-        }
3684
-        
3685
-        $this->_template_args['success'] = $success;
3686
-        $this->_return_json();
3687
-    }
3688
-    
3689
-    
3690
-    
3691
-    
3692
-    /**  EE MESSAGE PROCESSING ACTIONS **/
3693
-    
3694
-    
3695
-    /**
3696
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3697
-     * However, this does not send immediately, it just queues for sending.
3698
-     *
3699
-     * @since 4.9.0
3700
-     */
3701
-    protected function _generate_now()
3702
-    {
3703
-        $msg_ids = $this->_get_msg_ids_from_request();
3704
-        EED_Messages::generate_now($msg_ids);
3705
-        $this->_redirect_after_action(false, '', '', array(), true);
3706
-    }
3707
-    
3708
-    
3709
-    /**
3710
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3711
-     * are EEM_Message::status_resend or EEM_Message::status_idle
3712
-     *
3713
-     * @since 4.9.0
3714
-     *
3715
-     */
3716
-    protected function _generate_and_send_now()
3717
-    {
3718
-        $this->_generate_now();
3719
-        $this->_send_now();
3720
-        $this->_redirect_after_action(false, '', '', array(), true);
3721
-    }
3722
-    
3723
-    
3724
-    /**
3725
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3726
-     *
3727
-     * @since 4.9.0
3728
-     */
3729
-    protected function _queue_for_resending()
3730
-    {
3731
-        $msg_ids = $this->_get_msg_ids_from_request();
3732
-        EED_Messages::queue_for_resending($msg_ids);
3733
-        $this->_redirect_after_action(false, '', '', array(), true);
3734
-    }
3735
-    
3736
-    
3737
-    /**
3738
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3739
-     *
3740
-     * @since 4.9.0
3741
-     */
3742
-    protected function _send_now()
3743
-    {
3744
-        $msg_ids = $this->_get_msg_ids_from_request();
3745
-        EED_Messages::send_now($msg_ids);
3746
-        $this->_redirect_after_action(false, '', '', array(), true);
3747
-    }
3748
-    
3749
-    
3750
-    /**
3751
-     * Deletes EE_messages for IDs in the request.
3752
-     *
3753
-     * @since 4.9.0
3754
-     */
3755
-    protected function _delete_ee_messages()
3756
-    {
3757
-        $msg_ids       = $this->_get_msg_ids_from_request();
3758
-        $deleted_count = 0;
3759
-        foreach ($msg_ids as $msg_id) {
3760
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3761
-                $deleted_count++;
3762
-            }
3763
-        }
3764
-        if ($deleted_count) {
3765
-            $this->_redirect_after_action(
3766
-                true,
3767
-                _n('message', 'messages', $deleted_count, 'event_espresso'),
3768
-                __('deleted', 'event_espresso')
3769
-            );
3770
-        } else {
3771
-            EE_Error::add_error(
3772
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3773
-                __FILE__, __FUNCTION__, __LINE__
3774
-            );
3775
-            $this->_redirect_after_action(false, '', '', array(), true);
3776
-        }
3777
-    }
3778
-    
3779
-    
3780
-    /**
3781
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3782
-     * @since 4.9.0
3783
-     * @return array
3784
-     */
3785
-    protected function _get_msg_ids_from_request()
3786
-    {
3787
-        if ( ! isset($this->_req_data['MSG_ID'])) {
3788
-            return array();
3789
-        }
3790
-        
3791
-        return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3792
-    }
3673
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
3674
+		}
3675
+        
3676
+		//okay we should have the data all setup.  Now we just update!
3677
+		$success = $this->_message_resource_manager->update_active_messengers_option();
3678
+        
3679
+		if ($success) {
3680
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
3681
+		} else {
3682
+			EE_Error::add_error(__('Settings did not get updated', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
3683
+		}
3684
+        
3685
+		$this->_template_args['success'] = $success;
3686
+		$this->_return_json();
3687
+	}
3688
+    
3689
+    
3690
+    
3691
+    
3692
+	/**  EE MESSAGE PROCESSING ACTIONS **/
3693
+    
3694
+    
3695
+	/**
3696
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
3697
+	 * However, this does not send immediately, it just queues for sending.
3698
+	 *
3699
+	 * @since 4.9.0
3700
+	 */
3701
+	protected function _generate_now()
3702
+	{
3703
+		$msg_ids = $this->_get_msg_ids_from_request();
3704
+		EED_Messages::generate_now($msg_ids);
3705
+		$this->_redirect_after_action(false, '', '', array(), true);
3706
+	}
3707
+    
3708
+    
3709
+	/**
3710
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
3711
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
3712
+	 *
3713
+	 * @since 4.9.0
3714
+	 *
3715
+	 */
3716
+	protected function _generate_and_send_now()
3717
+	{
3718
+		$this->_generate_now();
3719
+		$this->_send_now();
3720
+		$this->_redirect_after_action(false, '', '', array(), true);
3721
+	}
3722
+    
3723
+    
3724
+	/**
3725
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
3726
+	 *
3727
+	 * @since 4.9.0
3728
+	 */
3729
+	protected function _queue_for_resending()
3730
+	{
3731
+		$msg_ids = $this->_get_msg_ids_from_request();
3732
+		EED_Messages::queue_for_resending($msg_ids);
3733
+		$this->_redirect_after_action(false, '', '', array(), true);
3734
+	}
3735
+    
3736
+    
3737
+	/**
3738
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
3739
+	 *
3740
+	 * @since 4.9.0
3741
+	 */
3742
+	protected function _send_now()
3743
+	{
3744
+		$msg_ids = $this->_get_msg_ids_from_request();
3745
+		EED_Messages::send_now($msg_ids);
3746
+		$this->_redirect_after_action(false, '', '', array(), true);
3747
+	}
3748
+    
3749
+    
3750
+	/**
3751
+	 * Deletes EE_messages for IDs in the request.
3752
+	 *
3753
+	 * @since 4.9.0
3754
+	 */
3755
+	protected function _delete_ee_messages()
3756
+	{
3757
+		$msg_ids       = $this->_get_msg_ids_from_request();
3758
+		$deleted_count = 0;
3759
+		foreach ($msg_ids as $msg_id) {
3760
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
3761
+				$deleted_count++;
3762
+			}
3763
+		}
3764
+		if ($deleted_count) {
3765
+			$this->_redirect_after_action(
3766
+				true,
3767
+				_n('message', 'messages', $deleted_count, 'event_espresso'),
3768
+				__('deleted', 'event_espresso')
3769
+			);
3770
+		} else {
3771
+			EE_Error::add_error(
3772
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
3773
+				__FILE__, __FUNCTION__, __LINE__
3774
+			);
3775
+			$this->_redirect_after_action(false, '', '', array(), true);
3776
+		}
3777
+	}
3778
+    
3779
+    
3780
+	/**
3781
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
3782
+	 * @since 4.9.0
3783
+	 * @return array
3784
+	 */
3785
+	protected function _get_msg_ids_from_request()
3786
+	{
3787
+		if ( ! isset($this->_req_data['MSG_ID'])) {
3788
+			return array();
3789
+		}
3790
+        
3791
+		return is_array($this->_req_data['MSG_ID']) ? array_keys($this->_req_data['MSG_ID']) : array($this->_req_data['MSG_ID']);
3792
+	}
3793 3793
     
3794 3794
     
3795 3795
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/base/EE_Form_Section_Proper.form.php 1 patch
Indentation   +1348 added lines, -1348 removed lines patch added patch discarded remove patch
@@ -13,1354 +13,1354 @@
 block discarded – undo
13 13
 class EE_Form_Section_Proper extends EE_Form_Section_Validatable
14 14
 {
15 15
 
16
-    const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
17
-
18
-    /**
19
-     * Subsections
20
-     *
21
-     * @var EE_Form_Section_Validatable[]
22
-     */
23
-    protected $_subsections = array();
24
-
25
-    /**
26
-     * Strategy for laying out the form
27
-     *
28
-     * @var EE_Form_Section_Layout_Base
29
-     */
30
-    protected $_layout_strategy;
31
-
32
-    /**
33
-     * Whether or not this form has received and validated a form submission yet
34
-     *
35
-     * @var boolean
36
-     */
37
-    protected $_received_submission = false;
38
-
39
-    /**
40
-     * message displayed to users upon successful form submission
41
-     *
42
-     * @var string
43
-     */
44
-    protected $_form_submission_success_message = '';
45
-
46
-    /**
47
-     * message displayed to users upon unsuccessful form submission
48
-     *
49
-     * @var string
50
-     */
51
-    protected $_form_submission_error_message = '';
52
-
53
-    /**
54
-     * Stores all the data that will localized for form validation
55
-     *
56
-     * @var array
57
-     */
58
-    static protected $_js_localization = array();
59
-
60
-    /**
61
-     * whether or not the form's localized validation JS vars have been set
62
-     *
63
-     * @type boolean
64
-     */
65
-    static protected $_scripts_localized = false;
66
-
67
-
68
-
69
-    /**
70
-     * when constructing a proper form section, calls _construct_finalize on children
71
-     * so that they know who their parent is, and what name they've been given.
72
-     *
73
-     * @param array $options_array   {
74
-     * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
75
-     * @type        $include         string[] numerically-indexed where values are section names to be included,
76
-     *                               and in that order. This is handy if you want
77
-     *                               the subsections to be ordered differently than the default, and if you override
78
-     *                               which fields are shown
79
-     * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
80
-     *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
81
-     *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
82
-     *                               items from that list of inclusions)
83
-     * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
84
-     *                               } @see EE_Form_Section_Validatable::__construct()
85
-     * @throws \EE_Error
86
-     */
87
-    public function __construct($options_array = array())
88
-    {
89
-        $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
90
-            $this);
91
-        //call parent first, as it may be setting the name
92
-        parent::__construct($options_array);
93
-        //if they've included subsections in the constructor, add them now
94
-        if (isset($options_array['include'])) {
95
-            //we are going to make sure we ONLY have those subsections to include
96
-            //AND we are going to make sure they're in that specified order
97
-            $reordered_subsections = array();
98
-            foreach ($options_array['include'] as $input_name) {
99
-                if (isset($this->_subsections[$input_name])) {
100
-                    $reordered_subsections[$input_name] = $this->_subsections[$input_name];
101
-                }
102
-            }
103
-            $this->_subsections = $reordered_subsections;
104
-        }
105
-        if (isset($options_array['exclude'])) {
106
-            $exclude = $options_array['exclude'];
107
-            $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
108
-        }
109
-        if (isset($options_array['layout_strategy'])) {
110
-            $this->_layout_strategy = $options_array['layout_strategy'];
111
-        }
112
-        if ( ! $this->_layout_strategy) {
113
-            $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
114
-        }
115
-        $this->_layout_strategy->_construct_finalize($this);
116
-        //ok so we are definitely going to want the forms JS,
117
-        //so enqueue it or remember to enqueue it during wp_enqueue_scripts
118
-        if (did_action('wp_enqueue_scripts')
119
-            || did_action('admin_enqueue_scripts')
120
-        ) {
121
-            //ok so they've constructed this object after when they should have.
122
-            //just enqueue the generic form scripts and initialize the form immediately in the JS
123
-            \EE_Form_Section_Proper::wp_enqueue_scripts(true);
124
-        } else {
125
-            add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
126
-            add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
127
-        }
128
-        add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
129
-        if (isset($options_array['name'])) {
130
-            $this->_construct_finalize(null, $options_array['name']);
131
-        }
132
-    }
133
-
134
-
135
-
136
-    /**
137
-     * Finishes construction given the parent form section and this form section's name
138
-     *
139
-     * @param EE_Form_Section_Proper $parent_form_section
140
-     * @param string                 $name
141
-     * @throws \EE_Error
142
-     */
143
-    public function _construct_finalize($parent_form_section, $name)
144
-    {
145
-        parent::_construct_finalize($parent_form_section, $name);
146
-        $this->_set_default_name_if_empty();
147
-        $this->_set_default_html_id_if_empty();
148
-        foreach ($this->_subsections as $subsection_name => $subsection) {
149
-            if ($subsection instanceof EE_Form_Section_Base) {
150
-                $subsection->_construct_finalize($this, $subsection_name);
151
-            } else {
152
-                throw new EE_Error(
153
-                    sprintf(
154
-                        __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
155
-                            'event_espresso'),
156
-                        $subsection_name,
157
-                        get_class($this),
158
-                        $subsection ? get_class($subsection) : __('NULL', 'event_espresso')
159
-                    )
160
-                );
161
-            }
162
-        }
163
-        do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * Gets the layout strategy for this form section
170
-     *
171
-     * @return EE_Form_Section_Layout_Base
172
-     */
173
-    public function get_layout_strategy()
174
-    {
175
-        return $this->_layout_strategy;
176
-    }
177
-
178
-
179
-
180
-    /**
181
-     * Gets the HTML for a single input for this form section according
182
-     * to the layout strategy
183
-     *
184
-     * @param EE_Form_Input_Base $input
185
-     * @return string
186
-     */
187
-    public function get_html_for_input($input)
188
-    {
189
-        return $this->_layout_strategy->layout_input($input);
190
-    }
191
-
192
-
193
-
194
-    /**
195
-     * was_submitted - checks if form inputs are present in request data
196
-     * Basically an alias for form_data_present_in() (which is used by both
197
-     * proper form sections and form inputs)
198
-     *
199
-     * @param null $form_data
200
-     * @return boolean
201
-     */
202
-    public function was_submitted($form_data = null)
203
-    {
204
-        return $this->form_data_present_in($form_data);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * After the form section is initially created, call this to sanitize the data in the submission
211
-     * which relates to this form section, validate it, and set it as properties on the form.
212
-     *
213
-     * @param array|null $req_data should usually be $_POST (the default).
214
-     *                             However, you CAN supply a different array.
215
-     *                             Consider using set_defaults() instead however.
216
-     *                             (If you rendered the form in the page using echo $form_x->get_html()
217
-     *                             the inputs will have the correct name in the request data for this function
218
-     *                             to find them and populate the form with them.
219
-     *                             If you have a flat form (with only input subsections),
220
-     *                             you can supply a flat array where keys
221
-     *                             are the form input names and values are their values)
222
-     * @param boolean    $validate whether or not to perform validation on this data. Default is,
223
-     *                             of course, to validate that data, and set errors on the invalid values.
224
-     *                             But if the data has already been validated
225
-     *                             (eg you validated the data then stored it in the DB)
226
-     *                             you may want to skip this step.
227
-     */
228
-    public function receive_form_submission($req_data = null, $validate = true)
229
-    {
230
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
231
-            $validate);
232
-        if ($req_data === null) {
233
-            $req_data = array_merge($_GET, $_POST);
234
-        }
235
-        $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
236
-            $this);
237
-        $this->_normalize($req_data);
238
-        if ($validate) {
239
-            $this->_validate();
240
-            //if it's invalid, we're going to want to re-display so remember what they submitted
241
-            if ( ! $this->is_valid()) {
242
-                $this->store_submitted_form_data_in_session();
243
-            }
244
-        }
245
-        do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     * caches the originally submitted input values in the session
252
-     * so that they can be used to repopulate the form if it failed validation
253
-     *
254
-     * @return boolean whether or not the data was successfully stored in the session
255
-     */
256
-    protected function store_submitted_form_data_in_session()
257
-    {
258
-        return EE_Registry::instance()->SSN->set_session_data(
259
-            array(
260
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
261
-            )
262
-        );
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     * retrieves the originally submitted input values in the session
269
-     * so that they can be used to repopulate the form if it failed validation
270
-     *
271
-     * @return array
272
-     */
273
-    protected function get_submitted_form_data_from_session()
274
-    {
275
-        $session = EE_Registry::instance()->SSN;
276
-        if ($session instanceof EE_Session) {
277
-            return $session->get_session_data(
278
-                \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
279
-            );
280
-        } else {
281
-            return array();
282
-        }
283
-    }
284
-
285
-
286
-
287
-    /**
288
-     * flushed the originally submitted input values from the session
289
-     *
290
-     * @return boolean whether or not the data was successfully removed from the session
291
-     */
292
-    protected function flush_submitted_form_data_from_session()
293
-    {
294
-        return EE_Registry::instance()->SSN->reset_data(
295
-            array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
296
-        );
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * Populates this form and its subsections with data from the session.
303
-     * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
304
-     * validation errors when displaying too)
305
-     * Returns true if the form was populated from the session, false otherwise
306
-     *
307
-     * @return boolean
308
-     */
309
-    public function populate_from_session()
310
-    {
311
-        $form_data_in_session = $this->get_submitted_form_data_from_session();
312
-        if (empty($form_data_in_session)) {
313
-            return false;
314
-        }
315
-        $this->receive_form_submission($form_data_in_session);
316
-        $this->flush_submitted_form_data_from_session();
317
-        if ($this->form_data_present_in($form_data_in_session)) {
318
-            return true;
319
-        } else {
320
-            return false;
321
-        }
322
-    }
323
-
324
-
325
-
326
-    /**
327
-     * Populates the default data for the form, given an array where keys are
328
-     * the input names, and values are their values (preferably normalized to be their
329
-     * proper PHP types, not all strings... although that should be ok too).
330
-     * Proper subsections are sub-arrays, the key being the subsection's name, and
331
-     * the value being an array formatted in teh same way
332
-     *
333
-     * @param array $default_data
334
-     */
335
-    public function populate_defaults($default_data)
336
-    {
337
-        foreach ($this->subsections() as $subsection_name => $subsection) {
338
-            if (isset($default_data[$subsection_name])) {
339
-                if ($subsection instanceof EE_Form_Input_Base) {
340
-                    $subsection->set_default($default_data[$subsection_name]);
341
-                } elseif ($subsection instanceof EE_Form_Section_Proper) {
342
-                    $subsection->populate_defaults($default_data[$subsection_name]);
343
-                }
344
-            }
345
-        }
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * returns true if subsection exists
352
-     *
353
-     * @param string $name
354
-     * @return boolean
355
-     */
356
-    public function subsection_exists($name)
357
-    {
358
-        return isset($this->_subsections[$name]) ? true : false;
359
-    }
360
-
361
-
362
-
363
-    /**
364
-     * Gets the subsection specified by its name
365
-     *
366
-     * @param string  $name
367
-     * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
368
-     *                                                      so that the inputs will be properly configured.
369
-     *                                                      However, some client code may be ok
370
-     *                                                      with construction finalize being called later
371
-     *                                                      (realizing that the subsections' html names
372
-     *                                                      might not be set yet, etc.)
373
-     * @return EE_Form_Section_Base
374
-     * @throws \EE_Error
375
-     */
376
-    public function get_subsection($name, $require_construction_to_be_finalized = true)
377
-    {
378
-        if ($require_construction_to_be_finalized) {
379
-            $this->ensure_construct_finalized_called();
380
-        }
381
-        return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
382
-    }
383
-
384
-
385
-
386
-    /**
387
-     * Gets all the validatable subsections of this form section
388
-     *
389
-     * @return EE_Form_Section_Validatable[]
390
-     */
391
-    public function get_validatable_subsections()
392
-    {
393
-        $validatable_subsections = array();
394
-        foreach ($this->subsections() as $name => $obj) {
395
-            if ($obj instanceof EE_Form_Section_Validatable) {
396
-                $validatable_subsections[$name] = $obj;
397
-            }
398
-        }
399
-        return $validatable_subsections;
400
-    }
401
-
402
-
403
-
404
-    /**
405
-     * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
406
-     * throw an EE_Error.
407
-     *
408
-     * @param string  $name
409
-     * @param boolean $require_construction_to_be_finalized most client code should
410
-     *                                                      leave this as TRUE so that the inputs will be properly
411
-     *                                                      configured. However, some client code may be ok with
412
-     *                                                      construction finalize being called later
413
-     *                                                      (realizing that the subsections' html names might not be
414
-     *                                                      set yet, etc.)
415
-     * @return EE_Form_Input_Base
416
-     * @throws EE_Error
417
-     */
418
-    public function get_input($name, $require_construction_to_be_finalized = true)
419
-    {
420
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
421
-        if ( ! $subsection instanceof EE_Form_Input_Base) {
422
-            throw new EE_Error(
423
-                sprintf(
424
-                    __(
425
-                        "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
426
-                        'event_espresso'
427
-                    ),
428
-                    $name,
429
-                    get_class($this),
430
-                    $subsection ? get_class($subsection) : __("NULL", 'event_espresso')
431
-                )
432
-            );
433
-        }
434
-        return $subsection;
435
-    }
436
-
437
-
438
-
439
-    /**
440
-     * Like get_input(), gets the proper subsection of the form given the name,
441
-     * otherwise throws an EE_Error
442
-     *
443
-     * @param string  $name
444
-     * @param boolean $require_construction_to_be_finalized most client code should
445
-     *                                                      leave this as TRUE so that the inputs will be properly
446
-     *                                                      configured. However, some client code may be ok with
447
-     *                                                      construction finalize being called later
448
-     *                                                      (realizing that the subsections' html names might not be
449
-     *                                                      set yet, etc.)
450
-     * @return EE_Form_Section_Proper
451
-     * @throws EE_Error
452
-     */
453
-    public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
454
-    {
455
-        $subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
456
-        if ( ! $subsection instanceof EE_Form_Section_Proper) {
457
-            throw new EE_Error(
458
-                sprintf(
459
-                    __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
460
-                    $name,
461
-                    get_class($this)
462
-                )
463
-            );
464
-        }
465
-        return $subsection;
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     * Gets the value of the specified input. Should be called after receive_form_submission()
472
-     * or populate_defaults() on the form, where the normalized value on the input is set.
473
-     *
474
-     * @param string $name
475
-     * @return mixed depending on the input's type and its normalization strategy
476
-     * @throws \EE_Error
477
-     */
478
-    public function get_input_value($name)
479
-    {
480
-        $input = $this->get_input($name);
481
-        return $input->normalized_value();
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     * Checks if this form section itself is valid, and then checks its subsections
488
-     *
489
-     * @throws EE_Error
490
-     * @return boolean
491
-     */
492
-    public function is_valid()
493
-    {
494
-        if ( ! $this->has_received_submission()) {
495
-            throw new EE_Error(
496
-                sprintf(
497
-                    __(
498
-                        "You cannot check if a form is valid before receiving the form submission using receive_form_submission",
499
-                        "event_espresso"
500
-                    )
501
-                )
502
-            );
503
-        }
504
-        if ( ! parent::is_valid()) {
505
-            return false;
506
-        }
507
-        // ok so no general errors to this entire form section.
508
-        // so let's check the subsections, but only set errors if that hasn't been done yet
509
-        $set_submission_errors = $this->submission_error_message() === '' ? true : false;
510
-        foreach ($this->get_validatable_subsections() as $subsection) {
511
-            if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
512
-                if ($set_submission_errors) {
513
-                    $this->set_submission_error_message($subsection->get_validation_error_string());
514
-                }
515
-                return false;
516
-            }
517
-        }
518
-        return true;
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * gets teh default name of this form section if none is specified
525
-     *
526
-     * @return string
527
-     */
528
-    protected function _set_default_name_if_empty()
529
-    {
530
-        if ( ! $this->_name) {
531
-            $classname = get_class($this);
532
-            $default_name = str_replace("EE_", "", $classname);
533
-            $this->_name = $default_name;
534
-        }
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * Returns the HTML for the form, except for the form opening and closing tags
541
-     * (as the form section doesn't know where you necessarily want to send the information to),
542
-     * and except for a submit button. Enqueus JS and CSS; if called early enough we will
543
-     * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
544
-     * Not doing_it_wrong because theoretically this CAN be used properly,
545
-     * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
546
-     * any CSS.
547
-     *
548
-     * @throws \EE_Error
549
-     */
550
-    public function get_html_and_js()
551
-    {
552
-        $this->enqueue_js();
553
-        return $this->get_html();
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     * returns HTML for displaying this form section. recursively calls display_section() on all subsections
560
-     *
561
-     * @param bool $display_previously_submitted_data
562
-     * @return string
563
-     */
564
-    public function get_html($display_previously_submitted_data = true)
565
-    {
566
-        $this->ensure_construct_finalized_called();
567
-        if ($display_previously_submitted_data) {
568
-            $this->populate_from_session();
569
-        }
570
-        return $this->_layout_strategy->layout_form();
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * enqueues JS and CSS for the form.
577
-     * It is preferred to call this before wp_enqueue_scripts so the
578
-     * scripts and styles can be put in the header, but if called later
579
-     * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
580
-     * only be in the header; but in HTML5 its ok in the body.
581
-     * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
582
-     * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
583
-     *
584
-     * @return string
585
-     * @throws \EE_Error
586
-     */
587
-    public function enqueue_js()
588
-    {
589
-        $this->_enqueue_and_localize_form_js();
590
-        foreach ($this->subsections() as $subsection) {
591
-            $subsection->enqueue_js();
592
-        }
593
-    }
594
-
595
-
596
-
597
-    /**
598
-     * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
599
-     * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
600
-     * the wp_enqueue_scripts hook.
601
-     * However, registering the form js and localizing it can happen when we
602
-     * actually output the form (which is preferred, seeing how teh form's fields
603
-     * could change until it's actually outputted)
604
-     *
605
-     * @param boolean $init_form_validation_automatically whether or not we want the form validation
606
-     *                                                    to be triggered automatically or not
607
-     * @return void
608
-     */
609
-    public static function wp_enqueue_scripts($init_form_validation_automatically = true)
610
-    {
611
-        add_filter('FHEE_load_jquery_validate', '__return_true');
612
-        wp_register_script(
613
-            'ee_form_section_validation',
614
-            EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
615
-            array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
616
-            EVENT_ESPRESSO_VERSION,
617
-            true
618
-        );
619
-        wp_localize_script(
620
-            'ee_form_section_validation',
621
-            'ee_form_section_validation_init',
622
-            array('init' => $init_form_validation_automatically ? true : false)
623
-        );
624
-    }
625
-
626
-
627
-
628
-    /**
629
-     * gets the variables used by form_section_validation.js.
630
-     * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
631
-     * but before the wordpress hook wp_loaded
632
-     *
633
-     * @throws \EE_Error
634
-     */
635
-    public function _enqueue_and_localize_form_js()
636
-    {
637
-        $this->ensure_construct_finalized_called();
638
-        //actually, we don't want to localize just yet. There may be other forms on the page.
639
-        //so we need to add our form section data to a static variable accessible by all form sections
640
-        //and localize it just before the footer
641
-        $this->localize_validation_rules();
642
-        add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
643
-        add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * add our form section data to a static variable accessible by all form sections
650
-     *
651
-     * @param bool $return_for_subsection
652
-     * @return void
653
-     * @throws \EE_Error
654
-     */
655
-    public function localize_validation_rules($return_for_subsection = false)
656
-    {
657
-        // we only want to localize vars ONCE for the entire form,
658
-        // so if the form section doesn't have a parent, then it must be the top dog
659
-        if ($return_for_subsection || ! $this->parent_section()) {
660
-            EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
661
-                'form_section_id'  => $this->html_id(true),
662
-                'validation_rules' => $this->get_jquery_validation_rules(),
663
-                'other_data'       => $this->get_other_js_data(),
664
-                'errors'           => $this->subsection_validation_errors_by_html_name(),
665
-            );
666
-            EE_Form_Section_Proper::$_scripts_localized = true;
667
-        }
668
-    }
669
-
670
-
671
-
672
-    /**
673
-     * Gets an array of extra data that will be useful for client-side javascript.
674
-     * This is primarily data added by inputs and forms in addition to any
675
-     * scripts they might enqueue
676
-     *
677
-     * @param array $form_other_js_data
678
-     * @return array
679
-     */
680
-    public function get_other_js_data($form_other_js_data = array())
681
-    {
682
-        foreach ($this->subsections() as $subsection) {
683
-            $form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
684
-        }
685
-        return $form_other_js_data;
686
-    }
687
-
688
-
689
-
690
-    /**
691
-     * Gets a flat array of inputs for this form section and its subsections.
692
-     * Keys are their form names, and values are the inputs themselves
693
-     *
694
-     * @return EE_Form_Input_Base
695
-     */
696
-    public function inputs_in_subsections()
697
-    {
698
-        $inputs = array();
699
-        foreach ($this->subsections() as $subsection) {
700
-            if ($subsection instanceof EE_Form_Input_Base) {
701
-                $inputs[$subsection->html_name()] = $subsection;
702
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
703
-                $inputs += $subsection->inputs_in_subsections();
704
-            }
705
-        }
706
-        return $inputs;
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * Gets a flat array of all the validation errors.
713
-     * Keys are html names (because those should be unique)
714
-     * and values are a string of all their validation errors
715
-     *
716
-     * @return string[]
717
-     */
718
-    public function subsection_validation_errors_by_html_name()
719
-    {
720
-        $inputs = $this->inputs();
721
-        $errors = array();
722
-        foreach ($inputs as $form_input) {
723
-            if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
724
-                $errors[$form_input->html_name()] = $form_input->get_validation_error_string();
725
-            }
726
-        }
727
-        return $errors;
728
-    }
729
-
730
-
731
-
732
-    /**
733
-     * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
734
-     * Should be setup by each form during the _enqueues_and_localize_form_js
735
-     */
736
-    public static function localize_script_for_all_forms()
737
-    {
738
-        //allow inputs and stuff to hook in their JS and stuff here
739
-        do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
740
-        EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
741
-        $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
742
-            ? EE_Registry::instance()->CFG->registration->email_validation_level
743
-            : 'wp_default';
744
-        EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
745
-        wp_enqueue_script('ee_form_section_validation');
746
-        wp_localize_script(
747
-            'ee_form_section_validation',
748
-            'ee_form_section_vars',
749
-            EE_Form_Section_Proper::$_js_localization
750
-        );
751
-    }
752
-
753
-
754
-
755
-    /**
756
-     * ensure_scripts_localized
757
-     */
758
-    public function ensure_scripts_localized()
759
-    {
760
-        if ( ! EE_Form_Section_Proper::$_scripts_localized) {
761
-            $this->_enqueue_and_localize_form_js();
762
-        }
763
-    }
764
-
765
-
766
-
767
-    /**
768
-     * Gets the hard-coded validation error messages to be used in the JS. The convention
769
-     * is that the key here should be the same as the custom validation rule put in the JS file
770
-     *
771
-     * @return array keys are custom validation rules, and values are internationalized strings
772
-     */
773
-    private static function _get_localized_error_messages()
774
-    {
775
-        return array(
776
-            'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
777
-            'regex'    => __('Please check your input', 'event_espresso'),
778
-        );
779
-    }
780
-
781
-
782
-
783
-    /**
784
-     * @return array
785
-     */
786
-    public static function js_localization()
787
-    {
788
-        return self::$_js_localization;
789
-    }
790
-
791
-
792
-
793
-    /**
794
-     * @return array
795
-     */
796
-    public static function reset_js_localization()
797
-    {
798
-        self::$_js_localization = array();
799
-    }
800
-
801
-
802
-
803
-    /**
804
-     * Gets the JS to put inside the jquery validation rules for subsection of this form section.
805
-     * See parent function for more...
806
-     *
807
-     * @return array
808
-     */
809
-    public function get_jquery_validation_rules()
810
-    {
811
-        $jquery_validation_rules = array();
812
-        foreach ($this->get_validatable_subsections() as $subsection) {
813
-            $jquery_validation_rules = array_merge(
814
-                $jquery_validation_rules,
815
-                $subsection->get_jquery_validation_rules()
816
-            );
817
-        }
818
-        return $jquery_validation_rules;
819
-    }
820
-
821
-
822
-
823
-    /**
824
-     * Sanitizes all the data and sets the sanitized value of each field
825
-     *
826
-     * @param array $req_data like $_POST
827
-     * @return void
828
-     */
829
-    protected function _normalize($req_data)
830
-    {
831
-        $this->_received_submission = true;
832
-        $this->_validation_errors = array();
833
-        foreach ($this->get_validatable_subsections() as $subsection) {
834
-            try {
835
-                $subsection->_normalize($req_data);
836
-            } catch (EE_Validation_Error $e) {
837
-                $subsection->add_validation_error($e);
838
-            }
839
-        }
840
-    }
841
-
842
-
843
-
844
-    /**
845
-     * Performs validation on this form section and its subsections.
846
-     * For each subsection,
847
-     * calls _validate_{subsection_name} on THIS form (if the function exists)
848
-     * and passes it the subsection, then calls _validate on that subsection.
849
-     * If you need to perform validation on the form as a whole (considering multiple)
850
-     * you would be best to override this _validate method,
851
-     * calling parent::_validate() first.
852
-     */
853
-    protected function _validate()
854
-    {
855
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
856
-            if (method_exists($this, '_validate_' . $subsection_name)) {
857
-                call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
858
-            }
859
-            $subsection->_validate();
860
-        }
861
-    }
862
-
863
-
864
-
865
-    /**
866
-     * Gets all the validated inputs for the form section
867
-     *
868
-     * @return array
869
-     */
870
-    public function valid_data()
871
-    {
872
-        $inputs = array();
873
-        foreach ($this->subsections() as $subsection_name => $subsection) {
874
-            if ($subsection instanceof EE_Form_Section_Proper) {
875
-                $inputs[$subsection_name] = $subsection->valid_data();
876
-            } else if ($subsection instanceof EE_Form_Input_Base) {
877
-                $inputs[$subsection_name] = $subsection->normalized_value();
878
-            }
879
-        }
880
-        return $inputs;
881
-    }
882
-
883
-
884
-
885
-    /**
886
-     * Gets all the inputs on this form section
887
-     *
888
-     * @return EE_Form_Input_Base[]
889
-     */
890
-    public function inputs()
891
-    {
892
-        $inputs = array();
893
-        foreach ($this->subsections() as $subsection_name => $subsection) {
894
-            if ($subsection instanceof EE_Form_Input_Base) {
895
-                $inputs[$subsection_name] = $subsection;
896
-            }
897
-        }
898
-        return $inputs;
899
-    }
900
-
901
-
902
-
903
-    /**
904
-     * Gets all the subsections which are a proper form
905
-     *
906
-     * @return EE_Form_Section_Proper[]
907
-     */
908
-    public function subforms()
909
-    {
910
-        $form_sections = array();
911
-        foreach ($this->subsections() as $name => $obj) {
912
-            if ($obj instanceof EE_Form_Section_Proper) {
913
-                $form_sections[$name] = $obj;
914
-            }
915
-        }
916
-        return $form_sections;
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * Gets all the subsections (inputs, proper subsections, or html-only sections).
923
-     * Consider using inputs() or subforms()
924
-     * if you only want form inputs or proper form sections.
925
-     *
926
-     * @return EE_Form_Section_Proper[]
927
-     */
928
-    public function subsections()
929
-    {
930
-        $this->ensure_construct_finalized_called();
931
-        return $this->_subsections;
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * Returns a simple array where keys are input names, and values are their normalized
938
-     * values. (Similar to calling get_input_value on inputs)
939
-     *
940
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
941
-     *                                        or just this forms' direct children inputs
942
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
943
-     *                                        or allow multidimensional array
944
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
945
-     *                                        with array keys being input names
946
-     *                                        (regardless of whether they are from a subsection or not),
947
-     *                                        and if $flatten is FALSE it can be a multidimensional array
948
-     *                                        where keys are always subsection names and values are either
949
-     *                                        the input's normalized value, or an array like the top-level array
950
-     */
951
-    public function input_values($include_subform_inputs = false, $flatten = false)
952
-    {
953
-        return $this->_input_values(false, $include_subform_inputs, $flatten);
954
-    }
955
-
956
-
957
-
958
-    /**
959
-     * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
960
-     * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
961
-     * is not necessarily the value we want to display to users. This creates an array
962
-     * where keys are the input names, and values are their display values
963
-     *
964
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
965
-     *                                        or just this forms' direct children inputs
966
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
967
-     *                                        or allow multidimensional array
968
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array
969
-     *                                        with array keys being input names
970
-     *                                        (regardless of whether they are from a subsection or not),
971
-     *                                        and if $flatten is FALSE it can be a multidimensional array
972
-     *                                        where keys are always subsection names and values are either
973
-     *                                        the input's normalized value, or an array like the top-level array
974
-     */
975
-    public function input_pretty_values($include_subform_inputs = false, $flatten = false)
976
-    {
977
-        return $this->_input_values(true, $include_subform_inputs, $flatten);
978
-    }
979
-
980
-
981
-
982
-    /**
983
-     * Gets the input values from the form
984
-     *
985
-     * @param boolean $pretty                 Whether to retrieve the pretty value,
986
-     *                                        or just the normalized value
987
-     * @param boolean $include_subform_inputs Whether to include inputs from subforms,
988
-     *                                        or just this forms' direct children inputs
989
-     * @param boolean $flatten                Whether to force the results into 1-dimensional array,
990
-     *                                        or allow multidimensional array
991
-     * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
992
-     *                                        input names (regardless of whether they are from a subsection or not),
993
-     *                                        and if $flatten is FALSE it can be a multidimensional array
994
-     *                                        where keys are always subsection names and values are either
995
-     *                                        the input's normalized value, or an array like the top-level array
996
-     */
997
-    public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
998
-    {
999
-        $input_values = array();
1000
-        foreach ($this->subsections() as $subsection_name => $subsection) {
1001
-            if ($subsection instanceof EE_Form_Input_Base) {
1002
-                $input_values[$subsection_name] = $pretty
1003
-                    ? $subsection->pretty_value()
1004
-                    : $subsection->normalized_value();
1005
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1006
-                $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1007
-                if ($flatten) {
1008
-                    $input_values = array_merge($input_values, $subform_input_values);
1009
-                } else {
1010
-                    $input_values[$subsection_name] = $subform_input_values;
1011
-                }
1012
-            }
1013
-        }
1014
-        return $input_values;
1015
-    }
1016
-
1017
-
1018
-
1019
-    /**
1020
-     * Gets the originally submitted input values from the form
1021
-     *
1022
-     * @param boolean $include_subforms  Whether to include inputs from subforms,
1023
-     *                                   or just this forms' direct children inputs
1024
-     * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1025
-     *                                   with array keys being input names
1026
-     *                                   (regardless of whether they are from a subsection or not),
1027
-     *                                   and if $flatten is FALSE it can be a multidimensional array
1028
-     *                                   where keys are always subsection names and values are either
1029
-     *                                   the input's normalized value, or an array like the top-level array
1030
-     */
1031
-    public function submitted_values($include_subforms = false)
1032
-    {
1033
-        $submitted_values = array();
1034
-        foreach ($this->subsections() as $subsection) {
1035
-            if ($subsection instanceof EE_Form_Input_Base) {
1036
-                // is this input part of an array of inputs?
1037
-                if (strpos($subsection->html_name(), '[') !== false) {
1038
-                    $full_input_name = \EEH_Array::convert_array_values_to_keys(
1039
-                        explode('[', str_replace(']', '', $subsection->html_name())),
1040
-                        $subsection->raw_value()
1041
-                    );
1042
-                    $submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1043
-                } else {
1044
-                    $submitted_values[$subsection->html_name()] = $subsection->raw_value();
1045
-                }
1046
-            } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1047
-                $subform_input_values = $subsection->submitted_values($include_subforms);
1048
-                $submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1049
-            }
1050
-        }
1051
-        return $submitted_values;
1052
-    }
1053
-
1054
-
1055
-
1056
-    /**
1057
-     * Indicates whether or not this form has received a submission yet
1058
-     * (ie, had receive_form_submission called on it yet)
1059
-     *
1060
-     * @return boolean
1061
-     * @throws \EE_Error
1062
-     */
1063
-    public function has_received_submission()
1064
-    {
1065
-        $this->ensure_construct_finalized_called();
1066
-        return $this->_received_submission;
1067
-    }
1068
-
1069
-
1070
-
1071
-    /**
1072
-     * Equivalent to passing 'exclude' in the constructor's options array.
1073
-     * Removes the listed inputs from the form
1074
-     *
1075
-     * @param array $inputs_to_exclude values are the input names
1076
-     * @return void
1077
-     */
1078
-    public function exclude(array $inputs_to_exclude = array())
1079
-    {
1080
-        foreach ($inputs_to_exclude as $input_to_exclude_name) {
1081
-            unset($this->_subsections[$input_to_exclude_name]);
1082
-        }
1083
-    }
1084
-
1085
-
1086
-
1087
-    /**
1088
-     * @param array $inputs_to_hide
1089
-     * @throws \EE_Error
1090
-     */
1091
-    public function hide(array $inputs_to_hide = array())
1092
-    {
1093
-        foreach ($inputs_to_hide as $input_to_hide) {
1094
-            $input = $this->get_input($input_to_hide);
1095
-            $input->set_display_strategy(new EE_Hidden_Display_Strategy());
1096
-        }
1097
-    }
1098
-
1099
-
1100
-
1101
-    /**
1102
-     * add_subsections
1103
-     * Adds the listed subsections to the form section.
1104
-     * If $subsection_name_to_target is provided,
1105
-     * then new subsections are added before or after that subsection,
1106
-     * otherwise to the start or end of the entire subsections array.
1107
-     *
1108
-     * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1109
-     *                                                          where keys are their names
1110
-     * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1111
-     *                                                          should be added before or after
1112
-     *                                                          IF $subsection_name_to_target is null,
1113
-     *                                                          then $new_subsections will be added to
1114
-     *                                                          the beginning or end of the entire subsections array
1115
-     * @param boolean                $add_before                whether to add $new_subsections, before or after
1116
-     *                                                          $subsection_name_to_target,
1117
-     *                                                          or if $subsection_name_to_target is null,
1118
-     *                                                          before or after entire subsections array
1119
-     * @return void
1120
-     * @throws \EE_Error
1121
-     */
1122
-    public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1123
-    {
1124
-        foreach ($new_subsections as $subsection_name => $subsection) {
1125
-            if ( ! $subsection instanceof EE_Form_Section_Base) {
1126
-                EE_Error::add_error(
1127
-                    sprintf(
1128
-                        __(
1129
-                            "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1130
-                            "event_espresso"
1131
-                        ),
1132
-                        get_class($subsection),
1133
-                        $subsection_name,
1134
-                        $this->name()
1135
-                    )
1136
-                );
1137
-                unset($new_subsections[$subsection_name]);
1138
-            }
1139
-        }
1140
-        $this->_subsections = EEH_Array::insert_into_array(
1141
-            $this->_subsections,
1142
-            $new_subsections,
1143
-            $subsection_name_to_target,
1144
-            $add_before
1145
-        );
1146
-        if ($this->_construction_finalized) {
1147
-            foreach ($this->_subsections as $name => $subsection) {
1148
-                $subsection->_construct_finalize($this, $name);
1149
-            }
1150
-        }
1151
-    }
1152
-
1153
-
1154
-
1155
-    /**
1156
-     * Just gets all validatable subsections to clean their sensitive data
1157
-     */
1158
-    public function clean_sensitive_data()
1159
-    {
1160
-        foreach ($this->get_validatable_subsections() as $subsection) {
1161
-            $subsection->clean_sensitive_data();
1162
-        }
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * @param string $form_submission_error_message
1169
-     */
1170
-    public function set_submission_error_message($form_submission_error_message = '')
1171
-    {
1172
-        $this->_form_submission_error_message .= ! empty($form_submission_error_message)
1173
-            ? $form_submission_error_message
1174
-            : __('Form submission failed due to errors', 'event_espresso');
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * @return string
1181
-     */
1182
-    public function submission_error_message()
1183
-    {
1184
-        return $this->_form_submission_error_message;
1185
-    }
1186
-
1187
-
1188
-
1189
-    /**
1190
-     * @param string $form_submission_success_message
1191
-     */
1192
-    public function set_submission_success_message($form_submission_success_message)
1193
-    {
1194
-        $this->_form_submission_success_message .= ! empty($form_submission_success_message)
1195
-            ? $form_submission_success_message
1196
-            : __('Form submitted successfully', 'event_espresso');
1197
-    }
1198
-
1199
-
1200
-
1201
-    /**
1202
-     * @return string
1203
-     */
1204
-    public function submission_success_message()
1205
-    {
1206
-        return $this->_form_submission_success_message;
1207
-    }
1208
-
1209
-
1210
-
1211
-    /**
1212
-     * Returns the prefix that should be used on child of this form section for
1213
-     * their html names. If this form section itself has a parent, prepends ITS
1214
-     * prefix onto this form section's prefix. Used primarily by
1215
-     * EE_Form_Input_Base::_set_default_html_name_if_empty
1216
-     *
1217
-     * @return string
1218
-     * @throws \EE_Error
1219
-     */
1220
-    public function html_name_prefix()
1221
-    {
1222
-        if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1223
-            return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1224
-        } else {
1225
-            return $this->name();
1226
-        }
1227
-    }
1228
-
1229
-
1230
-
1231
-    /**
1232
-     * Gets the name, but first checks _construct_finalize has been called. If not,
1233
-     * calls it (assumes there is no parent and that we want the name to be whatever
1234
-     * was set, which is probably nothing, or the classname)
1235
-     *
1236
-     * @return string
1237
-     * @throws \EE_Error
1238
-     */
1239
-    public function name()
1240
-    {
1241
-        $this->ensure_construct_finalized_called();
1242
-        return parent::name();
1243
-    }
1244
-
1245
-
1246
-
1247
-    /**
1248
-     * @return EE_Form_Section_Proper
1249
-     * @throws \EE_Error
1250
-     */
1251
-    public function parent_section()
1252
-    {
1253
-        $this->ensure_construct_finalized_called();
1254
-        return parent::parent_section();
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * make sure construction finalized was called, otherwise children might not be ready
1261
-     *
1262
-     * @return void
1263
-     * @throws \EE_Error
1264
-     */
1265
-    public function ensure_construct_finalized_called()
1266
-    {
1267
-        if ( ! $this->_construction_finalized) {
1268
-            $this->_construct_finalize($this->_parent_section, $this->_name);
1269
-        }
1270
-    }
1271
-
1272
-
1273
-
1274
-    /**
1275
-     * Checks if any of this form section's inputs, or any of its children's inputs,
1276
-     * are in teh form data. If any are found, returns true. Else false
1277
-     *
1278
-     * @param array $req_data
1279
-     * @return boolean
1280
-     */
1281
-    public function form_data_present_in($req_data = null)
1282
-    {
1283
-        if ($req_data === null) {
1284
-            $req_data = $_POST;
1285
-        }
1286
-        foreach ($this->subsections() as $subsection) {
1287
-            if ($subsection instanceof EE_Form_Input_Base) {
1288
-                if ($subsection->form_data_present_in($req_data)) {
1289
-                    return true;
1290
-                }
1291
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
1292
-                if ($subsection->form_data_present_in($req_data)) {
1293
-                    return true;
1294
-                }
1295
-            }
1296
-        }
1297
-        return false;
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * Gets validation errors for this form section and subsections
1304
-     * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1305
-     * gets the validation errors for ALL subsection
1306
-     *
1307
-     * @return EE_Validation_Error[]
1308
-     */
1309
-    public function get_validation_errors_accumulated()
1310
-    {
1311
-        $validation_errors = $this->get_validation_errors();
1312
-        foreach ($this->get_validatable_subsections() as $subsection) {
1313
-            if ($subsection instanceof EE_Form_Section_Proper) {
1314
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1315
-            } else {
1316
-                $validation_errors_on_this_subsection = $subsection->get_validation_errors();
1317
-            }
1318
-            if ($validation_errors_on_this_subsection) {
1319
-                $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1320
-            }
1321
-        }
1322
-        return $validation_errors;
1323
-    }
1324
-
1325
-
1326
-
1327
-    /**
1328
-     * This isn't just the name of an input, it's a path pointing to an input. The
1329
-     * path is similar to a folder path: slash (/) means to descend into a subsection,
1330
-     * dot-dot-slash (../) means to ascend into the parent section.
1331
-     * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1332
-     * which will be returned.
1333
-     * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1334
-     * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1335
-     * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1336
-     * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1337
-     * Etc
1338
-     *
1339
-     * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1340
-     * @return EE_Form_Section_Base
1341
-     */
1342
-    public function find_section_from_path($form_section_path)
1343
-    {
1344
-        //check if we can find the input from purely going straight up the tree
1345
-        $input = parent::find_section_from_path($form_section_path);
1346
-        if ($input instanceof EE_Form_Section_Base) {
1347
-            return $input;
1348
-        }
1349
-        $next_slash_pos = strpos($form_section_path, '/');
1350
-        if ($next_slash_pos !== false) {
1351
-            $child_section_name = substr($form_section_path, 0, $next_slash_pos);
1352
-            $subpath = substr($form_section_path, $next_slash_pos + 1);
1353
-        } else {
1354
-            $child_section_name = $form_section_path;
1355
-            $subpath = '';
1356
-        }
1357
-        $child_section = $this->get_subsection($child_section_name);
1358
-        if ($child_section instanceof EE_Form_Section_Base) {
1359
-            return $child_section->find_section_from_path($subpath);
1360
-        } else {
1361
-            return null;
1362
-        }
1363
-    }
16
+	const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data';
17
+
18
+	/**
19
+	 * Subsections
20
+	 *
21
+	 * @var EE_Form_Section_Validatable[]
22
+	 */
23
+	protected $_subsections = array();
24
+
25
+	/**
26
+	 * Strategy for laying out the form
27
+	 *
28
+	 * @var EE_Form_Section_Layout_Base
29
+	 */
30
+	protected $_layout_strategy;
31
+
32
+	/**
33
+	 * Whether or not this form has received and validated a form submission yet
34
+	 *
35
+	 * @var boolean
36
+	 */
37
+	protected $_received_submission = false;
38
+
39
+	/**
40
+	 * message displayed to users upon successful form submission
41
+	 *
42
+	 * @var string
43
+	 */
44
+	protected $_form_submission_success_message = '';
45
+
46
+	/**
47
+	 * message displayed to users upon unsuccessful form submission
48
+	 *
49
+	 * @var string
50
+	 */
51
+	protected $_form_submission_error_message = '';
52
+
53
+	/**
54
+	 * Stores all the data that will localized for form validation
55
+	 *
56
+	 * @var array
57
+	 */
58
+	static protected $_js_localization = array();
59
+
60
+	/**
61
+	 * whether or not the form's localized validation JS vars have been set
62
+	 *
63
+	 * @type boolean
64
+	 */
65
+	static protected $_scripts_localized = false;
66
+
67
+
68
+
69
+	/**
70
+	 * when constructing a proper form section, calls _construct_finalize on children
71
+	 * so that they know who their parent is, and what name they've been given.
72
+	 *
73
+	 * @param array $options_array   {
74
+	 * @type        $subsections     EE_Form_Section_Validatable[] where keys are the section's name
75
+	 * @type        $include         string[] numerically-indexed where values are section names to be included,
76
+	 *                               and in that order. This is handy if you want
77
+	 *                               the subsections to be ordered differently than the default, and if you override
78
+	 *                               which fields are shown
79
+	 * @type        $exclude         string[] values are subsections to be excluded. This is handy if you want
80
+	 *                               to remove certain default subsections (note: if you specify BOTH 'include' AND
81
+	 *                               'exclude', the inclusions will be applied first, and the exclusions will exclude
82
+	 *                               items from that list of inclusions)
83
+	 * @type        $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form
84
+	 *                               } @see EE_Form_Section_Validatable::__construct()
85
+	 * @throws \EE_Error
86
+	 */
87
+	public function __construct($options_array = array())
88
+	{
89
+		$options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array,
90
+			$this);
91
+		//call parent first, as it may be setting the name
92
+		parent::__construct($options_array);
93
+		//if they've included subsections in the constructor, add them now
94
+		if (isset($options_array['include'])) {
95
+			//we are going to make sure we ONLY have those subsections to include
96
+			//AND we are going to make sure they're in that specified order
97
+			$reordered_subsections = array();
98
+			foreach ($options_array['include'] as $input_name) {
99
+				if (isset($this->_subsections[$input_name])) {
100
+					$reordered_subsections[$input_name] = $this->_subsections[$input_name];
101
+				}
102
+			}
103
+			$this->_subsections = $reordered_subsections;
104
+		}
105
+		if (isset($options_array['exclude'])) {
106
+			$exclude = $options_array['exclude'];
107
+			$this->_subsections = array_diff_key($this->_subsections, array_flip($exclude));
108
+		}
109
+		if (isset($options_array['layout_strategy'])) {
110
+			$this->_layout_strategy = $options_array['layout_strategy'];
111
+		}
112
+		if ( ! $this->_layout_strategy) {
113
+			$this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout();
114
+		}
115
+		$this->_layout_strategy->_construct_finalize($this);
116
+		//ok so we are definitely going to want the forms JS,
117
+		//so enqueue it or remember to enqueue it during wp_enqueue_scripts
118
+		if (did_action('wp_enqueue_scripts')
119
+			|| did_action('admin_enqueue_scripts')
120
+		) {
121
+			//ok so they've constructed this object after when they should have.
122
+			//just enqueue the generic form scripts and initialize the form immediately in the JS
123
+			\EE_Form_Section_Proper::wp_enqueue_scripts(true);
124
+		} else {
125
+			add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
126
+			add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts'));
127
+		}
128
+		add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1);
129
+		if (isset($options_array['name'])) {
130
+			$this->_construct_finalize(null, $options_array['name']);
131
+		}
132
+	}
133
+
134
+
135
+
136
+	/**
137
+	 * Finishes construction given the parent form section and this form section's name
138
+	 *
139
+	 * @param EE_Form_Section_Proper $parent_form_section
140
+	 * @param string                 $name
141
+	 * @throws \EE_Error
142
+	 */
143
+	public function _construct_finalize($parent_form_section, $name)
144
+	{
145
+		parent::_construct_finalize($parent_form_section, $name);
146
+		$this->_set_default_name_if_empty();
147
+		$this->_set_default_html_id_if_empty();
148
+		foreach ($this->_subsections as $subsection_name => $subsection) {
149
+			if ($subsection instanceof EE_Form_Section_Base) {
150
+				$subsection->_construct_finalize($this, $subsection_name);
151
+			} else {
152
+				throw new EE_Error(
153
+					sprintf(
154
+						__('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"',
155
+							'event_espresso'),
156
+						$subsection_name,
157
+						get_class($this),
158
+						$subsection ? get_class($subsection) : __('NULL', 'event_espresso')
159
+					)
160
+				);
161
+			}
162
+		}
163
+		do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * Gets the layout strategy for this form section
170
+	 *
171
+	 * @return EE_Form_Section_Layout_Base
172
+	 */
173
+	public function get_layout_strategy()
174
+	{
175
+		return $this->_layout_strategy;
176
+	}
177
+
178
+
179
+
180
+	/**
181
+	 * Gets the HTML for a single input for this form section according
182
+	 * to the layout strategy
183
+	 *
184
+	 * @param EE_Form_Input_Base $input
185
+	 * @return string
186
+	 */
187
+	public function get_html_for_input($input)
188
+	{
189
+		return $this->_layout_strategy->layout_input($input);
190
+	}
191
+
192
+
193
+
194
+	/**
195
+	 * was_submitted - checks if form inputs are present in request data
196
+	 * Basically an alias for form_data_present_in() (which is used by both
197
+	 * proper form sections and form inputs)
198
+	 *
199
+	 * @param null $form_data
200
+	 * @return boolean
201
+	 */
202
+	public function was_submitted($form_data = null)
203
+	{
204
+		return $this->form_data_present_in($form_data);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * After the form section is initially created, call this to sanitize the data in the submission
211
+	 * which relates to this form section, validate it, and set it as properties on the form.
212
+	 *
213
+	 * @param array|null $req_data should usually be $_POST (the default).
214
+	 *                             However, you CAN supply a different array.
215
+	 *                             Consider using set_defaults() instead however.
216
+	 *                             (If you rendered the form in the page using echo $form_x->get_html()
217
+	 *                             the inputs will have the correct name in the request data for this function
218
+	 *                             to find them and populate the form with them.
219
+	 *                             If you have a flat form (with only input subsections),
220
+	 *                             you can supply a flat array where keys
221
+	 *                             are the form input names and values are their values)
222
+	 * @param boolean    $validate whether or not to perform validation on this data. Default is,
223
+	 *                             of course, to validate that data, and set errors on the invalid values.
224
+	 *                             But if the data has already been validated
225
+	 *                             (eg you validated the data then stored it in the DB)
226
+	 *                             you may want to skip this step.
227
+	 */
228
+	public function receive_form_submission($req_data = null, $validate = true)
229
+	{
230
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this,
231
+			$validate);
232
+		if ($req_data === null) {
233
+			$req_data = array_merge($_GET, $_POST);
234
+		}
235
+		$req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data,
236
+			$this);
237
+		$this->_normalize($req_data);
238
+		if ($validate) {
239
+			$this->_validate();
240
+			//if it's invalid, we're going to want to re-display so remember what they submitted
241
+			if ( ! $this->is_valid()) {
242
+				$this->store_submitted_form_data_in_session();
243
+			}
244
+		}
245
+		do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate);
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 * caches the originally submitted input values in the session
252
+	 * so that they can be used to repopulate the form if it failed validation
253
+	 *
254
+	 * @return boolean whether or not the data was successfully stored in the session
255
+	 */
256
+	protected function store_submitted_form_data_in_session()
257
+	{
258
+		return EE_Registry::instance()->SSN->set_session_data(
259
+			array(
260
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true),
261
+			)
262
+		);
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 * retrieves the originally submitted input values in the session
269
+	 * so that they can be used to repopulate the form if it failed validation
270
+	 *
271
+	 * @return array
272
+	 */
273
+	protected function get_submitted_form_data_from_session()
274
+	{
275
+		$session = EE_Registry::instance()->SSN;
276
+		if ($session instanceof EE_Session) {
277
+			return $session->get_session_data(
278
+				\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY
279
+			);
280
+		} else {
281
+			return array();
282
+		}
283
+	}
284
+
285
+
286
+
287
+	/**
288
+	 * flushed the originally submitted input values from the session
289
+	 *
290
+	 * @return boolean whether or not the data was successfully removed from the session
291
+	 */
292
+	protected function flush_submitted_form_data_from_session()
293
+	{
294
+		return EE_Registry::instance()->SSN->reset_data(
295
+			array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY)
296
+		);
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * Populates this form and its subsections with data from the session.
303
+	 * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows
304
+	 * validation errors when displaying too)
305
+	 * Returns true if the form was populated from the session, false otherwise
306
+	 *
307
+	 * @return boolean
308
+	 */
309
+	public function populate_from_session()
310
+	{
311
+		$form_data_in_session = $this->get_submitted_form_data_from_session();
312
+		if (empty($form_data_in_session)) {
313
+			return false;
314
+		}
315
+		$this->receive_form_submission($form_data_in_session);
316
+		$this->flush_submitted_form_data_from_session();
317
+		if ($this->form_data_present_in($form_data_in_session)) {
318
+			return true;
319
+		} else {
320
+			return false;
321
+		}
322
+	}
323
+
324
+
325
+
326
+	/**
327
+	 * Populates the default data for the form, given an array where keys are
328
+	 * the input names, and values are their values (preferably normalized to be their
329
+	 * proper PHP types, not all strings... although that should be ok too).
330
+	 * Proper subsections are sub-arrays, the key being the subsection's name, and
331
+	 * the value being an array formatted in teh same way
332
+	 *
333
+	 * @param array $default_data
334
+	 */
335
+	public function populate_defaults($default_data)
336
+	{
337
+		foreach ($this->subsections() as $subsection_name => $subsection) {
338
+			if (isset($default_data[$subsection_name])) {
339
+				if ($subsection instanceof EE_Form_Input_Base) {
340
+					$subsection->set_default($default_data[$subsection_name]);
341
+				} elseif ($subsection instanceof EE_Form_Section_Proper) {
342
+					$subsection->populate_defaults($default_data[$subsection_name]);
343
+				}
344
+			}
345
+		}
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * returns true if subsection exists
352
+	 *
353
+	 * @param string $name
354
+	 * @return boolean
355
+	 */
356
+	public function subsection_exists($name)
357
+	{
358
+		return isset($this->_subsections[$name]) ? true : false;
359
+	}
360
+
361
+
362
+
363
+	/**
364
+	 * Gets the subsection specified by its name
365
+	 *
366
+	 * @param string  $name
367
+	 * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE
368
+	 *                                                      so that the inputs will be properly configured.
369
+	 *                                                      However, some client code may be ok
370
+	 *                                                      with construction finalize being called later
371
+	 *                                                      (realizing that the subsections' html names
372
+	 *                                                      might not be set yet, etc.)
373
+	 * @return EE_Form_Section_Base
374
+	 * @throws \EE_Error
375
+	 */
376
+	public function get_subsection($name, $require_construction_to_be_finalized = true)
377
+	{
378
+		if ($require_construction_to_be_finalized) {
379
+			$this->ensure_construct_finalized_called();
380
+		}
381
+		return $this->subsection_exists($name) ? $this->_subsections[$name] : null;
382
+	}
383
+
384
+
385
+
386
+	/**
387
+	 * Gets all the validatable subsections of this form section
388
+	 *
389
+	 * @return EE_Form_Section_Validatable[]
390
+	 */
391
+	public function get_validatable_subsections()
392
+	{
393
+		$validatable_subsections = array();
394
+		foreach ($this->subsections() as $name => $obj) {
395
+			if ($obj instanceof EE_Form_Section_Validatable) {
396
+				$validatable_subsections[$name] = $obj;
397
+			}
398
+		}
399
+		return $validatable_subsections;
400
+	}
401
+
402
+
403
+
404
+	/**
405
+	 * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child,
406
+	 * throw an EE_Error.
407
+	 *
408
+	 * @param string  $name
409
+	 * @param boolean $require_construction_to_be_finalized most client code should
410
+	 *                                                      leave this as TRUE so that the inputs will be properly
411
+	 *                                                      configured. However, some client code may be ok with
412
+	 *                                                      construction finalize being called later
413
+	 *                                                      (realizing that the subsections' html names might not be
414
+	 *                                                      set yet, etc.)
415
+	 * @return EE_Form_Input_Base
416
+	 * @throws EE_Error
417
+	 */
418
+	public function get_input($name, $require_construction_to_be_finalized = true)
419
+	{
420
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
421
+		if ( ! $subsection instanceof EE_Form_Input_Base) {
422
+			throw new EE_Error(
423
+				sprintf(
424
+					__(
425
+						"Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'",
426
+						'event_espresso'
427
+					),
428
+					$name,
429
+					get_class($this),
430
+					$subsection ? get_class($subsection) : __("NULL", 'event_espresso')
431
+				)
432
+			);
433
+		}
434
+		return $subsection;
435
+	}
436
+
437
+
438
+
439
+	/**
440
+	 * Like get_input(), gets the proper subsection of the form given the name,
441
+	 * otherwise throws an EE_Error
442
+	 *
443
+	 * @param string  $name
444
+	 * @param boolean $require_construction_to_be_finalized most client code should
445
+	 *                                                      leave this as TRUE so that the inputs will be properly
446
+	 *                                                      configured. However, some client code may be ok with
447
+	 *                                                      construction finalize being called later
448
+	 *                                                      (realizing that the subsections' html names might not be
449
+	 *                                                      set yet, etc.)
450
+	 * @return EE_Form_Section_Proper
451
+	 * @throws EE_Error
452
+	 */
453
+	public function get_proper_subsection($name, $require_construction_to_be_finalized = true)
454
+	{
455
+		$subsection = $this->get_subsection($name, $require_construction_to_be_finalized);
456
+		if ( ! $subsection instanceof EE_Form_Section_Proper) {
457
+			throw new EE_Error(
458
+				sprintf(
459
+					__("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'),
460
+					$name,
461
+					get_class($this)
462
+				)
463
+			);
464
+		}
465
+		return $subsection;
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 * Gets the value of the specified input. Should be called after receive_form_submission()
472
+	 * or populate_defaults() on the form, where the normalized value on the input is set.
473
+	 *
474
+	 * @param string $name
475
+	 * @return mixed depending on the input's type and its normalization strategy
476
+	 * @throws \EE_Error
477
+	 */
478
+	public function get_input_value($name)
479
+	{
480
+		$input = $this->get_input($name);
481
+		return $input->normalized_value();
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 * Checks if this form section itself is valid, and then checks its subsections
488
+	 *
489
+	 * @throws EE_Error
490
+	 * @return boolean
491
+	 */
492
+	public function is_valid()
493
+	{
494
+		if ( ! $this->has_received_submission()) {
495
+			throw new EE_Error(
496
+				sprintf(
497
+					__(
498
+						"You cannot check if a form is valid before receiving the form submission using receive_form_submission",
499
+						"event_espresso"
500
+					)
501
+				)
502
+			);
503
+		}
504
+		if ( ! parent::is_valid()) {
505
+			return false;
506
+		}
507
+		// ok so no general errors to this entire form section.
508
+		// so let's check the subsections, but only set errors if that hasn't been done yet
509
+		$set_submission_errors = $this->submission_error_message() === '' ? true : false;
510
+		foreach ($this->get_validatable_subsections() as $subsection) {
511
+			if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') {
512
+				if ($set_submission_errors) {
513
+					$this->set_submission_error_message($subsection->get_validation_error_string());
514
+				}
515
+				return false;
516
+			}
517
+		}
518
+		return true;
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * gets teh default name of this form section if none is specified
525
+	 *
526
+	 * @return string
527
+	 */
528
+	protected function _set_default_name_if_empty()
529
+	{
530
+		if ( ! $this->_name) {
531
+			$classname = get_class($this);
532
+			$default_name = str_replace("EE_", "", $classname);
533
+			$this->_name = $default_name;
534
+		}
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * Returns the HTML for the form, except for the form opening and closing tags
541
+	 * (as the form section doesn't know where you necessarily want to send the information to),
542
+	 * and except for a submit button. Enqueus JS and CSS; if called early enough we will
543
+	 * try to enqueue them in the header, otherwise they'll be enqueued in the footer.
544
+	 * Not doing_it_wrong because theoretically this CAN be used properly,
545
+	 * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue
546
+	 * any CSS.
547
+	 *
548
+	 * @throws \EE_Error
549
+	 */
550
+	public function get_html_and_js()
551
+	{
552
+		$this->enqueue_js();
553
+		return $this->get_html();
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 * returns HTML for displaying this form section. recursively calls display_section() on all subsections
560
+	 *
561
+	 * @param bool $display_previously_submitted_data
562
+	 * @return string
563
+	 */
564
+	public function get_html($display_previously_submitted_data = true)
565
+	{
566
+		$this->ensure_construct_finalized_called();
567
+		if ($display_previously_submitted_data) {
568
+			$this->populate_from_session();
569
+		}
570
+		return $this->_layout_strategy->layout_form();
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * enqueues JS and CSS for the form.
577
+	 * It is preferred to call this before wp_enqueue_scripts so the
578
+	 * scripts and styles can be put in the header, but if called later
579
+	 * they will be put in the footer (which is OK for JS, but in HTML4 CSS should
580
+	 * only be in the header; but in HTML5 its ok in the body.
581
+	 * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag.
582
+	 * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.)
583
+	 *
584
+	 * @return string
585
+	 * @throws \EE_Error
586
+	 */
587
+	public function enqueue_js()
588
+	{
589
+		$this->_enqueue_and_localize_form_js();
590
+		foreach ($this->subsections() as $subsection) {
591
+			$subsection->enqueue_js();
592
+		}
593
+	}
594
+
595
+
596
+
597
+	/**
598
+	 * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts().
599
+	 * This must be done BEFORE wp_enqueue_scripts() gets called, which is on
600
+	 * the wp_enqueue_scripts hook.
601
+	 * However, registering the form js and localizing it can happen when we
602
+	 * actually output the form (which is preferred, seeing how teh form's fields
603
+	 * could change until it's actually outputted)
604
+	 *
605
+	 * @param boolean $init_form_validation_automatically whether or not we want the form validation
606
+	 *                                                    to be triggered automatically or not
607
+	 * @return void
608
+	 */
609
+	public static function wp_enqueue_scripts($init_form_validation_automatically = true)
610
+	{
611
+		add_filter('FHEE_load_jquery_validate', '__return_true');
612
+		wp_register_script(
613
+			'ee_form_section_validation',
614
+			EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js',
615
+			array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'),
616
+			EVENT_ESPRESSO_VERSION,
617
+			true
618
+		);
619
+		wp_localize_script(
620
+			'ee_form_section_validation',
621
+			'ee_form_section_validation_init',
622
+			array('init' => $init_form_validation_automatically ? true : false)
623
+		);
624
+	}
625
+
626
+
627
+
628
+	/**
629
+	 * gets the variables used by form_section_validation.js.
630
+	 * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script,
631
+	 * but before the wordpress hook wp_loaded
632
+	 *
633
+	 * @throws \EE_Error
634
+	 */
635
+	public function _enqueue_and_localize_form_js()
636
+	{
637
+		$this->ensure_construct_finalized_called();
638
+		//actually, we don't want to localize just yet. There may be other forms on the page.
639
+		//so we need to add our form section data to a static variable accessible by all form sections
640
+		//and localize it just before the footer
641
+		$this->localize_validation_rules();
642
+		add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2);
643
+		add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'));
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * add our form section data to a static variable accessible by all form sections
650
+	 *
651
+	 * @param bool $return_for_subsection
652
+	 * @return void
653
+	 * @throws \EE_Error
654
+	 */
655
+	public function localize_validation_rules($return_for_subsection = false)
656
+	{
657
+		// we only want to localize vars ONCE for the entire form,
658
+		// so if the form section doesn't have a parent, then it must be the top dog
659
+		if ($return_for_subsection || ! $this->parent_section()) {
660
+			EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array(
661
+				'form_section_id'  => $this->html_id(true),
662
+				'validation_rules' => $this->get_jquery_validation_rules(),
663
+				'other_data'       => $this->get_other_js_data(),
664
+				'errors'           => $this->subsection_validation_errors_by_html_name(),
665
+			);
666
+			EE_Form_Section_Proper::$_scripts_localized = true;
667
+		}
668
+	}
669
+
670
+
671
+
672
+	/**
673
+	 * Gets an array of extra data that will be useful for client-side javascript.
674
+	 * This is primarily data added by inputs and forms in addition to any
675
+	 * scripts they might enqueue
676
+	 *
677
+	 * @param array $form_other_js_data
678
+	 * @return array
679
+	 */
680
+	public function get_other_js_data($form_other_js_data = array())
681
+	{
682
+		foreach ($this->subsections() as $subsection) {
683
+			$form_other_js_data = $subsection->get_other_js_data($form_other_js_data);
684
+		}
685
+		return $form_other_js_data;
686
+	}
687
+
688
+
689
+
690
+	/**
691
+	 * Gets a flat array of inputs for this form section and its subsections.
692
+	 * Keys are their form names, and values are the inputs themselves
693
+	 *
694
+	 * @return EE_Form_Input_Base
695
+	 */
696
+	public function inputs_in_subsections()
697
+	{
698
+		$inputs = array();
699
+		foreach ($this->subsections() as $subsection) {
700
+			if ($subsection instanceof EE_Form_Input_Base) {
701
+				$inputs[$subsection->html_name()] = $subsection;
702
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
703
+				$inputs += $subsection->inputs_in_subsections();
704
+			}
705
+		}
706
+		return $inputs;
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * Gets a flat array of all the validation errors.
713
+	 * Keys are html names (because those should be unique)
714
+	 * and values are a string of all their validation errors
715
+	 *
716
+	 * @return string[]
717
+	 */
718
+	public function subsection_validation_errors_by_html_name()
719
+	{
720
+		$inputs = $this->inputs();
721
+		$errors = array();
722
+		foreach ($inputs as $form_input) {
723
+			if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) {
724
+				$errors[$form_input->html_name()] = $form_input->get_validation_error_string();
725
+			}
726
+		}
727
+		return $errors;
728
+	}
729
+
730
+
731
+
732
+	/**
733
+	 * passes all the form data required by the JS to the JS, and enqueues the few required JS files.
734
+	 * Should be setup by each form during the _enqueues_and_localize_form_js
735
+	 */
736
+	public static function localize_script_for_all_forms()
737
+	{
738
+		//allow inputs and stuff to hook in their JS and stuff here
739
+		do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin');
740
+		EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages();
741
+		$email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level)
742
+			? EE_Registry::instance()->CFG->registration->email_validation_level
743
+			: 'wp_default';
744
+		EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level;
745
+		wp_enqueue_script('ee_form_section_validation');
746
+		wp_localize_script(
747
+			'ee_form_section_validation',
748
+			'ee_form_section_vars',
749
+			EE_Form_Section_Proper::$_js_localization
750
+		);
751
+	}
752
+
753
+
754
+
755
+	/**
756
+	 * ensure_scripts_localized
757
+	 */
758
+	public function ensure_scripts_localized()
759
+	{
760
+		if ( ! EE_Form_Section_Proper::$_scripts_localized) {
761
+			$this->_enqueue_and_localize_form_js();
762
+		}
763
+	}
764
+
765
+
766
+
767
+	/**
768
+	 * Gets the hard-coded validation error messages to be used in the JS. The convention
769
+	 * is that the key here should be the same as the custom validation rule put in the JS file
770
+	 *
771
+	 * @return array keys are custom validation rules, and values are internationalized strings
772
+	 */
773
+	private static function _get_localized_error_messages()
774
+	{
775
+		return array(
776
+			'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"),
777
+			'regex'    => __('Please check your input', 'event_espresso'),
778
+		);
779
+	}
780
+
781
+
782
+
783
+	/**
784
+	 * @return array
785
+	 */
786
+	public static function js_localization()
787
+	{
788
+		return self::$_js_localization;
789
+	}
790
+
791
+
792
+
793
+	/**
794
+	 * @return array
795
+	 */
796
+	public static function reset_js_localization()
797
+	{
798
+		self::$_js_localization = array();
799
+	}
800
+
801
+
802
+
803
+	/**
804
+	 * Gets the JS to put inside the jquery validation rules for subsection of this form section.
805
+	 * See parent function for more...
806
+	 *
807
+	 * @return array
808
+	 */
809
+	public function get_jquery_validation_rules()
810
+	{
811
+		$jquery_validation_rules = array();
812
+		foreach ($this->get_validatable_subsections() as $subsection) {
813
+			$jquery_validation_rules = array_merge(
814
+				$jquery_validation_rules,
815
+				$subsection->get_jquery_validation_rules()
816
+			);
817
+		}
818
+		return $jquery_validation_rules;
819
+	}
820
+
821
+
822
+
823
+	/**
824
+	 * Sanitizes all the data and sets the sanitized value of each field
825
+	 *
826
+	 * @param array $req_data like $_POST
827
+	 * @return void
828
+	 */
829
+	protected function _normalize($req_data)
830
+	{
831
+		$this->_received_submission = true;
832
+		$this->_validation_errors = array();
833
+		foreach ($this->get_validatable_subsections() as $subsection) {
834
+			try {
835
+				$subsection->_normalize($req_data);
836
+			} catch (EE_Validation_Error $e) {
837
+				$subsection->add_validation_error($e);
838
+			}
839
+		}
840
+	}
841
+
842
+
843
+
844
+	/**
845
+	 * Performs validation on this form section and its subsections.
846
+	 * For each subsection,
847
+	 * calls _validate_{subsection_name} on THIS form (if the function exists)
848
+	 * and passes it the subsection, then calls _validate on that subsection.
849
+	 * If you need to perform validation on the form as a whole (considering multiple)
850
+	 * you would be best to override this _validate method,
851
+	 * calling parent::_validate() first.
852
+	 */
853
+	protected function _validate()
854
+	{
855
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
856
+			if (method_exists($this, '_validate_' . $subsection_name)) {
857
+				call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection));
858
+			}
859
+			$subsection->_validate();
860
+		}
861
+	}
862
+
863
+
864
+
865
+	/**
866
+	 * Gets all the validated inputs for the form section
867
+	 *
868
+	 * @return array
869
+	 */
870
+	public function valid_data()
871
+	{
872
+		$inputs = array();
873
+		foreach ($this->subsections() as $subsection_name => $subsection) {
874
+			if ($subsection instanceof EE_Form_Section_Proper) {
875
+				$inputs[$subsection_name] = $subsection->valid_data();
876
+			} else if ($subsection instanceof EE_Form_Input_Base) {
877
+				$inputs[$subsection_name] = $subsection->normalized_value();
878
+			}
879
+		}
880
+		return $inputs;
881
+	}
882
+
883
+
884
+
885
+	/**
886
+	 * Gets all the inputs on this form section
887
+	 *
888
+	 * @return EE_Form_Input_Base[]
889
+	 */
890
+	public function inputs()
891
+	{
892
+		$inputs = array();
893
+		foreach ($this->subsections() as $subsection_name => $subsection) {
894
+			if ($subsection instanceof EE_Form_Input_Base) {
895
+				$inputs[$subsection_name] = $subsection;
896
+			}
897
+		}
898
+		return $inputs;
899
+	}
900
+
901
+
902
+
903
+	/**
904
+	 * Gets all the subsections which are a proper form
905
+	 *
906
+	 * @return EE_Form_Section_Proper[]
907
+	 */
908
+	public function subforms()
909
+	{
910
+		$form_sections = array();
911
+		foreach ($this->subsections() as $name => $obj) {
912
+			if ($obj instanceof EE_Form_Section_Proper) {
913
+				$form_sections[$name] = $obj;
914
+			}
915
+		}
916
+		return $form_sections;
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * Gets all the subsections (inputs, proper subsections, or html-only sections).
923
+	 * Consider using inputs() or subforms()
924
+	 * if you only want form inputs or proper form sections.
925
+	 *
926
+	 * @return EE_Form_Section_Proper[]
927
+	 */
928
+	public function subsections()
929
+	{
930
+		$this->ensure_construct_finalized_called();
931
+		return $this->_subsections;
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * Returns a simple array where keys are input names, and values are their normalized
938
+	 * values. (Similar to calling get_input_value on inputs)
939
+	 *
940
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
941
+	 *                                        or just this forms' direct children inputs
942
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
943
+	 *                                        or allow multidimensional array
944
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
945
+	 *                                        with array keys being input names
946
+	 *                                        (regardless of whether they are from a subsection or not),
947
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
948
+	 *                                        where keys are always subsection names and values are either
949
+	 *                                        the input's normalized value, or an array like the top-level array
950
+	 */
951
+	public function input_values($include_subform_inputs = false, $flatten = false)
952
+	{
953
+		return $this->_input_values(false, $include_subform_inputs, $flatten);
954
+	}
955
+
956
+
957
+
958
+	/**
959
+	 * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value'
960
+	 * of each input. On some inputs (especially radio boxes or checkboxes), the value stored
961
+	 * is not necessarily the value we want to display to users. This creates an array
962
+	 * where keys are the input names, and values are their display values
963
+	 *
964
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
965
+	 *                                        or just this forms' direct children inputs
966
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
967
+	 *                                        or allow multidimensional array
968
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array
969
+	 *                                        with array keys being input names
970
+	 *                                        (regardless of whether they are from a subsection or not),
971
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
972
+	 *                                        where keys are always subsection names and values are either
973
+	 *                                        the input's normalized value, or an array like the top-level array
974
+	 */
975
+	public function input_pretty_values($include_subform_inputs = false, $flatten = false)
976
+	{
977
+		return $this->_input_values(true, $include_subform_inputs, $flatten);
978
+	}
979
+
980
+
981
+
982
+	/**
983
+	 * Gets the input values from the form
984
+	 *
985
+	 * @param boolean $pretty                 Whether to retrieve the pretty value,
986
+	 *                                        or just the normalized value
987
+	 * @param boolean $include_subform_inputs Whether to include inputs from subforms,
988
+	 *                                        or just this forms' direct children inputs
989
+	 * @param boolean $flatten                Whether to force the results into 1-dimensional array,
990
+	 *                                        or allow multidimensional array
991
+	 * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being
992
+	 *                                        input names (regardless of whether they are from a subsection or not),
993
+	 *                                        and if $flatten is FALSE it can be a multidimensional array
994
+	 *                                        where keys are always subsection names and values are either
995
+	 *                                        the input's normalized value, or an array like the top-level array
996
+	 */
997
+	public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false)
998
+	{
999
+		$input_values = array();
1000
+		foreach ($this->subsections() as $subsection_name => $subsection) {
1001
+			if ($subsection instanceof EE_Form_Input_Base) {
1002
+				$input_values[$subsection_name] = $pretty
1003
+					? $subsection->pretty_value()
1004
+					: $subsection->normalized_value();
1005
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) {
1006
+				$subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten);
1007
+				if ($flatten) {
1008
+					$input_values = array_merge($input_values, $subform_input_values);
1009
+				} else {
1010
+					$input_values[$subsection_name] = $subform_input_values;
1011
+				}
1012
+			}
1013
+		}
1014
+		return $input_values;
1015
+	}
1016
+
1017
+
1018
+
1019
+	/**
1020
+	 * Gets the originally submitted input values from the form
1021
+	 *
1022
+	 * @param boolean $include_subforms  Whether to include inputs from subforms,
1023
+	 *                                   or just this forms' direct children inputs
1024
+	 * @return array                     if $flatten is TRUE it will always be a 1-dimensional array
1025
+	 *                                   with array keys being input names
1026
+	 *                                   (regardless of whether they are from a subsection or not),
1027
+	 *                                   and if $flatten is FALSE it can be a multidimensional array
1028
+	 *                                   where keys are always subsection names and values are either
1029
+	 *                                   the input's normalized value, or an array like the top-level array
1030
+	 */
1031
+	public function submitted_values($include_subforms = false)
1032
+	{
1033
+		$submitted_values = array();
1034
+		foreach ($this->subsections() as $subsection) {
1035
+			if ($subsection instanceof EE_Form_Input_Base) {
1036
+				// is this input part of an array of inputs?
1037
+				if (strpos($subsection->html_name(), '[') !== false) {
1038
+					$full_input_name = \EEH_Array::convert_array_values_to_keys(
1039
+						explode('[', str_replace(']', '', $subsection->html_name())),
1040
+						$subsection->raw_value()
1041
+					);
1042
+					$submitted_values = array_replace_recursive($submitted_values, $full_input_name);
1043
+				} else {
1044
+					$submitted_values[$subsection->html_name()] = $subsection->raw_value();
1045
+				}
1046
+			} else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) {
1047
+				$subform_input_values = $subsection->submitted_values($include_subforms);
1048
+				$submitted_values = array_replace_recursive($submitted_values, $subform_input_values);
1049
+			}
1050
+		}
1051
+		return $submitted_values;
1052
+	}
1053
+
1054
+
1055
+
1056
+	/**
1057
+	 * Indicates whether or not this form has received a submission yet
1058
+	 * (ie, had receive_form_submission called on it yet)
1059
+	 *
1060
+	 * @return boolean
1061
+	 * @throws \EE_Error
1062
+	 */
1063
+	public function has_received_submission()
1064
+	{
1065
+		$this->ensure_construct_finalized_called();
1066
+		return $this->_received_submission;
1067
+	}
1068
+
1069
+
1070
+
1071
+	/**
1072
+	 * Equivalent to passing 'exclude' in the constructor's options array.
1073
+	 * Removes the listed inputs from the form
1074
+	 *
1075
+	 * @param array $inputs_to_exclude values are the input names
1076
+	 * @return void
1077
+	 */
1078
+	public function exclude(array $inputs_to_exclude = array())
1079
+	{
1080
+		foreach ($inputs_to_exclude as $input_to_exclude_name) {
1081
+			unset($this->_subsections[$input_to_exclude_name]);
1082
+		}
1083
+	}
1084
+
1085
+
1086
+
1087
+	/**
1088
+	 * @param array $inputs_to_hide
1089
+	 * @throws \EE_Error
1090
+	 */
1091
+	public function hide(array $inputs_to_hide = array())
1092
+	{
1093
+		foreach ($inputs_to_hide as $input_to_hide) {
1094
+			$input = $this->get_input($input_to_hide);
1095
+			$input->set_display_strategy(new EE_Hidden_Display_Strategy());
1096
+		}
1097
+	}
1098
+
1099
+
1100
+
1101
+	/**
1102
+	 * add_subsections
1103
+	 * Adds the listed subsections to the form section.
1104
+	 * If $subsection_name_to_target is provided,
1105
+	 * then new subsections are added before or after that subsection,
1106
+	 * otherwise to the start or end of the entire subsections array.
1107
+	 *
1108
+	 * @param EE_Form_Section_Base[] $new_subsections           array of new form subsections
1109
+	 *                                                          where keys are their names
1110
+	 * @param string                 $subsection_name_to_target an existing for section that $new_subsections
1111
+	 *                                                          should be added before or after
1112
+	 *                                                          IF $subsection_name_to_target is null,
1113
+	 *                                                          then $new_subsections will be added to
1114
+	 *                                                          the beginning or end of the entire subsections array
1115
+	 * @param boolean                $add_before                whether to add $new_subsections, before or after
1116
+	 *                                                          $subsection_name_to_target,
1117
+	 *                                                          or if $subsection_name_to_target is null,
1118
+	 *                                                          before or after entire subsections array
1119
+	 * @return void
1120
+	 * @throws \EE_Error
1121
+	 */
1122
+	public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true)
1123
+	{
1124
+		foreach ($new_subsections as $subsection_name => $subsection) {
1125
+			if ( ! $subsection instanceof EE_Form_Section_Base) {
1126
+				EE_Error::add_error(
1127
+					sprintf(
1128
+						__(
1129
+							"Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.",
1130
+							"event_espresso"
1131
+						),
1132
+						get_class($subsection),
1133
+						$subsection_name,
1134
+						$this->name()
1135
+					)
1136
+				);
1137
+				unset($new_subsections[$subsection_name]);
1138
+			}
1139
+		}
1140
+		$this->_subsections = EEH_Array::insert_into_array(
1141
+			$this->_subsections,
1142
+			$new_subsections,
1143
+			$subsection_name_to_target,
1144
+			$add_before
1145
+		);
1146
+		if ($this->_construction_finalized) {
1147
+			foreach ($this->_subsections as $name => $subsection) {
1148
+				$subsection->_construct_finalize($this, $name);
1149
+			}
1150
+		}
1151
+	}
1152
+
1153
+
1154
+
1155
+	/**
1156
+	 * Just gets all validatable subsections to clean their sensitive data
1157
+	 */
1158
+	public function clean_sensitive_data()
1159
+	{
1160
+		foreach ($this->get_validatable_subsections() as $subsection) {
1161
+			$subsection->clean_sensitive_data();
1162
+		}
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * @param string $form_submission_error_message
1169
+	 */
1170
+	public function set_submission_error_message($form_submission_error_message = '')
1171
+	{
1172
+		$this->_form_submission_error_message .= ! empty($form_submission_error_message)
1173
+			? $form_submission_error_message
1174
+			: __('Form submission failed due to errors', 'event_espresso');
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * @return string
1181
+	 */
1182
+	public function submission_error_message()
1183
+	{
1184
+		return $this->_form_submission_error_message;
1185
+	}
1186
+
1187
+
1188
+
1189
+	/**
1190
+	 * @param string $form_submission_success_message
1191
+	 */
1192
+	public function set_submission_success_message($form_submission_success_message)
1193
+	{
1194
+		$this->_form_submission_success_message .= ! empty($form_submission_success_message)
1195
+			? $form_submission_success_message
1196
+			: __('Form submitted successfully', 'event_espresso');
1197
+	}
1198
+
1199
+
1200
+
1201
+	/**
1202
+	 * @return string
1203
+	 */
1204
+	public function submission_success_message()
1205
+	{
1206
+		return $this->_form_submission_success_message;
1207
+	}
1208
+
1209
+
1210
+
1211
+	/**
1212
+	 * Returns the prefix that should be used on child of this form section for
1213
+	 * their html names. If this form section itself has a parent, prepends ITS
1214
+	 * prefix onto this form section's prefix. Used primarily by
1215
+	 * EE_Form_Input_Base::_set_default_html_name_if_empty
1216
+	 *
1217
+	 * @return string
1218
+	 * @throws \EE_Error
1219
+	 */
1220
+	public function html_name_prefix()
1221
+	{
1222
+		if ($this->parent_section() instanceof EE_Form_Section_Proper) {
1223
+			return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']';
1224
+		} else {
1225
+			return $this->name();
1226
+		}
1227
+	}
1228
+
1229
+
1230
+
1231
+	/**
1232
+	 * Gets the name, but first checks _construct_finalize has been called. If not,
1233
+	 * calls it (assumes there is no parent and that we want the name to be whatever
1234
+	 * was set, which is probably nothing, or the classname)
1235
+	 *
1236
+	 * @return string
1237
+	 * @throws \EE_Error
1238
+	 */
1239
+	public function name()
1240
+	{
1241
+		$this->ensure_construct_finalized_called();
1242
+		return parent::name();
1243
+	}
1244
+
1245
+
1246
+
1247
+	/**
1248
+	 * @return EE_Form_Section_Proper
1249
+	 * @throws \EE_Error
1250
+	 */
1251
+	public function parent_section()
1252
+	{
1253
+		$this->ensure_construct_finalized_called();
1254
+		return parent::parent_section();
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * make sure construction finalized was called, otherwise children might not be ready
1261
+	 *
1262
+	 * @return void
1263
+	 * @throws \EE_Error
1264
+	 */
1265
+	public function ensure_construct_finalized_called()
1266
+	{
1267
+		if ( ! $this->_construction_finalized) {
1268
+			$this->_construct_finalize($this->_parent_section, $this->_name);
1269
+		}
1270
+	}
1271
+
1272
+
1273
+
1274
+	/**
1275
+	 * Checks if any of this form section's inputs, or any of its children's inputs,
1276
+	 * are in teh form data. If any are found, returns true. Else false
1277
+	 *
1278
+	 * @param array $req_data
1279
+	 * @return boolean
1280
+	 */
1281
+	public function form_data_present_in($req_data = null)
1282
+	{
1283
+		if ($req_data === null) {
1284
+			$req_data = $_POST;
1285
+		}
1286
+		foreach ($this->subsections() as $subsection) {
1287
+			if ($subsection instanceof EE_Form_Input_Base) {
1288
+				if ($subsection->form_data_present_in($req_data)) {
1289
+					return true;
1290
+				}
1291
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
1292
+				if ($subsection->form_data_present_in($req_data)) {
1293
+					return true;
1294
+				}
1295
+			}
1296
+		}
1297
+		return false;
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * Gets validation errors for this form section and subsections
1304
+	 * Similar to EE_Form_Section_Validatable::get_validation_errors() except this
1305
+	 * gets the validation errors for ALL subsection
1306
+	 *
1307
+	 * @return EE_Validation_Error[]
1308
+	 */
1309
+	public function get_validation_errors_accumulated()
1310
+	{
1311
+		$validation_errors = $this->get_validation_errors();
1312
+		foreach ($this->get_validatable_subsections() as $subsection) {
1313
+			if ($subsection instanceof EE_Form_Section_Proper) {
1314
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated();
1315
+			} else {
1316
+				$validation_errors_on_this_subsection = $subsection->get_validation_errors();
1317
+			}
1318
+			if ($validation_errors_on_this_subsection) {
1319
+				$validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection);
1320
+			}
1321
+		}
1322
+		return $validation_errors;
1323
+	}
1324
+
1325
+
1326
+
1327
+	/**
1328
+	 * This isn't just the name of an input, it's a path pointing to an input. The
1329
+	 * path is similar to a folder path: slash (/) means to descend into a subsection,
1330
+	 * dot-dot-slash (../) means to ascend into the parent section.
1331
+	 * After a series of slashes and dot-dot-slashes, there should be the name of an input,
1332
+	 * which will be returned.
1333
+	 * Eg, if you want the related input to be conditional on a sibling input name 'foobar'
1334
+	 * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name
1335
+	 * 'baz', use '../baz'. If you want it to be conditional on a cousin input,
1336
+	 * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'.
1337
+	 * Etc
1338
+	 *
1339
+	 * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false
1340
+	 * @return EE_Form_Section_Base
1341
+	 */
1342
+	public function find_section_from_path($form_section_path)
1343
+	{
1344
+		//check if we can find the input from purely going straight up the tree
1345
+		$input = parent::find_section_from_path($form_section_path);
1346
+		if ($input instanceof EE_Form_Section_Base) {
1347
+			return $input;
1348
+		}
1349
+		$next_slash_pos = strpos($form_section_path, '/');
1350
+		if ($next_slash_pos !== false) {
1351
+			$child_section_name = substr($form_section_path, 0, $next_slash_pos);
1352
+			$subpath = substr($form_section_path, $next_slash_pos + 1);
1353
+		} else {
1354
+			$child_section_name = $form_section_path;
1355
+			$subpath = '';
1356
+		}
1357
+		$child_section = $this->get_subsection($child_section_name);
1358
+		if ($child_section instanceof EE_Form_Section_Base) {
1359
+			return $child_section->find_section_from_path($subpath);
1360
+		} else {
1361
+			return null;
1362
+		}
1363
+	}
1364 1364
 
1365 1365
 }
1366 1366
 
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-thumbnail.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' &nbsp; <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
3 3
 global $post;
4
-do_action( 'AHEE_event_details_before_featured_img', $post );
4
+do_action('AHEE_event_details_before_featured_img', $post);
5 5
 
6
-if ( has_post_thumbnail( $post->ID )) :
7
-	if ( $img_ID = get_post_thumbnail_id( $post->ID )) :
8
-		if ( $featured_img = wp_get_attachment_image_src( $img_ID, 'large' )) :
9
-			$caption = esc_attr( get_post( get_post( $img_ID ))->post_excerpt );
6
+if (has_post_thumbnail($post->ID)) :
7
+	if ($img_ID = get_post_thumbnail_id($post->ID)) :
8
+		if ($featured_img = wp_get_attachment_image_src($img_ID, 'large')) :
9
+			$caption = esc_attr(get_post(get_post($img_ID))->post_excerpt);
10 10
 			?>
11 11
 <div id="ee-event-img-dv-<?php echo $post->ID; ?>" class="ee-event-img-dv">
12
-	<a class="ee-event-img-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target();?>>
12
+	<a class="ee-event-img-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target(); ?>>
13 13
 		<img class="ee-event-img" src="<?php echo $featured_img[0]; ?>" width="<?php echo $featured_img[1]; ?>" height="<?php echo $featured_img[2]; ?>" alt="<?php echo $caption; ?>"/>
14 14
 	</a>
15 15
 </div>
@@ -18,4 +18,4 @@  discard block
 block discarded – undo
18 18
 	endif;
19 19
 endif;
20 20
 ?>
21
-<?php do_action( 'AHEE_event_details_after_featured_img', $post );?>
21
+<?php do_action('AHEE_event_details_after_featured_img', $post); ?>
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-header.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@
 block discarded – undo
5 5
 ?>
6 6
 <header class="event-header">
7 7
 	<?php echo "<{$tag}  id=\"event-details-{$tag}-{$post->ID}\" class=\"entry-title\">"; ?>
8
-		<a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target();?>>
8
+		<a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target(); ?>>
9 9
             <?php the_title(); ?>
10 10
         </a>
11 11
 	<?php echo "</{$tag}"; ?>
12
-	<?php if ( ! is_archive() && has_excerpt( $post->ID )): the_excerpt(); endif;?>
12
+	<?php if ( ! is_archive() && has_excerpt($post->ID)): the_excerpt(); endif; ?>
13 13
 </header>
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 3 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	protected static $using_get_the_excerpt = false;
39 39
 
40
-    /**
41
-     * Used to flag when the event list is being called from an external iframe.
42
-     *
43
-     * @var bool $iframe
44
-     */
45
-    protected static $iframe = false;
46
-
47
-    /**
40
+	/**
41
+	 * Used to flag when the event list is being called from an external iframe.
42
+	 *
43
+	 * @var bool $iframe
44
+	 */
45
+	protected static $iframe = false;
46
+
47
+	/**
48 48
 	 * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button
49 49
 	 */
50 50
 	private static $_iframe_embed_button;
51 51
 
52
-    /**
52
+	/**
53 53
 	 * @type EE_Template_Part_Manager $template_parts
54 54
 	 */
55 55
 	protected $template_parts;
@@ -233,26 +233,26 @@  discard block
 block discarded – undo
233 233
 
234 234
 
235 235
 
236
-    /**
237
-     * @access    public
238
-     * @return    void
239
-     * @throws \EE_Error
240
-     * @throws \DomainException
241
-     */
236
+	/**
237
+	 * @access    public
238
+	 * @return    void
239
+	 * @throws \EE_Error
240
+	 * @throws \DomainException
241
+	 */
242 242
 	public function event_list_iframe() {
243
-        \EED_Events_Archive::$iframe = true;
243
+		\EED_Events_Archive::$iframe = true;
244 244
 		$event_list_iframe = new EventsArchiveIframe( $this );
245 245
 		$event_list_iframe->display();
246 246
 	}
247 247
 
248 248
 
249 249
 
250
-    /**
251
-     * @access public
252
-     * @return string
253
-     */
250
+	/**
251
+	 * @access public
252
+	 * @return string
253
+	 */
254 254
 	public static function link_target() {
255
-        return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
255
+		return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
256 256
 	}
257 257
 
258 258
 
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton;
4 4
 use EventEspresso\modules\events_archive\EventsArchiveIframe;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
6
+if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
7 7
 /**
8 8
  * Event Espresso
9 9
  *
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @return EED_Events_Archive
61 61
 	 */
62 62
 	public static function instance() {
63
-		return parent::get_instance( __CLASS__ );
63
+		return parent::get_instance(__CLASS__);
64 64
 	}
65 65
 
66 66
 
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
 	 *  @return 	void
73 73
 	 */
74 74
 	public static function set_hooks() {
75
-		EE_Config::register_route( EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run' );
76
-		EE_Config::register_route( 'event_list', 'Events_Archive', 'event_list' );
77
-		EE_Config::register_route( 'iframe', 'Events_Archive', 'event_list_iframe', 'event_list' );
78
-		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
75
+		EE_Config::register_route(EE_Registry::instance()->CFG->core->event_cpt_slug, 'Events_Archive', 'run');
76
+		EE_Config::register_route('event_list', 'Events_Archive', 'event_list');
77
+		EE_Config::register_route('iframe', 'Events_Archive', 'event_list_iframe', 'event_list');
78
+		add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
79 79
 	}
80 80
 
81 81
 	/**
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 	 *  @return 	void
86 86
 	 */
87 87
 	public static function set_hooks_admin() {
88
-		add_action( 'wp_loaded', array( 'EED_Events_Archive', 'set_definitions' ), 2 );
88
+		add_action('wp_loaded', array('EED_Events_Archive', 'set_definitions'), 2);
89 89
 		// hook into the end of the \EE_Admin_Page::_load_page_dependencies()
90 90
 		// to load assets for "espresso_events" page on the "default" route (action)
91 91
 		add_action(
92 92
 			'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__default',
93
-			array( 'EED_Events_Archive', 'event_list_iframe_embed_button' ),
93
+			array('EED_Events_Archive', 'event_list_iframe_embed_button'),
94 94
 			10
95 95
 		);
96 96
 	}
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 *  @return 	void
106 106
 	 */
107 107
 	public static function set_definitions() {
108
-		define( 'EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS );
109
-		define( 'EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
108
+		define('EVENTS_ARCHIVE_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
109
+		define('EVENTS_ARCHIVE_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
110 110
 	}
111 111
 
112 112
 
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 	/**
115 115
 	 * set up EE_Events_Archive_Config
116 116
 	 */
117
-	protected function set_config(){
118
-		$this->set_config_section( 'template_settings' );
119
-		$this->set_config_class( 'EE_Events_Archive_Config' );
120
-		$this->set_config_name( 'EED_Events_Archive' );
117
+	protected function set_config() {
118
+		$this->set_config_section('template_settings');
119
+		$this->set_config_class('EE_Events_Archive_Config');
120
+		$this->set_config_name('EED_Events_Archive');
121 121
 	}
122 122
 
123 123
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @return EventListIframeEmbedButton
127 127
 	 */
128 128
 	public static function get_iframe_embed_button() {
129
-		if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton ) {
129
+		if ( ! self::$_iframe_embed_button instanceof EventListIframeEmbedButton) {
130 130
 			self::$_iframe_embed_button = new EventListIframeEmbedButton();
131 131
 		}
132 132
 		return self::$_iframe_embed_button;
@@ -152,35 +152,35 @@  discard block
 block discarded – undo
152 152
 	 * @param \EE_Events_Archive_Config $config
153 153
 	 * @return \EE_Template_Part_Manager
154 154
 	 */
155
-	public function initialize_template_parts( EE_Events_Archive_Config $config = null ) {
155
+	public function initialize_template_parts(EE_Events_Archive_Config $config = null) {
156 156
 		$config = $config instanceof EE_Events_Archive_Config ? $config : $this->config();
157 157
 		EEH_Autoloader::instance()->register_template_part_autoloaders();
158 158
 		$template_parts = new EE_Template_Part_Manager();
159 159
 		$template_parts->add_template_part(
160 160
 			'tickets',
161
-			__( 'Ticket Selector', 'event_espresso' ),
161
+			__('Ticket Selector', 'event_espresso'),
162 162
 			'content-espresso_events-tickets.php',
163 163
 			$config->display_order_tickets
164 164
 		);
165 165
 		$template_parts->add_template_part(
166 166
 			'datetimes',
167
-			__( 'Dates and Times', 'event_espresso' ),
167
+			__('Dates and Times', 'event_espresso'),
168 168
 			'content-espresso_events-datetimes.php',
169 169
 			$config->display_order_datetimes
170 170
 		);
171 171
 		$template_parts->add_template_part(
172 172
 			'event',
173
-			__( 'Event Description', 'event_espresso' ),
173
+			__('Event Description', 'event_espresso'),
174 174
 			'content-espresso_events-details.php',
175 175
 			$config->display_order_event
176 176
 		);
177 177
 		$template_parts->add_template_part(
178 178
 			'venue',
179
-			__( 'Venue Information', 'event_espresso' ),
179
+			__('Venue Information', 'event_espresso'),
180 180
 			'content-espresso_events-venues.php',
181 181
 			$config->display_order_venue
182 182
 		);
183
-		do_action( 'AHEE__EED_Event_Archive__initialize_template_parts', $template_parts );
183
+		do_action('AHEE__EED_Event_Archive__initialize_template_parts', $template_parts);
184 184
 		return $template_parts;
185 185
 	}
186 186
 
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	 * @param WP $WP
194 194
 	 * @return    void
195 195
 	 */
196
-	public function run( $WP ) {
197
-		do_action( 'AHEE__EED_Events_Archive__before_run' );
196
+	public function run($WP) {
197
+		do_action('AHEE__EED_Events_Archive__before_run');
198 198
 		// ensure valid EE_Events_Archive_Config() object exists
199 199
 		$this->set_config();
200 200
 		/** @type EE_Events_Archive_Config $config */
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 		EEH_Event_Query::add_query_filters();
207 207
 		// set params that will get used by the filters
208 208
 		EEH_Event_Query::set_query_params(
209
-			'', 	// month
210
-			'', 	// category
211
-			$config->display_expired_events, 	// show_expired
212
-			'start_date', 	// orderby
209
+			'', // month
210
+			'', // category
211
+			$config->display_expired_events, // show_expired
212
+			'start_date', // orderby
213 213
 			'ASC' 	// sort
214 214
 		);
215 215
 		// check what template is loaded
216
-		add_filter( 'template_include',  array( $this, 'template_include' ), 999, 1 );
216
+		add_filter('template_include', array($this, 'template_include'), 999, 1);
217 217
 	}
218 218
 
219 219
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
 	public function event_list_iframe() {
243 243
         \EED_Events_Archive::$iframe = true;
244
-		$event_list_iframe = new EventsArchiveIframe( $this );
244
+		$event_list_iframe = new EventsArchiveIframe($this);
245 245
 		$event_list_iframe->display();
246 246
 	}
247 247
 
@@ -269,32 +269,32 @@  discard block
 block discarded – undo
269 269
 	 * @param string $template
270 270
 	 * @return    string
271 271
 	 */
272
-	public function template_include( $template = '' ) {
272
+	public function template_include($template = '') {
273 273
 		// don't add content filter for dedicated EE child themes or private posts
274
-		if ( ! EEH_Template::is_espresso_theme() ) {
274
+		if ( ! EEH_Template::is_espresso_theme()) {
275 275
 			/** @type EE_Events_Archive_Config $config */
276 276
 			$config = $this->config();
277 277
 			// add status banner ?
278
-			if ( $config->display_status_banner ) {
279
-				add_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100, 2 );
278
+			if ($config->display_status_banner) {
279
+				add_filter('the_title', array('EED_Events_Archive', 'the_title'), 100, 2);
280 280
 			}
281 281
 			// if NOT a custom template
282 282
 			if (
283
-				EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php'
284
-				|| apply_filters( 'FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', FALSE )
283
+				EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php'
284
+				|| apply_filters('FHEE__EED_Event_Archive__template_include__allow_custom_selected_template', FALSE)
285 285
 			) {
286 286
 				// don't display entry meta because the existing theme will take care of that
287
-				add_filter( 'FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true' );
287
+				add_filter('FHEE__EED_Events_Archive__template_include__events_list_active', '__return_true');
288 288
 			// load functions.php file for the theme (loaded by WP if using child theme)
289 289
 				EEH_Template::load_espresso_theme_functions();
290 290
 				// because we don't know if the theme is using the_excerpt()
291
-				add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
291
+				add_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100, 1);
292 292
 				// or the_content
293
-				add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
293
+				add_filter('the_content', array('EED_Events_Archive', 'event_details'), 100, 1);
294 294
 				// and just in case they are running get_the_excerpt() which DESTROYS things
295
-				add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
295
+				add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
296 296
 				// don't display entry meta because the existing theme will take care of that
297
-				add_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
297
+				add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
298 298
 			}
299 299
 		}
300 300
 		return $template;
@@ -309,17 +309,17 @@  discard block
 block discarded – undo
309 309
 	 * 	@param		string 	$excerpt
310 310
 	 * 	@return 		string
311 311
 	 */
312
-	public static function get_the_excerpt( $excerpt = '' ) {
313
-		if ( post_password_required() ) {
312
+	public static function get_the_excerpt($excerpt = '') {
313
+		if (post_password_required()) {
314 314
 			return $excerpt;
315 315
 		}
316
-		if ( apply_filters( 'FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false ) ) {
317
-			remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
318
-			remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
319
-			$excerpt = EED_Events_Archive::event_details( $excerpt );
316
+		if (apply_filters('FHEE__EED_Events_Archive__get_the_excerpt__theme_uses_get_the_excerpt', false)) {
317
+			remove_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100);
318
+			remove_filter('the_content', array('EED_Events_Archive', 'event_details'), 100);
319
+			$excerpt = EED_Events_Archive::event_details($excerpt);
320 320
 		} else {
321 321
 			EED_Events_Archive::$using_get_the_excerpt = true;
322
-			add_filter( 'wp_trim_excerpt', array( 'EED_Events_Archive', 'end_get_the_excerpt' ), 999, 1 );
322
+			add_filter('wp_trim_excerpt', array('EED_Events_Archive', 'end_get_the_excerpt'), 999, 1);
323 323
 		}
324 324
 		return $excerpt;
325 325
 	}
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @param  string $text
334 334
 	 * @return string
335 335
 	 */
336
-	public static function end_get_the_excerpt( $text = '' ) {
336
+	public static function end_get_the_excerpt($text = '') {
337 337
 		EED_Events_Archive::$using_get_the_excerpt = false;
338 338
 		return $text;
339 339
 	}
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
 	 * @param 		string 		$id
349 349
 	 * @return 		string
350 350
 	 */
351
-	public static function the_title( $title = '', $id = '' ) {
351
+	public static function the_title($title = '', $id = '') {
352 352
 	global $post;
353
-	if ( $post instanceof WP_Post ) {
354
-		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner( $post->ID  ) . $title :  $title;
353
+	if ($post instanceof WP_Post) {
354
+		return in_the_loop() && $post->ID == $id ? espresso_event_status_banner($post->ID).$title : $title;
355 355
 	}
356 356
 	return $title;
357 357
 }
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * 	@param		string 	$content
366 366
 	 * 	@return 		string
367 367
 	 */
368
-	public static function event_details( $content ) {
368
+	public static function event_details($content) {
369 369
 		global $post;
370 370
 		static $current_post_ID = 0;
371 371
 		if (
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 			&& ! EED_Events_Archive::$using_get_the_excerpt
375 375
 			&& ! post_password_required()
376 376
 			&& (
377
-				apply_filters( 'FHEE__EES_Espresso_Events__process_shortcode__true', false )
378
-				|| ! apply_filters( 'FHEE__content_espresso_events__template_loaded', false )
377
+				apply_filters('FHEE__EES_Espresso_Events__process_shortcode__true', false)
378
+				|| ! apply_filters('FHEE__content_espresso_events__template_loaded', false)
379 379
 			)
380 380
 		) {
381 381
 			// Set current post ID to prevent showing content twice, but only if headers have definitely been sent.
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 			// We want to allow those plugins to still do their thing and have access to our content, but depending on
385 385
 			// how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice,
386 386
 			// so the following allows this filter to be applied multiple times, but only once for real
387
-			$current_post_ID = did_action( 'loop_start' ) ? $post->ID : 0;
388
-			if ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order ) {
387
+			$current_post_ID = did_action('loop_start') ? $post->ID : 0;
388
+			if (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->use_sortable_display_order) {
389 389
 				$content = \EED_Events_Archive::use_sortable_display_order();
390 390
 			} else {
391 391
 				$content = \EED_Events_Archive::use_filterable_display_order();
@@ -404,20 +404,20 @@  discard block
 block discarded – undo
404 404
 	 */
405 405
 	protected static function use_sortable_display_order() {
406 406
 		// no further password checks required atm
407
-		add_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
407
+		add_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
408 408
 		// we need to first remove this callback from being applied to the_content() or the_excerpt() (otherwise it will recurse and blow up the interweb)
409
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
410
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
411
-		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
409
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100);
410
+		remove_filter('the_content', array('EED_Events_Archive', 'event_details'), 100);
411
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
412 412
 		// now add additional content depending on whether event is using the_excerpt() or the_content()
413 413
 		EED_Events_Archive::instance()->template_parts = EED_Events_Archive::instance()->initialize_template_parts();
414
-		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
415
-		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters( $content );
414
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
415
+		$content = EED_Events_Archive::instance()->template_parts->apply_template_part_filters($content);
416 416
 		// re-add our main filters (or else the next event won't have them)
417
-		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
418
-		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
419
-		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
420
-		remove_filter( 'FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true' );
417
+		add_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100, 1);
418
+		add_filter('the_content', array('EED_Events_Archive', 'event_details'), 100, 1);
419
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
420
+		remove_filter('FHEE__EED_Events_Archive__event_details__no_post_password_required', '__return_true');
421 421
 		return $content;
422 422
 	}
423 423
 
@@ -432,22 +432,22 @@  discard block
 block discarded – undo
432 432
 	protected static function use_filterable_display_order() {
433 433
 		// we need to first remove this callback from being applied to the_content()
434 434
 		// (otherwise it will recurse and blow up the interweb)
435
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
436
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
437
-		remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
435
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100);
436
+		remove_filter('the_content', array('EED_Events_Archive', 'event_details'), 100);
437
+		remove_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1);
438 438
 		//now add additional content depending on whether event is using the_excerpt() or the_content()
439 439
 		EED_Events_Archive::_add_additional_excerpt_filters();
440 440
 		EED_Events_Archive::_add_additional_content_filters();
441
-		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters' );
441
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_add_filters');
442 442
 		// now load our template
443
-		$content = EEH_Template::locate_template( 'content-espresso_events-details.php' );
443
+		$content = EEH_Template::locate_template('content-espresso_events-details.php');
444 444
 		// re-add our main filters (or else the next event won't have them)
445
-		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
446
-		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100, 1 );
447
-		add_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1, 1 );
445
+		add_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100, 1);
446
+		add_filter('the_content', array('EED_Events_Archive', 'event_details'), 100, 1);
447
+		add_filter('get_the_excerpt', array('EED_Events_Archive', 'get_the_excerpt'), 1, 1);
448 448
 		// but remove the other filters so that they don't get applied to the next post
449 449
 		EED_Events_Archive::_remove_additional_events_archive_filters();
450
-		do_action( 'AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters' );
450
+		do_action('AHEE__EED_Events_Archive__use_filterable_display_order__after_remove_filters');
451 451
 		// we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt)
452 452
 		//return ! empty( $template ) ? $template : $content;
453 453
 		return $content;
@@ -462,11 +462,11 @@  discard block
 block discarded – undo
462 462
 	 * 	@param		string 	$content
463 463
 	 *  	@return 		string
464 464
 	 */
465
-	public static function event_datetimes( $content ) {
466
-		if ( post_password_required() ) {
465
+	public static function event_datetimes($content) {
466
+		if (post_password_required()) {
467 467
 			return $content;
468 468
 		}
469
-		return EEH_Template::locate_template( 'content-espresso_events-datetimes.php' ) . $content;
469
+		return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content;
470 470
 	}
471 471
 
472 472
 	/**
@@ -476,11 +476,11 @@  discard block
 block discarded – undo
476 476
 	 * 	@param		string 	$content
477 477
 	 *  	@return 		string
478 478
 	 */
479
-	public static function event_tickets( $content ) {
480
-		if ( post_password_required() ) {
479
+	public static function event_tickets($content) {
480
+		if (post_password_required()) {
481 481
 			return $content;
482 482
 		}
483
-		return EEH_Template::locate_template( 'content-espresso_events-tickets.php' ) . $content;
483
+		return EEH_Template::locate_template('content-espresso_events-tickets.php').$content;
484 484
 	}
485 485
 
486 486
 
@@ -492,8 +492,8 @@  discard block
 block discarded – undo
492 492
 	 * @param    string $content
493 493
 	 * @return    string
494 494
 	 */
495
-	public static function event_venue( $content ) {
496
-		return EED_Events_Archive::event_venues( $content );
495
+	public static function event_venue($content) {
496
+		return EED_Events_Archive::event_venues($content);
497 497
 	}
498 498
 
499 499
 	/**
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 	 * 	@param		string 	$content
504 504
 	 *  	@return 		string
505 505
 	 */
506
-	public static function event_venues( $content ) {
507
-		if ( post_password_required() ) {
506
+	public static function event_venues($content) {
507
+		if (post_password_required()) {
508 508
 			return $content;
509 509
 		}
510
-		return $content . EEH_Template::locate_template( 'content-espresso_events-venues.php' );
510
+		return $content.EEH_Template::locate_template('content-espresso_events-venues.php');
511 511
 	}
512 512
 
513 513
 
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
 	 * @return        void
520 520
 	 */
521 521
 	private static function _add_additional_excerpt_filters() {
522
-		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
523
-		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
524
-		add_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
522
+		add_filter('the_excerpt', array('EED_Events_Archive', 'event_datetimes'), 110, 1);
523
+		add_filter('the_excerpt', array('EED_Events_Archive', 'event_tickets'), 120, 1);
524
+		add_filter('the_excerpt', array('EED_Events_Archive', 'event_venues'), 130, 1);
525 525
 	}
526 526
 
527 527
 
@@ -533,9 +533,9 @@  discard block
 block discarded – undo
533 533
 	 * @return        void
534 534
 	 */
535 535
 	private static function _add_additional_content_filters() {
536
-		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110, 1 );
537
-		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120, 1 );
538
-		add_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130, 1 );
536
+		add_filter('the_content', array('EED_Events_Archive', 'event_datetimes'), 110, 1);
537
+		add_filter('the_content', array('EED_Events_Archive', 'event_tickets'), 120, 1);
538
+		add_filter('the_content', array('EED_Events_Archive', 'event_venues'), 130, 1);
539 539
 	}
540 540
 
541 541
 
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
 	 * @return        void
548 548
 	 */
549 549
 	private static function _remove_additional_events_archive_filters() {
550
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
551
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
552
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
553
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
554
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
555
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
550
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_datetimes'), 110);
551
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_tickets'), 120);
552
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_venues'), 130);
553
+		remove_filter('the_content', array('EED_Events_Archive', 'event_datetimes'), 110);
554
+		remove_filter('the_content', array('EED_Events_Archive', 'event_tickets'), 120);
555
+		remove_filter('the_content', array('EED_Events_Archive', 'event_venues'), 130);
556 556
 	}
557 557
 
558 558
 
@@ -565,17 +565,17 @@  discard block
 block discarded – undo
565 565
 	 */
566 566
 	public static function remove_all_events_archive_filters() {
567 567
 		//remove_filter( 'get_the_excerpt', array( 'EED_Events_Archive', 'get_the_excerpt' ), 1 );
568
-		remove_filter( 'the_title', array( 'EED_Events_Archive', 'the_title' ), 100 );
569
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_details' ), 100 );
570
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
571
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
572
-		remove_filter( 'the_excerpt', array( 'EED_Events_Archive', 'event_venues' ), 130 );
573
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_details' ), 100 );
574
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_datetimes' ), 110 );
575
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_tickets' ), 120 );
576
-		remove_filter( 'the_content', array( 'EED_Events_Archive', 'event_venues' ), 130 );
568
+		remove_filter('the_title', array('EED_Events_Archive', 'the_title'), 100);
569
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_details'), 100);
570
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_datetimes'), 110);
571
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_tickets'), 120);
572
+		remove_filter('the_excerpt', array('EED_Events_Archive', 'event_venues'), 130);
573
+		remove_filter('the_content', array('EED_Events_Archive', 'event_details'), 100);
574
+		remove_filter('the_content', array('EED_Events_Archive', 'event_datetimes'), 110);
575
+		remove_filter('the_content', array('EED_Events_Archive', 'event_tickets'), 120);
576
+		remove_filter('the_content', array('EED_Events_Archive', 'event_venues'), 130);
577 577
 		// don't display entry meta because the existing theme will take care of that
578
-		remove_filter( 'FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false' );
578
+		remove_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false');
579 579
 	}
580 580
 
581 581
 
@@ -590,12 +590,12 @@  discard block
 block discarded – undo
590 590
 	 *  @return 	void
591 591
 	 */
592 592
 	public function load_event_list_assets() {
593
-		do_action( 'AHEE__EED_Events_Archive__before_load_assets' );
594
-		add_filter( 'FHEE_load_EE_Session', '__return_true' );
595
-		add_filter( 'FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true' );
596
-		add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 );
597
-		if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) {
598
-			add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 );
593
+		do_action('AHEE__EED_Events_Archive__before_load_assets');
594
+		add_filter('FHEE_load_EE_Session', '__return_true');
595
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
596
+		add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10);
597
+		if (EE_Registry::instance()->CFG->map_settings->use_google_maps) {
598
+			add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11);
599 599
 		}
600 600
 	}
601 601
 
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
612 612
 	 */
613 613
 	public function wp_enqueue_scripts() {
614 614
 		// get some style
615
-		if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) {
615
+		if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) {
616 616
 			// first check uploads folder
617
-			if ( EEH_File::is_readable( get_stylesheet_directory() . $this->theme . DS . 'style.css' )) {
618
-				wp_register_style( $this->theme, get_stylesheet_directory_uri() . $this->theme . DS . 'style.css', array( 'dashicons', 'espresso_default' ));
617
+			if (EEH_File::is_readable(get_stylesheet_directory().$this->theme.DS.'style.css')) {
618
+				wp_register_style($this->theme, get_stylesheet_directory_uri().$this->theme.DS.'style.css', array('dashicons', 'espresso_default'));
619 619
 			} else {
620 620
 		}
621
-		wp_enqueue_style( $this->theme );
621
+		wp_enqueue_style($this->theme);
622 622
 
623 623
 	}
624 624
 }
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
 	 */
637 637
 	public static function template_settings_form() {
638 638
 	$template_settings = EE_Registry::instance()->CFG->template_settings;
639
-	$template_settings->EED_Events_Archive = isset( $template_settings->EED_Events_Archive ) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
640
-	$template_settings->EED_Events_Archive = apply_filters( 'FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive );
639
+	$template_settings->EED_Events_Archive = isset($template_settings->EED_Events_Archive) ? $template_settings->EED_Events_Archive : new EE_Events_Archive_Config();
640
+	$template_settings->EED_Events_Archive = apply_filters('FHEE__EED_Events_Archive__template_settings_form__event_list_config', $template_settings->EED_Events_Archive);
641 641
 	$events_archive_settings = array(
642 642
 		'display_status_banner' => 0,
643 643
 		'display_description' => 1,
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 		'display_venue' => 0,
647 647
 		'display_expired_events' => 0
648 648
 	);
649
-	$events_archive_settings = array_merge( $events_archive_settings, (array)$template_settings->EED_Events_Archive );
650
-	EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $events_archive_settings );
649
+	$events_archive_settings = array_merge($events_archive_settings, (array) $template_settings->EED_Events_Archive);
650
+	EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $events_archive_settings);
651 651
 }
652 652
 
653 653
 
@@ -663,16 +663,16 @@  discard block
 block discarded – undo
663 663
 	 *  @param 	EE_Request_Handler $REQ
664 664
 	 *  @return 	EE_Template_Config
665 665
 	 */
666
-	public static function update_template_settings( $CFG, $REQ ) {
666
+	public static function update_template_settings($CFG, $REQ) {
667 667
 		$CFG->EED_Events_Archive = new EE_Events_Archive_Config();
668 668
 		// unless we are resetting the config...
669
-		if ( ! isset( $REQ['EED_Events_Archive_reset_event_list_settings'] ) || absint( $REQ['EED_Events_Archive_reset_event_list_settings'] ) !== 1 ) {
670
-			$CFG->EED_Events_Archive->display_status_banner = isset( $REQ['EED_Events_Archive_display_status_banner'] ) ? absint( $REQ['EED_Events_Archive_display_status_banner'] ) : 0;
671
-			$CFG->EED_Events_Archive->display_description = isset( $REQ['EED_Events_Archive_display_description'] ) ? absint( $REQ['EED_Events_Archive_display_description'] ) : 1;
672
-			$CFG->EED_Events_Archive->display_ticket_selector = isset( $REQ['EED_Events_Archive_display_ticket_selector'] ) ? absint( $REQ['EED_Events_Archive_display_ticket_selector'] ) : 0;
673
-			$CFG->EED_Events_Archive->display_datetimes = isset( $REQ['EED_Events_Archive_display_datetimes'] ) ? absint( $REQ['EED_Events_Archive_display_datetimes'] ) : 1;
674
-			$CFG->EED_Events_Archive->display_venue = isset( $REQ['EED_Events_Archive_display_venue'] ) ? absint( $REQ['EED_Events_Archive_display_venue'] ) : 0;
675
-			$CFG->EED_Events_Archive->display_expired_events = isset( $REQ['EED_Events_Archive_display_expired_events'] ) ? absint( $REQ['EED_Events_Archive_display_expired_events'] ) : 0;			}
669
+		if ( ! isset($REQ['EED_Events_Archive_reset_event_list_settings']) || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1) {
670
+			$CFG->EED_Events_Archive->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner']) ? absint($REQ['EED_Events_Archive_display_status_banner']) : 0;
671
+			$CFG->EED_Events_Archive->display_description = isset($REQ['EED_Events_Archive_display_description']) ? absint($REQ['EED_Events_Archive_display_description']) : 1;
672
+			$CFG->EED_Events_Archive->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector']) ? absint($REQ['EED_Events_Archive_display_ticket_selector']) : 0;
673
+			$CFG->EED_Events_Archive->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes']) ? absint($REQ['EED_Events_Archive_display_datetimes']) : 1;
674
+			$CFG->EED_Events_Archive->display_venue = isset($REQ['EED_Events_Archive_display_venue']) ? absint($REQ['EED_Events_Archive_display_venue']) : 0;
675
+			$CFG->EED_Events_Archive->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events']) ? absint($REQ['EED_Events_Archive_display_expired_events']) : 0; }
676 676
 		return $CFG;
677 677
 	}
678 678
 
@@ -685,10 +685,10 @@  discard block
 block discarded – undo
685 685
 	 * @param string $extra_class
686 686
 	 * @return    string
687 687
 	 */
688
-	public static function event_list_css( $extra_class = '' ) {
689
-		$event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array();
688
+	public static function event_list_css($extra_class = '') {
689
+		$event_list_css = ! empty($extra_class) ? array($extra_class) : array();
690 690
 		$event_list_css[] = 'espresso-event-list-event';
691
-		return implode( ' ', $event_list_css );
691
+		return implode(' ', $event_list_css);
692 692
 	}
693 693
 
694 694
 
@@ -715,9 +715,9 @@  discard block
 block discarded – undo
715 715
 	 * @param $value
716 716
 	 * @return    bool
717 717
 	 */
718
-	public static function display_description( $value ) {
718
+	public static function display_description($value) {
719 719
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
720
-		$display_description= isset( $config->display_description ) ? $config->display_description : 1;
720
+		$display_description = isset($config->display_description) ? $config->display_description : 1;
721 721
 		return $display_description === $value ? TRUE : FALSE;
722 722
 	}
723 723
 
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 	 */
731 731
 	public static function display_ticket_selector() {
732 732
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
733
-		return isset( $config->display_ticket_selector ) && $config->display_ticket_selector ? TRUE : FALSE;
733
+		return isset($config->display_ticket_selector) && $config->display_ticket_selector ? TRUE : FALSE;
734 734
 	}
735 735
 
736 736
 
@@ -743,7 +743,7 @@  discard block
 block discarded – undo
743 743
 	 */
744 744
 	public static function display_venue() {
745 745
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
746
-		return isset( $config->display_venue ) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
746
+		return isset($config->display_venue) && $config->display_venue && EEH_Venue_View::venue_name() ? TRUE : FALSE;
747 747
 	}
748 748
 
749 749
 
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 	 */
756 756
 	public static function display_datetimes() {
757 757
 		$config = EE_Registry::instance()->CFG->template_settings->EED_Events_Archive;
758
-		return isset( $config->display_datetimes ) && $config->display_datetimes ? TRUE : FALSE;
758
+		return isset($config->display_datetimes) && $config->display_datetimes ? TRUE : FALSE;
759 759
 }
760 760
 
761 761
 
@@ -770,7 +770,7 @@  discard block
 block discarded – undo
770 770
 	 *  @return 	string
771 771
 	 */
772 772
 	public static function event_list_title() {
773
-		return apply_filters( 'FHEE__archive_espresso_events_template__upcoming_events_h1', __( 'Upcoming Events', 'event_espresso' ));
773
+		return apply_filters('FHEE__archive_espresso_events_template__upcoming_events_h1', __('Upcoming Events', 'event_espresso'));
774 774
 	}
775 775
 
776 776
 
@@ -779,11 +779,11 @@  discard block
 block discarded – undo
779 779
 	/**
780 780
 	 * 	@since 4.4.0
781 781
 	 */
782
-	public static function _doing_it_wrong_notice( $function = '' ) {
782
+	public static function _doing_it_wrong_notice($function = '') {
783 783
 		EE_Error::doing_it_wrong(
784 784
 			__FUNCTION__,
785 785
 			sprintf(
786
-				__( 'EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso' ),
786
+				__('EED_Events_Archive::%1$s was moved to EEH_Event_Query::%1$s:%2$sPlease update your existing code because the method it calls will be removed in version %3$s', 'event_espresso'),
787 787
 				$function,
788 788
 				'<br />',
789 789
 				'4.6.0'
@@ -805,89 +805,89 @@  discard block
 block discarded – undo
805 805
 	 * 	@deprecated
806 806
 	 * 	@since 4.4.0
807 807
 	 */
808
-	public function posts_fields( $SQL, WP_Query $wp_query ) {
809
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
810
-		return EEH_Event_Query::posts_fields( $SQL, $wp_query );
808
+	public function posts_fields($SQL, WP_Query $wp_query) {
809
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
810
+		return EEH_Event_Query::posts_fields($SQL, $wp_query);
811 811
 	}
812 812
 	/**
813 813
 	 * 	@deprecated
814 814
 	 * 	@since 4.4.0
815 815
 	 */
816
-	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
817
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
818
-		return EEH_Event_Query::posts_fields_sql_for_orderby( $orderby_params );
816
+	public static function posts_fields_sql_for_orderby($orderby_params = array()) {
817
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
818
+		return EEH_Event_Query::posts_fields_sql_for_orderby($orderby_params);
819 819
 	}
820 820
 	/**
821 821
 	 * 	@deprecated
822 822
 	 * 	@since 4.4.0
823 823
 	 */
824
-	public function posts_join( $SQL, WP_Query $wp_query ) {
825
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
826
-		return EEH_Event_Query::posts_join( $SQL, $wp_query );
824
+	public function posts_join($SQL, WP_Query $wp_query) {
825
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
826
+		return EEH_Event_Query::posts_join($SQL, $wp_query);
827 827
 	}
828 828
 	/**
829 829
 	 * 	@deprecated
830 830
 	 * 	@since 4.4.0
831 831
 	 */
832
-	public static function posts_join_sql_for_terms( $join_terms = NULL ) {
833
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
834
-		return EEH_Event_Query::posts_join_sql_for_terms( $join_terms );
832
+	public static function posts_join_sql_for_terms($join_terms = NULL) {
833
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
834
+		return EEH_Event_Query::posts_join_sql_for_terms($join_terms);
835 835
 	}
836 836
 	/**
837 837
 	 * 	@deprecated
838 838
 	 * 	@since 4.4.0
839 839
 	 */
840
-	public static function posts_join_for_orderby( $orderby_params = array() ) {
841
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
842
-		return EEH_Event_Query::posts_join_for_orderby( $orderby_params );
840
+	public static function posts_join_for_orderby($orderby_params = array()) {
841
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
842
+		return EEH_Event_Query::posts_join_for_orderby($orderby_params);
843 843
 	}
844 844
 	/**
845 845
 	 * 	@deprecated
846 846
 	 * 	@since 4.4.0
847 847
 	 */
848
-	public function posts_where( $SQL, WP_Query $wp_query ) {
849
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
850
-		return EEH_Event_Query::posts_where( $SQL, $wp_query );
848
+	public function posts_where($SQL, WP_Query $wp_query) {
849
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
850
+		return EEH_Event_Query::posts_where($SQL, $wp_query);
851 851
 	}
852 852
 	/**
853 853
 	 * 	@deprecated
854 854
 	 * 	@since 4.4.0
855 855
 	 */
856
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
857
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
858
-		return EEH_Event_Query::posts_where_sql_for_show_expired( $show_expired );
856
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
857
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
858
+		return EEH_Event_Query::posts_where_sql_for_show_expired($show_expired);
859 859
 	}
860 860
 	/**
861 861
 	 * 	@deprecated
862 862
 	 * 	@since 4.4.0
863 863
 	 */
864
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
865
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
866
-		return EEH_Event_Query::posts_where_sql_for_event_category_slug( $event_category_slug );
864
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
865
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
866
+		return EEH_Event_Query::posts_where_sql_for_event_category_slug($event_category_slug);
867 867
 	}
868 868
 	/**
869 869
 	 * 	@deprecated
870 870
 	 * 	@since 4.4.0
871 871
 	 */
872
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
873
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
874
-		return EEH_Event_Query::posts_where_sql_for_event_list_month( $month );
872
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
873
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
874
+		return EEH_Event_Query::posts_where_sql_for_event_list_month($month);
875 875
 	}
876 876
 	/**
877 877
 	 * 	@deprecated
878 878
 	 * 	@since 4.4.0
879 879
 	 */
880
-	public function posts_orderby( $SQL, WP_Query $wp_query ) {
881
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
882
-		return EEH_Event_Query::posts_orderby( $SQL, $wp_query );
880
+	public function posts_orderby($SQL, WP_Query $wp_query) {
881
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
882
+		return EEH_Event_Query::posts_orderby($SQL, $wp_query);
883 883
 	}
884 884
 	/**
885 885
 	 * 	@deprecated
886 886
 	 * 	@since 4.4.0
887 887
 	 */
888
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
889
-		EED_Events_Archive::_doing_it_wrong_notice( __FUNCTION__ );
890
-		return EEH_Event_Query::posts_orderby_sql( $orderby_params, $sort );
888
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
889
+		EED_Events_Archive::_doing_it_wrong_notice(__FUNCTION__);
890
+		return EEH_Event_Query::posts_orderby_sql($orderby_params, $sort);
891 891
 	}
892 892
 
893 893
 
@@ -918,8 +918,8 @@  discard block
 block discarded – undo
918 918
  * @param string $extra_class
919 919
  * @return string
920 920
  */
921
-function espresso_event_list_css( $extra_class = '' ) {
922
-	return EED_Events_Archive::event_list_css( $extra_class );
921
+function espresso_event_list_css($extra_class = '') {
922
+	return EED_Events_Archive::event_list_css($extra_class);
923 923
 }
924 924
 
925 925
 /**
@@ -933,14 +933,14 @@  discard block
 block discarded – undo
933 933
  * @return bool
934 934
  */
935 935
 function espresso_display_full_description_in_event_list() {
936
-	return EED_Events_Archive::display_description( 2 );
936
+	return EED_Events_Archive::display_description(2);
937 937
 }
938 938
 
939 939
 /**
940 940
  * @return bool
941 941
  */
942 942
 function espresso_display_excerpt_in_event_list() {
943
-	return EED_Events_Archive::display_description( 1 );
943
+	return EED_Events_Archive::display_description(1);
944 944
 }
945 945
 
946 946
 /**
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,9 @@
 block discarded – undo
3 3
 use EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton;
4 4
 use EventEspresso\modules\events_archive\EventsArchiveIframe;
5 5
 
6
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
6
+if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {
7
+	exit('No direct script access allowed');
8
+}
7 9
 /**
8 10
  * Event Espresso
9 11
  *
Please login to merge, or discard this patch.
core/db_models/EEM_Payment_Method.model.php 1 patch
Spacing   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  *
@@ -37,33 +37,33 @@  discard block
 block discarded – undo
37 37
 	 * @access   protected
38 38
 	 * @return EEM_Payment_Method
39 39
 	 */
40
-	protected function __construct( $timezone = NULL ) {
41
-		$this->singlular_item = __( 'Payment Method', 'event_espresso' );
42
-		$this->plural_item = __( 'Payment Methods', 'event_espresso' );
43
-		$this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) );
40
+	protected function __construct($timezone = NULL) {
41
+		$this->singlular_item = __('Payment Method', 'event_espresso');
42
+		$this->plural_item = __('Payment Methods', 'event_espresso');
43
+		$this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'));
44 44
 		$this->_fields = array(
45 45
 			'Payment_Method' => array(
46
-				'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ),
47
-				'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ),
48
-				'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ),
49
-				'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ),
50
-				'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ),
51
-				'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ),
52
-				'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ),
53
-				'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ),
54
-				'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ),
55
-				'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ),
56
-				'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ),
57
-				'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API'
46
+				'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')),
47
+				'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'),
48
+				'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE),
49
+				'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''),
50
+				'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE),
51
+				'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE),
52
+				'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE),
53
+				'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0),
54
+				'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE),
55
+				'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE),
56
+				'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''),
57
+				'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API'
58 58
 		) );
59 59
 		$this->_model_relations = array(
60 60
  //			'Event'=>new EE_HABTM_Relation('Event_Payment_Method'),
61 61
 			'Payment' => new EE_Has_Many_Relation(),
62
-			'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ),
62
+			'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'),
63 63
 			'Transaction' => new EE_Has_Many_Relation(),
64 64
 			'WP_User' => new EE_Belongs_To_Relation(),
65 65
 		);
66
-		parent::__construct( $timezone );
66
+		parent::__construct($timezone);
67 67
 	}
68 68
 
69 69
 
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
 	 * @param string $slug
74 74
 	 * @return EE_Payment_Method
75 75
 	 */
76
-	public function get_one_by_slug( $slug ) {
77
-		return $this->get_one( array( array( 'PMD_slug' => $slug ) ) );
76
+	public function get_one_by_slug($slug) {
77
+		return $this->get_one(array(array('PMD_slug' => $slug)));
78 78
 	}
79 79
 
80 80
 
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 		return apply_filters(
89 89
 			'FHEE__EEM_Payment_Method__scopes',
90 90
 			array(
91
-				self::scope_cart 		=> __( "Front-end Registration Page", 'event_espresso' ),
92
-				self::scope_admin 	=> __( "Admin Registration Page (no online processing)", 'event_espresso' )
91
+				self::scope_cart 		=> __("Front-end Registration Page", 'event_espresso'),
92
+				self::scope_admin 	=> __("Admin Registration Page (no online processing)", 'event_espresso')
93 93
 			)
94 94
 		);
95 95
 	}
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
 	 * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
102 102
 	 * @return boolean
103 103
 	 */
104
-	public function is_valid_scope( $scope ) {
104
+	public function is_valid_scope($scope) {
105 105
 		$scopes = $this->scopes();
106
-		if ( isset( $scopes[ $scope ] ) ) {
106
+		if (isset($scopes[$scope])) {
107 107
 			return TRUE;
108 108
 		} else {
109 109
 			return FALSE;
@@ -119,11 +119,11 @@  discard block
 block discarded – undo
119 119
 	 * @throws EE_Error
120 120
 	 * @return EE_Payment_Method[]
121 121
 	 */
122
-	public function get_all_active( $scope = NULL, $query_params = array() ) {
123
-		if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) {
124
-			$query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );
122
+	public function get_all_active($scope = NULL, $query_params = array()) {
123
+		if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) {
124
+			$query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC');
125 125
 		}
126
-		return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) );
126
+		return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
127 127
 	}
128 128
 
129 129
 	/**
@@ -132,8 +132,8 @@  discard block
 block discarded – undo
132 132
 	 * @param array $query_params
133 133
 	 * @return int
134 134
 	 */
135
-	public function count_active( $scope = NULL, $query_params = array() ){
136
-		return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) );
135
+	public function count_active($scope = NULL, $query_params = array()) {
136
+		return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
137 137
 	}
138 138
 
139 139
 	/**
@@ -144,21 +144,21 @@  discard block
 block discarded – undo
144 144
 	 * @return array like param of EEM_Base::get_all()
145 145
 	 * @throws EE_Error
146 146
 	 */
147
-	protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){
148
-		if ( $scope ) {
149
-			if ( $this->is_valid_scope( $scope ) ) {
150
-				return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params );
147
+	protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) {
148
+		if ($scope) {
149
+			if ($this->is_valid_scope($scope)) {
150
+				return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params);
151 151
 			} else {
152
-				throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) );
152
+				throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope));
153 153
 			}
154 154
 		} else {
155 155
 			$acceptable_scopes = array();
156 156
 			$count = 0;
157
-			foreach ( $this->scopes() as $scope_name => $desc ) {
157
+			foreach ($this->scopes() as $scope_name => $desc) {
158 158
 				$count++;
159
-				$acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );
159
+				$acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%');
160 160
 			}
161
-			return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params );
161
+			return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params);
162 162
 		}
163 163
 	}
164 164
 
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 * @return array like param of EEM_Base::get_all()
171 171
 	 * @throws EE_Error
172 172
 	 */
173
-	public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) {
174
-		return $this->_get_query_params_for_all_active( $scope, $query_params );
173
+	public function get_query_params_for_all_active($scope = NULL, $query_params = array()) {
174
+		return $this->_get_query_params_for_all_active($scope, $query_params);
175 175
 	}
176 176
 
177 177
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 	 * @param array  $query_params
182 182
 	 * @return EE_Payment_Method
183 183
 	 */
184
-	public function get_one_active( $scope = NULL, $query_params = array() ) {
185
-		return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) );
184
+	public function get_one_active($scope = NULL, $query_params = array()) {
185
+		return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
186 186
 	}
187 187
 
188 188
 
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 	 * @param string $type
193 193
 	 * @return EE_Payment_Method
194 194
 	 */
195
-	public function get_one_of_type( $type ) {
196
-		return $this->get_one( array( array( 'PMD_type' => $type ) ) );
195
+	public function get_one_of_type($type) {
196
+		return $this->get_one(array(array('PMD_type' => $type)));
197 197
 	}
198 198
 
199 199
 
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
 	 * @return EE_Payment_Method
207 207
 	 * @throws EE_Error
208 208
 	 */
209
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) {
209
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
210 210
 		//first: check if it's a slug
211
-		if( is_string( $base_class_obj_or_id ) ) {
212
-			$obj = $this->get_one_by_slug( $base_class_obj_or_id );
213
-			if( $obj ) {
211
+		if (is_string($base_class_obj_or_id)) {
212
+			$obj = $this->get_one_by_slug($base_class_obj_or_id);
213
+			if ($obj) {
214 214
 				return $obj;
215 215
 			}
216 216
 		}
217 217
 		//ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
218 218
 		try {
219
-			return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db );
219
+			return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
220 220
 		}
221
-		catch ( EE_Error $e ) {
221
+		catch (EE_Error $e) {
222 222
 			//handle it outside the catch
223 223
 		}
224
-		throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) );
224
+		throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id));
225 225
 	}
226 226
 
227 227
 
@@ -232,12 +232,12 @@  discard block
 block discarded – undo
232 232
 	 * @param mixed $base_obj_or_id_or_slug
233 233
 	 * @return int
234 234
 	 */
235
-	function ensure_is_ID( $base_obj_or_id_or_slug ) {
236
-		if ( is_string( $base_obj_or_id_or_slug ) ) {
235
+	function ensure_is_ID($base_obj_or_id_or_slug) {
236
+		if (is_string($base_obj_or_id_or_slug)) {
237 237
 			//assume it's a slug
238
-			$base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug );
238
+			$base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
239 239
 		}
240
-		return parent::ensure_is_ID( $base_obj_or_id_or_slug );
240
+		return parent::ensure_is_ID($base_obj_or_id_or_slug);
241 241
 	}
242 242
 
243 243
 
@@ -246,36 +246,36 @@  discard block
 block discarded – undo
246 246
 	 * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.
247 247
 	 * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart
248 248
 	 */
249
-	function verify_button_urls( $payment_methods = NULL ) {
250
-		$payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
251
-		foreach ( $payment_methods as $payment_method ) {
249
+	function verify_button_urls($payment_methods = NULL) {
250
+		$payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
251
+		foreach ($payment_methods as $payment_method) {
252 252
 			try {
253 253
 				$current_button_url = $payment_method->button_url();
254
-				$buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
255
-					'current_ssl' => str_replace( "http://", "https://", $current_button_url ),
256
-					'current' => str_replace( "https://", "http://", $current_button_url ),
257
-					'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ),
258
-					'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ),
259
-				) );
260
-				foreach( $buttons_urls_to_try as $button_url_to_try ) {
261
-					if(
254
+				$buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
255
+					'current_ssl' => str_replace("http://", "https://", $current_button_url),
256
+					'current' => str_replace("https://", "http://", $current_button_url),
257
+					'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()),
258
+					'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()),
259
+				));
260
+				foreach ($buttons_urls_to_try as $button_url_to_try) {
261
+					if (
262 262
 							(//this is the current url and it exists, regardless of SSL issues
263 263
 								$button_url_to_try == $current_button_url &&
264 264
 								EEH_URL::remote_file_exists(
265 265
 										$button_url_to_try,
266 266
 										array(
267 267
 											'sslverify' => false,
268
-											'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
268
+											'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
269 269
 											) )
270 270
 							)
271 271
 							||
272 272
 							(//this is NOT the current url and it exists with a working SSL cert
273 273
 								$button_url_to_try != $current_button_url &&
274
-								EEH_URL::remote_file_exists( $button_url_to_try )
274
+								EEH_URL::remote_file_exists($button_url_to_try)
275 275
 							) ) {
276
-						if( $current_button_url != $button_url_to_try ){
277
-							$payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) );
278
-							EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) );
276
+						if ($current_button_url != $button_url_to_try) {
277
+							$payment_method->save(array('PMD_button_url' => $button_url_to_try));
278
+							EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try));
279 279
 						}
280 280
 						//this image exists. So if wasn't set before, now it is;
281 281
 						//or if it was already set, we have nothing to do
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 					}
284 284
 				}
285 285
 			}
286
-			catch ( EE_Error $e ) {
287
-				$payment_method->set_active( FALSE );
286
+			catch (EE_Error $e) {
287
+				$payment_method->set_active(FALSE);
288 288
 			}
289 289
 		}
290 290
 	}
@@ -298,29 +298,29 @@  discard block
 block discarded – undo
298 298
 	 * @param array $rows
299 299
 	 * @return EE_Payment_Method[]
300 300
 	 */
301
-	protected function _create_objects( $rows = array() ) {
302
-		EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
303
-		$payment_methods = parent::_create_objects( $rows );
301
+	protected function _create_objects($rows = array()) {
302
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
303
+		$payment_methods = parent::_create_objects($rows);
304 304
 		/* @var $payment_methods EE_Payment_Method[] */
305 305
 		$usable_payment_methods = array();
306
-		foreach ( $payment_methods as $key => $payment_method ) {
307
-			if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) {
308
-				$usable_payment_methods[ $key ] = $payment_method;
306
+		foreach ($payment_methods as $key => $payment_method) {
307
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
308
+				$usable_payment_methods[$key] = $payment_method;
309 309
 				//some payment methods enqueue their scripts in EE_PMT_*::__construct
310 310
 				//which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
311 311
 				//its scripts). but for backwards-compat we should continue to do that
312 312
 				$payment_method->type_obj();
313
-			} elseif( $payment_method->active() ) {				
313
+			} elseif ($payment_method->active()) {				
314 314
 				//only deactivate and notify the admin if the payment is active somewhere
315 315
 				$payment_method->deactivate();
316 316
 				$payment_method->save();
317 317
 				EE_Error::add_persistent_admin_notice(
318
-					'auto-deactivated-' . $payment_method->type(),
318
+					'auto-deactivated-'.$payment_method->type(),
319 319
 					sprintf(
320
-						__( 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso' ),
320
+						__('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', 'event_espresso'),
321 321
 						$payment_method->admin_name(),
322 322
 						'<br />',
323
-						'<a href="' . admin_url('plugins.php') . '">',
323
+						'<a href="'.admin_url('plugins.php').'">',
324 324
 						'</a>'
325 325
 					),
326 326
 					true
@@ -340,11 +340,11 @@  discard block
 block discarded – undo
340 340
 	 * @param string 	$scope @see EEM_Payment_Method::get_all_for_events
341 341
 	 * @return EE_Payment_Method[]
342 342
 	 */
343
-	public function get_all_for_transaction( $transaction, $scope ) {
343
+	public function get_all_for_transaction($transaction, $scope) {
344 344
 		//give addons a chance to override what payment methods are chosen based on the transaction
345 345
 		return apply_filters(
346 346
 			'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
347
-			$this->get_all_active( $scope ),
347
+			$this->get_all_active($scope),
348 348
 			$transaction,
349 349
 			$scope
350 350
 		);
@@ -360,16 +360,16 @@  discard block
 block discarded – undo
360 360
 	 * @param EE_Registration|int $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
361 361
 	 * @return EE_Payment|null
362 362
 	 */
363
-	public function get_last_used_for_registration( $registration_or_reg_id ) {
364
-		$registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id );
363
+	public function get_last_used_for_registration($registration_or_reg_id) {
364
+		$registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
365 365
 
366 366
 		$query_params = array(
367 367
 			0 => array(
368 368
 				'Payment.Registration.REG_ID' => $registration_id,
369 369
 			),
370
-			'order_by' => array( 'Payment.PAY_ID' => 'DESC' )
370
+			'order_by' => array('Payment.PAY_ID' => 'DESC')
371 371
 		);
372
-		return $this->get_one( $query_params );
372
+		return $this->get_one($query_params);
373 373
 	}
374 374
 
375 375
 }
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 1 patch
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (!defined('EVENT_ESPRESSO_VERSION') )
2
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
3 3
 	exit('NO direct script access allowed');
4 4
 
5 5
 /**
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
45 45
 	 * @return \Payments_Admin_Page
46 46
 	 */
47
-	public function __construct( $routing = TRUE ) {
48
-		parent::__construct( $routing );
47
+	public function __construct($routing = TRUE) {
48
+		parent::__construct($routing);
49 49
 	}
50 50
 
51 51
 
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
 	protected function _set_page_config() {
131 131
 		$payment_method_list_config = array(
132 132
 			'nav'           => array(
133
-				'label' => __( 'Payment Methods', 'event_espresso' ),
133
+				'label' => __('Payment Methods', 'event_espresso'),
134 134
 				'order' => 10
135 135
 			),
136 136
 			'metaboxes'     => $this->_default_espresso_metaboxes,
137 137
 			'help_tabs'     => array_merge(
138 138
 				array(
139 139
 					'payment_methods_overview_help_tab' => array(
140
-						'title'    => __( 'Payment Methods Overview', 'event_espresso' ),
140
+						'title'    => __('Payment Methods Overview', 'event_espresso'),
141 141
 						'filename' => 'payment_methods_overview'
142 142
 					)
143 143
 				),
144 144
 				$this->_add_payment_method_help_tabs() ),
145
-			'help_tour'     => array( 'Payment_Methods_Selection_Help_Tour' ),
145
+			'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
146 146
 			'require_nonce' => false
147 147
 		);
148 148
 
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 					)
161 161
 				),
162 162
 				//'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
163
-				'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ),
163
+				'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
164 164
 				'require_nonce' => FALSE
165 165
 			),
166 166
 			'payment_log'=>array(
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
 	/**
180 180
 	 * @return array
181 181
 	 */
182
-	protected function _add_payment_method_help_tabs(){
182
+	protected function _add_payment_method_help_tabs() {
183 183
 		EE_Registry::instance()->load_lib('Payment_Method_Manager');
184 184
 		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
185 185
 		$all_pmt_help_tabs_config = array();
186
-		foreach( $payment_method_types as $payment_method_type ){
187
-			if ( ! EE_Registry::instance()->CAP->current_user_can( $payment_method_type->cap_name(), 'specific_payment_method_type_access' ) ) {
186
+		foreach ($payment_method_types as $payment_method_type) {
187
+			if ( ! EE_Registry::instance()->CAP->current_user_can($payment_method_type->cap_name(), 'specific_payment_method_type_access')) {
188 188
 				continue;
189 189
 			}
190
-			foreach( $payment_method_type->help_tabs_config() as $help_tab_name => $config ){
191
-				$template_args = isset( $config[ 'template_args' ] ) ? $config[ 'template_args' ] : array();
192
-				$template_args[ 'admin_page_obj' ] = $this;
190
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
191
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
192
+				$template_args['admin_page_obj'] = $this;
193 193
 				$all_pmt_help_tabs_config[$help_tab_name] = array(
194 194
 					'title'=>$config['title'],
195 195
 					'content'=>EEH_Template::display_template(
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 
217 217
 
218 218
 	public function load_scripts_styles() {
219
-		wp_enqueue_script( 'ee_admin_js' );
220
-		wp_enqueue_script( 'ee-text-links' );
221
-		wp_enqueue_script( 'espresso_payments', EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js', array( 'espresso-ui-theme', 'ee-datepicker' ), EVENT_ESPRESSO_VERSION, TRUE );
219
+		wp_enqueue_script('ee_admin_js');
220
+		wp_enqueue_script('ee-text-links');
221
+		wp_enqueue_script('espresso_payments', EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js', array('espresso-ui-theme', 'ee-datepicker'), EVENT_ESPRESSO_VERSION, TRUE);
222 222
 	}
223 223
 
224 224
 
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 
228 228
 	public function load_scripts_styles_default() {
229 229
 		//styles
230
-		wp_register_style( 'espresso_payments', EE_PAYMENTS_ASSETS_URL . 'ee-payments.css', array(), EVENT_ESPRESSO_VERSION );
231
-		wp_enqueue_style( 'espresso_payments' );
232
-		wp_enqueue_style( 'ee-text-links' );
230
+		wp_register_style('espresso_payments', EE_PAYMENTS_ASSETS_URL.'ee-payments.css', array(), EVENT_ESPRESSO_VERSION);
231
+		wp_enqueue_style('espresso_payments');
232
+		wp_enqueue_style('ee-text-links');
233 233
 		//scripts
234 234
 	}
235 235
 
@@ -243,44 +243,44 @@  discard block
 block discarded – undo
243 243
 		 * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
244 244
 		 * recheck here.
245 245
 		 */
246
-		EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
246
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
247 247
 		EEM_Payment_Method::instance()->verify_button_urls();
248 248
 		//setup tabs, one for each payment method type
249 249
 		$tabs = array();
250 250
 		$payment_methods = array();
251
-		foreach( EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj ) {
251
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
252 252
 			// we don't want to show admin-only PMTs for now
253
-			if ( $pmt_obj instanceof EE_PMT_Admin_Only ) {
253
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
254 254
 				continue;
255 255
 			}
256 256
 			//check access
257
-			if ( ! EE_Registry::instance()->CAP->current_user_can( $pmt_obj->cap_name(), 'specific_payment_method_type_access' ) ) {
257
+			if ( ! EE_Registry::instance()->CAP->current_user_can($pmt_obj->cap_name(), 'specific_payment_method_type_access')) {
258 258
 				continue;
259 259
 			}
260 260
 			//check for any active pms of that type
261
-			$payment_method = EEM_Payment_Method::instance()->get_one_of_type( $pmt_obj->system_name() );
262
-			if ( ! $payment_method instanceof EE_Payment_Method ) {
261
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
262
+			if ( ! $payment_method instanceof EE_Payment_Method) {
263 263
 				$payment_method = EE_Payment_Method::new_instance(
264 264
 					array(
265
-						'PMD_slug'					=>sanitize_key( $pmt_obj->system_name() ),
265
+						'PMD_slug'					=>sanitize_key($pmt_obj->system_name()),
266 266
 						'PMD_type'					=>$pmt_obj->system_name(),
267 267
 						'PMD_name'				=>$pmt_obj->pretty_name(),
268 268
 						'PMD_admin_name'	=>$pmt_obj->pretty_name()
269 269
 					)
270 270
 				);
271 271
 			}
272
-			$payment_methods[ $payment_method->slug() ] = $payment_method;
272
+			$payment_methods[$payment_method->slug()] = $payment_method;
273 273
 		}
274
-		$payment_methods = apply_filters( 'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', $payment_methods );
275
-		foreach( $payment_methods as $payment_method ) {
276
-			if ( $payment_method instanceof EE_Payment_Method ) {
274
+		$payment_methods = apply_filters('FHEE__Payments_Admin_Page___payment_methods_list__payment_methods', $payment_methods);
275
+		foreach ($payment_methods as $payment_method) {
276
+			if ($payment_method instanceof EE_Payment_Method) {
277 277
 				add_meta_box(
278 278
 					//html id
279
-					'espresso_' . $payment_method->slug() . '_payment_settings',
279
+					'espresso_'.$payment_method->slug().'_payment_settings',
280 280
 					//title
281
-					sprintf( __( '%s Settings', 'event_espresso' ), $payment_method->admin_name() ),
281
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
282 282
 					//callback
283
-					array( $this, 'payment_method_settings_meta_box' ),
283
+					array($this, 'payment_method_settings_meta_box'),
284 284
 					//post type
285 285
 					null,
286 286
 					//context
@@ -288,19 +288,19 @@  discard block
 block discarded – undo
288 288
 					//priority
289 289
 					'default',
290 290
 					//callback args
291
-					array( 'payment_method' => $payment_method )
291
+					array('payment_method' => $payment_method)
292 292
 				);
293 293
 				//setup for tabbed content
294
-				$tabs[ $payment_method->slug() ] = array(
294
+				$tabs[$payment_method->slug()] = array(
295 295
 					'label' => $payment_method->admin_name(),
296 296
 					'class' => $payment_method->active() ? 'gateway-active' : '',
297
-					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
298
-					'title' => __( 'Modify this Payment Method', 'event_espresso' ),
297
+					'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
298
+					'title' => __('Modify this Payment Method', 'event_espresso'),
299 299
 					'slug'  => $payment_method->slug()
300 300
 				);
301 301
 			}
302 302
 		}
303
-		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links( $tabs, 'payment_method_links', '|', $this->_get_active_payment_method_slug() );
303
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links($tabs, 'payment_method_links', '|', $this->_get_active_payment_method_slug());
304 304
 		$this->display_admin_page_with_sidebar();
305 305
 
306 306
 	}
@@ -311,20 +311,20 @@  discard block
 block discarded – undo
311 311
 	 *   _get_active_payment_method_slug
312 312
 	 * 	@return string
313 313
 	 */
314
-	protected function _get_active_payment_method_slug(){
314
+	protected function _get_active_payment_method_slug() {
315 315
 		$payment_method_slug = FALSE;
316 316
 		//decide which payment method tab to open first, as dictated by the request's 'payment_method'
317
-		if ( isset( $this->_req_data['payment_method'] )) {
317
+		if (isset($this->_req_data['payment_method'])) {
318 318
 			// if they provided the current payment method, use it
319
-			$payment_method_slug = sanitize_key( $this->_req_data['payment_method'] );
319
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
320 320
 		}
321
-		$payment_method = EEM_Payment_Method::instance()->get_one( array( array( 'PMD_slug' => $payment_method_slug )));
321
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
322 322
 		// if that didn't work or wasn't provided, find another way to select the current pm
323
-		if ( ! $this->_verify_payment_method( $payment_method )) {
323
+		if ( ! $this->_verify_payment_method($payment_method)) {
324 324
 			// like, looking for an active one
325
-			$payment_method = EEM_Payment_Method::instance()->get_one_active( 'CART' );
325
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
326 326
 			// test that one as well
327
-			if ( $this->_verify_payment_method( $payment_method )) {
327
+			if ($this->_verify_payment_method($payment_method)) {
328 328
 				$payment_method_slug = $payment_method->slug();
329 329
 			} else {
330 330
 				$payment_method_slug = 'paypal_standard';
@@ -342,11 +342,11 @@  discard block
 block discarded – undo
342 342
 	 * @param \EE_Payment_Method $payment_method
343 343
 	 * @return boolean
344 344
 	 */
345
-	protected function _verify_payment_method( $payment_method ){
345
+	protected function _verify_payment_method($payment_method) {
346 346
 		if (
347 347
 			$payment_method instanceof EE_Payment_Method &&
348 348
 			$payment_method->type_obj() instanceof EE_PMT_Base &&
349
-			EE_Registry::instance()->CAP->current_user_can( $payment_method->type_obj()->cap_name(), 'specific_payment_method_type_access' )
349
+			EE_Registry::instance()->CAP->current_user_can($payment_method->type_obj()->cap_name(), 'specific_payment_method_type_access')
350 350
 		) {
351 351
 			return TRUE;
352 352
 		}
@@ -363,21 +363,21 @@  discard block
 block discarded – undo
363 363
 	 * @return string
364 364
 	 * @throws EE_Error
365 365
 	 */
366
-	public function payment_method_settings_meta_box( $post_obj_which_is_null, $metabox ){
367
-		$payment_method = isset( $metabox['args'], $metabox['args']['payment_method'] ) ? $metabox['args']['payment_method'] : NULL;
368
-		if ( ! $payment_method instanceof EE_Payment_Method ){
369
-			throw new EE_Error( sprintf( __( 'Payment method metabox setup incorrectly. No Payment method object was supplied', 'event_espresso' )));
366
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox) {
367
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method']) ? $metabox['args']['payment_method'] : NULL;
368
+		if ( ! $payment_method instanceof EE_Payment_Method) {
369
+			throw new EE_Error(sprintf(__('Payment method metabox setup incorrectly. No Payment method object was supplied', 'event_espresso')));
370 370
 		}
371 371
 		$payment_method_scopes = $payment_method->active();
372 372
 		// if the payment method really exists show its form, otherwise the activation template
373
-		if ( $payment_method->ID() && ! empty( $payment_method_scopes )) {
374
-				$form = $this->_generate_payment_method_settings_form( $payment_method );
375
-				if ( $form->form_data_present_in( $this->_req_data )) {
376
-					$form->receive_form_submission( $this->_req_data );
373
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
374
+				$form = $this->_generate_payment_method_settings_form($payment_method);
375
+				if ($form->form_data_present_in($this->_req_data)) {
376
+					$form->receive_form_submission($this->_req_data);
377 377
 				}
378
-				echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
378
+				echo $form->form_open().$form->get_html_and_js().$form->form_close();
379 379
 		} else {
380
-			echo $this->_activate_payment_method_button( $payment_method )->get_html_and_js();
380
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
381 381
 		}
382 382
 	}
383 383
 
@@ -390,14 +390,14 @@  discard block
 block discarded – undo
390 390
 	 * @param \EE_Payment_Method $payment_method
391 391
 	 * @return \EE_Form_Section_Proper
392 392
 	 */
393
-	protected function _generate_payment_method_settings_form( EE_Payment_Method $payment_method ) {
394
-		if ( ! $payment_method instanceof EE_Payment_Method ){
393
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method) {
394
+		if ( ! $payment_method instanceof EE_Payment_Method) {
395 395
 			return new EE_Form_Section_Proper();
396 396
 		}
397 397
 		return new EE_Form_Section_Proper(
398 398
 			array(
399
-				'name' 	=> $payment_method->slug() . '_settings_form',
400
-				'html_id' 	=> $payment_method->slug() . '_settings_form',
399
+				'name' 	=> $payment_method->slug().'_settings_form',
400
+				'html_id' 	=> $payment_method->slug().'_settings_form',
401 401
 				'action' 	=> EE_Admin_Page::add_query_args_and_nonce(
402 402
 					array(
403 403
 						'action' 						=> 'update_payment_method',
@@ -409,12 +409,12 @@  discard block
 block discarded – undo
409 409
 				'subsections' 			=> apply_filters(
410 410
 					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
411 411
 					array(
412
-						'pci_dss_compliance_' . $payment_method->slug() 				=> $this->_pci_dss_compliance( $payment_method ),
413
-						'currency_support_' . $payment_method->slug()					=> $this->_currency_support( $payment_method ),
414
-						'payment_method_settings_' . $payment_method->slug() 	=> $this->_payment_method_settings( $payment_method ),
415
-						'update_' . $payment_method->slug()										=> $this->_update_payment_method_button( $payment_method ),
416
-						'deactivate_' . $payment_method->slug()								=> $this->_deactivate_payment_method_button( $payment_method ),
417
-						'fine_print_' . $payment_method->slug()									=> $this->_fine_print()
412
+						'pci_dss_compliance_'.$payment_method->slug() 				=> $this->_pci_dss_compliance($payment_method),
413
+						'currency_support_'.$payment_method->slug()					=> $this->_currency_support($payment_method),
414
+						'payment_method_settings_'.$payment_method->slug() 	=> $this->_payment_method_settings($payment_method),
415
+						'update_'.$payment_method->slug()										=> $this->_update_payment_method_button($payment_method),
416
+						'deactivate_'.$payment_method->slug()								=> $this->_deactivate_payment_method_button($payment_method),
417
+						'fine_print_'.$payment_method->slug()									=> $this->_fine_print()
418 418
 					),
419 419
 					$payment_method
420 420
 				)
@@ -431,19 +431,19 @@  discard block
 block discarded – undo
431 431
 	 * @param \EE_Payment_Method $payment_method
432 432
 	 * @return \EE_Form_Section_Proper
433 433
 	 */
434
-	protected function _pci_dss_compliance( EE_Payment_Method $payment_method ) {
435
-		if ( $payment_method->type_obj()->requires_https() ) {
434
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method) {
435
+		if ($payment_method->type_obj()->requires_https()) {
436 436
 			return new EE_Form_Section_HTML(
437 437
 				EEH_HTML::tr(
438 438
 					EEH_HTML::th(
439 439
 						EEH_HTML::label(
440
-							EEH_HTML::strong( __( 'IMPORTANT', 'event_espresso' ), '', 'important-notice' )
440
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
441 441
 						)
442
-					) .
442
+					).
443 443
 					EEH_HTML::td(
444
-						EEH_HTML::strong( __( 'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', 'event_espresso' )) .
445
-						EEH_HTML::br() .
446
-						__( 'Learn more about ', 'event_espresso' ) . EEH_HTML::link( 'https://www.pcisecuritystandards.org/merchants/index.php', __( 'PCI DSS compliance', 'event_espresso' ))
444
+						EEH_HTML::strong(__('You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.', 'event_espresso')).
445
+						EEH_HTML::br().
446
+						__('Learn more about ', 'event_espresso').EEH_HTML::link('https://www.pcisecuritystandards.org/merchants/index.php', __('PCI DSS compliance', 'event_espresso'))
447 447
 					)
448 448
 				)
449 449
 			);
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
 	 * @param \EE_Payment_Method $payment_method
462 462
 	 * @return \EE_Form_Section_Proper
463 463
 	 */
464
-	protected function _currency_support( EE_Payment_Method $payment_method ) {
465
-		if ( ! $payment_method->usable_for_currency( EE_Config::instance()->currency->code )) {
464
+	protected function _currency_support(EE_Payment_Method $payment_method) {
465
+		if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
466 466
 			return new EE_Form_Section_HTML(
467 467
 				EEH_HTML::tr(
468 468
 					EEH_HTML::th(
469 469
 						EEH_HTML::label(
470
-							EEH_HTML::strong( __( 'IMPORTANT', 'event_espresso' ), '', 'important-notice' )
470
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
471 471
 						)
472
-					) .
472
+					).
473 473
 					EEH_HTML::td(
474 474
 						EEH_HTML::strong(
475 475
 							sprintf(
476
-								__( 'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', 'event_espresso'),
476
+								__('This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.', 'event_espresso'),
477 477
 								EE_Config::instance()->currency->code
478 478
 							)
479 479
 						)
@@ -493,9 +493,9 @@  discard block
 block discarded – undo
493 493
 	 * @param \EE_Payment_Method $payment_method
494 494
 	 * @return \EE_Form_Section_HTML
495 495
 	 */
496
-	protected function _payment_method_settings( EE_Payment_Method $payment_method ) {
496
+	protected function _payment_method_settings(EE_Payment_Method $payment_method) {
497 497
 		//modify the form so we only have/show fields that will be implemented for this version
498
-		return $this->_simplify_form( $payment_method->type_obj()->settings_form(), $payment_method->name() );
498
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
499 499
 	}
500 500
 
501 501
 
@@ -508,8 +508,8 @@  discard block
 block discarded – undo
508 508
 	 * @return \EE_Payment_Method_Form
509 509
 	 * @throws \EE_Error
510 510
 	 */
511
-	protected function _simplify_form( $form_section, $payment_method_name = '' ){
512
-		if ( $form_section instanceof EE_Payment_Method_Form ) {
511
+	protected function _simplify_form($form_section, $payment_method_name = '') {
512
+		if ($form_section instanceof EE_Payment_Method_Form) {
513 513
 			$form_section->exclude(
514 514
 				array(
515 515
 					'PMD_type', //dont want them changing the type
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 			);
521 521
 			return $form_section;
522 522
 		} else {
523
-			throw new EE_Error( sprintf( __( 'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', 'event_espresso' ), $payment_method_name ));
523
+			throw new EE_Error(sprintf(__('The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.', 'event_espresso'), $payment_method_name));
524 524
 		}
525 525
 	}
526 526
 
@@ -533,19 +533,19 @@  discard block
 block discarded – undo
533 533
 	 * @param \EE_Payment_Method $payment_method
534 534
 	 * @return \EE_Form_Section_HTML
535 535
 	 */
536
-	protected function _update_payment_method_button( EE_Payment_Method $payment_method ) {
536
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method) {
537 537
 		$update_button = new EE_Submit_Input(
538 538
 			array(
539 539
 				'name' => 'submit',
540
-				'html_id' 		=> 'save_' . $payment_method->slug() . '_settings',
541
-				'default' 		=> sprintf( __( 'Update %s Payment Settings', 'event_espresso' ), $payment_method->admin_name() ),
540
+				'html_id' 		=> 'save_'.$payment_method->slug().'_settings',
541
+				'default' 		=> sprintf(__('Update %s Payment Settings', 'event_espresso'), $payment_method->admin_name()),
542 542
 				'html_label' => EEH_HTML::nbsp()
543 543
 			)
544 544
 		);
545 545
 		return new EE_Form_Section_HTML(
546
-			EEH_HTML::no_row( EEH_HTML::br(2) ) .
546
+			EEH_HTML::no_row(EEH_HTML::br(2)).
547 547
 			EEH_HTML::tr(
548
-				EEH_HTML::th( __( 'Update Settings', 'event_espresso') ) .
548
+				EEH_HTML::th(__('Update Settings', 'event_espresso')).
549 549
 				EEH_HTML::td(
550 550
 					$update_button->get_html_for_input()
551 551
 				)
@@ -562,11 +562,11 @@  discard block
 block discarded – undo
562 562
 	 * @param \EE_Payment_Method $payment_method
563 563
 	 * @return \EE_Form_Section_Proper
564 564
 	 */
565
-	protected function _deactivate_payment_method_button( EE_Payment_Method $payment_method ) {
566
-		$link_text_and_title = sprintf( __( 'Deactivate %1$s Payments?', 'event_espresso'), $payment_method->admin_name() );
565
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method) {
566
+		$link_text_and_title = sprintf(__('Deactivate %1$s Payments?', 'event_espresso'), $payment_method->admin_name());
567 567
 		return new EE_Form_Section_HTML(
568 568
 			EEH_HTML::tr(
569
-				EEH_HTML::th( __( 'Deactivate Payment Method', 'event_espresso') ) .
569
+				EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')).
570 570
 				EEH_HTML::td(
571 571
 					EEH_HTML::link(
572 572
 						EE_Admin_Page::add_query_args_and_nonce(
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 						),
579 579
 						$link_text_and_title,
580 580
 						$link_text_and_title,
581
-						'deactivate_' . $payment_method->slug(),
581
+						'deactivate_'.$payment_method->slug(),
582 582
 						'espresso-button button-secondary'
583 583
 					)
584 584
 				)
@@ -594,12 +594,12 @@  discard block
 block discarded – undo
594 594
 	 * @param \EE_Payment_Method $payment_method
595 595
 	 * @return \EE_Form_Section_Proper
596 596
 	 */
597
-	protected function _activate_payment_method_button( EE_Payment_Method $payment_method ) {
598
-		$link_text_and_title = sprintf( __( 'Activate %1$s Payment Method?', 'event_espresso'), $payment_method->admin_name() );
597
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method) {
598
+		$link_text_and_title = sprintf(__('Activate %1$s Payment Method?', 'event_espresso'), $payment_method->admin_name());
599 599
 		return new EE_Form_Section_Proper(
600 600
 			array(
601
-				'name' 	=> 'activate_' . $payment_method->slug() . '_settings_form',
602
-				'html_id' 	=> 'activate_' . $payment_method->slug() . '_settings_form',
601
+				'name' 	=> 'activate_'.$payment_method->slug().'_settings_form',
602
+				'html_id' 	=> 'activate_'.$payment_method->slug().'_settings_form',
603 603
 				'action' 	=> '#',
604 604
 				'layout_strategy'		=> new EE_Admin_Two_Column_Layout(),
605 605
 				'subsections' 			=> apply_filters(
@@ -607,17 +607,17 @@  discard block
 block discarded – undo
607 607
 					array(
608 608
 						new EE_Form_Section_HTML(
609 609
 							EEH_HTML::tr(
610
-								EEH_HTML::td( $payment_method->type_obj()->introductory_html(),
610
+								EEH_HTML::td($payment_method->type_obj()->introductory_html(),
611 611
 									'',
612 612
 									'',
613 613
 									'',
614 614
 									'colspan="2"' 
615 615
 								)
616
-							) . 
616
+							). 
617 617
 							EEH_HTML::tr(
618 618
 								EEH_HTML::th(
619
-									EEH_HTML::label( __( 'Click to Activate ', 'event_espresso' ))
620
-								) .
619
+									EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
620
+								).
621 621
 								EEH_HTML::td(
622 622
 									EEH_HTML::link(
623 623
 										EE_Admin_Page::add_query_args_and_nonce(
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 										),
630 630
 										$link_text_and_title,
631 631
 										$link_text_and_title,
632
-										'activate_' . $payment_method->slug(),
632
+										'activate_'.$payment_method->slug(),
633 633
 										'espresso-button-green button-primary'
634 634
 									)
635 635
 								)
@@ -651,9 +651,9 @@  discard block
 block discarded – undo
651 651
 	protected function _fine_print() {
652 652
 		return new EE_Form_Section_HTML(
653 653
 			EEH_HTML::tr(
654
-				EEH_HTML::th() .
654
+				EEH_HTML::th().
655 655
 				EEH_HTML::td(
656
-					EEH_HTML::p( __( 'All fields marked with a * are required fields', 'event_espresso' ), '', 'grey-text' )
656
+					EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
657 657
 				)
658 658
 			)
659 659
 		);
@@ -665,15 +665,15 @@  discard block
 block discarded – undo
665 665
 	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
666 666
 	 * @global WP_User $current_user
667 667
 	 */
668
-	protected function _activate_payment_method(){
669
-		if(isset($this->_req_data['payment_method_type'])){
668
+	protected function _activate_payment_method() {
669
+		if (isset($this->_req_data['payment_method_type'])) {
670 670
 			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
671 671
 			//see if one exists
672
-			EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
673
-			$payment_method = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type( $payment_method_type );
672
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
673
+			$payment_method = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type($payment_method_type);
674 674
 
675
-			$this->_redirect_after_action(1, 'Payment Method', 'activated', array('action' => 'default','payment_method'=>$payment_method->slug()));
676
-		}else{
675
+			$this->_redirect_after_action(1, 'Payment Method', 'activated', array('action' => 'default', 'payment_method'=>$payment_method->slug()));
676
+		} else {
677 677
 			$this->_redirect_after_action(FALSE, 'Payment Method', 'activated', array('action' => 'default'));
678 678
 		}
679 679
 	}
@@ -681,14 +681,14 @@  discard block
 block discarded – undo
681 681
 	/**
682 682
 	 * Deactivates the payment method with the specified slug, and redirects.
683 683
 	 */
684
-	protected function _deactivate_payment_method(){
685
-		if(isset($this->_req_data['payment_method'])){
684
+	protected function _deactivate_payment_method() {
685
+		if (isset($this->_req_data['payment_method'])) {
686 686
 			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
687 687
 			//deactivate it
688 688
 			EE_Registry::instance()->load_lib('Payment_Method_Manager');
689
-			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method( $payment_method_slug );
690
-			$this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', array('action' => 'default','payment_method'=>$payment_method_slug));
691
-		}else{
689
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
690
+			$this->_redirect_after_action($count_updated, 'Payment Method', 'deactivated', array('action' => 'default', 'payment_method'=>$payment_method_slug));
691
+		} else {
692 692
 			$this->_redirect_after_action(FALSE, 'Payment Method', 'deactivated', array('action' => 'default'));
693 693
 		}
694 694
 	}
@@ -702,46 +702,46 @@  discard block
 block discarded – undo
702 702
 	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
703 703
 	 * @return void
704 704
 	 */
705
-	protected function _update_payment_method(){
706
-		if( $_SERVER['REQUEST_METHOD'] == 'POST'){
705
+	protected function _update_payment_method() {
706
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
707 707
 			//ok let's find which gateway form to use based on the form input
708 708
 			EE_Registry::instance()->load_lib('Payment_Method_Manager');
709 709
 			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
710 710
 			$correct_pmt_form_to_use = NULL;
711 711
 			$payment_method = NULL;
712
-			foreach( EEM_Payment_Method::instance()->get_all() as $payment_method){
712
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
713 713
 				//get the form and simplify it, like what we do when we display it
714
-				$pmt_form = $this->_generate_payment_method_settings_form( $payment_method );
715
-				if($pmt_form->form_data_present_in($this->_req_data)){
714
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
715
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
716 716
 					$correct_pmt_form_to_use = $pmt_form;
717 717
 					break;
718 718
 				}
719 719
 			}
720 720
 			//if we couldn't find the correct payment method type...
721
-			if( ! $correct_pmt_form_to_use ){
721
+			if ( ! $correct_pmt_form_to_use) {
722 722
 				EE_Error::add_error(__("We could not find which payment method type your form submission related to. Please contact support", 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
723 723
 				$this->_redirect_after_action(FALSE, 'Payment Method', 'activated', array('action' => 'default'));
724 724
 			}
725 725
 			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
726
-			if($correct_pmt_form_to_use->is_valid()){
727
-				$subsection_name = 'payment_method_settings_' . $payment_method->slug();
728
-				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection( $subsection_name );
729
-				if( ! $payment_settings_subform instanceof EE_Payment_Method_Form ) {
726
+			if ($correct_pmt_form_to_use->is_valid()) {
727
+				$subsection_name = 'payment_method_settings_'.$payment_method->slug();
728
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection($subsection_name);
729
+				if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
730 730
 					throw new EE_Error( 
731 731
 						sprintf(
732
-							__( 'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.','event_espresso' ),
732
+							__('The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.', 'event_espresso'),
733 733
 							$subsection_name
734 734
 						)
735 735
 					);
736 736
 				}
737 737
 				$payment_settings_subform->save();
738 738
 				/** @var $pm EE_Payment_Method */
739
-				$this->_redirect_after_action(TRUE, 'Payment Method', 'updated', array('action' => 'default','payment_method'=>$payment_method->slug()));
740
-			}else{
739
+				$this->_redirect_after_action(TRUE, 'Payment Method', 'updated', array('action' => 'default', 'payment_method'=>$payment_method->slug()));
740
+			} else {
741 741
 				EE_Error::add_error(
742 742
 					sprintf(
743 743
 						__('Payment method of type %s was not saved because there were validation errors. They have been marked in the form', 'event_espresso'),
744
-						$payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name() : __( '"(unknown)"', 'event_espresso' )
744
+						$payment_method instanceof EE_PMT_Base ? $payment_method->pretty_name() : __('"(unknown)"', 'event_espresso')
745 745
 					),
746 746
 					__FILE__,
747 747
 					__FUNCTION__,
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
 	protected function _payment_settings() {
759 759
 
760 760
 		$this->_template_args['values'] = $this->_yes_no_values;
761
-		$this->_template_args['show_pending_payment_options'] = isset( EE_Registry::instance()->CFG->registration->show_pending_payment_options ) ? absint( EE_Registry::instance()->CFG->registration->show_pending_payment_options ) : FALSE;
761
+		$this->_template_args['show_pending_payment_options'] = isset(EE_Registry::instance()->CFG->registration->show_pending_payment_options) ? absint(EE_Registry::instance()->CFG->registration->show_pending_payment_options) : FALSE;
762 762
 
763
-		$this->_set_add_edit_form_tags( 'update_payment_settings' );
764
-		$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
765
-		$this->_template_args['admin_page_content'] = EEH_Template::display_template( EE_PAYMENTS_TEMPLATE_PATH . 'payment_settings.template.php', $this->_template_args, TRUE );
763
+		$this->_set_add_edit_form_tags('update_payment_settings');
764
+		$this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE);
765
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(EE_PAYMENTS_TEMPLATE_PATH.'payment_settings.template.php', $this->_template_args, TRUE);
766 766
 		$this->display_admin_page_with_sidebar();
767 767
 
768 768
 	}
@@ -776,8 +776,8 @@  discard block
 block discarded – undo
776 776
 	*		@return array
777 777
 	*/
778 778
 	protected function _update_payment_settings() {
779
-		EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset( $this->_req_data['show_pending_payment_options'] ) ? $this->_req_data['show_pending_payment_options'] : FALSE;
780
-		EE_Registry::instance()->CFG = apply_filters( 'FHEE__Payments_Admin_Page___update_payment_settings__CFG', EE_Registry::instance()->CFG );
779
+		EE_Registry::instance()->CFG->registration->show_pending_payment_options = isset($this->_req_data['show_pending_payment_options']) ? $this->_req_data['show_pending_payment_options'] : FALSE;
780
+		EE_Registry::instance()->CFG = apply_filters('FHEE__Payments_Admin_Page___update_payment_settings__CFG', EE_Registry::instance()->CFG);
781 781
 
782 782
 //		 $superform = new EE_Form_Section_Proper(
783 783
 //		 	array(
@@ -797,9 +797,9 @@  discard block
 block discarded – undo
797 797
 //		 	$this->_redirect_after_action( 0, 'settings', 'updated', array( 'action' => 'payment_settings' ) );
798 798
 //		 }
799 799
 
800
-		$what = __('Payment Settings','event_espresso');
801
-		$success = $this->_update_espresso_configuration( $what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__ );
802
-		$this->_redirect_after_action( $success, $what, __('updated','event_espresso'), array( 'action' => 'payment_settings' ) );
800
+		$what = __('Payment Settings', 'event_espresso');
801
+		$success = $this->_update_espresso_configuration($what, EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__);
802
+		$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), array('action' => 'payment_settings'));
803 803
 
804 804
 	}
805 805
 	protected function _payment_log_overview_list_table() {
@@ -825,18 +825,18 @@  discard block
 block discarded – undo
825 825
 	 * @param bool $count
826 826
 	 * @return array
827 827
 	 */
828
-	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false){
829
-		EE_Registry::instance()->load_model( 'Change_Log' );
828
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false) {
829
+		EE_Registry::instance()->load_model('Change_Log');
830 830
 		//we may need to do multiple queries (joining differently), so we actually wan tan array of query params
831
-		$query_params =  array(array('LOG_type'=>  EEM_Change_Log::type_gateway));
831
+		$query_params = array(array('LOG_type'=>  EEM_Change_Log::type_gateway));
832 832
 		//check if they've selected a specific payment method
833
-		if( isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all'){
833
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
834 834
 			$query_params[0]['OR*pm_or_pay_pm'] = array('Payment.Payment_Method.PMD_ID'=>$this->_req_data['_payment_method'],
835 835
 				'Payment_Method.PMD_ID'=>$this->_req_data['_payment_method']);
836 836
 		}
837 837
 		//take into account search
838
-		if(isset($this->_req_data['s']) && $this->_req_data['s']){
839
-			$similarity_string = array('LIKE','%'.str_replace("","%",$this->_req_data['s']) .'%');
838
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
839
+			$similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
840 840
 			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
841 841
 			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
842 842
 			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -851,48 +851,48 @@  discard block
 block discarded – undo
851 851
 			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
852 852
 
853 853
 		}
854
-		if(isset( $this->_req_data['payment-filter-start-date'] ) && isset( $this->_req_data['payment-filter-end-date'] )){
854
+		if (isset($this->_req_data['payment-filter-start-date']) && isset($this->_req_data['payment-filter-end-date'])) {
855 855
 			//add date
856
-			$start_date =wp_strip_all_tags( $this->_req_data['payment-filter-start-date'] );
857
-			$end_date = wp_strip_all_tags( $this->_req_data['payment-filter-end-date'] );
856
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
857
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
858 858
 			//make sure our timestamps start and end right at the boundaries for each day
859
-			$start_date = date( 'Y-m-d', strtotime( $start_date ) ) . ' 00:00:00';
860
-			$end_date = date( 'Y-m-d', strtotime( $end_date ) ) . ' 23:59:59';
859
+			$start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
860
+			$end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
861 861
 
862 862
 			//convert to timestamps
863
-			$start_date = strtotime( $start_date );
864
-			$end_date = strtotime( $end_date );
863
+			$start_date = strtotime($start_date);
864
+			$end_date = strtotime($end_date);
865 865
 
866 866
 			//makes sure start date is the lowest value and vice versa
867
-			$start_date = min( $start_date, $end_date );
868
-			$end_date = max( $start_date, $end_date );
867
+			$start_date = min($start_date, $end_date);
868
+			$end_date = max($start_date, $end_date);
869 869
 
870 870
 			//convert for query
871
-			$start_date = EEM_Change_Log::instance()->convert_datetime_for_query( 'LOG_time', date( 'Y-m-d H:i:s', $start_date ), 'Y-m-d H:i:s' );
872
-			$end_date = EEM_Change_Log::instance()->convert_datetime_for_query( 'LOG_time', date( 'Y-m-d H:i:s', $end_date ), 'Y-m-d H:i:s' );
871
+			$start_date = EEM_Change_Log::instance()->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s');
872
+			$end_date = EEM_Change_Log::instance()->convert_datetime_for_query('LOG_time', date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s');
873 873
 
874
-			$query_params[0]['LOG_time'] = array('BETWEEN',array($start_date,$end_date));
874
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
875 875
 
876 876
 		}
877
-		if($count){
877
+		if ($count) {
878 878
 			return EEM_Change_Log::instance()->count($query_params);
879 879
 		}
880
-		if(isset($this->_req_data['order'])){
881
-			$sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'DESC';
880
+		if (isset($this->_req_data['order'])) {
881
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC';
882 882
 			$query_params['order_by'] = array('LOG_time' => $sort);
883
-		}else{
883
+		} else {
884 884
 				$query_params['order_by'] = array('LOG_time' => 'DESC');
885 885
 		}
886
-		$offset = ($current_page-1)*$per_page;
886
+		$offset = ($current_page - 1) * $per_page;
887 887
 
888
-		if( ! isset($this->_req_data['download_results'])){
889
-			$query_params['limit'] = array( $offset, $per_page );
888
+		if ( ! isset($this->_req_data['download_results'])) {
889
+			$query_params['limit'] = array($offset, $per_page);
890 890
 		}
891 891
 
892 892
 
893 893
 
894 894
 		//now they've requested to instead just download the file instead of viewing it.
895
-		if(isset($this->_req_data['download_results'])){
895
+		if (isset($this->_req_data['download_results'])) {
896 896
 			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
897 897
 			header('Content-Disposition: attachment');
898 898
 			header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
@@ -914,36 +914,36 @@  discard block
 block discarded – undo
914 914
 	 * @param EE_Change_Log $logB
915 915
 	 * @return int
916 916
 	 */
917
-	protected function _sort_logs_again($logA,$logB){
917
+	protected function _sort_logs_again($logA, $logB) {
918 918
 		$timeA = $logA->get_raw('LOG_time');
919 919
 		$timeB = $logB->get_raw('LOG_time');
920
-		if($timeA == $timeB){
920
+		if ($timeA == $timeB) {
921 921
 			return 0;
922 922
 		}
923 923
 		$comparison = $timeA < $timeB ? -1 : 1;
924
-		if(strtoupper($this->_sort_logs_again_direction) == 'DESC'){
924
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
925 925
 			return $comparison * -1;
926
-		}else{
926
+		} else {
927 927
 			return $comparison;
928 928
 		}
929 929
 	}
930 930
 
931 931
 	protected function _payment_log_details() {
932
-		EE_Registry::instance()->load_model( 'Change_Log' );
932
+		EE_Registry::instance()->load_model('Change_Log');
933 933
 		/** @var $payment_log EE_Change_Log */
934 934
 		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
935 935
 		$payment_method = NULL;
936 936
 		$transaction = NULL;
937
-		if( $payment_log instanceof EE_Change_Log ){
938
-			if( $payment_log->object() instanceof EE_Payment ){
937
+		if ($payment_log instanceof EE_Change_Log) {
938
+			if ($payment_log->object() instanceof EE_Payment) {
939 939
 				$payment_method = $payment_log->object()->payment_method();
940 940
 				$transaction = $payment_log->object()->transaction();
941
-			}elseif($payment_log->object() instanceof EE_Payment_Method){
941
+			}elseif ($payment_log->object() instanceof EE_Payment_Method) {
942 942
 				$payment_method = $payment_log->object();
943 943
 			}
944 944
 		}
945 945
 		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
946
-			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
946
+			EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
947 947
 			array(
948 948
 				'payment_log'=>$payment_log,
949 949
 				'payment_method'=>$payment_method,
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -128,7 +128,8 @@
 block discarded – undo
128 128
      *
129 129
      * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130 130
      * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
131
+     * @param boolean $remaining
132
+     * @return string status int if the display string isn't requested
132 133
      * @throws \EE_Error
133 134
      */
134 135
 	public function ticket_status( $display = FALSE, $remaining = null ) {
Please login to merge, or discard this patch.
Indentation   +566 added lines, -566 removed lines patch added patch discarded remove patch
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 
62 62
 
63 63
 
64
-    /**
65
-     * @param array  $props_n_values          incoming values
66
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
-     *                                        used.)
68
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
-     *                                        date_format and the second value is the time format
70
-     * @return EE_Ticket
71
-     * @throws \EE_Error
72
-     */
64
+	/**
65
+	 * @param array  $props_n_values          incoming values
66
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
67
+	 *                                        used.)
68
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
69
+	 *                                        date_format and the second value is the time format
70
+	 * @return EE_Ticket
71
+	 * @throws \EE_Error
72
+	 */
73 73
 	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74 74
 		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75 75
 		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
@@ -77,36 +77,36 @@  discard block
 block discarded – undo
77 77
 
78 78
 
79 79
 
80
-    /**
81
-     * @param array  $props_n_values  incoming values from the database
82
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
-     *                                the website will be used.
84
-     * @return EE_Ticket
85
-     * @throws \EE_Error
86
-     */
80
+	/**
81
+	 * @param array  $props_n_values  incoming values from the database
82
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
83
+	 *                                the website will be used.
84
+	 * @return EE_Ticket
85
+	 * @throws \EE_Error
86
+	 */
87 87
 	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88 88
 		return new self( $props_n_values, TRUE, $timezone );
89 89
 	}
90 90
 
91 91
 
92 92
 
93
-    /**
94
-     * @return bool
95
-     * @throws \EE_Error
96
-     */
93
+	/**
94
+	 * @return bool
95
+	 * @throws \EE_Error
96
+	 */
97 97
 	public function parent() {
98 98
 		return $this->get( 'TKT_parent' );
99 99
 	}
100 100
 
101 101
 
102 102
 
103
-    /**
104
-     * return if a ticket has quantities available for purchase
105
-     *
106
-     * @param  int $DTT_ID the primary key for a particular datetime
107
-     * @return boolean
108
-     * @throws \EE_Error
109
-     */
103
+	/**
104
+	 * return if a ticket has quantities available for purchase
105
+	 *
106
+	 * @param  int $DTT_ID the primary key for a particular datetime
107
+	 * @return boolean
108
+	 * @throws \EE_Error
109
+	 */
110 110
 	public function available( $DTT_ID = 0 ) {
111 111
 		// are we checking availability for a particular datetime ?
112 112
 		if ( $DTT_ID ) {
@@ -123,14 +123,14 @@  discard block
 block discarded – undo
123 123
 
124 124
 
125 125
 
126
-    /**
127
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
-     *
129
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
-     * @return mixed status int if the display string isn't requested
132
-     * @throws \EE_Error
133
-     */
126
+	/**
127
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
128
+	 *
129
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the relevant status const
130
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing
131
+	 * @return mixed status int if the display string isn't requested
132
+	 * @throws \EE_Error
133
+	 */
134 134
 	public function ticket_status( $display = FALSE, $remaining = null ) {
135 135
 		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136 136
 		if ( ! $remaining ) {
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 
156
-    /**
157
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
-     *
159
-     * @access public
160
-     * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
-     * @return boolean         true = tickets remaining, false not.
162
-     * @throws \EE_Error
163
-     */
156
+	/**
157
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out.
158
+	 *
159
+	 * @access public
160
+	 * @param  int $DTT_ID if an int above 0 is included here then we get a specific dtt.
161
+	 * @return boolean         true = tickets remaining, false not.
162
+	 * @throws \EE_Error
163
+	 */
164 164
 	public function is_remaining( $DTT_ID = 0 ) {
165 165
 		$num_remaining = $this->remaining( $DTT_ID );
166 166
 		if ( $num_remaining === 0 ) {
@@ -174,76 +174,76 @@  discard block
 block discarded – undo
174 174
 
175 175
 
176 176
 
177
-    /**
178
-     * return the total number of tickets available for purchase
179
-     *
180
-     * @param  int $DTT_ID the primary key for a particular datetime.
181
-     *                     set to 0 for all related datetimes
182
-     * @return int
183
-     * @throws \EE_Error
184
-     */
177
+	/**
178
+	 * return the total number of tickets available for purchase
179
+	 *
180
+	 * @param  int $DTT_ID the primary key for a particular datetime.
181
+	 *                     set to 0 for all related datetimes
182
+	 * @return int
183
+	 * @throws \EE_Error
184
+	 */
185 185
 	public function remaining( $DTT_ID = 0 ) {
186 186
 		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
187 187
 	}
188 188
 
189 189
 
190 190
 
191
-    /**
192
-     * Gets min
193
-     *
194
-     * @return int
195
-     * @throws \EE_Error
196
-     */
191
+	/**
192
+	 * Gets min
193
+	 *
194
+	 * @return int
195
+	 * @throws \EE_Error
196
+	 */
197 197
 	public function min() {
198 198
 		return $this->get( 'TKT_min' );
199 199
 	}
200 200
 
201 201
 
202 202
 
203
-    /**
204
-     * return if a ticket is no longer available cause its available dates have expired.
205
-     *
206
-     * @return boolean
207
-     * @throws \EE_Error
208
-     */
203
+	/**
204
+	 * return if a ticket is no longer available cause its available dates have expired.
205
+	 *
206
+	 * @return boolean
207
+	 * @throws \EE_Error
208
+	 */
209 209
 	public function is_expired() {
210 210
 		return ( $this->get_raw( 'TKT_end_date' ) < time() );
211 211
 	}
212 212
 
213 213
 
214 214
 
215
-    /**
216
-     * Return if a ticket is yet to go on sale or not
217
-     *
218
-     * @return boolean
219
-     * @throws \EE_Error
220
-     */
215
+	/**
216
+	 * Return if a ticket is yet to go on sale or not
217
+	 *
218
+	 * @return boolean
219
+	 * @throws \EE_Error
220
+	 */
221 221
 	public function is_pending() {
222 222
 		return ( $this->get_raw( 'TKT_start_date' ) > time() );
223 223
 	}
224 224
 
225 225
 
226 226
 
227
-    /**
228
-     * Return if a ticket is on sale or not
229
-     *
230
-     * @return boolean
231
-     * @throws \EE_Error
232
-     */
227
+	/**
228
+	 * Return if a ticket is on sale or not
229
+	 *
230
+	 * @return boolean
231
+	 * @throws \EE_Error
232
+	 */
233 233
 	public function is_on_sale() {
234 234
 		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
235 235
 	}
236 236
 
237 237
 
238 238
 
239
-    /**
240
-     * This returns the chronologically last datetime that this ticket is associated with
241
-     *
242
-     * @param string $dt_frmt
243
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
-     * @return string
245
-     * @throws \EE_Error
246
-     */
239
+	/**
240
+	 * This returns the chronologically last datetime that this ticket is associated with
241
+	 *
242
+	 * @param string $dt_frmt
243
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31
244
+	 * @return string
245
+	 * @throws \EE_Error
246
+	 */
247 247
 	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248 248
 		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249 249
 		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
@@ -253,12 +253,12 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     * This returns the chronologically first datetime that this ticket is associated with
258
-     *
259
-     * @return EE_Datetime
260
-     * @throws \EE_Error
261
-     */
256
+	/**
257
+	 * This returns the chronologically first datetime that this ticket is associated with
258
+	 *
259
+	 * @return EE_Datetime
260
+	 * @throws \EE_Error
261
+	 */
262 262
 	public function first_datetime() {
263 263
 		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264 264
 		return reset( $datetimes );
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets all the datetimes this ticket can be used for attending.
271
-     * Unless otherwise specified, orders datetimes by start date.
272
-     *
273
-     * @param array $query_params see EEM_Base::get_all()
274
-     * @return EE_Datetime[]|EE_Base_Class[]
275
-     * @throws \EE_Error
276
-     */
269
+	/**
270
+	 * Gets all the datetimes this ticket can be used for attending.
271
+	 * Unless otherwise specified, orders datetimes by start date.
272
+	 *
273
+	 * @param array $query_params see EEM_Base::get_all()
274
+	 * @return EE_Datetime[]|EE_Base_Class[]
275
+	 * @throws \EE_Error
276
+	 */
277 277
 	public function datetimes( $query_params = array() ) {
278 278
 		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279 279
 			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
@@ -283,12 +283,12 @@  discard block
 block discarded – undo
283 283
 
284 284
 
285 285
 
286
-    /**
287
-     * This returns the chronologically last datetime that this ticket is associated with
288
-     *
289
-     * @return EE_Datetime
290
-     * @throws \EE_Error
291
-     */
286
+	/**
287
+	 * This returns the chronologically last datetime that this ticket is associated with
288
+	 *
289
+	 * @return EE_Datetime
290
+	 * @throws \EE_Error
291
+	 */
292 292
 	public function last_datetime() {
293 293
 		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294 294
 		return end( $datetimes );
@@ -296,19 +296,19 @@  discard block
 block discarded – undo
296 296
 
297 297
 
298 298
 
299
-    /**
300
-     * This returns the total tickets sold depending on the given parameters.
301
-     *
302
-     * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
306
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
-     * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
-     * @return mixed (array|int)          how many tickets have sold
310
-     * @throws \EE_Error
311
-     */
299
+	/**
300
+	 * This returns the total tickets sold depending on the given parameters.
301
+	 *
302
+	 * @param  string $what   Can be one of two options: 'ticket', 'datetime'.
303
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
304
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
305
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
306
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
307
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
308
+	 * @param  int    $dtt_id [optional] include the dtt_id with $what = 'datetime'.
309
+	 * @return mixed (array|int)          how many tickets have sold
310
+	 * @throws \EE_Error
311
+	 */
312 312
 	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 
334 334
 
335 335
 
336
-    /**
337
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
-     *
339
-     * @return EE_Ticket[]
340
-     * @throws \EE_Error
341
-     */
336
+	/**
337
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
338
+	 *
339
+	 * @return EE_Ticket[]
340
+	 * @throws \EE_Error
341
+	 */
342 342
 	protected function _all_tickets_sold() {
343 343
 		$datetimes = $this->get_many_related( 'Datetime' );
344 344
 		$tickets_sold = array();
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
 
356 356
 
357
-    /**
358
-     * This returns the base price object for the ticket.
359
-     *
360
-     * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
-     * @throws \EE_Error
363
-     */
357
+	/**
358
+	 * This returns the base price object for the ticket.
359
+	 *
360
+	 * @param  bool $return_array whether to return as an array indexed by price id or just the object.
361
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362
+	 * @throws \EE_Error
363
+	 */
364 364
 	public function base_price( $return_array = FALSE ) {
365 365
 		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+			? $this->get_many_related( 'Price', array( $_where ) )
368
+			: $this->get_first_related( 'Price', array( $_where ) );
369 369
 	}
370 370
 
371 371
 
372 372
 
373
-    /**
374
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
-     *
376
-     * @access public
377
-     * @return EE_Price[]
378
-     * @throws \EE_Error
379
-     */
373
+	/**
374
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
375
+	 *
376
+	 * @access public
377
+	 * @return EE_Price[]
378
+	 * @throws \EE_Error
379
+	 */
380 380
 	public function price_modifiers() {
381 381
 		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382 382
 		return $this->prices( $query_params );
@@ -384,132 +384,132 @@  discard block
 block discarded – undo
384 384
 
385 385
 
386 386
 
387
-    /**
388
-     * Gets all the prices that combine to form the final price of this ticket
389
-     *
390
-     * @param array $query_params like EEM_Base::get_all
391
-     * @return EE_Price[]|EE_Base_Class[]
392
-     * @throws \EE_Error
393
-     */
387
+	/**
388
+	 * Gets all the prices that combine to form the final price of this ticket
389
+	 *
390
+	 * @param array $query_params like EEM_Base::get_all
391
+	 * @return EE_Price[]|EE_Base_Class[]
392
+	 * @throws \EE_Error
393
+	 */
394 394
 	public function prices( $query_params = array() ) {
395 395
 		return $this->get_many_related( 'Price', $query_params );
396 396
 	}
397 397
 
398 398
 
399 399
 
400
-    /**
401
-     * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
-     *
403
-     * @param array $query_params see EEM_Base::get_all()
404
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
405
-     * @throws \EE_Error
406
-     */
400
+	/**
401
+	 * Gets all the ticket applicabilities (ie, relations between datetimes and tickets)
402
+	 *
403
+	 * @param array $query_params see EEM_Base::get_all()
404
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
405
+	 * @throws \EE_Error
406
+	 */
407 407
 	public function datetime_tickets( $query_params = array() ) {
408 408
 		return $this->get_many_related( 'Datetime_Ticket', $query_params );
409 409
 	}
410 410
 
411 411
 
412 412
 
413
-    /**
414
-     * Gets all the datetimes from the db ordered by DTT_order
415
-     *
416
-     * @param boolean $show_expired
417
-     * @param boolean $show_deleted
418
-     * @return EE_Datetime[]
419
-     * @throws \EE_Error
420
-     */
413
+	/**
414
+	 * Gets all the datetimes from the db ordered by DTT_order
415
+	 *
416
+	 * @param boolean $show_expired
417
+	 * @param boolean $show_deleted
418
+	 * @return EE_Datetime[]
419
+	 * @throws \EE_Error
420
+	 */
421 421
 	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422 422
 		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
423 423
 	}
424 424
 
425 425
 
426 426
 
427
-    /**
428
-     * Gets ID
429
-     *
430
-     * @return string
431
-     * @throws \EE_Error
432
-     */
427
+	/**
428
+	 * Gets ID
429
+	 *
430
+	 * @return string
431
+	 * @throws \EE_Error
432
+	 */
433 433
 	public function ID() {
434 434
 		return $this->get( 'TKT_ID' );
435 435
 	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * get the author of the ticket.
441
-     *
442
-     * @since 4.5.0
443
-     * @return int
444
-     * @throws \EE_Error
445
-     */
439
+	/**
440
+	 * get the author of the ticket.
441
+	 *
442
+	 * @since 4.5.0
443
+	 * @return int
444
+	 * @throws \EE_Error
445
+	 */
446 446
 	public function wp_user() {
447 447
 		return $this->get('TKT_wp_user');
448 448
 	}
449 449
 
450 450
 
451 451
 
452
-    /**
453
-     * Gets the template for the ticket
454
-     *
455
-     * @return EE_Ticket_Template|EE_Base_Class
456
-     * @throws \EE_Error
457
-     */
452
+	/**
453
+	 * Gets the template for the ticket
454
+	 *
455
+	 * @return EE_Ticket_Template|EE_Base_Class
456
+	 * @throws \EE_Error
457
+	 */
458 458
 	public function template() {
459 459
 		return $this->get_first_related( 'Ticket_Template' );
460 460
 	}
461 461
 
462 462
 
463 463
 
464
-    /**
465
-     * Simply returns an array of EE_Price objects that are taxes.
466
-     *
467
-     * @return EE_Price[]
468
-     * @throws \EE_Error
469
-     */
464
+	/**
465
+	 * Simply returns an array of EE_Price objects that are taxes.
466
+	 *
467
+	 * @return EE_Price[]
468
+	 * @throws \EE_Error
469
+	 */
470 470
 	public function get_ticket_taxes_for_admin() {
471 471
 		return EE_Taxes::get_taxes_for_admin();
472 472
 	}
473 473
 
474 474
 
475 475
 
476
-    /**
477
-     * @return float
478
-     * @throws \EE_Error
479
-     */
476
+	/**
477
+	 * @return float
478
+	 * @throws \EE_Error
479
+	 */
480 480
 	public function ticket_price() {
481 481
 		return $this->get( 'TKT_price' );
482 482
 	}
483 483
 
484 484
 
485 485
 
486
-    /**
487
-     * @return mixed
488
-     * @throws \EE_Error
489
-     */
486
+	/**
487
+	 * @return mixed
488
+	 * @throws \EE_Error
489
+	 */
490 490
 	public function pretty_price() {
491 491
 		return $this->get_pretty( 'TKT_price' );
492 492
 	}
493 493
 
494 494
 
495 495
 
496
-    /**
497
-     * @return bool
498
-     * @throws \EE_Error
499
-     */
496
+	/**
497
+	 * @return bool
498
+	 * @throws \EE_Error
499
+	 */
500 500
 	public function is_free() {
501 501
 		return $this->get_ticket_total_with_taxes() === 0;
502 502
 	}
503 503
 
504 504
 
505 505
 
506
-    /**
507
-     * get_ticket_total_with_taxes
508
-     *
509
-     * @param bool $no_cache
510
-     * @return float
511
-     * @throws \EE_Error
512
-     */
506
+	/**
507
+	 * get_ticket_total_with_taxes
508
+	 *
509
+	 * @param bool $no_cache
510
+	 * @return float
511
+	 * @throws \EE_Error
512
+	 */
513 513
 	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514 514
 		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
@@ -526,201 +526,201 @@  discard block
 block discarded – undo
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @return float
531
-     * @throws \EE_Error
532
-     */
529
+	/**
530
+	 * @return float
531
+	 * @throws \EE_Error
532
+	 */
533 533
 	public function get_ticket_subtotal() {
534 534
 		return EE_Taxes::get_subtotal_for_admin( $this );
535 535
 	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * Returns the total taxes applied to this ticket
541
-     *
542
-     * @return float
543
-     * @throws \EE_Error
544
-     */
539
+	/**
540
+	 * Returns the total taxes applied to this ticket
541
+	 *
542
+	 * @return float
543
+	 * @throws \EE_Error
544
+	 */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546 546
 		return EE_Taxes::get_total_taxes_for_admin( $this );
547 547
 	}
548 548
 
549 549
 
550 550
 
551
-    /**
552
-     * Sets name
553
-     *
554
-     * @param string $name
555
-     * @throws \EE_Error
556
-     */
551
+	/**
552
+	 * Sets name
553
+	 *
554
+	 * @param string $name
555
+	 * @throws \EE_Error
556
+	 */
557 557
 	public function set_name( $name ) {
558 558
 		$this->set( 'TKT_name', $name );
559 559
 	}
560 560
 
561 561
 
562 562
 
563
-    /**
564
-     * Gets description
565
-     *
566
-     * @return string
567
-     * @throws \EE_Error
568
-     */
563
+	/**
564
+	 * Gets description
565
+	 *
566
+	 * @return string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public function description() {
570 570
 		return $this->get( 'TKT_description' );
571 571
 	}
572 572
 
573 573
 
574 574
 
575
-    /**
576
-     * Sets description
577
-     *
578
-     * @param string $description
579
-     * @throws \EE_Error
580
-     */
575
+	/**
576
+	 * Sets description
577
+	 *
578
+	 * @param string $description
579
+	 * @throws \EE_Error
580
+	 */
581 581
 	public function set_description( $description ) {
582 582
 		$this->set( 'TKT_description', $description );
583 583
 	}
584 584
 
585 585
 
586 586
 
587
-    /**
588
-     * Gets start_date
589
-     *
590
-     * @param string $dt_frmt
591
-     * @param string $tm_frmt
592
-     * @return string
593
-     * @throws \EE_Error
594
-     */
587
+	/**
588
+	 * Gets start_date
589
+	 *
590
+	 * @param string $dt_frmt
591
+	 * @param string $tm_frmt
592
+	 * @return string
593
+	 * @throws \EE_Error
594
+	 */
595 595
 	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596 596
 		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
597 597
 	}
598 598
 
599 599
 
600 600
 
601
-    /**
602
-     * Sets start_date
603
-     *
604
-     * @param string $start_date
605
-     * @return void
606
-     * @throws \EE_Error
607
-     */
601
+	/**
602
+	 * Sets start_date
603
+	 *
604
+	 * @param string $start_date
605
+	 * @return void
606
+	 * @throws \EE_Error
607
+	 */
608 608
 	public function set_start_date( $start_date ) {
609 609
 		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
610 610
 	}
611 611
 
612 612
 
613 613
 
614
-    /**
615
-     * Gets end_date
616
-     *
617
-     * @param string $dt_frmt
618
-     * @param string $tm_frmt
619
-     * @return string
620
-     * @throws \EE_Error
621
-     */
614
+	/**
615
+	 * Gets end_date
616
+	 *
617
+	 * @param string $dt_frmt
618
+	 * @param string $tm_frmt
619
+	 * @return string
620
+	 * @throws \EE_Error
621
+	 */
622 622
 	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623 623
 		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
624 624
 	}
625 625
 
626 626
 
627 627
 
628
-    /**
629
-     * Sets end_date
630
-     *
631
-     * @param string $end_date
632
-     * @return void
633
-     * @throws \EE_Error
634
-     */
628
+	/**
629
+	 * Sets end_date
630
+	 *
631
+	 * @param string $end_date
632
+	 * @return void
633
+	 * @throws \EE_Error
634
+	 */
635 635
 	public function set_end_date( $end_date ) {
636 636
 		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
637 637
 	}
638 638
 
639 639
 
640 640
 
641
-    /**
642
-     * Sets sell until time
643
-     *
644
-     * @since 4.5.0
645
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
-     * @throws \EE_Error
647
-     */
641
+	/**
642
+	 * Sets sell until time
643
+	 *
644
+	 * @since 4.5.0
645
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646
+	 * @throws \EE_Error
647
+	 */
648 648
 	public function set_end_time( $time ) {
649 649
 		$this->_set_time_for( $time, 'TKT_end_date' );
650 650
 	}
651 651
 
652 652
 
653 653
 
654
-    /**
655
-     * Sets min
656
-     *
657
-     * @param int $min
658
-     * @return void
659
-     * @throws \EE_Error
660
-     */
654
+	/**
655
+	 * Sets min
656
+	 *
657
+	 * @param int $min
658
+	 * @return void
659
+	 * @throws \EE_Error
660
+	 */
661 661
 	public function set_min( $min ) {
662 662
 		$this->set( 'TKT_min', $min );
663 663
 	}
664 664
 
665 665
 
666 666
 
667
-    /**
668
-     * Gets max
669
-     *
670
-     * @return int
671
-     * @throws \EE_Error
672
-     */
667
+	/**
668
+	 * Gets max
669
+	 *
670
+	 * @return int
671
+	 * @throws \EE_Error
672
+	 */
673 673
 	public function max() {
674 674
 		return $this->get( 'TKT_max' );
675 675
 	}
676 676
 
677 677
 
678 678
 
679
-    /**
680
-     * Sets max
681
-     *
682
-     * @param int $max
683
-     * @return void
684
-     * @throws \EE_Error
685
-     */
679
+	/**
680
+	 * Sets max
681
+	 *
682
+	 * @param int $max
683
+	 * @return void
684
+	 * @throws \EE_Error
685
+	 */
686 686
 	public function set_max( $max ) {
687 687
 		$this->set( 'TKT_max', $max );
688 688
 	}
689 689
 
690 690
 
691 691
 
692
-    /**
693
-     * Sets price
694
-     *
695
-     * @param float $price
696
-     * @return void
697
-     * @throws \EE_Error
698
-     */
692
+	/**
693
+	 * Sets price
694
+	 *
695
+	 * @param float $price
696
+	 * @return void
697
+	 * @throws \EE_Error
698
+	 */
699 699
 	public function set_price( $price ) {
700 700
 		$this->set( 'TKT_price', $price );
701 701
 	}
702 702
 
703 703
 
704 704
 
705
-    /**
706
-     * Gets sold
707
-     *
708
-     * @return int
709
-     * @throws \EE_Error
710
-     */
705
+	/**
706
+	 * Gets sold
707
+	 *
708
+	 * @return int
709
+	 * @throws \EE_Error
710
+	 */
711 711
 	public function sold() {
712 712
 		return $this->get_raw( 'TKT_sold' );
713 713
 	}
714 714
 
715 715
 
716 716
 
717
-    /**
718
-     * Sets sold
719
-     *
720
-     * @param int $sold
721
-     * @return void
722
-     * @throws \EE_Error
723
-     */
717
+	/**
718
+	 * Sets sold
719
+	 *
720
+	 * @param int $sold
721
+	 * @return void
722
+	 * @throws \EE_Error
723
+	 */
724 724
 	public function set_sold( $sold ) {
725 725
 		// sold can not go below zero
726 726
 		$sold = max( 0, $sold );
@@ -729,13 +729,13 @@  discard block
 block discarded – undo
729 729
 
730 730
 
731 731
 
732
-    /**
733
-     * increments sold by amount passed by $qty
734
-     *
735
-     * @param int $qty
736
-     * @return void
737
-     * @throws \EE_Error
738
-     */
732
+	/**
733
+	 * increments sold by amount passed by $qty
734
+	 *
735
+	 * @param int $qty
736
+	 * @return void
737
+	 * @throws \EE_Error
738
+	 */
739 739
 	public function increase_sold( $qty = 1 ) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 
748 748
 
749 749
 
750
-    /**
751
-     * Increases sold on related datetimes
752
-     *
753
-     * @param int $qty
754
-     * @return void
755
-     * @throws \EE_Error
756
-     */
750
+	/**
751
+	 * Increases sold on related datetimes
752
+	 *
753
+	 * @param int $qty
754
+	 * @return void
755
+	 * @throws \EE_Error
756
+	 */
757 757
 	protected function _increase_sold_for_datetimes( $qty = 1 ) {
758 758
 		$datetimes = $this->datetimes();
759 759
 		if ( is_array( $datetimes ) ) {
@@ -768,13 +768,13 @@  discard block
 block discarded – undo
768 768
 
769 769
 
770 770
 
771
-    /**
772
-     * decrements (subtracts) sold by amount passed by $qty
773
-     *
774
-     * @param int $qty
775
-     * @return void
776
-     * @throws \EE_Error
777
-     */
771
+	/**
772
+	 * decrements (subtracts) sold by amount passed by $qty
773
+	 *
774
+	 * @param int $qty
775
+	 * @return void
776
+	 * @throws \EE_Error
777
+	 */
778 778
 	public function decrease_sold( $qty = 1 ) {
779 779
 		$sold = $this->sold() - $qty;
780 780
 		$this->_decrease_sold_for_datetimes( $qty );
@@ -783,13 +783,13 @@  discard block
 block discarded – undo
783 783
 
784 784
 
785 785
 
786
-    /**
787
-     * Decreases sold on related datetimes
788
-     *
789
-     * @param int $qty
790
-     * @return void
791
-     * @throws \EE_Error
792
-     */
786
+	/**
787
+	 * Decreases sold on related datetimes
788
+	 *
789
+	 * @param int $qty
790
+	 * @return void
791
+	 * @throws \EE_Error
792
+	 */
793 793
 	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
794 794
 		$datetimes = $this->datetimes();
795 795
 		if ( is_array( $datetimes ) ) {
@@ -804,25 +804,25 @@  discard block
 block discarded – undo
804 804
 
805 805
 
806 806
 
807
-    /**
808
-     * Gets qty of reserved tickets
809
-     *
810
-     * @return int
811
-     * @throws \EE_Error
812
-     */
807
+	/**
808
+	 * Gets qty of reserved tickets
809
+	 *
810
+	 * @return int
811
+	 * @throws \EE_Error
812
+	 */
813 813
 	public function reserved() {
814 814
 		return $this->get_raw( 'TKT_reserved' );
815 815
 	}
816 816
 
817 817
 
818 818
 
819
-    /**
820
-     * Sets reserved
821
-     *
822
-     * @param int $reserved
823
-     * @return void
824
-     * @throws \EE_Error
825
-     */
819
+	/**
820
+	 * Sets reserved
821
+	 *
822
+	 * @param int $reserved
823
+	 * @return void
824
+	 * @throws \EE_Error
825
+	 */
826 826
 	public function set_reserved( $reserved ) {
827 827
 		// reserved can not go below zero
828 828
 		$reserved = max( 0, (int) $reserved );
@@ -831,13 +831,13 @@  discard block
 block discarded – undo
831 831
 
832 832
 
833 833
 
834
-    /**
835
-     * increments reserved by amount passed by $qty
836
-     *
837
-     * @param int $qty
838
-     * @return void
839
-     * @throws \EE_Error
840
-     */
834
+	/**
835
+	 * increments reserved by amount passed by $qty
836
+	 *
837
+	 * @param int $qty
838
+	 * @return void
839
+	 * @throws \EE_Error
840
+	 */
841 841
 	public function increase_reserved( $qty = 1 ) {
842 842
 		$qty = absint( $qty );
843 843
 		$reserved = $this->reserved() + $qty;
@@ -847,13 +847,13 @@  discard block
 block discarded – undo
847 847
 
848 848
 
849 849
 
850
-    /**
851
-     * Increases sold on related datetimes
852
-     *
853
-     * @param int $qty
854
-     * @return void
855
-     * @throws \EE_Error
856
-     */
850
+	/**
851
+	 * Increases sold on related datetimes
852
+	 *
853
+	 * @param int $qty
854
+	 * @return void
855
+	 * @throws \EE_Error
856
+	 */
857 857
 	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
858 858
 		$datetimes = $this->datetimes();
859 859
 		if ( is_array( $datetimes ) ) {
@@ -868,14 +868,14 @@  discard block
 block discarded – undo
868 868
 
869 869
 
870 870
 
871
-    /**
872
-     * decrements (subtracts) reserved by amount passed by $qty
873
-     *
874
-     * @param int  $qty
875
-     * @param bool $adjust_datetimes
876
-     * @return void
877
-     * @throws \EE_Error
878
-     */
871
+	/**
872
+	 * decrements (subtracts) reserved by amount passed by $qty
873
+	 *
874
+	 * @param int  $qty
875
+	 * @param bool $adjust_datetimes
876
+	 * @return void
877
+	 * @throws \EE_Error
878
+	 */
879 879
 	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880 880
 		$reserved = $this->reserved() - absint( $qty );
881 881
 		if ( $adjust_datetimes ) {
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
 
887 887
 
888 888
 
889
-    /**
890
-     * Increases sold on related datetimes
891
-     *
892
-     * @param int $qty
893
-     * @return void
894
-     * @throws \EE_Error
895
-     */
889
+	/**
890
+	 * Increases sold on related datetimes
891
+	 *
892
+	 * @param int $qty
893
+	 * @return void
894
+	 * @throws \EE_Error
895
+	 */
896 896
 	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
897 897
 		$datetimes = $this->datetimes();
898 898
 		if ( is_array( $datetimes ) ) {
@@ -907,18 +907,18 @@  discard block
 block discarded – undo
907 907
 
908 908
 
909 909
 
910
-    /**
911
-     * Gets ticket quantity
912
-     *
913
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
919
-     * @return int
920
-     * @throws \EE_Error
921
-     */
910
+	/**
911
+	 * Gets ticket quantity
912
+	 *
913
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
914
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
915
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
916
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
917
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
918
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
919
+	 * @return int
920
+	 * @throws \EE_Error
921
+	 */
922 922
 	public function qty( $context = '' ) {
923 923
 		switch ( $context ) {
924 924
 			case 'reg_limit' :
@@ -932,19 +932,19 @@  discard block
 block discarded – undo
932 932
 
933 933
 
934 934
 
935
-    /**
936
-     * Gets ticket quantity
937
-     *
938
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
943
-     * @param  int   $DTT_ID      the primary key for a particular datetime.
944
-     *                            set to 0 for all related datetimes
945
-     * @return int
946
-     * @throws \EE_Error
947
-     */
935
+	/**
936
+	 * Gets ticket quantity
937
+	 *
938
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
939
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
940
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
941
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
942
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
943
+	 * @param  int   $DTT_ID      the primary key for a particular datetime.
944
+	 *                            set to 0 for all related datetimes
945
+	 * @return int
946
+	 * @throws \EE_Error
947
+	 */
948 948
 	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949 949
 		$raw = $this->get_raw( 'TKT_qty' );
950 950
 		// return immediately if it's zero
@@ -1027,212 +1027,212 @@  discard block
 block discarded – undo
1027 1027
 
1028 1028
 
1029 1029
 
1030
-    /**
1031
-     * Gets uses
1032
-     *
1033
-     * @return int
1034
-     * @throws \EE_Error
1035
-     */
1030
+	/**
1031
+	 * Gets uses
1032
+	 *
1033
+	 * @return int
1034
+	 * @throws \EE_Error
1035
+	 */
1036 1036
 	public function uses() {
1037 1037
 		return $this->get( 'TKT_uses' );
1038 1038
 	}
1039 1039
 
1040 1040
 
1041 1041
 
1042
-    /**
1043
-     * Sets uses
1044
-     *
1045
-     * @param int $uses
1046
-     * @return void
1047
-     * @throws \EE_Error
1048
-     */
1042
+	/**
1043
+	 * Sets uses
1044
+	 *
1045
+	 * @param int $uses
1046
+	 * @return void
1047
+	 * @throws \EE_Error
1048
+	 */
1049 1049
 	public function set_uses( $uses ) {
1050 1050
 		$this->set( 'TKT_uses', $uses );
1051 1051
 	}
1052 1052
 
1053 1053
 
1054 1054
 
1055
-    /**
1056
-     * returns whether ticket is required or not.
1057
-     *
1058
-     * @return boolean
1059
-     * @throws \EE_Error
1060
-     */
1055
+	/**
1056
+	 * returns whether ticket is required or not.
1057
+	 *
1058
+	 * @return boolean
1059
+	 * @throws \EE_Error
1060
+	 */
1061 1061
 	public function required() {
1062 1062
 		return $this->get( 'TKT_required' );
1063 1063
 	}
1064 1064
 
1065 1065
 
1066 1066
 
1067
-    /**
1068
-     * sets the TKT_required property
1069
-     *
1070
-     * @param boolean $required
1071
-     * @return void
1072
-     * @throws \EE_Error
1073
-     */
1067
+	/**
1068
+	 * sets the TKT_required property
1069
+	 *
1070
+	 * @param boolean $required
1071
+	 * @return void
1072
+	 * @throws \EE_Error
1073
+	 */
1074 1074
 	public function set_required( $required ) {
1075 1075
 		$this->set( 'TKT_required', $required );
1076 1076
 	}
1077 1077
 
1078 1078
 
1079 1079
 
1080
-    /**
1081
-     * Gets taxable
1082
-     *
1083
-     * @return boolean
1084
-     * @throws \EE_Error
1085
-     */
1080
+	/**
1081
+	 * Gets taxable
1082
+	 *
1083
+	 * @return boolean
1084
+	 * @throws \EE_Error
1085
+	 */
1086 1086
 	public function taxable() {
1087 1087
 		return $this->get( 'TKT_taxable' );
1088 1088
 	}
1089 1089
 
1090 1090
 
1091 1091
 
1092
-    /**
1093
-     * Sets taxable
1094
-     *
1095
-     * @param boolean $taxable
1096
-     * @return void
1097
-     * @throws \EE_Error
1098
-     */
1092
+	/**
1093
+	 * Sets taxable
1094
+	 *
1095
+	 * @param boolean $taxable
1096
+	 * @return void
1097
+	 * @throws \EE_Error
1098
+	 */
1099 1099
 	public function set_taxable( $taxable ) {
1100 1100
 		$this->set( 'TKT_taxable', $taxable );
1101 1101
 	}
1102 1102
 
1103 1103
 
1104 1104
 
1105
-    /**
1106
-     * Gets is_default
1107
-     *
1108
-     * @return boolean
1109
-     * @throws \EE_Error
1110
-     */
1105
+	/**
1106
+	 * Gets is_default
1107
+	 *
1108
+	 * @return boolean
1109
+	 * @throws \EE_Error
1110
+	 */
1111 1111
 	public function is_default() {
1112 1112
 		return $this->get( 'TKT_is_default' );
1113 1113
 	}
1114 1114
 
1115 1115
 
1116 1116
 
1117
-    /**
1118
-     * Sets is_default
1119
-     *
1120
-     * @param boolean $is_default
1121
-     * @return void
1122
-     * @throws \EE_Error
1123
-     */
1117
+	/**
1118
+	 * Sets is_default
1119
+	 *
1120
+	 * @param boolean $is_default
1121
+	 * @return void
1122
+	 * @throws \EE_Error
1123
+	 */
1124 1124
 	public function set_is_default( $is_default ) {
1125 1125
 		$this->set( 'TKT_is_default', $is_default );
1126 1126
 	}
1127 1127
 
1128 1128
 
1129 1129
 
1130
-    /**
1131
-     * Gets order
1132
-     *
1133
-     * @return int
1134
-     * @throws \EE_Error
1135
-     */
1130
+	/**
1131
+	 * Gets order
1132
+	 *
1133
+	 * @return int
1134
+	 * @throws \EE_Error
1135
+	 */
1136 1136
 	public function order() {
1137 1137
 		return $this->get( 'TKT_order' );
1138 1138
 	}
1139 1139
 
1140 1140
 
1141 1141
 
1142
-    /**
1143
-     * Sets order
1144
-     *
1145
-     * @param int $order
1146
-     * @return void
1147
-     * @throws \EE_Error
1148
-     */
1142
+	/**
1143
+	 * Sets order
1144
+	 *
1145
+	 * @param int $order
1146
+	 * @return void
1147
+	 * @throws \EE_Error
1148
+	 */
1149 1149
 	public function set_order( $order ) {
1150 1150
 		$this->set( 'TKT_order', $order );
1151 1151
 	}
1152 1152
 
1153 1153
 
1154 1154
 
1155
-    /**
1156
-     * Gets row
1157
-     *
1158
-     * @return int
1159
-     * @throws \EE_Error
1160
-     */
1155
+	/**
1156
+	 * Gets row
1157
+	 *
1158
+	 * @return int
1159
+	 * @throws \EE_Error
1160
+	 */
1161 1161
 	public function row() {
1162 1162
 		return $this->get( 'TKT_row' );
1163 1163
 	}
1164 1164
 
1165 1165
 
1166 1166
 
1167
-    /**
1168
-     * Sets row
1169
-     *
1170
-     * @param int $row
1171
-     * @return void
1172
-     * @throws \EE_Error
1173
-     */
1167
+	/**
1168
+	 * Sets row
1169
+	 *
1170
+	 * @param int $row
1171
+	 * @return void
1172
+	 * @throws \EE_Error
1173
+	 */
1174 1174
 	public function set_row( $row ) {
1175 1175
 		$this->set( 'TKT_row', $row );
1176 1176
 	}
1177 1177
 
1178 1178
 
1179 1179
 
1180
-    /**
1181
-     * Gets deleted
1182
-     *
1183
-     * @return boolean
1184
-     * @throws \EE_Error
1185
-     */
1180
+	/**
1181
+	 * Gets deleted
1182
+	 *
1183
+	 * @return boolean
1184
+	 * @throws \EE_Error
1185
+	 */
1186 1186
 	public function deleted() {
1187 1187
 		return $this->get( 'TKT_deleted' );
1188 1188
 	}
1189 1189
 
1190 1190
 
1191 1191
 
1192
-    /**
1193
-     * Sets deleted
1194
-     *
1195
-     * @param boolean $deleted
1196
-     * @return void
1197
-     * @throws \EE_Error
1198
-     */
1192
+	/**
1193
+	 * Sets deleted
1194
+	 *
1195
+	 * @param boolean $deleted
1196
+	 * @return void
1197
+	 * @throws \EE_Error
1198
+	 */
1199 1199
 	public function set_deleted( $deleted ) {
1200 1200
 		$this->set( 'TKT_deleted', $deleted );
1201 1201
 	}
1202 1202
 
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Gets parent
1207
-     *
1208
-     * @return int
1209
-     * @throws \EE_Error
1210
-     */
1205
+	/**
1206
+	 * Gets parent
1207
+	 *
1208
+	 * @return int
1209
+	 * @throws \EE_Error
1210
+	 */
1211 1211
 	public function parent_ID() {
1212 1212
 		return $this->get( 'TKT_parent' );
1213 1213
 	}
1214 1214
 
1215 1215
 
1216 1216
 
1217
-    /**
1218
-     * Sets parent
1219
-     *
1220
-     * @param int $parent
1221
-     * @return void
1222
-     * @throws \EE_Error
1223
-     */
1217
+	/**
1218
+	 * Sets parent
1219
+	 *
1220
+	 * @param int $parent
1221
+	 * @return void
1222
+	 * @throws \EE_Error
1223
+	 */
1224 1224
 	public function set_parent_ID( $parent ) {
1225 1225
 		$this->set( 'TKT_parent', $parent );
1226 1226
 	}
1227 1227
 
1228 1228
 
1229 1229
 
1230
-    /**
1231
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
-     *
1233
-     * @return string
1234
-     * @throws \EE_Error
1235
-     */
1230
+	/**
1231
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1232
+	 *
1233
+	 * @return string
1234
+	 * @throws \EE_Error
1235
+	 */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238 1238
 		foreach ( $this->datetimes() as $datetime ) {
@@ -1243,50 +1243,50 @@  discard block
 block discarded – undo
1243 1243
 
1244 1244
 
1245 1245
 
1246
-    /**
1247
-     * Gets name
1248
-     *
1249
-     * @return string
1250
-     * @throws \EE_Error
1251
-     */
1246
+	/**
1247
+	 * Gets name
1248
+	 *
1249
+	 * @return string
1250
+	 * @throws \EE_Error
1251
+	 */
1252 1252
 	public function name() {
1253 1253
 		return $this->get( 'TKT_name' );
1254 1254
 	}
1255 1255
 
1256 1256
 
1257 1257
 
1258
-    /**
1259
-     * Gets price
1260
-     *
1261
-     * @return float
1262
-     * @throws \EE_Error
1263
-     */
1258
+	/**
1259
+	 * Gets price
1260
+	 *
1261
+	 * @return float
1262
+	 * @throws \EE_Error
1263
+	 */
1264 1264
 	public function price() {
1265 1265
 		return $this->get( 'TKT_price' );
1266 1266
 	}
1267 1267
 
1268 1268
 
1269 1269
 
1270
-    /**
1271
-     * Gets all the registrations for this ticket
1272
-     *
1273
-     * @param array $query_params like EEM_Base::get_all's
1274
-     * @return EE_Registration[]|EE_Base_Class[]
1275
-     * @throws \EE_Error
1276
-     */
1270
+	/**
1271
+	 * Gets all the registrations for this ticket
1272
+	 *
1273
+	 * @param array $query_params like EEM_Base::get_all's
1274
+	 * @return EE_Registration[]|EE_Base_Class[]
1275
+	 * @throws \EE_Error
1276
+	 */
1277 1277
 	public function registrations( $query_params = array() ) {
1278 1278
 		return $this->get_many_related( 'Registration', $query_params );
1279 1279
 	}
1280 1280
 
1281 1281
 
1282 1282
 
1283
-    /**
1284
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
-     * into account
1286
-     *
1287
-     * @return int
1288
-     * @throws \EE_Error
1289
-     */
1283
+	/**
1284
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1285
+	 * into account
1286
+	 *
1287
+	 * @return int
1288
+	 * @throws \EE_Error
1289
+	 */
1290 1290
 	public function update_tickets_sold() {
1291 1291
 		$count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) );
1292 1292
 		$this->set_sold( $count_regs_for_this_ticket );
@@ -1318,21 +1318,21 @@  discard block
 block discarded – undo
1318 1318
 
1319 1319
 
1320 1320
 
1321
-    /**
1322
-     * Implementation of the EEI_Event_Relation interface method
1323
-     *
1324
-     * @see EEI_Event_Relation for comments
1325
-     * @return EE_Event
1326
-     * @throws \EE_Error
1327
-     * @throws UnexpectedEntityException
1328
-     */
1321
+	/**
1322
+	 * Implementation of the EEI_Event_Relation interface method
1323
+	 *
1324
+	 * @see EEI_Event_Relation for comments
1325
+	 * @return EE_Event
1326
+	 * @throws \EE_Error
1327
+	 * @throws UnexpectedEntityException
1328
+	 */
1329 1329
 	public function get_related_event() {
1330 1330
 		//get one datetime to use for getting the event
1331 1331
 		$datetime = $this->first_datetime();
1332 1332
 		if ( ! $datetime instanceof \EE_Datetime ) {
1333 1333
 			throw new UnexpectedEntityException(
1334 1334
 				$datetime,
1335
-                'EE_Datetime',
1335
+				'EE_Datetime',
1336 1336
 				sprintf(
1337 1337
 					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1338 1338
 					$this->name()
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 		if ( ! $event instanceof \EE_Event ) {
1344 1344
 			throw new UnexpectedEntityException(
1345 1345
 				$event,
1346
-                'EE_Event',
1346
+				'EE_Event',
1347 1347
 				sprintf(
1348 1348
 					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1349 1349
 					$this->name()
@@ -1355,14 +1355,14 @@  discard block
 block discarded – undo
1355 1355
 
1356 1356
 
1357 1357
 
1358
-    /**
1359
-     * Implementation of the EEI_Event_Relation interface method
1360
-     *
1361
-     * @see EEI_Event_Relation for comments
1362
-     * @return string
1363
-     * @throws UnexpectedEntityException
1364
-     * @throws \EE_Error
1365
-     */
1358
+	/**
1359
+	 * Implementation of the EEI_Event_Relation interface method
1360
+	 *
1361
+	 * @see EEI_Event_Relation for comments
1362
+	 * @return string
1363
+	 * @throws UnexpectedEntityException
1364
+	 * @throws \EE_Error
1365
+	 */
1366 1366
 	public function get_event_name() {
1367 1367
 		$event = $this->get_related_event();
1368 1368
 		return $event instanceof EE_Event ? $event->name() : '';
@@ -1370,14 +1370,14 @@  discard block
 block discarded – undo
1370 1370
 
1371 1371
 
1372 1372
 
1373
-    /**
1374
-     * Implementation of the EEI_Event_Relation interface method
1375
-     *
1376
-     * @see EEI_Event_Relation for comments
1377
-     * @return int
1378
-     * @throws UnexpectedEntityException
1379
-     * @throws \EE_Error
1380
-     */
1373
+	/**
1374
+	 * Implementation of the EEI_Event_Relation interface method
1375
+	 *
1376
+	 * @see EEI_Event_Relation for comments
1377
+	 * @return int
1378
+	 * @throws UnexpectedEntityException
1379
+	 * @throws \EE_Error
1380
+	 */
1381 1381
 	public function get_event_ID() {
1382 1382
 		$event = $this->get_related_event();
1383 1383
 		return $event instanceof EE_Event ? $event->ID() : 0;
Please login to merge, or discard this patch.
Spacing   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\UnexpectedEntityException;
2 2
 
3
-if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
-	exit( 'No direct script access allowed' );
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 /**
7 7
  * Event Espresso
@@ -70,9 +70,9 @@  discard block
 block discarded – undo
70 70
      * @return EE_Ticket
71 71
      * @throws \EE_Error
72 72
      */
73
-	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
74
-		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
75
-		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
73
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) {
74
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
75
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
76 76
 	}
77 77
 
78 78
 
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
      * @return EE_Ticket
85 85
      * @throws \EE_Error
86 86
      */
87
-	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
88
-		return new self( $props_n_values, TRUE, $timezone );
87
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null) {
88
+		return new self($props_n_values, TRUE, $timezone);
89 89
 	}
90 90
 
91 91
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      * @throws \EE_Error
96 96
      */
97 97
 	public function parent() {
98
-		return $this->get( 'TKT_parent' );
98
+		return $this->get('TKT_parent');
99 99
 	}
100 100
 
101 101
 
@@ -107,13 +107,13 @@  discard block
 block discarded – undo
107 107
      * @return boolean
108 108
      * @throws \EE_Error
109 109
      */
110
-	public function available( $DTT_ID = 0 ) {
110
+	public function available($DTT_ID = 0) {
111 111
 		// are we checking availability for a particular datetime ?
112
-		if ( $DTT_ID ) {
112
+		if ($DTT_ID) {
113 113
 			// get that datetime object
114
-			$datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) );
114
+			$datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID)));
115 115
 			// if  ticket sales for this datetime have exceeded the reg limit...
116
-			if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) {
116
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
117 117
 				return FALSE;
118 118
 			}
119 119
 		}
@@ -131,22 +131,22 @@  discard block
 block discarded – undo
131 131
      * @return mixed status int if the display string isn't requested
132 132
      * @throws \EE_Error
133 133
      */
134
-	public function ticket_status( $display = FALSE, $remaining = null ) {
135
-		$remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining();
136
-		if ( ! $remaining ) {
137
-			return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out;
134
+	public function ticket_status($display = FALSE, $remaining = null) {
135
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
136
+		if ( ! $remaining) {
137
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out;
138 138
 		}
139
-		if ( $this->get( 'TKT_deleted' ) ) {
140
-			return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived;
139
+		if ($this->get('TKT_deleted')) {
140
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived;
141 141
 		}
142
-		if ( $this->is_expired() ) {
143
-			return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired;
142
+		if ($this->is_expired()) {
143
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired;
144 144
 		}
145
-		if ( $this->is_pending() ) {
146
-			return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending;
145
+		if ($this->is_pending()) {
146
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending;
147 147
 		}
148
-		if ( $this->is_on_sale() ) {
149
-			return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale;
148
+		if ($this->is_on_sale()) {
149
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale;
150 150
 		}
151 151
 		return '';
152 152
 	}
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
      * @return boolean         true = tickets remaining, false not.
162 162
      * @throws \EE_Error
163 163
      */
164
-	public function is_remaining( $DTT_ID = 0 ) {
165
-		$num_remaining = $this->remaining( $DTT_ID );
166
-		if ( $num_remaining === 0 ) {
164
+	public function is_remaining($DTT_ID = 0) {
165
+		$num_remaining = $this->remaining($DTT_ID);
166
+		if ($num_remaining === 0) {
167 167
 			return FALSE;
168 168
 		}
169
-		if ( $num_remaining > 0 && $num_remaining < $this->min() ) {
169
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
170 170
 			return FALSE;
171 171
 		}
172 172
 		return TRUE;
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
      * @return int
183 183
      * @throws \EE_Error
184 184
      */
185
-	public function remaining( $DTT_ID = 0 ) {
186
-		return $this->real_quantity_on_ticket('saleable', $DTT_ID );
185
+	public function remaining($DTT_ID = 0) {
186
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
187 187
 	}
188 188
 
189 189
 
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * @throws \EE_Error
196 196
      */
197 197
 	public function min() {
198
-		return $this->get( 'TKT_min' );
198
+		return $this->get('TKT_min');
199 199
 	}
200 200
 
201 201
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @throws \EE_Error
208 208
      */
209 209
 	public function is_expired() {
210
-		return ( $this->get_raw( 'TKT_end_date' ) < time() );
210
+		return ($this->get_raw('TKT_end_date') < time());
211 211
 	}
212 212
 
213 213
 
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * @throws \EE_Error
220 220
      */
221 221
 	public function is_pending() {
222
-		return ( $this->get_raw( 'TKT_start_date' ) > time() );
222
+		return ($this->get_raw('TKT_start_date') > time());
223 223
 	}
224 224
 
225 225
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      * @throws \EE_Error
232 232
      */
233 233
 	public function is_on_sale() {
234
-		return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() );
234
+		return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time());
235 235
 	}
236 236
 
237 237
 
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
      * @return string
245 245
      * @throws \EE_Error
246 246
      */
247
-	public function date_range( $dt_frmt = '', $conjunction = ' - ' ) {
248
-		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : '';
249
-		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : '';
247
+	public function date_range($dt_frmt = '', $conjunction = ' - ') {
248
+		$first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : '';
249
+		$last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : '';
250 250
 
251
-		return $first_date && $last_date ? $first_date . $conjunction  . $last_date : '';
251
+		return $first_date && $last_date ? $first_date.$conjunction.$last_date : '';
252 252
 	}
253 253
 
254 254
 
@@ -260,8 +260,8 @@  discard block
 block discarded – undo
260 260
      * @throws \EE_Error
261 261
      */
262 262
 	public function first_datetime() {
263
-		$datetimes = $this->datetimes( array( 'limit' => 1 ) );
264
-		return reset( $datetimes );
263
+		$datetimes = $this->datetimes(array('limit' => 1));
264
+		return reset($datetimes);
265 265
 	}
266 266
 
267 267
 
@@ -274,11 +274,11 @@  discard block
 block discarded – undo
274 274
      * @return EE_Datetime[]|EE_Base_Class[]
275 275
      * @throws \EE_Error
276 276
      */
277
-	public function datetimes( $query_params = array() ) {
278
-		if ( ! isset( $query_params[ 'order_by' ] ) ) {
279
-			$query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC';
277
+	public function datetimes($query_params = array()) {
278
+		if ( ! isset($query_params['order_by'])) {
279
+			$query_params['order_by']['DTT_order'] = 'ASC';
280 280
 		}
281
-		return $this->get_many_related( 'Datetime', $query_params );
281
+		return $this->get_many_related('Datetime', $query_params);
282 282
 	}
283 283
 
284 284
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
      * @throws \EE_Error
291 291
      */
292 292
 	public function last_datetime() {
293
-		$datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) );
294
-		return end( $datetimes );
293
+		$datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC')));
294
+		return end($datetimes);
295 295
 	}
296 296
 
297 297
 
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
      * @return mixed (array|int)          how many tickets have sold
310 310
      * @throws \EE_Error
311 311
      */
312
-	public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) {
312
+	public function tickets_sold($what = 'ticket', $dtt_id = NULL) {
313 313
 		$total = 0;
314 314
 		$tickets_sold = $this->_all_tickets_sold();
315
-		switch ( $what ) {
315
+		switch ($what) {
316 316
 			case 'ticket' :
317
-				return $tickets_sold[ 'ticket' ];
317
+				return $tickets_sold['ticket'];
318 318
 				break;
319 319
 			case 'datetime' :
320
-				if ( empty( $tickets_sold[ 'datetime' ] ) ) {
320
+				if (empty($tickets_sold['datetime'])) {
321 321
 					return $total;
322 322
 				}
323
-				if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) {
324
-					EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ );
323
+				if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) {
324
+					EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
325 325
 					return $total;
326 326
 				}
327
-				return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ];
327
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id];
328 328
 				break;
329 329
 			default:
330 330
 				return $total;
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
      * @throws \EE_Error
341 341
      */
342 342
 	protected function _all_tickets_sold() {
343
-		$datetimes = $this->get_many_related( 'Datetime' );
343
+		$datetimes = $this->get_many_related('Datetime');
344 344
 		$tickets_sold = array();
345
-		if ( ! empty( $datetimes ) ) {
346
-			foreach ( $datetimes as $datetime ) {
347
-				$tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' );
345
+		if ( ! empty($datetimes)) {
346
+			foreach ($datetimes as $datetime) {
347
+				$tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold');
348 348
 			}
349 349
 		}
350 350
 		//Tickets sold
351
-		$tickets_sold[ 'ticket' ] = $this->sold();
351
+		$tickets_sold['ticket'] = $this->sold();
352 352
 		return $tickets_sold;
353 353
 	}
354 354
 
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
      * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
362 362
      * @throws \EE_Error
363 363
      */
364
-	public function base_price( $return_array = FALSE ) {
365
-		$_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price );
364
+	public function base_price($return_array = FALSE) {
365
+		$_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price);
366 366
 		return $return_array
367
-            ? $this->get_many_related( 'Price', array( $_where ) )
368
-            : $this->get_first_related( 'Price', array( $_where ) );
367
+            ? $this->get_many_related('Price', array($_where))
368
+            : $this->get_first_related('Price', array($_where));
369 369
 	}
370 370
 
371 371
 
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
      * @throws \EE_Error
379 379
      */
380 380
 	public function price_modifiers() {
381
-		$query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) );
382
-		return $this->prices( $query_params );
381
+		$query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax))));
382
+		return $this->prices($query_params);
383 383
 	}
384 384
 
385 385
 
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
      * @return EE_Price[]|EE_Base_Class[]
392 392
      * @throws \EE_Error
393 393
      */
394
-	public function prices( $query_params = array() ) {
395
-		return $this->get_many_related( 'Price', $query_params );
394
+	public function prices($query_params = array()) {
395
+		return $this->get_many_related('Price', $query_params);
396 396
 	}
397 397
 
398 398
 
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
      * @return EE_Datetime_Ticket|EE_Base_Class[]
405 405
      * @throws \EE_Error
406 406
      */
407
-	public function datetime_tickets( $query_params = array() ) {
408
-		return $this->get_many_related( 'Datetime_Ticket', $query_params );
407
+	public function datetime_tickets($query_params = array()) {
408
+		return $this->get_many_related('Datetime_Ticket', $query_params);
409 409
 	}
410 410
 
411 411
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
      * @return EE_Datetime[]
419 419
      * @throws \EE_Error
420 420
      */
421
-	public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) {
422
-		return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted );
421
+	public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) {
422
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted);
423 423
 	}
424 424
 
425 425
 
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
      * @throws \EE_Error
432 432
      */
433 433
 	public function ID() {
434
-		return $this->get( 'TKT_ID' );
434
+		return $this->get('TKT_ID');
435 435
 	}
436 436
 
437 437
 
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
      * @throws \EE_Error
457 457
      */
458 458
 	public function template() {
459
-		return $this->get_first_related( 'Ticket_Template' );
459
+		return $this->get_first_related('Ticket_Template');
460 460
 	}
461 461
 
462 462
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
      * @throws \EE_Error
479 479
      */
480 480
 	public function ticket_price() {
481
-		return $this->get( 'TKT_price' );
481
+		return $this->get('TKT_price');
482 482
 	}
483 483
 
484 484
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
      * @throws \EE_Error
489 489
      */
490 490
 	public function pretty_price() {
491
-		return $this->get_pretty( 'TKT_price' );
491
+		return $this->get_pretty('TKT_price');
492 492
 	}
493 493
 
494 494
 
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
      * @return float
511 511
      * @throws \EE_Error
512 512
      */
513
-	public function get_ticket_total_with_taxes( $no_cache = FALSE ) {
514
-		if ($this->_ticket_total_with_taxes === null || $no_cache ) {
513
+	public function get_ticket_total_with_taxes($no_cache = FALSE) {
514
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
515 515
 			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
516 516
 		}
517 517
 		return (float) $this->_ticket_total_with_taxes;
@@ -520,7 +520,7 @@  discard block
 block discarded – undo
520 520
 
521 521
 
522 522
 	public function ensure_TKT_Price_correct() {
523
-		$this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) );
523
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
524 524
 		$this->save();
525 525
 	}
526 526
 
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
      * @throws \EE_Error
532 532
      */
533 533
 	public function get_ticket_subtotal() {
534
-		return EE_Taxes::get_subtotal_for_admin( $this );
534
+		return EE_Taxes::get_subtotal_for_admin($this);
535 535
 	}
536 536
 
537 537
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      * @throws \EE_Error
544 544
      */
545 545
 	public function get_ticket_taxes_total_for_admin() {
546
-		return EE_Taxes::get_total_taxes_for_admin( $this );
546
+		return EE_Taxes::get_total_taxes_for_admin($this);
547 547
 	}
548 548
 
549 549
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
      * @param string $name
555 555
      * @throws \EE_Error
556 556
      */
557
-	public function set_name( $name ) {
558
-		$this->set( 'TKT_name', $name );
557
+	public function set_name($name) {
558
+		$this->set('TKT_name', $name);
559 559
 	}
560 560
 
561 561
 
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
      * @throws \EE_Error
568 568
      */
569 569
 	public function description() {
570
-		return $this->get( 'TKT_description' );
570
+		return $this->get('TKT_description');
571 571
 	}
572 572
 
573 573
 
@@ -578,8 +578,8 @@  discard block
 block discarded – undo
578 578
      * @param string $description
579 579
      * @throws \EE_Error
580 580
      */
581
-	public function set_description( $description ) {
582
-		$this->set( 'TKT_description', $description );
581
+	public function set_description($description) {
582
+		$this->set('TKT_description', $description);
583 583
 	}
584 584
 
585 585
 
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
      * @return string
593 593
      * @throws \EE_Error
594 594
      */
595
-	public function start_date( $dt_frmt = '', $tm_frmt = '' ) {
596
-		return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt );
595
+	public function start_date($dt_frmt = '', $tm_frmt = '') {
596
+		return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt);
597 597
 	}
598 598
 
599 599
 
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
      * @return void
606 606
      * @throws \EE_Error
607 607
      */
608
-	public function set_start_date( $start_date ) {
609
-		$this->_set_date_time( 'B', $start_date, 'TKT_start_date' );
608
+	public function set_start_date($start_date) {
609
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
610 610
 	}
611 611
 
612 612
 
@@ -619,8 +619,8 @@  discard block
 block discarded – undo
619 619
      * @return string
620 620
      * @throws \EE_Error
621 621
      */
622
-	public function end_date( $dt_frmt = '', $tm_frmt = '' ) {
623
-		return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt );
622
+	public function end_date($dt_frmt = '', $tm_frmt = '') {
623
+		return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt);
624 624
 	}
625 625
 
626 626
 
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
      * @return void
633 633
      * @throws \EE_Error
634 634
      */
635
-	public function set_end_date( $end_date ) {
636
-		$this->_set_date_time( 'B', $end_date, 'TKT_end_date' );
635
+	public function set_end_date($end_date) {
636
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
637 637
 	}
638 638
 
639 639
 
@@ -645,8 +645,8 @@  discard block
 block discarded – undo
645 645
      * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
646 646
      * @throws \EE_Error
647 647
      */
648
-	public function set_end_time( $time ) {
649
-		$this->_set_time_for( $time, 'TKT_end_date' );
648
+	public function set_end_time($time) {
649
+		$this->_set_time_for($time, 'TKT_end_date');
650 650
 	}
651 651
 
652 652
 
@@ -658,8 +658,8 @@  discard block
 block discarded – undo
658 658
      * @return void
659 659
      * @throws \EE_Error
660 660
      */
661
-	public function set_min( $min ) {
662
-		$this->set( 'TKT_min', $min );
661
+	public function set_min($min) {
662
+		$this->set('TKT_min', $min);
663 663
 	}
664 664
 
665 665
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
      * @throws \EE_Error
672 672
      */
673 673
 	public function max() {
674
-		return $this->get( 'TKT_max' );
674
+		return $this->get('TKT_max');
675 675
 	}
676 676
 
677 677
 
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
      * @return void
684 684
      * @throws \EE_Error
685 685
      */
686
-	public function set_max( $max ) {
687
-		$this->set( 'TKT_max', $max );
686
+	public function set_max($max) {
687
+		$this->set('TKT_max', $max);
688 688
 	}
689 689
 
690 690
 
@@ -696,8 +696,8 @@  discard block
 block discarded – undo
696 696
      * @return void
697 697
      * @throws \EE_Error
698 698
      */
699
-	public function set_price( $price ) {
700
-		$this->set( 'TKT_price', $price );
699
+	public function set_price($price) {
700
+		$this->set('TKT_price', $price);
701 701
 	}
702 702
 
703 703
 
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
      * @throws \EE_Error
710 710
      */
711 711
 	public function sold() {
712
-		return $this->get_raw( 'TKT_sold' );
712
+		return $this->get_raw('TKT_sold');
713 713
 	}
714 714
 
715 715
 
@@ -721,10 +721,10 @@  discard block
 block discarded – undo
721 721
      * @return void
722 722
      * @throws \EE_Error
723 723
      */
724
-	public function set_sold( $sold ) {
724
+	public function set_sold($sold) {
725 725
 		// sold can not go below zero
726
-		$sold = max( 0, $sold );
727
-		$this->set( 'TKT_sold', $sold );
726
+		$sold = max(0, $sold);
727
+		$this->set('TKT_sold', $sold);
728 728
 	}
729 729
 
730 730
 
@@ -736,13 +736,13 @@  discard block
 block discarded – undo
736 736
      * @return void
737 737
      * @throws \EE_Error
738 738
      */
739
-	public function increase_sold( $qty = 1 ) {
739
+	public function increase_sold($qty = 1) {
740 740
 		$sold = $this->sold() + $qty;
741 741
 		// remove ticket reservation, but don't adjust datetime reservations,  because that will happen
742 742
 		// via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called
743
-		$this->decrease_reserved( $qty, false );
744
-		$this->_increase_sold_for_datetimes( $qty );
745
-		$this->set_sold( $sold );
743
+		$this->decrease_reserved($qty, false);
744
+		$this->_increase_sold_for_datetimes($qty);
745
+		$this->set_sold($sold);
746 746
 	}
747 747
 
748 748
 
@@ -754,12 +754,12 @@  discard block
 block discarded – undo
754 754
      * @return void
755 755
      * @throws \EE_Error
756 756
      */
757
-	protected function _increase_sold_for_datetimes( $qty = 1 ) {
757
+	protected function _increase_sold_for_datetimes($qty = 1) {
758 758
 		$datetimes = $this->datetimes();
759
-		if ( is_array( $datetimes ) ) {
760
-			foreach ( $datetimes as $datetime ) {
761
-				if ( $datetime instanceof EE_Datetime ) {
762
-					$datetime->increase_sold( $qty );
759
+		if (is_array($datetimes)) {
760
+			foreach ($datetimes as $datetime) {
761
+				if ($datetime instanceof EE_Datetime) {
762
+					$datetime->increase_sold($qty);
763 763
 					$datetime->save();
764 764
 				}
765 765
 			}
@@ -775,10 +775,10 @@  discard block
 block discarded – undo
775 775
      * @return void
776 776
      * @throws \EE_Error
777 777
      */
778
-	public function decrease_sold( $qty = 1 ) {
778
+	public function decrease_sold($qty = 1) {
779 779
 		$sold = $this->sold() - $qty;
780
-		$this->_decrease_sold_for_datetimes( $qty );
781
-		$this->set_sold( $sold );
780
+		$this->_decrease_sold_for_datetimes($qty);
781
+		$this->set_sold($sold);
782 782
 	}
783 783
 
784 784
 
@@ -790,12 +790,12 @@  discard block
 block discarded – undo
790 790
      * @return void
791 791
      * @throws \EE_Error
792 792
      */
793
-	protected function _decrease_sold_for_datetimes( $qty = 1 ) {
793
+	protected function _decrease_sold_for_datetimes($qty = 1) {
794 794
 		$datetimes = $this->datetimes();
795
-		if ( is_array( $datetimes ) ) {
796
-			foreach ( $datetimes as $datetime ) {
797
-				if ( $datetime instanceof EE_Datetime ) {
798
-					$datetime->decrease_sold( $qty );
795
+		if (is_array($datetimes)) {
796
+			foreach ($datetimes as $datetime) {
797
+				if ($datetime instanceof EE_Datetime) {
798
+					$datetime->decrease_sold($qty);
799 799
 					$datetime->save();
800 800
 				}
801 801
 			}
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
      * @throws \EE_Error
812 812
      */
813 813
 	public function reserved() {
814
-		return $this->get_raw( 'TKT_reserved' );
814
+		return $this->get_raw('TKT_reserved');
815 815
 	}
816 816
 
817 817
 
@@ -823,10 +823,10 @@  discard block
 block discarded – undo
823 823
      * @return void
824 824
      * @throws \EE_Error
825 825
      */
826
-	public function set_reserved( $reserved ) {
826
+	public function set_reserved($reserved) {
827 827
 		// reserved can not go below zero
828
-		$reserved = max( 0, (int) $reserved );
829
-		$this->set( 'TKT_reserved', $reserved );
828
+		$reserved = max(0, (int) $reserved);
829
+		$this->set('TKT_reserved', $reserved);
830 830
 	}
831 831
 
832 832
 
@@ -838,11 +838,11 @@  discard block
 block discarded – undo
838 838
      * @return void
839 839
      * @throws \EE_Error
840 840
      */
841
-	public function increase_reserved( $qty = 1 ) {
842
-		$qty = absint( $qty );
841
+	public function increase_reserved($qty = 1) {
842
+		$qty = absint($qty);
843 843
 		$reserved = $this->reserved() + $qty;
844
-		$this->_increase_reserved_for_datetimes( $qty );
845
-		$this->set_reserved( $reserved );
844
+		$this->_increase_reserved_for_datetimes($qty);
845
+		$this->set_reserved($reserved);
846 846
 	}
847 847
 
848 848
 
@@ -854,12 +854,12 @@  discard block
 block discarded – undo
854 854
      * @return void
855 855
      * @throws \EE_Error
856 856
      */
857
-	protected function _increase_reserved_for_datetimes( $qty = 1 ) {
857
+	protected function _increase_reserved_for_datetimes($qty = 1) {
858 858
 		$datetimes = $this->datetimes();
859
-		if ( is_array( $datetimes ) ) {
860
-			foreach ( $datetimes as $datetime ) {
861
-				if ( $datetime instanceof EE_Datetime ) {
862
-					$datetime->increase_reserved( $qty );
859
+		if (is_array($datetimes)) {
860
+			foreach ($datetimes as $datetime) {
861
+				if ($datetime instanceof EE_Datetime) {
862
+					$datetime->increase_reserved($qty);
863 863
 					$datetime->save();
864 864
 				}
865 865
 			}
@@ -876,12 +876,12 @@  discard block
 block discarded – undo
876 876
      * @return void
877 877
      * @throws \EE_Error
878 878
      */
879
-	public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) {
880
-		$reserved = $this->reserved() - absint( $qty );
881
-		if ( $adjust_datetimes ) {
882
-			$this->_decrease_reserved_for_datetimes( $qty );
879
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true) {
880
+		$reserved = $this->reserved() - absint($qty);
881
+		if ($adjust_datetimes) {
882
+			$this->_decrease_reserved_for_datetimes($qty);
883 883
 		}
884
-		$this->set_reserved( $reserved );
884
+		$this->set_reserved($reserved);
885 885
 	}
886 886
 
887 887
 
@@ -893,12 +893,12 @@  discard block
 block discarded – undo
893 893
      * @return void
894 894
      * @throws \EE_Error
895 895
      */
896
-	protected function _decrease_reserved_for_datetimes( $qty = 1 ) {
896
+	protected function _decrease_reserved_for_datetimes($qty = 1) {
897 897
 		$datetimes = $this->datetimes();
898
-		if ( is_array( $datetimes ) ) {
899
-			foreach ( $datetimes as $datetime ) {
900
-				if ( $datetime instanceof EE_Datetime ) {
901
-					$datetime->decrease_reserved( $qty );
898
+		if (is_array($datetimes)) {
899
+			foreach ($datetimes as $datetime) {
900
+				if ($datetime instanceof EE_Datetime) {
901
+					$datetime->decrease_reserved($qty);
902 902
 					$datetime->save();
903 903
 				}
904 904
 			}
@@ -919,14 +919,14 @@  discard block
 block discarded – undo
919 919
      * @return int
920 920
      * @throws \EE_Error
921 921
      */
922
-	public function qty( $context = '' ) {
923
-		switch ( $context ) {
922
+	public function qty($context = '') {
923
+		switch ($context) {
924 924
 			case 'reg_limit' :
925 925
 				return $this->real_quantity_on_ticket();
926 926
 			case 'saleable' :
927
-				return $this->real_quantity_on_ticket( 'saleable' );
927
+				return $this->real_quantity_on_ticket('saleable');
928 928
 			default:
929
-				return $this->get_raw( 'TKT_qty' );
929
+				return $this->get_raw('TKT_qty');
930 930
 		}
931 931
 	}
932 932
 
@@ -945,15 +945,15 @@  discard block
 block discarded – undo
945 945
      * @return int
946 946
      * @throws \EE_Error
947 947
      */
948
-	public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) {
949
-		$raw = $this->get_raw( 'TKT_qty' );
948
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) {
949
+		$raw = $this->get_raw('TKT_qty');
950 950
 		// return immediately if it's zero
951
-		if ( $raw === 0 ) {
951
+		if ($raw === 0) {
952 952
 			return $raw;
953 953
 		}
954 954
 		//echo "\n\n<br />Ticket: " . $this->name() . '<br />';
955 955
 		// ensure qty doesn't exceed raw value for THIS ticket
956
-		$qty = min( EE_INF, $raw );
956
+		$qty = min(EE_INF, $raw);
957 957
 		//echo "\n . qty: " . $qty . '<br />';
958 958
 		// calculate this ticket's total sales and reservations
959 959
 		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
@@ -962,23 +962,23 @@  discard block
 block discarded – undo
962 962
 		//echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
963 963
 		// first we need to calculate the maximum number of tickets available for the datetime
964 964
 		// do we want data for one datetime or all of them ?
965
-		$query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array();
966
-		$datetimes = $this->datetimes( $query_params );
967
-		if ( is_array( $datetimes ) && ! empty( $datetimes ) ) {
968
-			foreach ( $datetimes as $datetime ) {
969
-				if ( $datetime instanceof EE_Datetime ) {
965
+		$query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array();
966
+		$datetimes = $this->datetimes($query_params);
967
+		if (is_array($datetimes) && ! empty($datetimes)) {
968
+			foreach ($datetimes as $datetime) {
969
+				if ($datetime instanceof EE_Datetime) {
970 970
 					$datetime->refresh_from_db();
971 971
 					//echo "\n . . datetime name: " . $datetime->name() . '<br />';
972 972
 					//echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
973 973
 					// initialize with no restrictions for each datetime
974 974
 					// but adjust datetime qty based on datetime reg limit
975
-					$datetime_qty = min( EE_INF, $datetime->reg_limit() );
975
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
976 976
 					//echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
977 977
 					//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
978 978
 					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
979 979
 					// and reservations for this datetime, that do NOT include sales and reservations
980 980
 					// for this ticket (so we add $this->sold() and $this->reserved() back in)
981
-					if ( $context === 'saleable' ) {
981
+					if ($context === 'saleable') {
982 982
 						$datetime_qty = max(
983 983
 							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
984 984
 							0
@@ -990,16 +990,16 @@  discard block
 block discarded – undo
990 990
 						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
991 991
 						//echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
992 992
 					}
993
-					$qty = min( $datetime_qty, $qty );
993
+					$qty = min($datetime_qty, $qty);
994 994
 					//echo "\n . . qty: " . $qty . '<br />';
995 995
 				}
996 996
 			}
997 997
 		}
998 998
 		// NOW that we know the  maximum number of tickets available for the datetime
999 999
 		// we can finally factor in the details for this specific ticket
1000
-		if ( $qty > 0 && $context === 'saleable' ) {
1000
+		if ($qty > 0 && $context === 'saleable') {
1001 1001
 			// and subtract the sales for THIS ticket
1002
-			$qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 );
1002
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1003 1003
 			//echo "\n . qty: " . $qty . '<br />';
1004 1004
 		}
1005 1005
 		//echo "\nFINAL QTY: " . $qty . "<br /><br />";
@@ -1015,14 +1015,14 @@  discard block
 block discarded – undo
1015 1015
 	 * @return void
1016 1016
 	 * @throws \EE_Error
1017 1017
 	 */
1018
-	public function set_qty( $qty ) {
1018
+	public function set_qty($qty) {
1019 1019
 		$datetimes = $this->datetimes();
1020
-		foreach ( $datetimes as $datetime ) {
1021
-			if ( $datetime instanceof EE_Datetime ) {
1022
-				$qty = min( $qty, $datetime->reg_limit() );
1020
+		foreach ($datetimes as $datetime) {
1021
+			if ($datetime instanceof EE_Datetime) {
1022
+				$qty = min($qty, $datetime->reg_limit());
1023 1023
 			}
1024 1024
 		}
1025
-		$this->set( 'TKT_qty', $qty );
1025
+		$this->set('TKT_qty', $qty);
1026 1026
 	}
1027 1027
 
1028 1028
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
      * @throws \EE_Error
1035 1035
      */
1036 1036
 	public function uses() {
1037
-		return $this->get( 'TKT_uses' );
1037
+		return $this->get('TKT_uses');
1038 1038
 	}
1039 1039
 
1040 1040
 
@@ -1046,8 +1046,8 @@  discard block
 block discarded – undo
1046 1046
      * @return void
1047 1047
      * @throws \EE_Error
1048 1048
      */
1049
-	public function set_uses( $uses ) {
1050
-		$this->set( 'TKT_uses', $uses );
1049
+	public function set_uses($uses) {
1050
+		$this->set('TKT_uses', $uses);
1051 1051
 	}
1052 1052
 
1053 1053
 
@@ -1059,7 +1059,7 @@  discard block
 block discarded – undo
1059 1059
      * @throws \EE_Error
1060 1060
      */
1061 1061
 	public function required() {
1062
-		return $this->get( 'TKT_required' );
1062
+		return $this->get('TKT_required');
1063 1063
 	}
1064 1064
 
1065 1065
 
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
      * @return void
1072 1072
      * @throws \EE_Error
1073 1073
      */
1074
-	public function set_required( $required ) {
1075
-		$this->set( 'TKT_required', $required );
1074
+	public function set_required($required) {
1075
+		$this->set('TKT_required', $required);
1076 1076
 	}
1077 1077
 
1078 1078
 
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
      * @throws \EE_Error
1085 1085
      */
1086 1086
 	public function taxable() {
1087
-		return $this->get( 'TKT_taxable' );
1087
+		return $this->get('TKT_taxable');
1088 1088
 	}
1089 1089
 
1090 1090
 
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
      * @return void
1097 1097
      * @throws \EE_Error
1098 1098
      */
1099
-	public function set_taxable( $taxable ) {
1100
-		$this->set( 'TKT_taxable', $taxable );
1099
+	public function set_taxable($taxable) {
1100
+		$this->set('TKT_taxable', $taxable);
1101 1101
 	}
1102 1102
 
1103 1103
 
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
      * @throws \EE_Error
1110 1110
      */
1111 1111
 	public function is_default() {
1112
-		return $this->get( 'TKT_is_default' );
1112
+		return $this->get('TKT_is_default');
1113 1113
 	}
1114 1114
 
1115 1115
 
@@ -1121,8 +1121,8 @@  discard block
 block discarded – undo
1121 1121
      * @return void
1122 1122
      * @throws \EE_Error
1123 1123
      */
1124
-	public function set_is_default( $is_default ) {
1125
-		$this->set( 'TKT_is_default', $is_default );
1124
+	public function set_is_default($is_default) {
1125
+		$this->set('TKT_is_default', $is_default);
1126 1126
 	}
1127 1127
 
1128 1128
 
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
      * @throws \EE_Error
1135 1135
      */
1136 1136
 	public function order() {
1137
-		return $this->get( 'TKT_order' );
1137
+		return $this->get('TKT_order');
1138 1138
 	}
1139 1139
 
1140 1140
 
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
      * @return void
1147 1147
      * @throws \EE_Error
1148 1148
      */
1149
-	public function set_order( $order ) {
1150
-		$this->set( 'TKT_order', $order );
1149
+	public function set_order($order) {
1150
+		$this->set('TKT_order', $order);
1151 1151
 	}
1152 1152
 
1153 1153
 
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
      * @throws \EE_Error
1160 1160
      */
1161 1161
 	public function row() {
1162
-		return $this->get( 'TKT_row' );
1162
+		return $this->get('TKT_row');
1163 1163
 	}
1164 1164
 
1165 1165
 
@@ -1171,8 +1171,8 @@  discard block
 block discarded – undo
1171 1171
      * @return void
1172 1172
      * @throws \EE_Error
1173 1173
      */
1174
-	public function set_row( $row ) {
1175
-		$this->set( 'TKT_row', $row );
1174
+	public function set_row($row) {
1175
+		$this->set('TKT_row', $row);
1176 1176
 	}
1177 1177
 
1178 1178
 
@@ -1184,7 +1184,7 @@  discard block
 block discarded – undo
1184 1184
      * @throws \EE_Error
1185 1185
      */
1186 1186
 	public function deleted() {
1187
-		return $this->get( 'TKT_deleted' );
1187
+		return $this->get('TKT_deleted');
1188 1188
 	}
1189 1189
 
1190 1190
 
@@ -1196,8 +1196,8 @@  discard block
 block discarded – undo
1196 1196
      * @return void
1197 1197
      * @throws \EE_Error
1198 1198
      */
1199
-	public function set_deleted( $deleted ) {
1200
-		$this->set( 'TKT_deleted', $deleted );
1199
+	public function set_deleted($deleted) {
1200
+		$this->set('TKT_deleted', $deleted);
1201 1201
 	}
1202 1202
 
1203 1203
 
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
      * @throws \EE_Error
1210 1210
      */
1211 1211
 	public function parent_ID() {
1212
-		return $this->get( 'TKT_parent' );
1212
+		return $this->get('TKT_parent');
1213 1213
 	}
1214 1214
 
1215 1215
 
@@ -1221,8 +1221,8 @@  discard block
 block discarded – undo
1221 1221
      * @return void
1222 1222
      * @throws \EE_Error
1223 1223
      */
1224
-	public function set_parent_ID( $parent ) {
1225
-		$this->set( 'TKT_parent', $parent );
1224
+	public function set_parent_ID($parent) {
1225
+		$this->set('TKT_parent', $parent);
1226 1226
 	}
1227 1227
 
1228 1228
 
@@ -1235,10 +1235,10 @@  discard block
 block discarded – undo
1235 1235
      */
1236 1236
 	public function name_and_info() {
1237 1237
 		$times = array();
1238
-		foreach ( $this->datetimes() as $datetime ) {
1238
+		foreach ($this->datetimes() as $datetime) {
1239 1239
 			$times[] = $datetime->start_date_and_time();
1240 1240
 		}
1241
-		return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price();
1241
+		return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price();
1242 1242
 	}
1243 1243
 
1244 1244
 
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
      * @throws \EE_Error
1251 1251
      */
1252 1252
 	public function name() {
1253
-		return $this->get( 'TKT_name' );
1253
+		return $this->get('TKT_name');
1254 1254
 	}
1255 1255
 
1256 1256
 
@@ -1262,7 +1262,7 @@  discard block
 block discarded – undo
1262 1262
      * @throws \EE_Error
1263 1263
      */
1264 1264
 	public function price() {
1265
-		return $this->get( 'TKT_price' );
1265
+		return $this->get('TKT_price');
1266 1266
 	}
1267 1267
 
1268 1268
 
@@ -1274,8 +1274,8 @@  discard block
 block discarded – undo
1274 1274
      * @return EE_Registration[]|EE_Base_Class[]
1275 1275
      * @throws \EE_Error
1276 1276
      */
1277
-	public function registrations( $query_params = array() ) {
1278
-		return $this->get_many_related( 'Registration', $query_params );
1277
+	public function registrations($query_params = array()) {
1278
+		return $this->get_many_related('Registration', $query_params);
1279 1279
 	}
1280 1280
 
1281 1281
 
@@ -1288,8 +1288,8 @@  discard block
 block discarded – undo
1288 1288
      * @throws \EE_Error
1289 1289
      */
1290 1290
 	public function update_tickets_sold() {
1291
-		$count_regs_for_this_ticket = $this->count_registrations( array( array( 'STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0 ) ) );
1292
-		$this->set_sold( $count_regs_for_this_ticket );
1291
+		$count_regs_for_this_ticket = $this->count_registrations(array(array('STS_ID' => EEM_Registration::status_id_approved, 'REG_deleted' => 0)));
1292
+		$this->set_sold($count_regs_for_this_ticket);
1293 1293
 		$this->save();
1294 1294
 		return $count_regs_for_this_ticket;
1295 1295
 	}
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 	 * @param array $query_params like EEM_Base::get_all's
1302 1302
 	 * @return int
1303 1303
 	 */
1304
-	public function count_registrations( $query_params = array() ) {
1304
+	public function count_registrations($query_params = array()) {
1305 1305
 		return $this->count_related('Registration', $query_params);
1306 1306
 	}
1307 1307
 
@@ -1329,23 +1329,23 @@  discard block
 block discarded – undo
1329 1329
 	public function get_related_event() {
1330 1330
 		//get one datetime to use for getting the event
1331 1331
 		$datetime = $this->first_datetime();
1332
-		if ( ! $datetime instanceof \EE_Datetime ) {
1332
+		if ( ! $datetime instanceof \EE_Datetime) {
1333 1333
 			throw new UnexpectedEntityException(
1334 1334
 				$datetime,
1335 1335
                 'EE_Datetime',
1336 1336
 				sprintf(
1337
-					__( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1337
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1338 1338
 					$this->name()
1339 1339
 				)
1340 1340
 			);
1341 1341
 		}
1342 1342
 		$event = $datetime->event();
1343
-		if ( ! $event instanceof \EE_Event ) {
1343
+		if ( ! $event instanceof \EE_Event) {
1344 1344
 			throw new UnexpectedEntityException(
1345 1345
 				$event,
1346 1346
                 'EE_Event',
1347 1347
 				sprintf(
1348
-					__( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1348
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1349 1349
 					$this->name()
1350 1350
 				)
1351 1351
 			);
Please login to merge, or discard this patch.