Completed
Branch BUG/batch-strings-overridden (415991)
by
unknown
09:29 queued 38s
created
core/services/options/JsonWpOptionManager.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -16,39 +16,39 @@
 block discarded – undo
16 16
  */
17 17
 class JsonWpOptionManager
18 18
 {
19
-    /**
20
-     * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves
21
-     * the object alone and returns false.
22
-     * @since 4.9.80.p
23
-     * @param JsonWpOptionSerializableInterface $obj
24
-     * @return bool
25
-     */
26
-    public function populateFromDb(JsonWpOptionSerializableInterface $obj)
27
-    {
28
-        $option = get_option($obj->getWpOptionName());
29
-        if ($option) {
30
-            $json = json_decode($option);
31
-            if (is_array($json) || $json instanceof stdClass) {
32
-                return $obj->fromJsonSerializedData($json);
33
-            }
34
-        }
35
-        return false;
36
-    }
19
+	/**
20
+	 * Updates the object with what's in the DB (specifically, the wp_options table). If nothing is in the DB, leaves
21
+	 * the object alone and returns false.
22
+	 * @since 4.9.80.p
23
+	 * @param JsonWpOptionSerializableInterface $obj
24
+	 * @return bool
25
+	 */
26
+	public function populateFromDb(JsonWpOptionSerializableInterface $obj)
27
+	{
28
+		$option = get_option($obj->getWpOptionName());
29
+		if ($option) {
30
+			$json = json_decode($option);
31
+			if (is_array($json) || $json instanceof stdClass) {
32
+				return $obj->fromJsonSerializedData($json);
33
+			}
34
+		}
35
+		return false;
36
+	}
37 37
 
38
-    /**
39
-     * Saves the object's data to the wp_options table for later use.
40
-     * @since 4.9.80.p
41
-     * @param JsonWpOptionSerializableInterface $obj
42
-     * @return bool
43
-     */
44
-    public function saveToDb(JsonWpOptionSerializableInterface $obj)
45
-    {
46
-        return update_option(
47
-            $obj->getWpOptionName(),
48
-            wp_json_encode($obj->toJsonSerializableData()),
49
-            false
50
-        );
51
-    }
38
+	/**
39
+	 * Saves the object's data to the wp_options table for later use.
40
+	 * @since 4.9.80.p
41
+	 * @param JsonWpOptionSerializableInterface $obj
42
+	 * @return bool
43
+	 */
44
+	public function saveToDb(JsonWpOptionSerializableInterface $obj)
45
+	{
46
+		return update_option(
47
+			$obj->getWpOptionName(),
48
+			wp_json_encode($obj->toJsonSerializableData()),
49
+			false
50
+		);
51
+	}
52 52
 }
53 53
 // End of file JsonWpOptionManager.php
54 54
 // Location: EventEspresso\core\services\options/JsonWpOptionManager.php
Please login to merge, or discard this patch.
core/services/options/JsonWpOptionSerializableInterface.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@
 block discarded – undo
17 17
  */
18 18
 interface JsonWpOptionSerializableInterface extends JsonSerializableAndUnserializable
19 19
 {
20
-    /**
21
-     * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to
22
-     * determine what option name to use.
23
-     * @since 4.9.80.p
24
-     * @return string
25
-     */
26
-    public function getWpOptionName();
20
+	/**
21
+	 * Gets the value to use for wp_options.option_name. Note this is not static, so it can use object properties to
22
+	 * determine what option name to use.
23
+	 * @since 4.9.80.p
24
+	 * @return string
25
+	 */
26
+	public function getWpOptionName();
27 27
 }
28 28
 // End of file JsonWpOptionSerializableInterface.php
29 29
 // Location: EventEspresso\core\services\options/JsonWpOptionSerializableInterface.php
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 1 patch
Indentation   +510 added lines, -510 removed lines patch added patch discarded remove patch
@@ -31,530 +31,530 @@
 block discarded – undo
31 31
  */
32 32
 class RegistrationsReport extends JobHandlerFile
33 33
 {
34
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
-    /**
37
-     * Performs any necessary setup for starting the job. This is also a good
38
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
-     * when continue_job will be called
40
-     *
41
-     * @param JobParameters $job_parameters
42
-     * @throws BatchRequestException
43
-     * @return JobStepResponse
44
-     */
45
-    public function create_job(JobParameters $job_parameters)
46
-    {
47
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
-        }
51
-        $filepath = $this->create_file_from_job_with_name(
52
-            $job_parameters->job_id(),
53
-            $this->get_filename($event_id)
54
-        );
55
-        $job_parameters->add_extra_data('filepath', $filepath);
56
-        if ($job_parameters->request_datum('use_filters', false)) {
57
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
-        } else {
59
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-                array(
61
-                    'OR'                 => array(
62
-                        // don't include registrations from failed or abandoned transactions...
63
-                        'Transaction.STS_ID' => array(
64
-                            'NOT IN',
65
-                            array(
66
-                                EEM_Transaction::failed_status_code,
67
-                                EEM_Transaction::abandoned_status_code,
68
-                            ),
69
-                        ),
70
-                        // unless the registration is approved, in which case include it regardless of transaction status
71
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                    ),
73
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-                ),
75
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-                'caps'       => \EEM_Base::caps_read_admin,
78
-            ), $event_id);
79
-            if ($event_id) {
80
-                $query_params[0]['EVT_ID'] = $event_id;
81
-            } else {
82
-                $query_params['force_join'][] = 'Event';
83
-            }
84
-        }
85
-        if (! isset($query_params['force_join'])) {
86
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
-        }
88
-        $job_parameters->add_extra_data('query_params', $query_params);
89
-        $question_labels = $this->_get_question_labels($query_params);
90
-        $job_parameters->add_extra_data('question_labels', $question_labels);
91
-        $job_parameters->set_job_size(
92
-            \EEM_Registration::instance()->count(
93
-                array_diff_key(
94
-                    $query_params,
95
-                    array_flip(
96
-                        array('limit')
97
-                    )
98
-                )
99
-            )
100
-        );
101
-        // we should also set the header columns
102
-        $csv_data_for_row = $this->get_csv_data_for(
103
-            $event_id,
104
-            0,
105
-            1,
106
-            $job_parameters->extra_datum('question_labels'),
107
-            $job_parameters->extra_datum('query_params')
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            __('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
34
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
+	/**
37
+	 * Performs any necessary setup for starting the job. This is also a good
38
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
+	 * when continue_job will be called
40
+	 *
41
+	 * @param JobParameters $job_parameters
42
+	 * @throws BatchRequestException
43
+	 * @return JobStepResponse
44
+	 */
45
+	public function create_job(JobParameters $job_parameters)
46
+	{
47
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
+		}
51
+		$filepath = $this->create_file_from_job_with_name(
52
+			$job_parameters->job_id(),
53
+			$this->get_filename($event_id)
54
+		);
55
+		$job_parameters->add_extra_data('filepath', $filepath);
56
+		if ($job_parameters->request_datum('use_filters', false)) {
57
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
+		} else {
59
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+				array(
61
+					'OR'                 => array(
62
+						// don't include registrations from failed or abandoned transactions...
63
+						'Transaction.STS_ID' => array(
64
+							'NOT IN',
65
+							array(
66
+								EEM_Transaction::failed_status_code,
67
+								EEM_Transaction::abandoned_status_code,
68
+							),
69
+						),
70
+						// unless the registration is approved, in which case include it regardless of transaction status
71
+						'STS_ID'             => \EEM_Registration::status_id_approved,
72
+					),
73
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+				),
75
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+				'caps'       => \EEM_Base::caps_read_admin,
78
+			), $event_id);
79
+			if ($event_id) {
80
+				$query_params[0]['EVT_ID'] = $event_id;
81
+			} else {
82
+				$query_params['force_join'][] = 'Event';
83
+			}
84
+		}
85
+		if (! isset($query_params['force_join'])) {
86
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
+		}
88
+		$job_parameters->add_extra_data('query_params', $query_params);
89
+		$question_labels = $this->_get_question_labels($query_params);
90
+		$job_parameters->add_extra_data('question_labels', $question_labels);
91
+		$job_parameters->set_job_size(
92
+			\EEM_Registration::instance()->count(
93
+				array_diff_key(
94
+					$query_params,
95
+					array_flip(
96
+						array('limit')
97
+					)
98
+				)
99
+			)
100
+		);
101
+		// we should also set the header columns
102
+		$csv_data_for_row = $this->get_csv_data_for(
103
+			$event_id,
104
+			0,
105
+			1,
106
+			$job_parameters->extra_datum('question_labels'),
107
+			$job_parameters->extra_datum('query_params')
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Gets the questions which are to be used for this report, so they
134
-     * can be remembered for later
135
-     *
136
-     * @param array $registration_query_params
137
-     * @return array question admin labels to be used for this report
138
-     */
139
-    protected function _get_question_labels($registration_query_params)
140
-    {
141
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
-        $question_query_params = array();
143
-        if ($where !== null) {
144
-            $question_query_params = array(
145
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
-            );
147
-        }
148
-        // Make sure it's not a system question
149
-        $question_query_params[0]['OR*not-system-questions'] = [
150
-            'QST_system' => '',
151
-            'QST_system*null' => ['IS_NULL']
152
-        ];
153
-        if (apply_filters(
154
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
155
-            false,
156
-            $registration_query_params
157
-        )) {
158
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
159
-        }
160
-        $question_query_params['group_by'] = array('QST_ID');
161
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
162
-    }
132
+	/**
133
+	 * Gets the questions which are to be used for this report, so they
134
+	 * can be remembered for later
135
+	 *
136
+	 * @param array $registration_query_params
137
+	 * @return array question admin labels to be used for this report
138
+	 */
139
+	protected function _get_question_labels($registration_query_params)
140
+	{
141
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
+		$question_query_params = array();
143
+		if ($where !== null) {
144
+			$question_query_params = array(
145
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
+			);
147
+		}
148
+		// Make sure it's not a system question
149
+		$question_query_params[0]['OR*not-system-questions'] = [
150
+			'QST_system' => '',
151
+			'QST_system*null' => ['IS_NULL']
152
+		];
153
+		if (apply_filters(
154
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
155
+			false,
156
+			$registration_query_params
157
+		)) {
158
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
159
+		}
160
+		$question_query_params['group_by'] = array('QST_ID');
161
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
162
+	}
163 163
 
164 164
 
165
-    /**
166
-     * Takes where params meant for registrations and changes them to work for questions
167
-     *
168
-     * @param array $reg_where_params
169
-     * @return array
170
-     */
171
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
172
-    {
173
-        $question_where_params = array();
174
-        foreach ($reg_where_params as $key => $val) {
175
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
176
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
177
-            } else {
178
-                // it's a normal where condition
179
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
180
-            }
181
-        }
182
-        return $question_where_params;
183
-    }
165
+	/**
166
+	 * Takes where params meant for registrations and changes them to work for questions
167
+	 *
168
+	 * @param array $reg_where_params
169
+	 * @return array
170
+	 */
171
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
172
+	{
173
+		$question_where_params = array();
174
+		foreach ($reg_where_params as $key => $val) {
175
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
176
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
177
+			} else {
178
+				// it's a normal where condition
179
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
180
+			}
181
+		}
182
+		return $question_where_params;
183
+	}
184 184
 
185 185
 
186
-    /**
187
-     * Performs another step of the job
188
-     *
189
-     * @param JobParameters $job_parameters
190
-     * @param int           $batch_size
191
-     * @return JobStepResponse
192
-     * @throws \EE_Error
193
-     */
194
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
195
-    {
196
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
197
-            $csv_data = $this->get_csv_data_for(
198
-                $job_parameters->request_datum('EVT_ID', '0'),
199
-                $job_parameters->units_processed(),
200
-                $batch_size,
201
-                $job_parameters->extra_datum('question_labels'),
202
-                $job_parameters->extra_datum('query_params')
203
-            );
204
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
205
-            $units_processed = count($csv_data);
206
-        } else {
207
-            $csv_data = array();
208
-            $units_processed = 0;
209
-        }
210
-        $job_parameters->mark_processed($units_processed);
211
-        $extra_response_data = array(
212
-            'file_url' => '',
213
-        );
214
-        if ($units_processed < $batch_size) {
215
-            $job_parameters->set_status(JobParameters::status_complete);
216
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
217
-        }
186
+	/**
187
+	 * Performs another step of the job
188
+	 *
189
+	 * @param JobParameters $job_parameters
190
+	 * @param int           $batch_size
191
+	 * @return JobStepResponse
192
+	 * @throws \EE_Error
193
+	 */
194
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
195
+	{
196
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
197
+			$csv_data = $this->get_csv_data_for(
198
+				$job_parameters->request_datum('EVT_ID', '0'),
199
+				$job_parameters->units_processed(),
200
+				$batch_size,
201
+				$job_parameters->extra_datum('question_labels'),
202
+				$job_parameters->extra_datum('query_params')
203
+			);
204
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
205
+			$units_processed = count($csv_data);
206
+		} else {
207
+			$csv_data = array();
208
+			$units_processed = 0;
209
+		}
210
+		$job_parameters->mark_processed($units_processed);
211
+		$extra_response_data = array(
212
+			'file_url' => '',
213
+		);
214
+		if ($units_processed < $batch_size) {
215
+			$job_parameters->set_status(JobParameters::status_complete);
216
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
217
+		}
218 218
 
219
-        return new JobStepResponse(
220
-            $job_parameters,
221
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
222
-            $extra_response_data
223
-        );
224
-    }
219
+		return new JobStepResponse(
220
+			$job_parameters,
221
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
222
+			$extra_response_data
223
+		);
224
+	}
225 225
 
226 226
 
227
-    /**
228
-     * Gets the csv data for a batch of registrations
229
-     *
230
-     * @param int|null $event_id
231
-     * @param int $offset
232
-     * @param int $limit
233
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
234
-     * @param array $query_params for using where querying the model
235
-     * @return array top-level keys are numeric, next-level keys are column headers
236
-     * @throws \EE_Error
237
-     */
238
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
239
-    {
240
-        $reg_fields_to_include = array(
241
-            'TXN_ID',
242
-            'ATT_ID',
243
-            'REG_ID',
244
-            'REG_date',
245
-            'REG_code',
246
-            'REG_count',
247
-            'REG_final_price',
248
-        );
249
-        $att_fields_to_include = array(
250
-            'ATT_fname',
251
-            'ATT_lname',
252
-            'ATT_email',
253
-            'ATT_address',
254
-            'ATT_address2',
255
-            'ATT_city',
256
-            'STA_ID',
257
-            'CNT_ISO',
258
-            'ATT_zip',
259
-            'ATT_phone',
260
-        );
261
-        $registrations_csv_ready_array = array();
262
-        $reg_model = EE_Registry::instance()->load_model('Registration');
263
-        $query_params['limit'] = array($offset, $limit);
264
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
265
-        $registration_ids = array();
266
-        foreach ($registration_rows as $reg_row) {
267
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
268
-        }
269
-        foreach ($registration_rows as $reg_row) {
270
-            if (is_array($reg_row)) {
271
-                $reg_csv_array = array();
272
-                if (! $event_id) {
273
-                    // get the event's name and Id
274
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
275
-                        /* translators: 1: event name, 2: event ID */
276
-                        __('%1$s (%2$s)', 'event_espresso'),
277
-                        EEH_Export::prepare_value_from_db_for_display(
278
-                            EEM_Event::instance(),
279
-                            'EVT_name',
280
-                            $reg_row['Event_CPT.post_title']
281
-                        ),
282
-                        $reg_row['Event_CPT.ID']
283
-                    );
284
-                }
285
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
286
-                /*@var $reg_row EE_Registration */
287
-                foreach ($reg_fields_to_include as $field_name) {
288
-                    $field = $reg_model->field_settings_for($field_name);
289
-                    if ($field_name == 'REG_final_price') {
290
-                        $value = EEH_Export::prepare_value_from_db_for_display(
291
-                            $reg_model,
292
-                            $field_name,
293
-                            $reg_row['Registration.REG_final_price'],
294
-                            'localized_float'
295
-                        );
296
-                    } elseif ($field_name == 'REG_count') {
297
-                        $value = sprintf(
298
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
299
-                            __('%1$s of %2$s', 'event_espresso'),
300
-                            EEH_Export::prepare_value_from_db_for_display(
301
-                                $reg_model,
302
-                                'REG_count',
303
-                                $reg_row['Registration.REG_count']
304
-                            ),
305
-                            EEH_Export::prepare_value_from_db_for_display(
306
-                                $reg_model,
307
-                                'REG_group_size',
308
-                                $reg_row['Registration.REG_group_size']
309
-                            )
310
-                        );
311
-                    } elseif ($field_name == 'REG_date') {
312
-                        $value = EEH_Export::prepare_value_from_db_for_display(
313
-                            $reg_model,
314
-                            $field_name,
315
-                            $reg_row['Registration.REG_date'],
316
-                            'no_html'
317
-                        );
318
-                    } else {
319
-                        $value = EEH_Export::prepare_value_from_db_for_display(
320
-                            $reg_model,
321
-                            $field_name,
322
-                            $reg_row[ $field->get_qualified_column() ]
323
-                        );
324
-                    }
325
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
326
-                    if ($field_name == 'REG_final_price') {
327
-                        // add a column named Currency after the final price
328
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
329
-                    }
330
-                }
331
-                // get pretty status
332
-                $stati = EEM_Status::instance()->localized_status(
333
-                    array(
334
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
335
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
336
-                    ),
337
-                    false,
338
-                    'sentence'
339
-                );
340
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
341
-                // get pretty transaction status
342
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
343
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
344
-                    ? EEH_Export::prepare_value_from_db_for_display(
345
-                        EEM_Transaction::instance(),
346
-                        'TXN_total',
347
-                        $reg_row['TransactionTable.TXN_total'],
348
-                        'localized_float'
349
-                    ) : '0.00';
350
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
351
-                    ? EEH_Export::prepare_value_from_db_for_display(
352
-                        EEM_Transaction::instance(),
353
-                        'TXN_paid',
354
-                        $reg_row['TransactionTable.TXN_paid'],
355
-                        'localized_float'
356
-                    ) : '0.00';
357
-                $payment_methods = array();
358
-                $gateway_txn_ids_etc = array();
359
-                $payment_times = array();
360
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
361
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
362
-                        array(
363
-                            array(
364
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
365
-                                'STS_ID' => EEM_Payment::status_id_approved,
366
-                            ),
367
-                            'force_join' => array('Payment_Method'),
368
-                        ),
369
-                        ARRAY_A,
370
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
371
-                    );
372
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
373
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
374
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
375
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
376
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
377
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
378
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
379
-                    }
380
-                }
381
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
382
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
383
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
384
-                    ',',
385
-                    $gateway_txn_ids_etc
386
-                );
387
-                // get whether or not the user has checked in
388
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
389
-                    $reg_row['Registration.REG_ID'],
390
-                    'Checkin'
391
-                );
392
-                // get ticket of registration and its price
393
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
394
-                if ($reg_row['Ticket.TKT_ID']) {
395
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
396
-                        $ticket_model,
397
-                        'TKT_name',
398
-                        $reg_row['Ticket.TKT_name']
399
-                    );
400
-                    $datetimes_strings = array();
401
-                    foreach (EEM_Datetime::instance()->get_all_wpdb_results(
402
-                        array(
403
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
404
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
405
-                            'default_where_conditions' => 'none',
406
-                        )
407
-                    ) as $datetime) {
408
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
409
-                            EEM_Datetime::instance(),
410
-                            'DTT_EVT_start',
411
-                            $datetime['Datetime.DTT_EVT_start']
412
-                        );
413
-                    }
414
-                } else {
415
-                    $ticket_name = __('Unknown', 'event_espresso');
416
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
417
-                }
418
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
419
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
420
-                // get datetime(s) of registration
421
-                // add attendee columns
422
-                foreach ($att_fields_to_include as $att_field_name) {
423
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
424
-                    if ($reg_row['Attendee_CPT.ID']) {
425
-                        if ($att_field_name == 'STA_ID') {
426
-                            $value = EEM_State::instance()->get_var(
427
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
428
-                                'STA_name'
429
-                            );
430
-                        } elseif ($att_field_name == 'CNT_ISO') {
431
-                            $value = EEM_Country::instance()->get_var(
432
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
433
-                                'CNT_name'
434
-                            );
435
-                        } else {
436
-                            $value = EEH_Export::prepare_value_from_db_for_display(
437
-                                EEM_Attendee::instance(),
438
-                                $att_field_name,
439
-                                $reg_row[ $field_obj->get_qualified_column() ]
440
-                            );
441
-                        }
442
-                    } else {
443
-                        $value = '';
444
-                    }
445
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
446
-                }
447
-                // make sure each registration has the same questions in the same order
448
-                foreach ($question_labels as $question_label) {
449
-                    if (! isset($reg_csv_array[ $question_label ])) {
450
-                        $reg_csv_array[ $question_label ] = null;
451
-                    }
452
-                }
453
-                $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
454
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
455
-                    'force_join' => array('Question'),
456
-                ));
457
-                // now fill out the questions THEY answered
458
-                foreach ($answers as $answer_row) {
459
-                    if ($answer_row['Question.QST_system']) {
460
-                        // it's an answer to a system question. That was already displayed as part of the attendee
461
-                        // fields, so don't write it out again thanks.
462
-                        continue;
463
-                    }
464
-                    if ($answer_row['Question.QST_ID']) {
465
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
466
-                            EEM_Question::instance(),
467
-                            'QST_admin_label',
468
-                            $answer_row['Question.QST_admin_label']
469
-                        );
470
-                    } else {
471
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
472
-                    }
473
-                    if (isset($answer_row['Question.QST_type'])
474
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
475
-                    ) {
476
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
477
-                            $answer_row['Answer.ANS_value']
478
-                        );
479
-                    } else {
480
-                        // this isn't for html, so don't show html entities
481
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
482
-                            EEH_Export::prepare_value_from_db_for_display(
483
-                                EEM_Answer::instance(),
484
-                                'ANS_value',
485
-                                $answer_row['Answer.ANS_value']
486
-                            )
487
-                        );
488
-                    }
489
-                }
227
+	/**
228
+	 * Gets the csv data for a batch of registrations
229
+	 *
230
+	 * @param int|null $event_id
231
+	 * @param int $offset
232
+	 * @param int $limit
233
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
234
+	 * @param array $query_params for using where querying the model
235
+	 * @return array top-level keys are numeric, next-level keys are column headers
236
+	 * @throws \EE_Error
237
+	 */
238
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
239
+	{
240
+		$reg_fields_to_include = array(
241
+			'TXN_ID',
242
+			'ATT_ID',
243
+			'REG_ID',
244
+			'REG_date',
245
+			'REG_code',
246
+			'REG_count',
247
+			'REG_final_price',
248
+		);
249
+		$att_fields_to_include = array(
250
+			'ATT_fname',
251
+			'ATT_lname',
252
+			'ATT_email',
253
+			'ATT_address',
254
+			'ATT_address2',
255
+			'ATT_city',
256
+			'STA_ID',
257
+			'CNT_ISO',
258
+			'ATT_zip',
259
+			'ATT_phone',
260
+		);
261
+		$registrations_csv_ready_array = array();
262
+		$reg_model = EE_Registry::instance()->load_model('Registration');
263
+		$query_params['limit'] = array($offset, $limit);
264
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
265
+		$registration_ids = array();
266
+		foreach ($registration_rows as $reg_row) {
267
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
268
+		}
269
+		foreach ($registration_rows as $reg_row) {
270
+			if (is_array($reg_row)) {
271
+				$reg_csv_array = array();
272
+				if (! $event_id) {
273
+					// get the event's name and Id
274
+					$reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
275
+						/* translators: 1: event name, 2: event ID */
276
+						__('%1$s (%2$s)', 'event_espresso'),
277
+						EEH_Export::prepare_value_from_db_for_display(
278
+							EEM_Event::instance(),
279
+							'EVT_name',
280
+							$reg_row['Event_CPT.post_title']
281
+						),
282
+						$reg_row['Event_CPT.ID']
283
+					);
284
+				}
285
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
286
+				/*@var $reg_row EE_Registration */
287
+				foreach ($reg_fields_to_include as $field_name) {
288
+					$field = $reg_model->field_settings_for($field_name);
289
+					if ($field_name == 'REG_final_price') {
290
+						$value = EEH_Export::prepare_value_from_db_for_display(
291
+							$reg_model,
292
+							$field_name,
293
+							$reg_row['Registration.REG_final_price'],
294
+							'localized_float'
295
+						);
296
+					} elseif ($field_name == 'REG_count') {
297
+						$value = sprintf(
298
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
299
+							__('%1$s of %2$s', 'event_espresso'),
300
+							EEH_Export::prepare_value_from_db_for_display(
301
+								$reg_model,
302
+								'REG_count',
303
+								$reg_row['Registration.REG_count']
304
+							),
305
+							EEH_Export::prepare_value_from_db_for_display(
306
+								$reg_model,
307
+								'REG_group_size',
308
+								$reg_row['Registration.REG_group_size']
309
+							)
310
+						);
311
+					} elseif ($field_name == 'REG_date') {
312
+						$value = EEH_Export::prepare_value_from_db_for_display(
313
+							$reg_model,
314
+							$field_name,
315
+							$reg_row['Registration.REG_date'],
316
+							'no_html'
317
+						);
318
+					} else {
319
+						$value = EEH_Export::prepare_value_from_db_for_display(
320
+							$reg_model,
321
+							$field_name,
322
+							$reg_row[ $field->get_qualified_column() ]
323
+						);
324
+					}
325
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
326
+					if ($field_name == 'REG_final_price') {
327
+						// add a column named Currency after the final price
328
+						$reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
329
+					}
330
+				}
331
+				// get pretty status
332
+				$stati = EEM_Status::instance()->localized_status(
333
+					array(
334
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
335
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
336
+					),
337
+					false,
338
+					'sentence'
339
+				);
340
+				$reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
341
+				// get pretty transaction status
342
+				$reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
343
+				$reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
344
+					? EEH_Export::prepare_value_from_db_for_display(
345
+						EEM_Transaction::instance(),
346
+						'TXN_total',
347
+						$reg_row['TransactionTable.TXN_total'],
348
+						'localized_float'
349
+					) : '0.00';
350
+				$reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
351
+					? EEH_Export::prepare_value_from_db_for_display(
352
+						EEM_Transaction::instance(),
353
+						'TXN_paid',
354
+						$reg_row['TransactionTable.TXN_paid'],
355
+						'localized_float'
356
+					) : '0.00';
357
+				$payment_methods = array();
358
+				$gateway_txn_ids_etc = array();
359
+				$payment_times = array();
360
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
361
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
362
+						array(
363
+							array(
364
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
365
+								'STS_ID' => EEM_Payment::status_id_approved,
366
+							),
367
+							'force_join' => array('Payment_Method'),
368
+						),
369
+						ARRAY_A,
370
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
371
+					);
372
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
373
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
374
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
375
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
376
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
377
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
378
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
379
+					}
380
+				}
381
+				$reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
382
+				$reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
383
+				$reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
384
+					',',
385
+					$gateway_txn_ids_etc
386
+				);
387
+				// get whether or not the user has checked in
388
+				$reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
389
+					$reg_row['Registration.REG_ID'],
390
+					'Checkin'
391
+				);
392
+				// get ticket of registration and its price
393
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
394
+				if ($reg_row['Ticket.TKT_ID']) {
395
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
396
+						$ticket_model,
397
+						'TKT_name',
398
+						$reg_row['Ticket.TKT_name']
399
+					);
400
+					$datetimes_strings = array();
401
+					foreach (EEM_Datetime::instance()->get_all_wpdb_results(
402
+						array(
403
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
404
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
405
+							'default_where_conditions' => 'none',
406
+						)
407
+					) as $datetime) {
408
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
409
+							EEM_Datetime::instance(),
410
+							'DTT_EVT_start',
411
+							$datetime['Datetime.DTT_EVT_start']
412
+						);
413
+					}
414
+				} else {
415
+					$ticket_name = __('Unknown', 'event_espresso');
416
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
417
+				}
418
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
419
+				$reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
420
+				// get datetime(s) of registration
421
+				// add attendee columns
422
+				foreach ($att_fields_to_include as $att_field_name) {
423
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
424
+					if ($reg_row['Attendee_CPT.ID']) {
425
+						if ($att_field_name == 'STA_ID') {
426
+							$value = EEM_State::instance()->get_var(
427
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
428
+								'STA_name'
429
+							);
430
+						} elseif ($att_field_name == 'CNT_ISO') {
431
+							$value = EEM_Country::instance()->get_var(
432
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
433
+								'CNT_name'
434
+							);
435
+						} else {
436
+							$value = EEH_Export::prepare_value_from_db_for_display(
437
+								EEM_Attendee::instance(),
438
+								$att_field_name,
439
+								$reg_row[ $field_obj->get_qualified_column() ]
440
+							);
441
+						}
442
+					} else {
443
+						$value = '';
444
+					}
445
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
446
+				}
447
+				// make sure each registration has the same questions in the same order
448
+				foreach ($question_labels as $question_label) {
449
+					if (! isset($reg_csv_array[ $question_label ])) {
450
+						$reg_csv_array[ $question_label ] = null;
451
+					}
452
+				}
453
+				$answers = EEM_Answer::instance()->get_all_wpdb_results(array(
454
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
455
+					'force_join' => array('Question'),
456
+				));
457
+				// now fill out the questions THEY answered
458
+				foreach ($answers as $answer_row) {
459
+					if ($answer_row['Question.QST_system']) {
460
+						// it's an answer to a system question. That was already displayed as part of the attendee
461
+						// fields, so don't write it out again thanks.
462
+						continue;
463
+					}
464
+					if ($answer_row['Question.QST_ID']) {
465
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
466
+							EEM_Question::instance(),
467
+							'QST_admin_label',
468
+							$answer_row['Question.QST_admin_label']
469
+						);
470
+					} else {
471
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
472
+					}
473
+					if (isset($answer_row['Question.QST_type'])
474
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
475
+					) {
476
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
477
+							$answer_row['Answer.ANS_value']
478
+						);
479
+					} else {
480
+						// this isn't for html, so don't show html entities
481
+						$reg_csv_array[ $question_label ] = html_entity_decode(
482
+							EEH_Export::prepare_value_from_db_for_display(
483
+								EEM_Answer::instance(),
484
+								'ANS_value',
485
+								$answer_row['Answer.ANS_value']
486
+							)
487
+						);
488
+					}
489
+				}
490 490
 
491
-                /**
492
-                 * Filter to change the contents of each row of the registrations report CSV file.
493
-                 * This can be used to add or remote columns from the CSV file, or change their values.
494
-                 * Note when using: all rows in the CSV should have the same columns.
495
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
496
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
497
-                 */
498
-                $registrations_csv_ready_array[] = apply_filters(
499
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
500
-                    $reg_csv_array,
501
-                    $reg_row
502
-                );
503
-            }
504
-        }
505
-        // if we couldn't export anything, we want to at least show the column headers
506
-        if (empty($registrations_csv_ready_array)) {
507
-            $reg_csv_array = array();
508
-            $model_and_fields_to_include = array(
509
-                'Registration' => $reg_fields_to_include,
510
-                'Attendee'     => $att_fields_to_include,
511
-            );
512
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
513
-                $model = EE_Registry::instance()->load_model($model_name);
514
-                foreach ($field_list as $field_name) {
515
-                    $field = $model->field_settings_for($field_name);
516
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
517
-                }
518
-            }
519
-            $registrations_csv_ready_array[] = $reg_csv_array;
520
-        }
521
-        return $registrations_csv_ready_array;
522
-    }
491
+				/**
492
+				 * Filter to change the contents of each row of the registrations report CSV file.
493
+				 * This can be used to add or remote columns from the CSV file, or change their values.
494
+				 * Note when using: all rows in the CSV should have the same columns.
495
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
496
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
497
+				 */
498
+				$registrations_csv_ready_array[] = apply_filters(
499
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
500
+					$reg_csv_array,
501
+					$reg_row
502
+				);
503
+			}
504
+		}
505
+		// if we couldn't export anything, we want to at least show the column headers
506
+		if (empty($registrations_csv_ready_array)) {
507
+			$reg_csv_array = array();
508
+			$model_and_fields_to_include = array(
509
+				'Registration' => $reg_fields_to_include,
510
+				'Attendee'     => $att_fields_to_include,
511
+			);
512
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
513
+				$model = EE_Registry::instance()->load_model($model_name);
514
+				foreach ($field_list as $field_name) {
515
+					$field = $model->field_settings_for($field_name);
516
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
517
+				}
518
+			}
519
+			$registrations_csv_ready_array[] = $reg_csv_array;
520
+		}
521
+		return $registrations_csv_ready_array;
522
+	}
523 523
 
524 524
 
525
-    /**
526
-     * Counts total unit to process
527
-     *
528
-     * @deprecated since 4.9.19
529
-     * @param int|array $event_id
530
-     * @return int
531
-     */
532
-    public function count_units_to_process($event_id)
533
-    {
534
-        // use the legacy filter
535
-        if ($event_id) {
536
-            $query_params[0]['EVT_ID'] = $event_id;
537
-        } else {
538
-            $query_params['force_join'][] = 'Event';
539
-        }
540
-        return \EEM_Registration::instance()->count($query_params);
541
-    }
525
+	/**
526
+	 * Counts total unit to process
527
+	 *
528
+	 * @deprecated since 4.9.19
529
+	 * @param int|array $event_id
530
+	 * @return int
531
+	 */
532
+	public function count_units_to_process($event_id)
533
+	{
534
+		// use the legacy filter
535
+		if ($event_id) {
536
+			$query_params[0]['EVT_ID'] = $event_id;
537
+		} else {
538
+			$query_params['force_join'][] = 'Event';
539
+		}
540
+		return \EEM_Registration::instance()->count($query_params);
541
+	}
542 542
 
543 543
 
544
-    /**
545
-     * Performs any clean-up logic when we know the job is completed.
546
-     * In this case, we delete the temporary file
547
-     *
548
-     * @param JobParameters $job_parameters
549
-     * @return boolean
550
-     */
551
-    public function cleanup_job(JobParameters $job_parameters)
552
-    {
553
-        $this->_file_helper->delete(
554
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
555
-            true,
556
-            'd'
557
-        );
558
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
559
-    }
544
+	/**
545
+	 * Performs any clean-up logic when we know the job is completed.
546
+	 * In this case, we delete the temporary file
547
+	 *
548
+	 * @param JobParameters $job_parameters
549
+	 * @return boolean
550
+	 */
551
+	public function cleanup_job(JobParameters $job_parameters)
552
+	{
553
+		$this->_file_helper->delete(
554
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
555
+			true,
556
+			'd'
557
+		);
558
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
559
+	}
560 560
 }
Please login to merge, or discard this patch.
data_migration_scripts/4_1_0_stages/EE_DMS_4_1_0_questions.dmsstage.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -57,119 +57,119 @@
 block discarded – undo
57 57
  */
58 58
 class EE_DMS_4_1_0_questions extends EE_Data_Migration_Script_Stage
59 59
 {
60
-    private $_old_table;
61
-    private $_new_table;
62
-    private $_option_table;
63
-    public function _migration_step($num_items = 50)
64
-    {
65
-        global $wpdb;
66
-        $start_at_record = $this->count_records_migrated();
67
-        $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
68
-        $items_actually_migrated = 0;
69
-        foreach ($rows as $question_row) {
70
-            $new_id = $this->_insert_new_question($question_row);
71
-            $this->get_migration_script()->set_mapping($this->_old_table, $question_row['id'], $this->_new_table, $new_id);
72
-            $items_actually_migrated++;
73
-        }
74
-        if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
75
-            $this->set_completed();
76
-        }
77
-        return $items_actually_migrated;
78
-    }
79
-    public function _count_records_to_migrate()
80
-    {
81
-        global $wpdb;
82
-        $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
83
-        return $count;
84
-    }
85
-    public function __construct()
86
-    {
87
-        global $wpdb;
88
-        $this->_pretty_name = __("Questions", "event_espresso");
89
-        $this->_old_table = $wpdb->prefix."events_question";
90
-        $this->_new_table = $wpdb->prefix."esp_question";
91
-        $this->_option_table = $wpdb->prefix."esp_question_option";
92
-        parent::__construct();
93
-    }
94
-    private function _insert_new_question($old_question)
95
-    {
96
-        global $wpdb;
97
-        // if this pretends to be a 'system' question, check if we already have a
98
-        // system question for that string. If so, pretend THAT new question
99
-        // is what we just isnerted
100
-        if ($old_question['system_name']) {
101
-            $id_of_new_system_question = intval($wpdb->get_var($wpdb->prepare("SELECT QST_ID FROM {$this->_new_table} WHERE QST_system = %s", $old_question['system_name'])));
102
-            if ($id_of_new_system_question) {
103
-                return $id_of_new_system_question;
104
-            }
105
-            // ok so this must be the first one. Carry on.
106
-        }
60
+	private $_old_table;
61
+	private $_new_table;
62
+	private $_option_table;
63
+	public function _migration_step($num_items = 50)
64
+	{
65
+		global $wpdb;
66
+		$start_at_record = $this->count_records_migrated();
67
+		$rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A);
68
+		$items_actually_migrated = 0;
69
+		foreach ($rows as $question_row) {
70
+			$new_id = $this->_insert_new_question($question_row);
71
+			$this->get_migration_script()->set_mapping($this->_old_table, $question_row['id'], $this->_new_table, $new_id);
72
+			$items_actually_migrated++;
73
+		}
74
+		if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) {
75
+			$this->set_completed();
76
+		}
77
+		return $items_actually_migrated;
78
+	}
79
+	public function _count_records_to_migrate()
80
+	{
81
+		global $wpdb;
82
+		$count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table);
83
+		return $count;
84
+	}
85
+	public function __construct()
86
+	{
87
+		global $wpdb;
88
+		$this->_pretty_name = __("Questions", "event_espresso");
89
+		$this->_old_table = $wpdb->prefix."events_question";
90
+		$this->_new_table = $wpdb->prefix."esp_question";
91
+		$this->_option_table = $wpdb->prefix."esp_question_option";
92
+		parent::__construct();
93
+	}
94
+	private function _insert_new_question($old_question)
95
+	{
96
+		global $wpdb;
97
+		// if this pretends to be a 'system' question, check if we already have a
98
+		// system question for that string. If so, pretend THAT new question
99
+		// is what we just isnerted
100
+		if ($old_question['system_name']) {
101
+			$id_of_new_system_question = intval($wpdb->get_var($wpdb->prepare("SELECT QST_ID FROM {$this->_new_table} WHERE QST_system = %s", $old_question['system_name'])));
102
+			if ($id_of_new_system_question) {
103
+				return $id_of_new_system_question;
104
+			}
105
+			// ok so this must be the first one. Carry on.
106
+		}
107 107
 
108
-        $cols_n_values = array(
109
-            'QST_display_text' => stripslashes($old_question['question']),
110
-            'QST_admin_label' => $old_question['system_name'] ? $old_question['system_name'] : sanitize_title($old_question['question']),
111
-            'QST_system' => (string) $old_question['system_name'],
112
-            'QST_type' => $old_question['question_type'],
113
-            'QST_required' => 'Y' == $old_question['required'],
114
-            'QST_required_text' => stripslashes($old_question['required_text']),
115
-            'QST_order' => $old_question['sequence'],
116
-            'QST_admin_only' => 'Y' == $old_question['admin_only'],
117
-            'QST_wp_user' => $old_question['wp_user'],
118
-            'QST_deleted' => false
119
-        );
120
-        $datatypes = array(
121
-            '%s',// QST_display_text
122
-            '%s',// QST-admin_label
123
-            '%s',// QST_system
124
-            '%s',// QST_type
125
-            '%d',// QST_required
126
-            '%s',// QST_required_text
127
-            '%d',// QST_order
128
-            '%d',// QST_admin_only
129
-            '%d',// QST_wp_user
130
-            '%d',// QST_deleted
131
-        );
132
-        $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
-        if (! $success) {
134
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135
-            return 0;
136
-        }
137
-        $new_id = $wpdb->insert_id;
138
-        // now take care of posisbly adding question options
139
-        if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
140
-            $options = explode(",", $old_question['response']);
141
-            foreach ($options as $option) {
142
-                $this->_insert_question_option($option, $new_id);
143
-            }
144
-        }
145
-        return $new_id;
146
-    }
147
-    /**
148
-     * Adds a question option to the db
149
-     * @global type $wpdb
150
-     * @param string $option
151
-     * @param int $question_id
152
-     * @return int
153
-     */
154
-    private function _insert_question_option($option, $question_id)
155
-    {
156
-        $option = trim($option);
157
-        global $wpdb;
158
-        $cols_n_values = array(
159
-            'QST_ID'=>$question_id,
160
-            'QSO_value'=>$option,
161
-            'QSO_deleted'=>false
162
-        );
163
-        $datatypes= array(
164
-            '%d',// QST_ID
165
-            '%s',// QSO_value
166
-            '%d',// QSO_deleted
167
-        );
168
-        $success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
-        if (! $success) {
170
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171
-            return 0;
172
-        }
173
-        return $wpdb->insert_id;
174
-    }
108
+		$cols_n_values = array(
109
+			'QST_display_text' => stripslashes($old_question['question']),
110
+			'QST_admin_label' => $old_question['system_name'] ? $old_question['system_name'] : sanitize_title($old_question['question']),
111
+			'QST_system' => (string) $old_question['system_name'],
112
+			'QST_type' => $old_question['question_type'],
113
+			'QST_required' => 'Y' == $old_question['required'],
114
+			'QST_required_text' => stripslashes($old_question['required_text']),
115
+			'QST_order' => $old_question['sequence'],
116
+			'QST_admin_only' => 'Y' == $old_question['admin_only'],
117
+			'QST_wp_user' => $old_question['wp_user'],
118
+			'QST_deleted' => false
119
+		);
120
+		$datatypes = array(
121
+			'%s',// QST_display_text
122
+			'%s',// QST-admin_label
123
+			'%s',// QST_system
124
+			'%s',// QST_type
125
+			'%d',// QST_required
126
+			'%s',// QST_required_text
127
+			'%d',// QST_order
128
+			'%d',// QST_admin_only
129
+			'%d',// QST_wp_user
130
+			'%d',// QST_deleted
131
+		);
132
+		$success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
+		if (! $success) {
134
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135
+			return 0;
136
+		}
137
+		$new_id = $wpdb->insert_id;
138
+		// now take care of posisbly adding question options
139
+		if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
140
+			$options = explode(",", $old_question['response']);
141
+			foreach ($options as $option) {
142
+				$this->_insert_question_option($option, $new_id);
143
+			}
144
+		}
145
+		return $new_id;
146
+	}
147
+	/**
148
+	 * Adds a question option to the db
149
+	 * @global type $wpdb
150
+	 * @param string $option
151
+	 * @param int $question_id
152
+	 * @return int
153
+	 */
154
+	private function _insert_question_option($option, $question_id)
155
+	{
156
+		$option = trim($option);
157
+		global $wpdb;
158
+		$cols_n_values = array(
159
+			'QST_ID'=>$question_id,
160
+			'QSO_value'=>$option,
161
+			'QSO_deleted'=>false
162
+		);
163
+		$datatypes= array(
164
+			'%d',// QST_ID
165
+			'%s',// QSO_value
166
+			'%d',// QSO_deleted
167
+		);
168
+		$success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
+		if (! $success) {
170
+			$this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171
+			return 0;
172
+		}
173
+		return $wpdb->insert_id;
174
+	}
175 175
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -118,25 +118,25 @@  discard block
 block discarded – undo
118 118
             'QST_deleted' => false
119 119
         );
120 120
         $datatypes = array(
121
-            '%s',// QST_display_text
122
-            '%s',// QST-admin_label
123
-            '%s',// QST_system
124
-            '%s',// QST_type
125
-            '%d',// QST_required
126
-            '%s',// QST_required_text
127
-            '%d',// QST_order
128
-            '%d',// QST_admin_only
129
-            '%d',// QST_wp_user
130
-            '%d',// QST_deleted
121
+            '%s', // QST_display_text
122
+            '%s', // QST-admin_label
123
+            '%s', // QST_system
124
+            '%s', // QST_type
125
+            '%d', // QST_required
126
+            '%s', // QST_required_text
127
+            '%d', // QST_order
128
+            '%d', // QST_admin_only
129
+            '%d', // QST_wp_user
130
+            '%d', // QST_deleted
131 131
         );
132 132
         $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes);
133
-        if (! $success) {
133
+        if ( ! $success) {
134 134
             $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_question, $this->_new_table, $cols_n_values, $datatypes));
135 135
             return 0;
136 136
         }
137 137
         $new_id = $wpdb->insert_id;
138 138
         // now take care of posisbly adding question options
139
-        if (in_array($old_question['question_type'], array('DROPDOWN','SINGLE','MULTIPLE'))) {
139
+        if (in_array($old_question['question_type'], array('DROPDOWN', 'SINGLE', 'MULTIPLE'))) {
140 140
             $options = explode(",", $old_question['response']);
141 141
             foreach ($options as $option) {
142 142
                 $this->_insert_question_option($option, $new_id);
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
             'QSO_value'=>$option,
161 161
             'QSO_deleted'=>false
162 162
         );
163
-        $datatypes= array(
164
-            '%d',// QST_ID
165
-            '%s',// QSO_value
166
-            '%d',// QSO_deleted
163
+        $datatypes = array(
164
+            '%d', // QST_ID
165
+            '%s', // QSO_value
166
+            '%d', // QSO_deleted
167 167
         );
168 168
         $success = $wpdb->insert($this->_option_table, $cols_n_values, $datatypes);
169
-        if (! $success) {
170
-            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option,'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
169
+        if ( ! $success) {
170
+            $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, array('option'=>$option, 'new_question_id'=>$question_id), $this->_option_table, $cols_n_values, $datatypes));
171 171
             return 0;
172 172
         }
173 173
         return $wpdb->insert_id;
Please login to merge, or discard this patch.
core/admin/EE_Admin_Hooks.core.php 2 patches
Indentation   +718 added lines, -718 removed lines patch added patch discarded remove patch
@@ -13,722 +13,722 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * we're just going to use this to hold the name of the caller class (child class name)
18
-     *
19
-     * @var string
20
-     */
21
-    public $caller;
22
-
23
-
24
-    /**
25
-     * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
-     * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
-     * used later to make sure we require the needed files.
28
-     *
29
-     * @var bool
30
-     */
31
-    protected $_extend;
32
-
33
-
34
-    /**
35
-     * child classes MUST set this property so that the page object can be loaded correctly
36
-     *
37
-     * @var string
38
-     */
39
-    protected $_name;
40
-
41
-
42
-    /**
43
-     * This is set by child classes and is an associative array of ajax hooks in the format:
44
-     * array(
45
-     *    'ajax_action_ref' => 'executing_method'; //must be public
46
-     * )
47
-     *
48
-     * @var array
49
-     */
50
-    protected $_ajax_func;
51
-
52
-
53
-    /**
54
-     * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
-     * array(
56
-     *    'page_route' => 'executing_method' //must be public
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_init_func;
62
-
63
-
64
-    /**
65
-     * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
-     * array(
67
-     *    0 => array(
68
-     *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
-     *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
-     *        will be added to each route.
71
-     *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
-     *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
-     *        method arguments.
74
-     *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
-     *        automatically)
76
-     *        'priority' => 'default', //default 'default' (optional)
77
-     *        'label' => __('Localized Title', 'event_espresso'),
78
-     *        'context' => 'advanced' //advanced is default (optional),
79
-     *    'callback_args' => array() //any callback args to include (optional)
80
-     * )
81
-     * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
-     *
83
-     * @var array
84
-     */
85
-    protected $_metaboxes;
86
-
87
-
88
-    /**
89
-     * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
-     * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
-     * array: array(
92
-     *    0 => array(
93
-     *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
-     *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
-     *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
-     *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
-     *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
-     *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
-     *        id for the screen the metabox is on.
100
-     *    )
101
-     * )
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_remove_metaboxes;
106
-
107
-
108
-    /**
109
-     * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
-     * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
-     * second array index is for indicating what routes each script/style loads on. array(
112
-     * 'registers' => array(
113
-     *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
-     *        argument to link scripts together.
115
-     *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
-     *            'url' => 'http://urltoscript.css.js',
117
-     *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
-     *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
-     *            gets loaded before the one you are setting here.
120
-     *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
-     *        ),
122
-     *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
-     *    the script gets enqueued on.
124
-     *        'script_ref' => array('route_one', 'route_two')
125
-     *    ),
126
-     *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
-     *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
-     *    the object.
129
-     *        'scrip_ref' => array(
130
-     *            'NAME_OF_JS_OBJECT' => array(
131
-     *                'translate_ref' => __('localized_string', 'event_espresso'),
132
-     *                'some_data' => 5
133
-     *            )
134
-     *        )
135
-     *    )
136
-     * )
137
-     *
138
-     * @var array
139
-     */
140
-    protected $_scripts_styles;
141
-
142
-
143
-    /**
144
-     * This is a property that will contain the current route.
145
-     *
146
-     * @var string;
147
-     */
148
-    protected $_current_route;
149
-
150
-
151
-    /**
152
-     * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
-     * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
-     *    'wp_hook_reference' => 1
155
-     *    )
156
-     * )
157
-     *
158
-     * @var array
159
-     */
160
-    protected $_wp_action_filters_priority;
161
-
162
-
163
-    /**
164
-     * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
-     *
166
-     * @var array
167
-     */
168
-    protected $_req_data;
169
-
170
-
171
-    /**
172
-     * This just holds an instance of the page object for this hook
173
-     *
174
-     * @var EE_Admin_Page
175
-     */
176
-    protected $_page_object;
177
-
178
-
179
-    /**
180
-     * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
-     *
182
-     * @var EE_Admin_Page|EE_Admin_Page_CPT
183
-     */
184
-    protected $_adminpage_obj;
185
-
186
-
187
-    /**
188
-     * Holds EE_Registry object
189
-     *
190
-     * @var EE_Registry
191
-     */
192
-    protected $EE = null;
193
-
194
-
195
-    /**
196
-     * constructor
197
-     *
198
-     * @param EE_Admin_Page $admin_page the calling admin_page_object
199
-     */
200
-    public function __construct(EE_Admin_Page $adminpage)
201
-    {
202
-
203
-        $this->_adminpage_obj = $adminpage;
204
-        $this->_req_data = array_merge($_GET, $_POST);
205
-        $this->_set_defaults();
206
-        $this->_set_hooks_properties();
207
-        // first let's verify we're on the right page
208
-        if (! isset($this->_req_data['page'])
209
-            || (isset($this->_req_data['page'])
210
-                && $this->_adminpage_obj->page_slug
211
-                   != $this->_req_data['page'])) {
212
-            return;
213
-        } //get out nothing more to be done here.
214
-        // allow for extends to modify properties
215
-        if (method_exists($this, '_extend_properties')) {
216
-            $this->_extend_properties();
217
-        }
218
-        $this->_set_page_object();
219
-        $this->_init_hooks();
220
-        $this->_load_custom_methods();
221
-        $this->_load_routed_hooks();
222
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
223
-        add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
224
-        add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
225
-        $this->_ajax_hooks();
226
-    }
227
-
228
-
229
-    /**
230
-     * used by child classes to set the following properties:
231
-     * $_ajax_func (optional)
232
-     * $_init_func (optional)
233
-     * $_metaboxes (optional)
234
-     * $_scripts (optional)
235
-     * $_styles (optional)
236
-     * $_name (required)
237
-     * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
238
-     * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
239
-     * really early on page load (just after admin_init) if they want to have them registered for handling early.
240
-     *
241
-     * @access protected
242
-     * @abstract
243
-     * @return void
244
-     */
245
-    abstract protected function _set_hooks_properties();
246
-
247
-
248
-    /**
249
-     * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
250
-     * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
251
-     * registered the scripts and styles using wp_register_script and wp_register_style functions.
252
-     *
253
-     * @access public
254
-     * @return void
255
-     */
256
-    public function enqueue_scripts_styles()
257
-    {
258
-
259
-        if (! empty($this->_scripts_styles)) {
260
-            // first let's do all the registrations
261
-            if (! isset($this->_scripts_styles['registers'])) {
262
-                $msg[] = __(
263
-                    'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
-                    'event_espresso'
265
-                );
266
-                $msg[] = sprintf(
267
-                    __(
268
-                        'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
-                        'event_espresso'
270
-                    ),
271
-                    '<strong>' . $this->caller . '</strong>'
272
-                );
273
-                throw new EE_Error(implode('||', $msg));
274
-            }
275
-            foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
-                $defaults = array(
277
-                    'type'    => 'js',
278
-                    'url'     => '',
279
-                    'depends' => array(),
280
-                    'version' => EVENT_ESPRESSO_VERSION,
281
-                    'footer'  => true,
282
-                );
283
-                $details = wp_parse_args($details, $defaults);
284
-                extract($details);
285
-                // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
-                // let's make sure we're not missing any REQUIRED parameters
288
-                if (empty($url)) {
289
-                    $msg[] = sprintf(
290
-                        __('Missing the url for the requested %s', 'event_espresso'),
291
-                        $type == 'js' ? 'script' : 'stylesheet'
292
-                    );
293
-                    $msg[] = sprintf(
294
-                        __(
295
-                            'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
-                            'event_espresso'
297
-                        ),
298
-                        '<strong>' . $this->caller . '</strong>',
299
-                        $ref
300
-                    );
301
-                    throw new EE_Error(implode('||', $msg));
302
-                }
303
-                // made it here so let's do the appropriate registration
304
-                $type == 'js'
305
-                    ? wp_register_script($ref, $url, $depends, $version, $footer)
306
-                    : wp_register_style(
307
-                        $ref,
308
-                        $url,
309
-                        $depends,
310
-                        $version
311
-                    );
312
-            }
313
-            // k now lets do the enqueues
314
-            if (! isset($this->_scripts_styles['enqueues'])) {
315
-                return;
316
-            }  //not sure if we should throw an error here or not.
317
-
318
-            foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
-                // make sure $routes is an array
320
-                $routes = (array) $routes;
321
-                if (in_array($this->_current_route, $routes)) {
322
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
-                        : wp_enqueue_style($ref);
324
-                    // if we have a localization for the script let's do that too.
325
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
-                            wp_localize_script(
328
-                                $ref,
329
-                                $object_name,
330
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
-                            );
332
-                        }
333
-                    }
334
-                }
335
-            }
336
-            // let's do the deregisters
337
-            if (! isset($this->_scripts_styles['deregisters'])) {
338
-                return;
339
-            }
340
-            foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
-                $defaults = array(
342
-                    'type' => 'js',
343
-                );
344
-                $details = wp_parse_args($details, $defaults);
345
-                extract($details);
346
-                $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
-            }
348
-        }
349
-    }
350
-
351
-
352
-    /**
353
-     * just set the defaults for the hooks properties.
354
-     *
355
-     * @access private
356
-     * @return void
357
-     */
358
-    private function _set_defaults()
359
-    {
360
-        $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
-        $this->_current_route = $this->getCurrentRoute();
362
-        $this->caller = get_class($this);
363
-        $this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
-    }
365
-
366
-
367
-    /**
368
-     * A helper for determining the current route.
369
-     * @return string
370
-     */
371
-    private function getCurrentRoute()
372
-    {
373
-        // list tables do something else with 'action' for bulk actions.
374
-        $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
-        // we set a 'route' variable in some cases where action is being used by something else.
376
-        $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
-        return sanitize_key($action);
378
-    }
379
-
380
-
381
-    /**
382
-     * this sets the _page_object property
383
-     *
384
-     * @access protected
385
-     * @return void
386
-     */
387
-    protected function _set_page_object()
388
-    {
389
-        // first make sure $this->_name is set
390
-        if (empty($this->_name)) {
391
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
392
-            $msg[] = sprintf(
393
-                __("This is because the %s child class has not set the '_name' property", 'event_espresso'),
394
-                $this->caller
395
-            );
396
-            throw new EE_Error(implode('||', $msg));
397
-        }
398
-        $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
400
-        // first default file (if exists)
401
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
402
-        if (is_readable($decaf_file)) {
403
-            require_once($decaf_file);
404
-        }
405
-        // now we have to do require for extended file (if needed)
406
-        if ($this->_extend) {
407
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
408
-        }
409
-        // if we've got an extended class we use that!
410
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
411
-        // let's make sure the class exists
412
-        if (! class_exists($ref)) {
413
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
414
-            $msg[] = sprintf(
415
-                __(
416
-                    'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
417
-                    'event_espresso'
418
-                ),
419
-                $ref
420
-            );
421
-            throw new EE_Error(implode('||', $msg));
422
-        }
423
-        $a = new ReflectionClass($ref);
424
-        $this->_page_object = $a->newInstance(false);
425
-    }
426
-
427
-
428
-    /**
429
-     * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
430
-     * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
431
-     * $this->_req_data (all the _POST and _GET data) is available to your methods.
432
-     *
433
-     * @access private
434
-     * @return void
435
-     */
436
-    private function _load_custom_methods()
437
-    {
438
-        /**
439
-         * method cannot be named 'default' (@see http://us3.php
440
-         * .net/manual/en/reserved.keywords.php) so need to
441
-         * handle routes that are "default"
442
-         *
443
-         * @since 4.3.0
444
-         */
445
-        $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
446
-        // these run before the Admin_Page route executes.
447
-        if (method_exists($this, $method_callback)) {
448
-            call_user_func(array($this, $method_callback));
449
-        }
450
-        // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
451
-        // first the actions
452
-        // note that these action hooks will have the $query_args value available.
453
-        $admin_class_name = get_class($this->_adminpage_obj);
454
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
455
-            add_action(
456
-                'AHEE__'
457
-                . $admin_class_name
458
-                . '___redirect_after_action__before_redirect_modification_'
459
-                . $this->_current_route,
460
-                array($this, '_redirect_action_early_' . $this->_current_route),
461
-                10
462
-            );
463
-        }
464
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
465
-            add_action(
466
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
-                array($this, '_redirect_action_' . $this->_current_route),
468
-                10
469
-            );
470
-        }
471
-        // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
473
-            add_filter(
474
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
-                array($this, '_redirect_filter_' . $this->_current_route),
476
-                10,
477
-                2
478
-            );
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
485
-     * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
486
-     * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
487
-     *
488
-     * @return void
489
-     */
490
-    private function _load_routed_hooks()
491
-    {
492
-
493
-        // this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
494
-        $hook_filter_array = array(
495
-            'admin_footer'                                                                            => array(
496
-                'type'     => 'action',
497
-                'argnum'   => 1,
498
-                'priority' => 10,
499
-            ),
500
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
501
-                'type'     => 'filter',
502
-                'argnum'   => 1,
503
-                'priority' => 10,
504
-            ),
505
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
506
-                'type'     => 'filter',
507
-                'argnum'   => 1,
508
-                'priority' => 10,
509
-            ),
510
-            'FHEE_list_table_views'                                                                   => array(
511
-                'type'     => 'filter',
512
-                'argnum'   => 1,
513
-                'priority' => 10,
514
-            ),
515
-            'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
516
-                'type'     => 'action',
517
-                'argnum'   => 1,
518
-                'priority' => 10,
519
-            ),
520
-        );
521
-        foreach ($hook_filter_array as $hook => $args) {
522
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
525
-                }
526
-                if ($args['type'] == 'action') {
527
-                    add_action(
528
-                        $hook,
529
-                        array($this, $this->_current_route . '_' . $hook),
530
-                        $args['priority'],
531
-                        $args['argnum']
532
-                    );
533
-                } else {
534
-                    add_filter(
535
-                        $hook,
536
-                        array($this, $this->_current_route . '_' . $hook),
537
-                        $args['priority'],
538
-                        $args['argnum']
539
-                    );
540
-                }
541
-            }
542
-        }
543
-    }
544
-
545
-
546
-    /**
547
-     * Loop throught the $_ajax_func array and add_actions for the array.
548
-     *
549
-     * @return void
550
-     */
551
-    private function _ajax_hooks()
552
-    {
553
-
554
-        if (empty($this->_ajax_func)) {
555
-            return;
556
-        } //get out there's nothing to take care of.
557
-        foreach ($this->_ajax_func as $action => $method) {
558
-            // make sure method exists
559
-            if (! method_exists($this, $method)) {
560
-                $msg[] = __(
561
-                    'There is no corresponding method for the hook labeled in the _ajax_func array',
562
-                    'event_espresso'
563
-                ) . '<br />';
564
-                $msg[] = sprintf(
565
-                    __(
566
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
567
-                        'event_espresso'
568
-                    ),
569
-                    $method,
570
-                    $this->caller
571
-                );
572
-                throw new EE_Error(implode('||', $msg));
573
-            }
574
-            add_action('wp_ajax_' . $action, array($this, $method));
575
-        }
576
-    }
577
-
578
-
579
-    /**
580
-     * Loop throught the $_init_func array and add_actions for the array.
581
-     *
582
-     * @return void
583
-     */
584
-    protected function _init_hooks()
585
-    {
586
-        if (empty($this->_init_func)) {
587
-            return;
588
-        } //get out there's nothing to take care of.
589
-        // We need to determine what page_route we are on!
590
-        $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591
-        foreach ($this->_init_func as $route => $method) {
592
-            // make sure method exists
593
-            if (! method_exists($this, $method)) {
594
-                $msg[] = __(
595
-                    'There is no corresponding method for the hook labeled in the _init_func array',
596
-                    'event_espresso'
597
-                ) . '<br />';
598
-                $msg[] = sprintf(
599
-                    __(
600
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
601
-                        'event_espresso'
602
-                    ),
603
-                    $method,
604
-                    $this->caller
605
-                );
606
-                throw new EE_Error(implode('||', $msg));
607
-            }
608
-            if ($route == $this->_current_route) {
609
-                add_action('admin_init', array($this, $method));
610
-            }
611
-        }
612
-    }
613
-
614
-
615
-    /**
616
-     * Loop through the _metaboxes property and add_metaboxes accordingly
617
-     * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
618
-     *
619
-     * @access public
620
-     * @return void
621
-     */
622
-    public function add_metaboxes()
623
-    {
624
-        if (empty($this->_metaboxes)) {
625
-            return;
626
-        } //get out we don't have any metaboxes to set for this connection
627
-        $this->_handle_metabox_array($this->_metaboxes);
628
-    }
629
-
630
-
631
-    private function _handle_metabox_array($boxes, $add = true)
632
-    {
633
-
634
-        foreach ($boxes as $box) {
635
-            if (! isset($box['page_route'])) {
636
-                continue;
637
-            } //we dont' have a valid array
638
-            // let's make sure $box['page_route'] is an array so the "foreach" will work.
639
-            $box['page_route'] = (array) $box['page_route'];
640
-            foreach ($box['page_route'] as $route) {
641
-                if ($route != $this->_current_route) {
642
-                    continue;
643
-                } //get out we only add metaboxes for set route.
644
-                if ($add) {
645
-                    $this->_add_metabox($box);
646
-                } else {
647
-                    $this->_remove_metabox($box);
648
-                }
649
-            }
650
-        }
651
-    }
652
-
653
-
654
-    /**
655
-     * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
656
-     *
657
-     * @access public
658
-     * @return void
659
-     */
660
-    public function remove_metaboxes()
661
-    {
662
-
663
-        if (empty($this->_remove_metaboxes)) {
664
-            return;
665
-        } //get out there are no metaboxes to remove
666
-        $this->_handle_metabox_array($this->_remove_metaboxes, false);
667
-    }
668
-
669
-
670
-    /**
671
-     * This just handles adding a metabox
672
-     *
673
-     * @access private
674
-     * @param array $args an array of args that have been set for this metabox by the child class
675
-     */
676
-    private function _add_metabox($args)
677
-    {
678
-        $current_screen = get_current_screen();
679
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
680
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
681
-        // set defaults
682
-        $defaults = array(
683
-            'func'          => $func,
684
-            'id'            => $this->caller . '_' . $func . '_metabox',
685
-            'priority'      => 'default',
686
-            'label'         => $this->caller,
687
-            'context'       => 'advanced',
688
-            'callback_args' => array(),
689
-            'page'          => isset($args['page']) ? $args['page'] : $screen_id,
690
-        );
691
-        $args = wp_parse_args($args, $defaults);
692
-        extract($args);
693
-        // make sure method exists
694
-        if (! method_exists($this, $func)) {
695
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
696
-            $msg[] = sprintf(
697
-                __(
698
-                    'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
699
-                    'event_espresso'
700
-                ),
701
-                $func,
702
-                $this->caller
703
-            );
704
-            throw new EE_Error(implode('||', $msg));
705
-        }
706
-        // everything checks out so lets add the metabox
707
-        add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
708
-    }
709
-
710
-
711
-    private function _remove_metabox($args)
712
-    {
713
-        $current_screen = get_current_screen();
714
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
715
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
716
-        // set defaults
717
-        $defaults = array(
718
-            'id'      => isset($args['id'])
719
-                ? $args['id']
720
-                : $this->_current_route
721
-                  . '_'
722
-                  . $this->caller
723
-                  . '_'
724
-                  . $func
725
-                  . '_metabox',
726
-            'context' => 'default',
727
-            'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
728
-        );
729
-        $args = wp_parse_args($args, $defaults);
730
-        extract($args);
731
-        // everything checks out so lets remove the box!
732
-        remove_meta_box($id, $screen, $context);
733
-    }
16
+	/**
17
+	 * we're just going to use this to hold the name of the caller class (child class name)
18
+	 *
19
+	 * @var string
20
+	 */
21
+	public $caller;
22
+
23
+
24
+	/**
25
+	 * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
+	 * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
+	 * used later to make sure we require the needed files.
28
+	 *
29
+	 * @var bool
30
+	 */
31
+	protected $_extend;
32
+
33
+
34
+	/**
35
+	 * child classes MUST set this property so that the page object can be loaded correctly
36
+	 *
37
+	 * @var string
38
+	 */
39
+	protected $_name;
40
+
41
+
42
+	/**
43
+	 * This is set by child classes and is an associative array of ajax hooks in the format:
44
+	 * array(
45
+	 *    'ajax_action_ref' => 'executing_method'; //must be public
46
+	 * )
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $_ajax_func;
51
+
52
+
53
+	/**
54
+	 * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
+	 * array(
56
+	 *    'page_route' => 'executing_method' //must be public
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_init_func;
62
+
63
+
64
+	/**
65
+	 * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
+	 * array(
67
+	 *    0 => array(
68
+	 *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
+	 *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
+	 *        will be added to each route.
71
+	 *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
+	 *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
+	 *        method arguments.
74
+	 *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
+	 *        automatically)
76
+	 *        'priority' => 'default', //default 'default' (optional)
77
+	 *        'label' => __('Localized Title', 'event_espresso'),
78
+	 *        'context' => 'advanced' //advanced is default (optional),
79
+	 *    'callback_args' => array() //any callback args to include (optional)
80
+	 * )
81
+	 * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
+	 *
83
+	 * @var array
84
+	 */
85
+	protected $_metaboxes;
86
+
87
+
88
+	/**
89
+	 * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
+	 * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
+	 * array: array(
92
+	 *    0 => array(
93
+	 *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
+	 *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
+	 *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
+	 *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
+	 *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
+	 *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
+	 *        id for the screen the metabox is on.
100
+	 *    )
101
+	 * )
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_remove_metaboxes;
106
+
107
+
108
+	/**
109
+	 * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
+	 * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
+	 * second array index is for indicating what routes each script/style loads on. array(
112
+	 * 'registers' => array(
113
+	 *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
+	 *        argument to link scripts together.
115
+	 *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
+	 *            'url' => 'http://urltoscript.css.js',
117
+	 *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
+	 *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
+	 *            gets loaded before the one you are setting here.
120
+	 *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
+	 *        ),
122
+	 *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
+	 *    the script gets enqueued on.
124
+	 *        'script_ref' => array('route_one', 'route_two')
125
+	 *    ),
126
+	 *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
+	 *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
+	 *    the object.
129
+	 *        'scrip_ref' => array(
130
+	 *            'NAME_OF_JS_OBJECT' => array(
131
+	 *                'translate_ref' => __('localized_string', 'event_espresso'),
132
+	 *                'some_data' => 5
133
+	 *            )
134
+	 *        )
135
+	 *    )
136
+	 * )
137
+	 *
138
+	 * @var array
139
+	 */
140
+	protected $_scripts_styles;
141
+
142
+
143
+	/**
144
+	 * This is a property that will contain the current route.
145
+	 *
146
+	 * @var string;
147
+	 */
148
+	protected $_current_route;
149
+
150
+
151
+	/**
152
+	 * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
+	 * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
+	 *    'wp_hook_reference' => 1
155
+	 *    )
156
+	 * )
157
+	 *
158
+	 * @var array
159
+	 */
160
+	protected $_wp_action_filters_priority;
161
+
162
+
163
+	/**
164
+	 * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
+	 *
166
+	 * @var array
167
+	 */
168
+	protected $_req_data;
169
+
170
+
171
+	/**
172
+	 * This just holds an instance of the page object for this hook
173
+	 *
174
+	 * @var EE_Admin_Page
175
+	 */
176
+	protected $_page_object;
177
+
178
+
179
+	/**
180
+	 * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
+	 *
182
+	 * @var EE_Admin_Page|EE_Admin_Page_CPT
183
+	 */
184
+	protected $_adminpage_obj;
185
+
186
+
187
+	/**
188
+	 * Holds EE_Registry object
189
+	 *
190
+	 * @var EE_Registry
191
+	 */
192
+	protected $EE = null;
193
+
194
+
195
+	/**
196
+	 * constructor
197
+	 *
198
+	 * @param EE_Admin_Page $admin_page the calling admin_page_object
199
+	 */
200
+	public function __construct(EE_Admin_Page $adminpage)
201
+	{
202
+
203
+		$this->_adminpage_obj = $adminpage;
204
+		$this->_req_data = array_merge($_GET, $_POST);
205
+		$this->_set_defaults();
206
+		$this->_set_hooks_properties();
207
+		// first let's verify we're on the right page
208
+		if (! isset($this->_req_data['page'])
209
+			|| (isset($this->_req_data['page'])
210
+				&& $this->_adminpage_obj->page_slug
211
+				   != $this->_req_data['page'])) {
212
+			return;
213
+		} //get out nothing more to be done here.
214
+		// allow for extends to modify properties
215
+		if (method_exists($this, '_extend_properties')) {
216
+			$this->_extend_properties();
217
+		}
218
+		$this->_set_page_object();
219
+		$this->_init_hooks();
220
+		$this->_load_custom_methods();
221
+		$this->_load_routed_hooks();
222
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
223
+		add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
224
+		add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
225
+		$this->_ajax_hooks();
226
+	}
227
+
228
+
229
+	/**
230
+	 * used by child classes to set the following properties:
231
+	 * $_ajax_func (optional)
232
+	 * $_init_func (optional)
233
+	 * $_metaboxes (optional)
234
+	 * $_scripts (optional)
235
+	 * $_styles (optional)
236
+	 * $_name (required)
237
+	 * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
238
+	 * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
239
+	 * really early on page load (just after admin_init) if they want to have them registered for handling early.
240
+	 *
241
+	 * @access protected
242
+	 * @abstract
243
+	 * @return void
244
+	 */
245
+	abstract protected function _set_hooks_properties();
246
+
247
+
248
+	/**
249
+	 * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
250
+	 * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
251
+	 * registered the scripts and styles using wp_register_script and wp_register_style functions.
252
+	 *
253
+	 * @access public
254
+	 * @return void
255
+	 */
256
+	public function enqueue_scripts_styles()
257
+	{
258
+
259
+		if (! empty($this->_scripts_styles)) {
260
+			// first let's do all the registrations
261
+			if (! isset($this->_scripts_styles['registers'])) {
262
+				$msg[] = __(
263
+					'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
+					'event_espresso'
265
+				);
266
+				$msg[] = sprintf(
267
+					__(
268
+						'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
+						'event_espresso'
270
+					),
271
+					'<strong>' . $this->caller . '</strong>'
272
+				);
273
+				throw new EE_Error(implode('||', $msg));
274
+			}
275
+			foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
+				$defaults = array(
277
+					'type'    => 'js',
278
+					'url'     => '',
279
+					'depends' => array(),
280
+					'version' => EVENT_ESPRESSO_VERSION,
281
+					'footer'  => true,
282
+				);
283
+				$details = wp_parse_args($details, $defaults);
284
+				extract($details);
285
+				// let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
+				$this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
+				// let's make sure we're not missing any REQUIRED parameters
288
+				if (empty($url)) {
289
+					$msg[] = sprintf(
290
+						__('Missing the url for the requested %s', 'event_espresso'),
291
+						$type == 'js' ? 'script' : 'stylesheet'
292
+					);
293
+					$msg[] = sprintf(
294
+						__(
295
+							'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
+							'event_espresso'
297
+						),
298
+						'<strong>' . $this->caller . '</strong>',
299
+						$ref
300
+					);
301
+					throw new EE_Error(implode('||', $msg));
302
+				}
303
+				// made it here so let's do the appropriate registration
304
+				$type == 'js'
305
+					? wp_register_script($ref, $url, $depends, $version, $footer)
306
+					: wp_register_style(
307
+						$ref,
308
+						$url,
309
+						$depends,
310
+						$version
311
+					);
312
+			}
313
+			// k now lets do the enqueues
314
+			if (! isset($this->_scripts_styles['enqueues'])) {
315
+				return;
316
+			}  //not sure if we should throw an error here or not.
317
+
318
+			foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
+				// make sure $routes is an array
320
+				$routes = (array) $routes;
321
+				if (in_array($this->_current_route, $routes)) {
322
+					$this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
+						: wp_enqueue_style($ref);
324
+					// if we have a localization for the script let's do that too.
325
+					if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
+						foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
+							wp_localize_script(
328
+								$ref,
329
+								$object_name,
330
+								$this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
+							);
332
+						}
333
+					}
334
+				}
335
+			}
336
+			// let's do the deregisters
337
+			if (! isset($this->_scripts_styles['deregisters'])) {
338
+				return;
339
+			}
340
+			foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
+				$defaults = array(
342
+					'type' => 'js',
343
+				);
344
+				$details = wp_parse_args($details, $defaults);
345
+				extract($details);
346
+				$type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
+			}
348
+		}
349
+	}
350
+
351
+
352
+	/**
353
+	 * just set the defaults for the hooks properties.
354
+	 *
355
+	 * @access private
356
+	 * @return void
357
+	 */
358
+	private function _set_defaults()
359
+	{
360
+		$this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
+		$this->_current_route = $this->getCurrentRoute();
362
+		$this->caller = get_class($this);
363
+		$this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * A helper for determining the current route.
369
+	 * @return string
370
+	 */
371
+	private function getCurrentRoute()
372
+	{
373
+		// list tables do something else with 'action' for bulk actions.
374
+		$action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
+		// we set a 'route' variable in some cases where action is being used by something else.
376
+		$action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
+		return sanitize_key($action);
378
+	}
379
+
380
+
381
+	/**
382
+	 * this sets the _page_object property
383
+	 *
384
+	 * @access protected
385
+	 * @return void
386
+	 */
387
+	protected function _set_page_object()
388
+	{
389
+		// first make sure $this->_name is set
390
+		if (empty($this->_name)) {
391
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
392
+			$msg[] = sprintf(
393
+				__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
394
+				$this->caller
395
+			);
396
+			throw new EE_Error(implode('||', $msg));
397
+		}
398
+		$ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
+		$ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
400
+		// first default file (if exists)
401
+		$decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
402
+		if (is_readable($decaf_file)) {
403
+			require_once($decaf_file);
404
+		}
405
+		// now we have to do require for extended file (if needed)
406
+		if ($this->_extend) {
407
+			require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
408
+		}
409
+		// if we've got an extended class we use that!
410
+		$ref = $this->_extend ? 'Extend_' . $ref : $ref;
411
+		// let's make sure the class exists
412
+		if (! class_exists($ref)) {
413
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
414
+			$msg[] = sprintf(
415
+				__(
416
+					'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
417
+					'event_espresso'
418
+				),
419
+				$ref
420
+			);
421
+			throw new EE_Error(implode('||', $msg));
422
+		}
423
+		$a = new ReflectionClass($ref);
424
+		$this->_page_object = $a->newInstance(false);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
430
+	 * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
431
+	 * $this->_req_data (all the _POST and _GET data) is available to your methods.
432
+	 *
433
+	 * @access private
434
+	 * @return void
435
+	 */
436
+	private function _load_custom_methods()
437
+	{
438
+		/**
439
+		 * method cannot be named 'default' (@see http://us3.php
440
+		 * .net/manual/en/reserved.keywords.php) so need to
441
+		 * handle routes that are "default"
442
+		 *
443
+		 * @since 4.3.0
444
+		 */
445
+		$method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
446
+		// these run before the Admin_Page route executes.
447
+		if (method_exists($this, $method_callback)) {
448
+			call_user_func(array($this, $method_callback));
449
+		}
450
+		// these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
451
+		// first the actions
452
+		// note that these action hooks will have the $query_args value available.
453
+		$admin_class_name = get_class($this->_adminpage_obj);
454
+		if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
455
+			add_action(
456
+				'AHEE__'
457
+				. $admin_class_name
458
+				. '___redirect_after_action__before_redirect_modification_'
459
+				. $this->_current_route,
460
+				array($this, '_redirect_action_early_' . $this->_current_route),
461
+				10
462
+			);
463
+		}
464
+		if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
465
+			add_action(
466
+				'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
+				array($this, '_redirect_action_' . $this->_current_route),
468
+				10
469
+			);
470
+		}
471
+		// let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
+		if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
473
+			add_filter(
474
+				'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
+				array($this, '_redirect_filter_' . $this->_current_route),
476
+				10,
477
+				2
478
+			);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
485
+	 * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
486
+	 * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
487
+	 *
488
+	 * @return void
489
+	 */
490
+	private function _load_routed_hooks()
491
+	{
492
+
493
+		// this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
494
+		$hook_filter_array = array(
495
+			'admin_footer'                                                                            => array(
496
+				'type'     => 'action',
497
+				'argnum'   => 1,
498
+				'priority' => 10,
499
+			),
500
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
501
+				'type'     => 'filter',
502
+				'argnum'   => 1,
503
+				'priority' => 10,
504
+			),
505
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
506
+				'type'     => 'filter',
507
+				'argnum'   => 1,
508
+				'priority' => 10,
509
+			),
510
+			'FHEE_list_table_views'                                                                   => array(
511
+				'type'     => 'filter',
512
+				'argnum'   => 1,
513
+				'priority' => 10,
514
+			),
515
+			'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
516
+				'type'     => 'action',
517
+				'argnum'   => 1,
518
+				'priority' => 10,
519
+			),
520
+		);
521
+		foreach ($hook_filter_array as $hook => $args) {
522
+			if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
+				if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
+					$args['priority'] = $this->_wp_action_filters_priority[ $hook ];
525
+				}
526
+				if ($args['type'] == 'action') {
527
+					add_action(
528
+						$hook,
529
+						array($this, $this->_current_route . '_' . $hook),
530
+						$args['priority'],
531
+						$args['argnum']
532
+					);
533
+				} else {
534
+					add_filter(
535
+						$hook,
536
+						array($this, $this->_current_route . '_' . $hook),
537
+						$args['priority'],
538
+						$args['argnum']
539
+					);
540
+				}
541
+			}
542
+		}
543
+	}
544
+
545
+
546
+	/**
547
+	 * Loop throught the $_ajax_func array and add_actions for the array.
548
+	 *
549
+	 * @return void
550
+	 */
551
+	private function _ajax_hooks()
552
+	{
553
+
554
+		if (empty($this->_ajax_func)) {
555
+			return;
556
+		} //get out there's nothing to take care of.
557
+		foreach ($this->_ajax_func as $action => $method) {
558
+			// make sure method exists
559
+			if (! method_exists($this, $method)) {
560
+				$msg[] = __(
561
+					'There is no corresponding method for the hook labeled in the _ajax_func array',
562
+					'event_espresso'
563
+				) . '<br />';
564
+				$msg[] = sprintf(
565
+					__(
566
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
567
+						'event_espresso'
568
+					),
569
+					$method,
570
+					$this->caller
571
+				);
572
+				throw new EE_Error(implode('||', $msg));
573
+			}
574
+			add_action('wp_ajax_' . $action, array($this, $method));
575
+		}
576
+	}
577
+
578
+
579
+	/**
580
+	 * Loop throught the $_init_func array and add_actions for the array.
581
+	 *
582
+	 * @return void
583
+	 */
584
+	protected function _init_hooks()
585
+	{
586
+		if (empty($this->_init_func)) {
587
+			return;
588
+		} //get out there's nothing to take care of.
589
+		// We need to determine what page_route we are on!
590
+		$current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591
+		foreach ($this->_init_func as $route => $method) {
592
+			// make sure method exists
593
+			if (! method_exists($this, $method)) {
594
+				$msg[] = __(
595
+					'There is no corresponding method for the hook labeled in the _init_func array',
596
+					'event_espresso'
597
+				) . '<br />';
598
+				$msg[] = sprintf(
599
+					__(
600
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
601
+						'event_espresso'
602
+					),
603
+					$method,
604
+					$this->caller
605
+				);
606
+				throw new EE_Error(implode('||', $msg));
607
+			}
608
+			if ($route == $this->_current_route) {
609
+				add_action('admin_init', array($this, $method));
610
+			}
611
+		}
612
+	}
613
+
614
+
615
+	/**
616
+	 * Loop through the _metaboxes property and add_metaboxes accordingly
617
+	 * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
618
+	 *
619
+	 * @access public
620
+	 * @return void
621
+	 */
622
+	public function add_metaboxes()
623
+	{
624
+		if (empty($this->_metaboxes)) {
625
+			return;
626
+		} //get out we don't have any metaboxes to set for this connection
627
+		$this->_handle_metabox_array($this->_metaboxes);
628
+	}
629
+
630
+
631
+	private function _handle_metabox_array($boxes, $add = true)
632
+	{
633
+
634
+		foreach ($boxes as $box) {
635
+			if (! isset($box['page_route'])) {
636
+				continue;
637
+			} //we dont' have a valid array
638
+			// let's make sure $box['page_route'] is an array so the "foreach" will work.
639
+			$box['page_route'] = (array) $box['page_route'];
640
+			foreach ($box['page_route'] as $route) {
641
+				if ($route != $this->_current_route) {
642
+					continue;
643
+				} //get out we only add metaboxes for set route.
644
+				if ($add) {
645
+					$this->_add_metabox($box);
646
+				} else {
647
+					$this->_remove_metabox($box);
648
+				}
649
+			}
650
+		}
651
+	}
652
+
653
+
654
+	/**
655
+	 * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
656
+	 *
657
+	 * @access public
658
+	 * @return void
659
+	 */
660
+	public function remove_metaboxes()
661
+	{
662
+
663
+		if (empty($this->_remove_metaboxes)) {
664
+			return;
665
+		} //get out there are no metaboxes to remove
666
+		$this->_handle_metabox_array($this->_remove_metaboxes, false);
667
+	}
668
+
669
+
670
+	/**
671
+	 * This just handles adding a metabox
672
+	 *
673
+	 * @access private
674
+	 * @param array $args an array of args that have been set for this metabox by the child class
675
+	 */
676
+	private function _add_metabox($args)
677
+	{
678
+		$current_screen = get_current_screen();
679
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
680
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
681
+		// set defaults
682
+		$defaults = array(
683
+			'func'          => $func,
684
+			'id'            => $this->caller . '_' . $func . '_metabox',
685
+			'priority'      => 'default',
686
+			'label'         => $this->caller,
687
+			'context'       => 'advanced',
688
+			'callback_args' => array(),
689
+			'page'          => isset($args['page']) ? $args['page'] : $screen_id,
690
+		);
691
+		$args = wp_parse_args($args, $defaults);
692
+		extract($args);
693
+		// make sure method exists
694
+		if (! method_exists($this, $func)) {
695
+			$msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
696
+			$msg[] = sprintf(
697
+				__(
698
+					'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
699
+					'event_espresso'
700
+				),
701
+				$func,
702
+				$this->caller
703
+			);
704
+			throw new EE_Error(implode('||', $msg));
705
+		}
706
+		// everything checks out so lets add the metabox
707
+		add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
708
+	}
709
+
710
+
711
+	private function _remove_metabox($args)
712
+	{
713
+		$current_screen = get_current_screen();
714
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
715
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
716
+		// set defaults
717
+		$defaults = array(
718
+			'id'      => isset($args['id'])
719
+				? $args['id']
720
+				: $this->_current_route
721
+				  . '_'
722
+				  . $this->caller
723
+				  . '_'
724
+				  . $func
725
+				  . '_metabox',
726
+			'context' => 'default',
727
+			'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
728
+		);
729
+		$args = wp_parse_args($args, $defaults);
730
+		extract($args);
731
+		// everything checks out so lets remove the box!
732
+		remove_meta_box($id, $screen, $context);
733
+	}
734 734
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
         $this->_set_defaults();
206 206
         $this->_set_hooks_properties();
207 207
         // first let's verify we're on the right page
208
-        if (! isset($this->_req_data['page'])
208
+        if ( ! isset($this->_req_data['page'])
209 209
             || (isset($this->_req_data['page'])
210 210
                 && $this->_adminpage_obj->page_slug
211 211
                    != $this->_req_data['page'])) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
     public function enqueue_scripts_styles()
257 257
     {
258 258
 
259
-        if (! empty($this->_scripts_styles)) {
259
+        if ( ! empty($this->_scripts_styles)) {
260 260
             // first let's do all the registrations
261
-            if (! isset($this->_scripts_styles['registers'])) {
261
+            if ( ! isset($this->_scripts_styles['registers'])) {
262 262
                 $msg[] = __(
263 263
                     'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264 264
                     'event_espresso'
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
                         'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269 269
                         'event_espresso'
270 270
                     ),
271
-                    '<strong>' . $this->caller . '</strong>'
271
+                    '<strong>'.$this->caller.'</strong>'
272 272
                 );
273 273
                 throw new EE_Error(implode('||', $msg));
274 274
             }
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
                 $details = wp_parse_args($details, $defaults);
284 284
                 extract($details);
285 285
                 // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
286
+                $this->_scripts_styles['registers'][$ref]['type'] = $type;
287 287
                 // let's make sure we're not missing any REQUIRED parameters
288 288
                 if (empty($url)) {
289 289
                     $msg[] = sprintf(
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
                             'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296 296
                             'event_espresso'
297 297
                         ),
298
-                        '<strong>' . $this->caller . '</strong>',
298
+                        '<strong>'.$this->caller.'</strong>',
299 299
                         $ref
300 300
                     );
301 301
                     throw new EE_Error(implode('||', $msg));
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                     );
312 312
             }
313 313
             // k now lets do the enqueues
314
-            if (! isset($this->_scripts_styles['enqueues'])) {
314
+            if ( ! isset($this->_scripts_styles['enqueues'])) {
315 315
                 return;
316 316
             }  //not sure if we should throw an error here or not.
317 317
 
@@ -319,22 +319,22 @@  discard block
 block discarded – undo
319 319
                 // make sure $routes is an array
320 320
                 $routes = (array) $routes;
321 321
                 if (in_array($this->_current_route, $routes)) {
322
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
322
+                    $this->_scripts_styles['registers'][$ref]['type'] == 'js' ? wp_enqueue_script($ref)
323 323
                         : wp_enqueue_style($ref);
324 324
                     // if we have a localization for the script let's do that too.
325
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
325
+                    if (isset($this->_scripts_styles['localize'][$ref])) {
326
+                        foreach ($this->_scripts_styles['localize'][$ref] as $object_name => $indexes) {
327 327
                             wp_localize_script(
328 328
                                 $ref,
329 329
                                 $object_name,
330
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
330
+                                $this->_scripts_styles['localize'][$ref][$object_name]
331 331
                             );
332 332
                         }
333 333
                     }
334 334
                 }
335 335
             }
336 336
             // let's do the deregisters
337
-            if (! isset($this->_scripts_styles['deregisters'])) {
337
+            if ( ! isset($this->_scripts_styles['deregisters'])) {
338 338
                 return;
339 339
             }
340 340
             foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
@@ -396,20 +396,20 @@  discard block
 block discarded – undo
396 396
             throw new EE_Error(implode('||', $msg));
397 397
         }
398 398
         $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
399
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
399
+        $ref = str_replace(' ', '_', ucwords($ref)).'_Admin_Page'; // take the message -> The_Message
400 400
         // first default file (if exists)
401
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . DS . $ref . '.core.php';
401
+        $decaf_file = EE_ADMIN_PAGES.$this->_name.DS.$ref.'.core.php';
402 402
         if (is_readable($decaf_file)) {
403 403
             require_once($decaf_file);
404 404
         }
405 405
         // now we have to do require for extended file (if needed)
406 406
         if ($this->_extend) {
407
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . DS . 'Extend_' . $ref . '.core.php');
407
+            require_once(EE_CORE_CAF_ADMIN_EXTEND.$this->_name.DS.'Extend_'.$ref.'.core.php');
408 408
         }
409 409
         // if we've got an extended class we use that!
410
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
410
+        $ref = $this->_extend ? 'Extend_'.$ref : $ref;
411 411
         // let's make sure the class exists
412
-        if (! class_exists($ref)) {
412
+        if ( ! class_exists($ref)) {
413 413
             $msg[] = __('We can\'t load the page object', 'event_espresso');
414 414
             $msg[] = sprintf(
415 415
                 __(
@@ -451,28 +451,28 @@  discard block
 block discarded – undo
451 451
         // first the actions
452 452
         // note that these action hooks will have the $query_args value available.
453 453
         $admin_class_name = get_class($this->_adminpage_obj);
454
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
454
+        if (method_exists($this, '_redirect_action_early_'.$this->_current_route)) {
455 455
             add_action(
456 456
                 'AHEE__'
457 457
                 . $admin_class_name
458 458
                 . '___redirect_after_action__before_redirect_modification_'
459 459
                 . $this->_current_route,
460
-                array($this, '_redirect_action_early_' . $this->_current_route),
460
+                array($this, '_redirect_action_early_'.$this->_current_route),
461 461
                 10
462 462
             );
463 463
         }
464
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
464
+        if (method_exists($this, '_redirect_action_'.$this->_current_route)) {
465 465
             add_action(
466
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
467
-                array($this, '_redirect_action_' . $this->_current_route),
466
+                'AHEE_redirect_'.$admin_class_name.$this->_current_route,
467
+                array($this, '_redirect_action_'.$this->_current_route),
468 468
                 10
469 469
             );
470 470
         }
471 471
         // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
472
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
472
+        if (method_exists($this, '_redirect_filter_'.$this->_current_route)) {
473 473
             add_filter(
474
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
475
-                array($this, '_redirect_filter_' . $this->_current_route),
474
+                'FHEE_redirect_'.$admin_class_name.$this->_current_route,
475
+                array($this, '_redirect_filter_'.$this->_current_route),
476 476
                 10,
477 477
                 2
478 478
             );
@@ -497,12 +497,12 @@  discard block
 block discarded – undo
497 497
                 'argnum'   => 1,
498 498
                 'priority' => 10,
499 499
             ),
500
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
500
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug.'_'.$this->_current_route => array(
501 501
                 'type'     => 'filter',
502 502
                 'argnum'   => 1,
503 503
                 'priority' => 10,
504 504
             ),
505
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
505
+            'FHEE_list_table_views_'.$this->_adminpage_obj->page_slug                               => array(
506 506
                 'type'     => 'filter',
507 507
                 'argnum'   => 1,
508 508
                 'priority' => 10,
@@ -519,21 +519,21 @@  discard block
 block discarded – undo
519 519
             ),
520 520
         );
521 521
         foreach ($hook_filter_array as $hook => $args) {
522
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
523
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
524
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
522
+            if (method_exists($this, $this->_current_route.'_'.$hook)) {
523
+                if (isset($this->_wp_action_filters_priority[$hook])) {
524
+                    $args['priority'] = $this->_wp_action_filters_priority[$hook];
525 525
                 }
526 526
                 if ($args['type'] == 'action') {
527 527
                     add_action(
528 528
                         $hook,
529
-                        array($this, $this->_current_route . '_' . $hook),
529
+                        array($this, $this->_current_route.'_'.$hook),
530 530
                         $args['priority'],
531 531
                         $args['argnum']
532 532
                     );
533 533
                 } else {
534 534
                     add_filter(
535 535
                         $hook,
536
-                        array($this, $this->_current_route . '_' . $hook),
536
+                        array($this, $this->_current_route.'_'.$hook),
537 537
                         $args['priority'],
538 538
                         $args['argnum']
539 539
                     );
@@ -556,11 +556,11 @@  discard block
 block discarded – undo
556 556
         } //get out there's nothing to take care of.
557 557
         foreach ($this->_ajax_func as $action => $method) {
558 558
             // make sure method exists
559
-            if (! method_exists($this, $method)) {
559
+            if ( ! method_exists($this, $method)) {
560 560
                 $msg[] = __(
561 561
                     'There is no corresponding method for the hook labeled in the _ajax_func array',
562 562
                     'event_espresso'
563
-                ) . '<br />';
563
+                ).'<br />';
564 564
                 $msg[] = sprintf(
565 565
                     __(
566 566
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
                 );
572 572
                 throw new EE_Error(implode('||', $msg));
573 573
             }
574
-            add_action('wp_ajax_' . $action, array($this, $method));
574
+            add_action('wp_ajax_'.$action, array($this, $method));
575 575
         }
576 576
     }
577 577
 
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
         $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
591 591
         foreach ($this->_init_func as $route => $method) {
592 592
             // make sure method exists
593
-            if (! method_exists($this, $method)) {
593
+            if ( ! method_exists($this, $method)) {
594 594
                 $msg[] = __(
595 595
                     'There is no corresponding method for the hook labeled in the _init_func array',
596 596
                     'event_espresso'
597
-                ) . '<br />';
597
+                ).'<br />';
598 598
                 $msg[] = sprintf(
599 599
                     __(
600 600
                         'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
     {
633 633
 
634 634
         foreach ($boxes as $box) {
635
-            if (! isset($box['page_route'])) {
635
+            if ( ! isset($box['page_route'])) {
636 636
                 continue;
637 637
             } //we dont' have a valid array
638 638
             // let's make sure $box['page_route'] is an array so the "foreach" will work.
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         // set defaults
682 682
         $defaults = array(
683 683
             'func'          => $func,
684
-            'id'            => $this->caller . '_' . $func . '_metabox',
684
+            'id'            => $this->caller.'_'.$func.'_metabox',
685 685
             'priority'      => 'default',
686 686
             'label'         => $this->caller,
687 687
             'context'       => 'advanced',
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
         $args = wp_parse_args($args, $defaults);
692 692
         extract($args);
693 693
         // make sure method exists
694
-        if (! method_exists($this, $func)) {
695
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
694
+        if ( ! method_exists($this, $func)) {
695
+            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso').'<br />';
696 696
             $msg[] = sprintf(
697 697
                 __(
698 698
                     'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
Please login to merge, or discard this patch.
core/domain/Domain.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -16,66 +16,66 @@
 block discarded – undo
16 16
 class Domain extends DomainBase implements CaffeinatedInterface
17 17
 {
18 18
 
19
-    /**
20
-     * URL path component used to denote an API request
21
-     */
22
-    const API_NAMESPACE = 'ee/v';
19
+	/**
20
+	 * URL path component used to denote an API request
21
+	 */
22
+	const API_NAMESPACE = 'ee/v';
23 23
 
24
-    /**
25
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
26
-     * Page ui.
27
-     */
28
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
29
-        = 'manual_registration_status_change_from_registration_admin';
24
+	/**
25
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
26
+	 * Page ui.
27
+	 */
28
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
29
+		= 'manual_registration_status_change_from_registration_admin';
30 30
 
31
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
32
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
31
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
32
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
33 33
 
34 34
 
35
-    /**
36
-     * Whether or not EE core is the full premium version.
37
-     * @since 4.9.59.p
38
-     * @var bool
39
-     */
40
-    private $caffeinated;
35
+	/**
36
+	 * Whether or not EE core is the full premium version.
37
+	 * @since 4.9.59.p
38
+	 * @var bool
39
+	 */
40
+	private $caffeinated;
41 41
 
42 42
 
43
-    public function __construct(FilePath $plugin_file, Version $version)
44
-    {
45
-        parent::__construct($plugin_file, $version);
46
-        $this->setCaffeinated();
47
-    }
43
+	public function __construct(FilePath $plugin_file, Version $version)
44
+	{
45
+		parent::__construct($plugin_file, $version);
46
+		$this->setCaffeinated();
47
+	}
48 48
 
49
-    /**
50
-     * Whether or not EE core is the full premium version.
51
-     * @since 4.9.59.p
52
-     * @return bool
53
-     */
54
-    public function isCaffeinated()
55
-    {
56
-        return $this->caffeinated;
57
-    }
49
+	/**
50
+	 * Whether or not EE core is the full premium version.
51
+	 * @since 4.9.59.p
52
+	 * @return bool
53
+	 */
54
+	public function isCaffeinated()
55
+	{
56
+		return $this->caffeinated;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * Setter for $is_caffeinated property.
62
-     * @since 4.9.59.p
63
-     */
64
-    private function setCaffeinated()
65
-    {
66
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
67
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
68
-    }
60
+	/**
61
+	 * Setter for $is_caffeinated property.
62
+	 * @since 4.9.59.p
63
+	 */
64
+	private function setCaffeinated()
65
+	{
66
+		$this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
67
+			&& is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces
73
-     * to allow for filtering the brand.
74
-     *
75
-     * @return string
76
-     */
77
-    public static function brandName()
78
-    {
79
-        return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso');
80
-    }
71
+	/**
72
+	 * This should be used everywhere the Event Espresso brand name is referenced in public facing interfaces
73
+	 * to allow for filtering the brand.
74
+	 *
75
+	 * @return string
76
+	 */
77
+	public static function brandName()
78
+	{
79
+		return (string) apply_filters('FHEE__EventEspresso_core_domain_Domain__brandName', 'Event Espresso');
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,8 +63,8 @@
 block discarded – undo
63 63
      */
64 64
     private function setCaffeinated()
65 65
     {
66
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
67
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
66
+        $this->caffeinated = ( ! defined('EE_DECAF') || EE_DECAF !== true)
67
+            && is_readable($this->pluginPath().'caffeinated/brewing_regular.php');
68 68
     }
69 69
 
70 70
 
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Email_messenger.class.php 1 patch
Indentation   +644 added lines, -644 removed lines patch added patch discarded remove patch
@@ -6,648 +6,648 @@
 block discarded – undo
6 6
 class EE_Email_messenger extends EE_messenger
7 7
 {
8 8
 
9
-    /**
10
-     * To field for email
11
-     * @var string
12
-     */
13
-    protected $_to = '';
14
-
15
-
16
-    /**
17
-     * CC field for email.
18
-     * @var string
19
-     */
20
-    protected $_cc = '';
21
-
22
-    /**
23
-     * From field for email
24
-     * @var string
25
-     */
26
-    protected $_from = '';
27
-
28
-
29
-    /**
30
-     * Subject field for email
31
-     * @var string
32
-     */
33
-    protected $_subject = '';
34
-
35
-
36
-    /**
37
-     * Content field for email
38
-     * @var string
39
-     */
40
-    protected $_content = '';
41
-
42
-
43
-    /**
44
-     * constructor
45
-     *
46
-     * @access public
47
-     */
48
-    public function __construct()
49
-    {
50
-        // set name and description properties
51
-        $this->name                = 'email';
52
-        $this->description         = sprintf(
53
-            esc_html__(
54
-                'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
-                'event_espresso'
56
-            ),
57
-            '<code>wp_mail</code>'
58
-        );
59
-        $this->label               = array(
60
-            'singular' => esc_html__('email', 'event_espresso'),
61
-            'plural'   => esc_html__('emails', 'event_espresso'),
62
-        );
63
-        $this->activate_on_install = true;
64
-
65
-        // we're using defaults so let's call parent constructor that will take care of setting up all the other
66
-        // properties
67
-        parent::__construct();
68
-    }
69
-
70
-
71
-    /**
72
-     * see abstract declaration in parent class for details.
73
-     */
74
-    protected function _set_admin_pages()
75
-    {
76
-        $this->admin_registered_pages = array(
77
-            'events_edit' => true,
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * see abstract declaration in parent class for details
84
-     */
85
-    protected function _set_valid_shortcodes()
86
-    {
87
-        // remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
-        // message type.
89
-        $this->_valid_shortcodes = array(
90
-            'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
-            'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
-            'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
-        );
94
-    }
95
-
96
-
97
-    /**
98
-     * see abstract declaration in parent class for details
99
-     *
100
-     * @access protected
101
-     * @return void
102
-     */
103
-    protected function _set_validator_config()
104
-    {
105
-        $valid_shortcodes = $this->get_valid_shortcodes();
106
-
107
-        $this->_validator_config = array(
108
-            'to'            => array(
109
-                'shortcodes' => $valid_shortcodes['to'],
110
-                'type'       => 'email',
111
-            ),
112
-            'cc' => array(
113
-                'shortcodes' => $valid_shortcodes['to'],
114
-                'type' => 'email',
115
-            ),
116
-            'from'          => array(
117
-                'shortcodes' => $valid_shortcodes['from'],
118
-                'type'       => 'email',
119
-            ),
120
-            'subject'       => array(
121
-                'shortcodes' => array(
122
-                    'organization',
123
-                    'primary_registration_details',
124
-                    'event_author',
125
-                    'primary_registration_details',
126
-                    'recipient_details',
127
-                ),
128
-            ),
129
-            'content'       => array(
130
-                'shortcodes' => array(
131
-                    'event_list',
132
-                    'attendee_list',
133
-                    'ticket_list',
134
-                    'organization',
135
-                    'primary_registration_details',
136
-                    'primary_registration_list',
137
-                    'event_author',
138
-                    'recipient_details',
139
-                    'recipient_list',
140
-                    'transaction',
141
-                    'messenger',
142
-                ),
143
-            ),
144
-            'attendee_list' => array(
145
-                'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
-                'required'   => array('[ATTENDEE_LIST]'),
147
-            ),
148
-            'event_list'    => array(
149
-                'shortcodes' => array(
150
-                    'event',
151
-                    'attendee_list',
152
-                    'ticket_list',
153
-                    'venue',
154
-                    'datetime_list',
155
-                    'attendee',
156
-                    'primary_registration_details',
157
-                    'primary_registration_list',
158
-                    'event_author',
159
-                    'recipient_details',
160
-                    'recipient_list',
161
-                ),
162
-                'required'   => array('[EVENT_LIST]'),
163
-            ),
164
-            'ticket_list'   => array(
165
-                'shortcodes' => array(
166
-                    'event_list',
167
-                    'attendee_list',
168
-                    'ticket',
169
-                    'datetime_list',
170
-                    'primary_registration_details',
171
-                    'recipient_details',
172
-                ),
173
-                'required'   => array('[TICKET_LIST]'),
174
-            ),
175
-            'datetime_list' => array(
176
-                'shortcodes' => array('datetime'),
177
-                'required'   => array('[DATETIME_LIST]'),
178
-            ),
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * @see   parent EE_messenger class for docs
185
-     * @since 4.5.0
186
-     */
187
-    public function do_secondary_messenger_hooks($sending_messenger_name)
188
-    {
189
-        if ($sending_messenger_name === 'html') {
190
-            add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
-        }
192
-    }
193
-
194
-
195
-    public function add_email_css(
196
-        $variation_path,
197
-        $messenger,
198
-        $message_type,
199
-        $type,
200
-        $variation,
201
-        $file_extension,
202
-        $url,
203
-        EE_Messages_Template_Pack $template_pack
204
-    ) {
205
-        // prevent recursion on this callback.
206
-        remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
-        $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
-
209
-        add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
-        return $variation;
211
-    }
212
-
213
-
214
-    /**
215
-     * See parent for details
216
-     *
217
-     * @access protected
218
-     * @return void
219
-     */
220
-    protected function _set_test_settings_fields()
221
-    {
222
-        $this->_test_settings_fields = array(
223
-            'to'      => array(
224
-                'input'      => 'text',
225
-                'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
-                'type'       => 'email',
227
-                'required'   => true,
228
-                'validation' => true,
229
-                'css_class'  => 'large-text',
230
-                'format'     => '%s',
231
-                'default'    => get_bloginfo('admin_email'),
232
-            ),
233
-            'subject' => array(
234
-                'input'      => 'hidden',
235
-                'label'      => '',
236
-                'type'       => 'string',
237
-                'required'   => false,
238
-                'validation' => false,
239
-                'format'     => '%s',
240
-                'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
-                'default'    => '',
242
-                'css_class'  => '',
243
-            ),
244
-        );
245
-    }
246
-
247
-
248
-    /**
249
-     * _set_template_fields
250
-     * This sets up the fields that a messenger requires for the message to go out.
251
-     *
252
-     * @access  protected
253
-     * @return void
254
-     */
255
-    protected function _set_template_fields()
256
-    {
257
-        // any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
-        // shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
-        // they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
-        //  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
-        // kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
-        // indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
-        // displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
-        // will not be displayed/parsed.
265
-        $this->_template_fields = array(
266
-            'to'      => array(
267
-                'input'      => 'text',
268
-                'label'      => esc_html_x(
269
-                    'To',
270
-                    'Label for the "To" field for email addresses',
271
-                    'event_espresso'
272
-                ),
273
-                'type'       => 'string',
274
-                'required'   => true,
275
-                'validation' => true,
276
-                'css_class'  => 'large-text',
277
-                'format'     => '%s',
278
-            ),
279
-            'cc'      => array(
280
-                'input'      => 'text',
281
-                'label'      => esc_html_x(
282
-                    'CC',
283
-                    'Label for the "Carbon Copy" field used for additional email addresses',
284
-                    'event_espresso'
285
-                ),
286
-                'type'       => 'string',
287
-                'required'   => false,
288
-                'validation' => true,
289
-                'css_class'  => 'large-text',
290
-                'format'     => '%s',
291
-            ),
292
-            'from'    => array(
293
-                'input'      => 'text',
294
-                'label'      => esc_html_x(
295
-                    'From',
296
-                    'Label for the "From" field for email addresses.',
297
-                    'event_espresso'
298
-                ),
299
-                'type'       => 'string',
300
-                'required'   => true,
301
-                'validation' => true,
302
-                'css_class'  => 'large-text',
303
-                'format'     => '%s',
304
-            ),
305
-            'subject' => array(
306
-                'input'      => 'text',
307
-                'label'      => esc_html_x(
308
-                    'Subject',
309
-                    'Label for the "Subject" field (short description of contents) for emails.',
310
-                    'event_espresso'
311
-                ),
312
-                'type'       => 'string',
313
-                'required'   => true,
314
-                'validation' => true,
315
-                'css_class'  => 'large-text',
316
-                'format'     => '%s',
317
-            ),
318
-            'content' => '',
319
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
-            'extra'   => array(
321
-                'content' => array(
322
-                    'main'          => array(
323
-                        'input'      => 'wp_editor',
324
-                        'label'      => esc_html__('Main Content', 'event_espresso'),
325
-                        'type'       => 'string',
326
-                        'required'   => true,
327
-                        'validation' => true,
328
-                        'format'     => '%s',
329
-                        'rows'       => '15',
330
-                    ),
331
-                    'event_list'    => array(
332
-                        'input'               => 'wp_editor',
333
-                        'label'               => '[EVENT_LIST]',
334
-                        'type'                => 'string',
335
-                        'required'            => true,
336
-                        'validation'          => true,
337
-                        'format'              => '%s',
338
-                        'rows'                => '15',
339
-                        'shortcodes_required' => array('[EVENT_LIST]'),
340
-                    ),
341
-                    'attendee_list' => array(
342
-                        'input'               => 'textarea',
343
-                        'label'               => '[ATTENDEE_LIST]',
344
-                        'type'                => 'string',
345
-                        'required'            => true,
346
-                        'validation'          => true,
347
-                        'format'              => '%s',
348
-                        'css_class'           => 'large-text',
349
-                        'rows'                => '5',
350
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
-                    ),
352
-                    'ticket_list'   => array(
353
-                        'input'               => 'textarea',
354
-                        'label'               => '[TICKET_LIST]',
355
-                        'type'                => 'string',
356
-                        'required'            => true,
357
-                        'validation'          => true,
358
-                        'format'              => '%s',
359
-                        'css_class'           => 'large-text',
360
-                        'rows'                => '10',
361
-                        'shortcodes_required' => array('[TICKET_LIST]'),
362
-                    ),
363
-                    'datetime_list' => array(
364
-                        'input'               => 'textarea',
365
-                        'label'               => '[DATETIME_LIST]',
366
-                        'type'                => 'string',
367
-                        'required'            => true,
368
-                        'validation'          => true,
369
-                        'format'              => '%s',
370
-                        'css_class'           => 'large-text',
371
-                        'rows'                => '10',
372
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
373
-                    ),
374
-                ),
375
-            ),
376
-        );
377
-    }
378
-
379
-
380
-    /**
381
-     * See definition of this class in parent
382
-     */
383
-    protected function _set_default_message_types()
384
-    {
385
-        $this->_default_message_types = array(
386
-            'payment',
387
-            'payment_refund',
388
-            'registration',
389
-            'not_approved_registration',
390
-            'pending_approval',
391
-        );
392
-    }
393
-
394
-
395
-    /**
396
-     * @see   definition of this class in parent
397
-     * @since 4.5.0
398
-     */
399
-    protected function _set_valid_message_types()
400
-    {
401
-        $this->_valid_message_types = array(
402
-            'payment',
403
-            'registration',
404
-            'not_approved_registration',
405
-            'declined_registration',
406
-            'cancelled_registration',
407
-            'pending_approval',
408
-            'registration_summary',
409
-            'payment_reminder',
410
-            'payment_declined',
411
-            'payment_refund',
412
-        );
413
-    }
414
-
415
-
416
-    /**
417
-     * setting up admin_settings_fields for messenger.
418
-     */
419
-    protected function _set_admin_settings_fields()
420
-    {
421
-    }
422
-
423
-    /**
424
-     * We just deliver the messages don't kill us!!
425
-     *
426
-     * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
-     *              present.
428
-     * @throws EE_Error
429
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
-     */
431
-    protected function _send_message()
432
-    {
433
-        $success = wp_mail(
434
-            $this->_to,
435
-            // some old values for subject may be expecting HTML entities to be decoded in the subject
436
-            // and subjects aren't interpreted as HTML, so there should be no HTML in them
437
-            wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
-            $this->_body(),
439
-            $this->_headers()
440
-        );
441
-        if (! $success) {
442
-            EE_Error::add_error(
443
-                sprintf(
444
-                    esc_html__(
445
-                        'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
-                        'event_espresso'
447
-                    ),
448
-                    $this->_to,
449
-                    $this->_from,
450
-                    '<br />'
451
-                ),
452
-                __FILE__,
453
-                __FUNCTION__,
454
-                __LINE__
455
-            );
456
-        }
457
-        return $success;
458
-    }
459
-
460
-
461
-    /**
462
-     * see parent for definition
463
-     *
464
-     * @return string html body of the message content and the related css.
465
-     * @throws EE_Error
466
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
-     */
468
-    protected function _preview()
469
-    {
470
-        return $this->_body(true);
471
-    }
472
-
473
-
474
-    /**
475
-     * Setup headers for email
476
-     *
477
-     * @access protected
478
-     * @return string formatted header for email
479
-     */
480
-    protected function _headers()
481
-    {
482
-        $this->_ensure_has_from_email_address();
483
-        $from    = $this->_from;
484
-        $headers = array(
485
-            'From:' . $from,
486
-            'Reply-To:' . $from,
487
-            'Content-Type:text/html; charset=utf-8',
488
-        );
489
-
490
-        /**
491
-         * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
-         * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
-         * type which they are no longer able to change.
494
-         */
495
-        if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
-            $headers[] = 'cc: ' . $this->_cc;
497
-        }
498
-
499
-        // but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
-        // header.
501
-        add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
-        add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
-        return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
-    }
505
-
506
-
507
-    /**
508
-     * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
-     * address for the from address to avoid problems with sending emails.
510
-     */
511
-    protected function _ensure_has_from_email_address()
512
-    {
513
-        if (empty($this->_from)) {
514
-            $this->_from = get_bloginfo('admin_email');
515
-        }
516
-    }
517
-
518
-
519
-    /**
520
-     * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
-     * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
-     * be empty
523
-     *
524
-     * @since 4.3.1
525
-     * @return array
526
-     */
527
-    private function _parse_from()
528
-    {
529
-        if (strpos($this->_from, '<') !== false) {
530
-            $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
-            $from_name = str_replace('"', '', $from_name);
532
-            $from_name = trim($from_name);
533
-
534
-            $from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
-            $from_email = str_replace('>', '', $from_email);
536
-            $from_email = trim($from_email);
537
-        } elseif (trim($this->_from) !== '') {
538
-            $from_name  = '';
539
-            $from_email = trim($this->_from);
540
-        } else {
541
-            $from_name = $from_email = '';
542
-        }
543
-        return array($from_name, $from_email);
544
-    }
545
-
546
-
547
-    /**
548
-     * Callback for the wp_mail_from filter.
549
-     *
550
-     * @since 4.3.1
551
-     * @param string $from_email What the original from_email is.
552
-     * @return string
553
-     */
554
-    public function set_from_address($from_email)
555
-    {
556
-        $parsed_from = $this->_parse_from();
557
-        // includes fallback if the parsing failed.
558
-        $from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
-            ? $parsed_from[1]
560
-            : get_bloginfo('admin_email');
561
-        return $from_email;
562
-    }
563
-
564
-
565
-    /**
566
-     * Callback fro the wp_mail_from_name filter.
567
-     *
568
-     * @since 4.3.1
569
-     * @param string $from_name The original from_name.
570
-     * @return string
571
-     */
572
-    public function set_from_name($from_name)
573
-    {
574
-        $parsed_from = $this->_parse_from();
575
-        if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
-            $from_name = $parsed_from[0];
577
-        }
578
-
579
-        // if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
-        // but realize the default name is HTML entity-encoded
581
-        $from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
-
583
-        return $from_name;
584
-    }
585
-
586
-
587
-    /**
588
-     * setup body for email
589
-     *
590
-     * @param bool $preview will determine whether this is preview template or not.
591
-     * @return string formatted body for email.
592
-     * @throws EE_Error
593
-     * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
-     */
595
-    protected function _body($preview = false)
596
-    {
597
-        // setup template args!
598
-        $this->_template_args = array(
599
-            'subject'   => $this->_subject,
600
-            'from'      => $this->_from,
601
-            'main_body' => wpautop($this->_content),
602
-        );
603
-        $body                 = $this->_get_main_template($preview);
604
-
605
-        /**
606
-         * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
-         *
608
-         * @type    bool $preview Indicates whether a preview is being generated or not.
609
-         * @return  bool    true  indicates to use the inliner, false bypasses it.
610
-         */
611
-        if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
-            // require CssToInlineStyles library and its dependencies via composer autoloader
613
-            require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
-
615
-            // now if this isn't a preview, let's setup the body so it has inline styles
616
-            if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
-                $style = file_get_contents(
618
-                    $this->get_variation(
619
-                        $this->_tmp_pack,
620
-                        $this->_incoming_message_type->name,
621
-                        false,
622
-                        'main',
623
-                        $this->_variation
624
-                    ),
625
-                    true
626
-                );
627
-                $CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
-                // for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
-                $body  = ltrim($CSS->convert(true), ">\n");
630
-                // see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
-                $body  = ltrim($body, "<?");
632
-            }
633
-        }
634
-        return $body;
635
-    }
636
-
637
-
638
-    /**
639
-     * This just returns any existing test settings that might be saved in the database
640
-     *
641
-     * @access public
642
-     * @return array
643
-     */
644
-    public function get_existing_test_settings()
645
-    {
646
-        $settings = parent::get_existing_test_settings();
647
-        // override subject if present because we always want it to be fresh.
648
-        if (is_array($settings) && ! empty($settings['subject'])) {
649
-            $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
-        }
651
-        return $settings;
652
-    }
9
+	/**
10
+	 * To field for email
11
+	 * @var string
12
+	 */
13
+	protected $_to = '';
14
+
15
+
16
+	/**
17
+	 * CC field for email.
18
+	 * @var string
19
+	 */
20
+	protected $_cc = '';
21
+
22
+	/**
23
+	 * From field for email
24
+	 * @var string
25
+	 */
26
+	protected $_from = '';
27
+
28
+
29
+	/**
30
+	 * Subject field for email
31
+	 * @var string
32
+	 */
33
+	protected $_subject = '';
34
+
35
+
36
+	/**
37
+	 * Content field for email
38
+	 * @var string
39
+	 */
40
+	protected $_content = '';
41
+
42
+
43
+	/**
44
+	 * constructor
45
+	 *
46
+	 * @access public
47
+	 */
48
+	public function __construct()
49
+	{
50
+		// set name and description properties
51
+		$this->name                = 'email';
52
+		$this->description         = sprintf(
53
+			esc_html__(
54
+				'This messenger delivers messages via email using the built-in %s function included with WordPress',
55
+				'event_espresso'
56
+			),
57
+			'<code>wp_mail</code>'
58
+		);
59
+		$this->label               = array(
60
+			'singular' => esc_html__('email', 'event_espresso'),
61
+			'plural'   => esc_html__('emails', 'event_espresso'),
62
+		);
63
+		$this->activate_on_install = true;
64
+
65
+		// we're using defaults so let's call parent constructor that will take care of setting up all the other
66
+		// properties
67
+		parent::__construct();
68
+	}
69
+
70
+
71
+	/**
72
+	 * see abstract declaration in parent class for details.
73
+	 */
74
+	protected function _set_admin_pages()
75
+	{
76
+		$this->admin_registered_pages = array(
77
+			'events_edit' => true,
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * see abstract declaration in parent class for details
84
+	 */
85
+	protected function _set_valid_shortcodes()
86
+	{
87
+		// remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the
88
+		// message type.
89
+		$this->_valid_shortcodes = array(
90
+			'to'   => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
91
+			'cc' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
92
+			'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'),
93
+		);
94
+	}
95
+
96
+
97
+	/**
98
+	 * see abstract declaration in parent class for details
99
+	 *
100
+	 * @access protected
101
+	 * @return void
102
+	 */
103
+	protected function _set_validator_config()
104
+	{
105
+		$valid_shortcodes = $this->get_valid_shortcodes();
106
+
107
+		$this->_validator_config = array(
108
+			'to'            => array(
109
+				'shortcodes' => $valid_shortcodes['to'],
110
+				'type'       => 'email',
111
+			),
112
+			'cc' => array(
113
+				'shortcodes' => $valid_shortcodes['to'],
114
+				'type' => 'email',
115
+			),
116
+			'from'          => array(
117
+				'shortcodes' => $valid_shortcodes['from'],
118
+				'type'       => 'email',
119
+			),
120
+			'subject'       => array(
121
+				'shortcodes' => array(
122
+					'organization',
123
+					'primary_registration_details',
124
+					'event_author',
125
+					'primary_registration_details',
126
+					'recipient_details',
127
+				),
128
+			),
129
+			'content'       => array(
130
+				'shortcodes' => array(
131
+					'event_list',
132
+					'attendee_list',
133
+					'ticket_list',
134
+					'organization',
135
+					'primary_registration_details',
136
+					'primary_registration_list',
137
+					'event_author',
138
+					'recipient_details',
139
+					'recipient_list',
140
+					'transaction',
141
+					'messenger',
142
+				),
143
+			),
144
+			'attendee_list' => array(
145
+				'shortcodes' => array('attendee', 'event_list', 'ticket_list'),
146
+				'required'   => array('[ATTENDEE_LIST]'),
147
+			),
148
+			'event_list'    => array(
149
+				'shortcodes' => array(
150
+					'event',
151
+					'attendee_list',
152
+					'ticket_list',
153
+					'venue',
154
+					'datetime_list',
155
+					'attendee',
156
+					'primary_registration_details',
157
+					'primary_registration_list',
158
+					'event_author',
159
+					'recipient_details',
160
+					'recipient_list',
161
+				),
162
+				'required'   => array('[EVENT_LIST]'),
163
+			),
164
+			'ticket_list'   => array(
165
+				'shortcodes' => array(
166
+					'event_list',
167
+					'attendee_list',
168
+					'ticket',
169
+					'datetime_list',
170
+					'primary_registration_details',
171
+					'recipient_details',
172
+				),
173
+				'required'   => array('[TICKET_LIST]'),
174
+			),
175
+			'datetime_list' => array(
176
+				'shortcodes' => array('datetime'),
177
+				'required'   => array('[DATETIME_LIST]'),
178
+			),
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * @see   parent EE_messenger class for docs
185
+	 * @since 4.5.0
186
+	 */
187
+	public function do_secondary_messenger_hooks($sending_messenger_name)
188
+	{
189
+		if ($sending_messenger_name === 'html') {
190
+			add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
191
+		}
192
+	}
193
+
194
+
195
+	public function add_email_css(
196
+		$variation_path,
197
+		$messenger,
198
+		$message_type,
199
+		$type,
200
+		$variation,
201
+		$file_extension,
202
+		$url,
203
+		EE_Messages_Template_Pack $template_pack
204
+	) {
205
+		// prevent recursion on this callback.
206
+		remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10);
207
+		$variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false);
208
+
209
+		add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8);
210
+		return $variation;
211
+	}
212
+
213
+
214
+	/**
215
+	 * See parent for details
216
+	 *
217
+	 * @access protected
218
+	 * @return void
219
+	 */
220
+	protected function _set_test_settings_fields()
221
+	{
222
+		$this->_test_settings_fields = array(
223
+			'to'      => array(
224
+				'input'      => 'text',
225
+				'label'      => esc_html__('Send a test email to', 'event_espresso'),
226
+				'type'       => 'email',
227
+				'required'   => true,
228
+				'validation' => true,
229
+				'css_class'  => 'large-text',
230
+				'format'     => '%s',
231
+				'default'    => get_bloginfo('admin_email'),
232
+			),
233
+			'subject' => array(
234
+				'input'      => 'hidden',
235
+				'label'      => '',
236
+				'type'       => 'string',
237
+				'required'   => false,
238
+				'validation' => false,
239
+				'format'     => '%s',
240
+				'value'      => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')),
241
+				'default'    => '',
242
+				'css_class'  => '',
243
+			),
244
+		);
245
+	}
246
+
247
+
248
+	/**
249
+	 * _set_template_fields
250
+	 * This sets up the fields that a messenger requires for the message to go out.
251
+	 *
252
+	 * @access  protected
253
+	 * @return void
254
+	 */
255
+	protected function _set_template_fields()
256
+	{
257
+		// any extra template fields that are NOT used by the messenger but will get used by a messenger field for
258
+		// shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field
259
+		// they relate to.  This is important for the Messages_admin to know what fields to display to the user.
260
+		//  Also, notice that the "values" are equal to the field type that messages admin will use to know what
261
+		// kind of field to display. The values ALSO have one index labeled "shortcode".  the values in that array
262
+		// indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be
263
+		// displayed.  If the required shortcode isn't part of the shortcodes array then the field is not needed and
264
+		// will not be displayed/parsed.
265
+		$this->_template_fields = array(
266
+			'to'      => array(
267
+				'input'      => 'text',
268
+				'label'      => esc_html_x(
269
+					'To',
270
+					'Label for the "To" field for email addresses',
271
+					'event_espresso'
272
+				),
273
+				'type'       => 'string',
274
+				'required'   => true,
275
+				'validation' => true,
276
+				'css_class'  => 'large-text',
277
+				'format'     => '%s',
278
+			),
279
+			'cc'      => array(
280
+				'input'      => 'text',
281
+				'label'      => esc_html_x(
282
+					'CC',
283
+					'Label for the "Carbon Copy" field used for additional email addresses',
284
+					'event_espresso'
285
+				),
286
+				'type'       => 'string',
287
+				'required'   => false,
288
+				'validation' => true,
289
+				'css_class'  => 'large-text',
290
+				'format'     => '%s',
291
+			),
292
+			'from'    => array(
293
+				'input'      => 'text',
294
+				'label'      => esc_html_x(
295
+					'From',
296
+					'Label for the "From" field for email addresses.',
297
+					'event_espresso'
298
+				),
299
+				'type'       => 'string',
300
+				'required'   => true,
301
+				'validation' => true,
302
+				'css_class'  => 'large-text',
303
+				'format'     => '%s',
304
+			),
305
+			'subject' => array(
306
+				'input'      => 'text',
307
+				'label'      => esc_html_x(
308
+					'Subject',
309
+					'Label for the "Subject" field (short description of contents) for emails.',
310
+					'event_espresso'
311
+				),
312
+				'type'       => 'string',
313
+				'required'   => true,
314
+				'validation' => true,
315
+				'css_class'  => 'large-text',
316
+				'format'     => '%s',
317
+			),
318
+			'content' => '',
319
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
320
+			'extra'   => array(
321
+				'content' => array(
322
+					'main'          => array(
323
+						'input'      => 'wp_editor',
324
+						'label'      => esc_html__('Main Content', 'event_espresso'),
325
+						'type'       => 'string',
326
+						'required'   => true,
327
+						'validation' => true,
328
+						'format'     => '%s',
329
+						'rows'       => '15',
330
+					),
331
+					'event_list'    => array(
332
+						'input'               => 'wp_editor',
333
+						'label'               => '[EVENT_LIST]',
334
+						'type'                => 'string',
335
+						'required'            => true,
336
+						'validation'          => true,
337
+						'format'              => '%s',
338
+						'rows'                => '15',
339
+						'shortcodes_required' => array('[EVENT_LIST]'),
340
+					),
341
+					'attendee_list' => array(
342
+						'input'               => 'textarea',
343
+						'label'               => '[ATTENDEE_LIST]',
344
+						'type'                => 'string',
345
+						'required'            => true,
346
+						'validation'          => true,
347
+						'format'              => '%s',
348
+						'css_class'           => 'large-text',
349
+						'rows'                => '5',
350
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
351
+					),
352
+					'ticket_list'   => array(
353
+						'input'               => 'textarea',
354
+						'label'               => '[TICKET_LIST]',
355
+						'type'                => 'string',
356
+						'required'            => true,
357
+						'validation'          => true,
358
+						'format'              => '%s',
359
+						'css_class'           => 'large-text',
360
+						'rows'                => '10',
361
+						'shortcodes_required' => array('[TICKET_LIST]'),
362
+					),
363
+					'datetime_list' => array(
364
+						'input'               => 'textarea',
365
+						'label'               => '[DATETIME_LIST]',
366
+						'type'                => 'string',
367
+						'required'            => true,
368
+						'validation'          => true,
369
+						'format'              => '%s',
370
+						'css_class'           => 'large-text',
371
+						'rows'                => '10',
372
+						'shortcodes_required' => array('[DATETIME_LIST]'),
373
+					),
374
+				),
375
+			),
376
+		);
377
+	}
378
+
379
+
380
+	/**
381
+	 * See definition of this class in parent
382
+	 */
383
+	protected function _set_default_message_types()
384
+	{
385
+		$this->_default_message_types = array(
386
+			'payment',
387
+			'payment_refund',
388
+			'registration',
389
+			'not_approved_registration',
390
+			'pending_approval',
391
+		);
392
+	}
393
+
394
+
395
+	/**
396
+	 * @see   definition of this class in parent
397
+	 * @since 4.5.0
398
+	 */
399
+	protected function _set_valid_message_types()
400
+	{
401
+		$this->_valid_message_types = array(
402
+			'payment',
403
+			'registration',
404
+			'not_approved_registration',
405
+			'declined_registration',
406
+			'cancelled_registration',
407
+			'pending_approval',
408
+			'registration_summary',
409
+			'payment_reminder',
410
+			'payment_declined',
411
+			'payment_refund',
412
+		);
413
+	}
414
+
415
+
416
+	/**
417
+	 * setting up admin_settings_fields for messenger.
418
+	 */
419
+	protected function _set_admin_settings_fields()
420
+	{
421
+	}
422
+
423
+	/**
424
+	 * We just deliver the messages don't kill us!!
425
+	 *
426
+	 * @return bool|WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if
427
+	 *              present.
428
+	 * @throws EE_Error
429
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
430
+	 */
431
+	protected function _send_message()
432
+	{
433
+		$success = wp_mail(
434
+			$this->_to,
435
+			// some old values for subject may be expecting HTML entities to be decoded in the subject
436
+			// and subjects aren't interpreted as HTML, so there should be no HTML in them
437
+			wp_strip_all_tags(wp_specialchars_decode($this->_subject, ENT_QUOTES)),
438
+			$this->_body(),
439
+			$this->_headers()
440
+		);
441
+		if (! $success) {
442
+			EE_Error::add_error(
443
+				sprintf(
444
+					esc_html__(
445
+						'The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s',
446
+						'event_espresso'
447
+					),
448
+					$this->_to,
449
+					$this->_from,
450
+					'<br />'
451
+				),
452
+				__FILE__,
453
+				__FUNCTION__,
454
+				__LINE__
455
+			);
456
+		}
457
+		return $success;
458
+	}
459
+
460
+
461
+	/**
462
+	 * see parent for definition
463
+	 *
464
+	 * @return string html body of the message content and the related css.
465
+	 * @throws EE_Error
466
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
467
+	 */
468
+	protected function _preview()
469
+	{
470
+		return $this->_body(true);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Setup headers for email
476
+	 *
477
+	 * @access protected
478
+	 * @return string formatted header for email
479
+	 */
480
+	protected function _headers()
481
+	{
482
+		$this->_ensure_has_from_email_address();
483
+		$from    = $this->_from;
484
+		$headers = array(
485
+			'From:' . $from,
486
+			'Reply-To:' . $from,
487
+			'Content-Type:text/html; charset=utf-8',
488
+		);
489
+
490
+		/**
491
+		 * Second condition added as a result of https://events.codebasehq.com/projects/event-espresso/tickets/11416 to
492
+		 * cover back compat where there may be users who have saved cc values in their db for the newsletter message
493
+		 * type which they are no longer able to change.
494
+		 */
495
+		if (! empty($this->_cc) && ! $this->_incoming_message_type instanceof EE_Newsletter_message_type) {
496
+			$headers[] = 'cc: ' . $this->_cc;
497
+		}
498
+
499
+		// but wait!  Header's for the from is NOT reliable because some plugins don't respect From: as set in the
500
+		// header.
501
+		add_filter('wp_mail_from', array($this, 'set_from_address'), 100);
502
+		add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100);
503
+		return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this);
504
+	}
505
+
506
+
507
+	/**
508
+	 * This simply ensures that the from address is not empty.  If it is, then we use whatever is set as the site email
509
+	 * address for the from address to avoid problems with sending emails.
510
+	 */
511
+	protected function _ensure_has_from_email_address()
512
+	{
513
+		if (empty($this->_from)) {
514
+			$this->_from = get_bloginfo('admin_email');
515
+		}
516
+	}
517
+
518
+
519
+	/**
520
+	 * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}>
521
+	 * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY*
522
+	 * be empty
523
+	 *
524
+	 * @since 4.3.1
525
+	 * @return array
526
+	 */
527
+	private function _parse_from()
528
+	{
529
+		if (strpos($this->_from, '<') !== false) {
530
+			$from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1);
531
+			$from_name = str_replace('"', '', $from_name);
532
+			$from_name = trim($from_name);
533
+
534
+			$from_email = substr($this->_from, strpos($this->_from, '<') + 1);
535
+			$from_email = str_replace('>', '', $from_email);
536
+			$from_email = trim($from_email);
537
+		} elseif (trim($this->_from) !== '') {
538
+			$from_name  = '';
539
+			$from_email = trim($this->_from);
540
+		} else {
541
+			$from_name = $from_email = '';
542
+		}
543
+		return array($from_name, $from_email);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Callback for the wp_mail_from filter.
549
+	 *
550
+	 * @since 4.3.1
551
+	 * @param string $from_email What the original from_email is.
552
+	 * @return string
553
+	 */
554
+	public function set_from_address($from_email)
555
+	{
556
+		$parsed_from = $this->_parse_from();
557
+		// includes fallback if the parsing failed.
558
+		$from_email = is_array($parsed_from) && ! empty($parsed_from[1])
559
+			? $parsed_from[1]
560
+			: get_bloginfo('admin_email');
561
+		return $from_email;
562
+	}
563
+
564
+
565
+	/**
566
+	 * Callback fro the wp_mail_from_name filter.
567
+	 *
568
+	 * @since 4.3.1
569
+	 * @param string $from_name The original from_name.
570
+	 * @return string
571
+	 */
572
+	public function set_from_name($from_name)
573
+	{
574
+		$parsed_from = $this->_parse_from();
575
+		if (is_array($parsed_from) && ! empty($parsed_from[0])) {
576
+			$from_name = $parsed_from[0];
577
+		}
578
+
579
+		// if from name is "WordPress" let's sub in the site name instead (more friendly!)
580
+		// but realize the default name is HTML entity-encoded
581
+		$from_name = $from_name == 'WordPress' ? wp_specialchars_decode(get_bloginfo(), ENT_QUOTES) : $from_name;
582
+
583
+		return $from_name;
584
+	}
585
+
586
+
587
+	/**
588
+	 * setup body for email
589
+	 *
590
+	 * @param bool $preview will determine whether this is preview template or not.
591
+	 * @return string formatted body for email.
592
+	 * @throws EE_Error
593
+	 * @throws \TijsVerkoyen\CssToInlineStyles\Exception
594
+	 */
595
+	protected function _body($preview = false)
596
+	{
597
+		// setup template args!
598
+		$this->_template_args = array(
599
+			'subject'   => $this->_subject,
600
+			'from'      => $this->_from,
601
+			'main_body' => wpautop($this->_content),
602
+		);
603
+		$body                 = $this->_get_main_template($preview);
604
+
605
+		/**
606
+		 * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched.
607
+		 *
608
+		 * @type    bool $preview Indicates whether a preview is being generated or not.
609
+		 * @return  bool    true  indicates to use the inliner, false bypasses it.
610
+		 */
611
+		if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) {
612
+			// require CssToInlineStyles library and its dependencies via composer autoloader
613
+			require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php';
614
+
615
+			// now if this isn't a preview, let's setup the body so it has inline styles
616
+			if (! $preview || ($preview && defined('DOING_AJAX'))) {
617
+				$style = file_get_contents(
618
+					$this->get_variation(
619
+						$this->_tmp_pack,
620
+						$this->_incoming_message_type->name,
621
+						false,
622
+						'main',
623
+						$this->_variation
624
+					),
625
+					true
626
+				);
627
+				$CSS   = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style);
628
+				// for some reason the library has a bracket and new line at the beginning.  This takes care of that.
629
+				$body  = ltrim($CSS->convert(true), ">\n");
630
+				// see https://events.codebasehq.com/projects/event-espresso/tickets/8609
631
+				$body  = ltrim($body, "<?");
632
+			}
633
+		}
634
+		return $body;
635
+	}
636
+
637
+
638
+	/**
639
+	 * This just returns any existing test settings that might be saved in the database
640
+	 *
641
+	 * @access public
642
+	 * @return array
643
+	 */
644
+	public function get_existing_test_settings()
645
+	{
646
+		$settings = parent::get_existing_test_settings();
647
+		// override subject if present because we always want it to be fresh.
648
+		if (is_array($settings) && ! empty($settings['subject'])) {
649
+			$settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name'));
650
+		}
651
+		return $settings;
652
+	}
653 653
 }
Please login to merge, or discard this patch.
core/libraries/messages/messenger/EE_Html_messenger.class.php 1 patch
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -12,548 +12,548 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The following are the properties that this messenger requires for displaying the html
17
-     */
18
-    /**
19
-     * This is the html body generated by the template via the message type.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $_content;
24
-
25
-
26
-    /**
27
-     * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
-     * equivalent to the "subject" of the page.
29
-     *
30
-     * @var string
31
-     */
32
-    protected $_subject;
33
-
34
-
35
-    /**
36
-     * EE_Html_messenger constructor.
37
-     */
38
-    public function __construct()
39
-    {
40
-        // set properties
41
-        $this->name = 'html';
42
-        $this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
-        $this->label = array(
44
-            'singular' => __('html', 'event_espresso'),
45
-            'plural' => __('html', 'event_espresso'),
46
-        );
47
-        $this->activate_on_install = true;
48
-        // add the "powered by EE" credit link to the HTML receipt and invoice
49
-        add_filter(
50
-            'FHEE__EE_Html_messenger___send_message__main_body',
51
-            array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
-            10,
53
-            3
54
-        );
55
-        parent::__construct();
56
-    }
57
-
58
-
59
-    /**
60
-     * HTML Messenger desires execution immediately.
61
-     *
62
-     * @see    parent::send_now() for documentation.
63
-     * @since  4.9.0
64
-     * @return bool
65
-     */
66
-    public function send_now()
67
-    {
68
-        return true;
69
-    }
70
-
71
-
72
-    /**
73
-     * HTML Messenger allows an empty to field.
74
-     *
75
-     * @see    parent::allow_empty_to_field() for documentation
76
-     * @since  4.9.0
77
-     * @return bool
78
-     */
79
-    public function allow_empty_to_field()
80
-    {
81
-        return true;
82
-    }
83
-
84
-
85
-    /**
86
-     * @see abstract declaration in EE_messenger for details.
87
-     */
88
-    protected function _set_admin_pages()
89
-    {
90
-        $this->admin_registered_pages = array('events_edit' => true);
91
-    }
92
-
93
-
94
-    /**
95
-     * @see abstract declaration in EE_messenger for details.
96
-     */
97
-    protected function _set_valid_shortcodes()
98
-    {
99
-        $this->_valid_shortcodes = array();
100
-    }
101
-
102
-
103
-    /**
104
-     * @see abstract declaration in EE_messenger for details.
105
-     */
106
-    protected function _set_validator_config()
107
-    {
108
-        $this->_validator_config = array(
109
-            'subject' => array(
110
-                'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
-            ),
112
-            'content' => array(
113
-                'shortcodes' => array(
114
-                    'organization',
115
-                    'primary_registration_list',
116
-                    'primary_registration_details',
117
-                    'email',
118
-                    'transaction',
119
-                    'event_list',
120
-                    'payment_list',
121
-                    'venue',
122
-                    'line_item_list',
123
-                    'messenger',
124
-                    'ticket_list',
125
-                ),
126
-            ),
127
-            'event_list' => array(
128
-                'shortcodes' => array(
129
-                    'event',
130
-                    'ticket_list',
131
-                    'venue',
132
-                    'primary_registration_details',
133
-                    'primary_registration_list',
134
-                    'event_author',
135
-                ),
136
-                'required' => array('[EVENT_LIST]'),
137
-            ),
138
-            'ticket_list' => array(
139
-                'shortcodes' => array(
140
-                    'attendee_list',
141
-                    'ticket',
142
-                    'datetime_list',
143
-                    'primary_registration_details',
144
-                    'line_item_list',
145
-                    'venue',
146
-                ),
147
-                'required' => array('[TICKET_LIST]'),
148
-            ),
149
-            'ticket_line_item_no_pms' => array(
150
-                'shortcodes' => array('line_item', 'ticket'),
151
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
-            ),
153
-            'ticket_line_item_pms' => array(
154
-                'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
-                'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
-            ),
157
-            'price_modifier_line_item_list' => array(
158
-                'shortcodes' => array('line_item'),
159
-                'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
-            ),
161
-            'datetime_list' => array(
162
-                'shortcodes' => array('datetime'),
163
-                'required' => array('[DATETIME_LIST]'),
164
-            ),
165
-            'attendee_list' => array(
166
-                'shortcodes' => array('attendee'),
167
-                'required' => array('[ATTENDEE_LIST]'),
168
-            ),
169
-            'tax_line_item_list' => array(
170
-                'shortcodes' => array('line_item'),
171
-                'required' => array('[TAX_LINE_ITEM_LIST]'),
172
-            ),
173
-            'additional_line_item_list' => array(
174
-                'shortcodes' => array('line_item'),
175
-                'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
-            ),
177
-            'payment_list' => array(
178
-                'shortcodes' => array('payment'),
179
-                'required' => array('[PAYMENT_LIST_*]'),
180
-            ),
181
-        );
182
-    }
183
-
184
-
185
-    /**
186
-     * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
-     * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
-     * (i.e. swap out css files or something else).
189
-     *
190
-     * @since 4.5.0
191
-     * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
-     * @return void
193
-     */
194
-    public function do_secondary_messenger_hooks($sending_messenger_name)
195
-    {
196
-        if ($sending_messenger_name === 'pdf') {
197
-            add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * @param                            $variation_path
204
-     * @param \EE_Messages_Template_Pack $template_pack
205
-     * @param                            $messenger_name
206
-     * @param                            $message_type_name
207
-     * @param                            $url
208
-     * @param                            $type
209
-     * @param                            $variation
210
-     * @param                            $skip_filters
211
-     * @return string
212
-     */
213
-    public function add_html_css(
214
-        $variation_path,
215
-        EE_Messages_Template_Pack $template_pack,
216
-        $messenger_name,
217
-        $message_type_name,
218
-        $url,
219
-        $type,
220
-        $variation,
221
-        $skip_filters
222
-    ) {
223
-        $variation = $template_pack->get_variation(
224
-            $this->name,
225
-            $message_type_name,
226
-            $type,
227
-            $variation,
228
-            $url,
229
-            '.css',
230
-            $skip_filters
231
-        );
232
-        return $variation;
233
-    }
234
-
235
-
236
-    /**
237
-     * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
-     * messenger can add their own js.
239
-     *
240
-     * @return void.
241
-     */
242
-    public function enqueue_scripts_styles()
243
-    {
244
-        parent::enqueue_scripts_styles();
245
-        do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
-    }
247
-
248
-
249
-    /**
250
-     * _set_template_fields
251
-     * This sets up the fields that a messenger requires for the message to go out.
252
-     *
253
-     * @access  protected
254
-     * @return void
255
-     */
256
-    protected function _set_template_fields()
257
-    {
258
-        // any extra template fields that are NOT used by the messenger
259
-        // but will get used by a messenger field for shortcode replacement
260
-        // get added to the 'extra' key in an associated array
261
-        // indexed by the messenger field they relate to.
262
-        // This is important for the Messages_admin to know what fields to display to the user.
263
-        // Also, notice that the "values" are equal to the field type
264
-        // that messages admin will use to know what kind of field to display.
265
-        // The values ALSO have one index labeled "shortcode".
266
-        // The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
-        // is required in order for this extra field to be displayed.
268
-        //  If the required shortcode isn't part of the shortcodes array
269
-        // then the field is not needed and will not be displayed/parsed.
270
-        $this->_template_fields = array(
271
-            'subject' => array(
272
-                'input' => 'text',
273
-                'label' => __('Page Title', 'event_espresso'),
274
-                'type' => 'string',
275
-                'required' => true,
276
-                'validation' => true,
277
-                'css_class' => 'large-text',
278
-                'format' => '%s',
279
-            ),
280
-            'content' => '',
281
-            // left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
-            'extra' => array(
283
-                'content' => array(
284
-                    'main' => array(
285
-                        'input' => 'wp_editor',
286
-                        'label' => __('Main Content', 'event_espresso'),
287
-                        'type' => 'string',
288
-                        'required' => true,
289
-                        'validation' => true,
290
-                        'format' => '%s',
291
-                        'rows' => '15',
292
-                    ),
293
-                    'event_list' => array(
294
-                        'input' => 'wp_editor',
295
-                        'label' => '[EVENT_LIST]',
296
-                        'type' => 'string',
297
-                        'required' => true,
298
-                        'validation' => true,
299
-                        'format' => '%s',
300
-                        'rows' => '15',
301
-                        'shortcodes_required' => array('[EVENT_LIST]'),
302
-                    ),
303
-                    'ticket_list' => array(
304
-                        'input' => 'textarea',
305
-                        'label' => '[TICKET_LIST]',
306
-                        'type' => 'string',
307
-                        'required' => true,
308
-                        'validation' => true,
309
-                        'format' => '%s',
310
-                        'css_class' => 'large-text',
311
-                        'rows' => '10',
312
-                        'shortcodes_required' => array('[TICKET_LIST]'),
313
-                    ),
314
-                    'ticket_line_item_no_pms' => array(
315
-                        'input' => 'textarea',
316
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
-                            'Ticket Line Item List with no Price Modifiers',
318
-                            'event_espresso'
319
-                        ),
320
-                        'type' => 'string',
321
-                        'required' => false,
322
-                        'validation' => true,
323
-                        'format' => '%s',
324
-                        'css_class' => 'large-text',
325
-                        'rows' => '5',
326
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
-                    ),
328
-                    'ticket_line_item_pms' => array(
329
-                        'input' => 'textarea',
330
-                        'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
-                            'Ticket Line Item List with Price Modifiers',
332
-                            'event_espresso'
333
-                        ),
334
-                        'type' => 'string',
335
-                        'required' => false,
336
-                        'validation' => true,
337
-                        'format' => '%s',
338
-                        'css_class' => 'large-text',
339
-                        'rows' => '5',
340
-                        'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
-                    ),
342
-                    'price_modifier_line_item_list' => array(
343
-                        'input' => 'textarea',
344
-                        'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
-                        'type' => 'string',
346
-                        'required' => false,
347
-                        'validation' => true,
348
-                        'format' => '%s',
349
-                        'css_class' => 'large-text',
350
-                        'rows' => '5',
351
-                        'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
-                    ),
353
-                    'datetime_list' => array(
354
-                        'input' => 'textarea',
355
-                        'label' => '[DATETIME_LIST]',
356
-                        'type' => 'string',
357
-                        'required' => true,
358
-                        'validation' => true,
359
-                        'format' => '%s',
360
-                        'css_class' => 'large-text',
361
-                        'rows' => '5',
362
-                        'shortcodes_required' => array('[DATETIME_LIST]'),
363
-                    ),
364
-                    'attendee_list' => array(
365
-                        'input' => 'textarea',
366
-                        'label' => '[ATTENDEE_LIST]',
367
-                        'type' => 'string',
368
-                        'required' => true,
369
-                        'validation' => true,
370
-                        'format' => '%s',
371
-                        'css_class' => 'large-text',
372
-                        'rows' => '5',
373
-                        'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
-                    ),
375
-                    'tax_line_item_list' => array(
376
-                        'input' => 'textarea',
377
-                        'label' => '[TAX_LINE_ITEM_LIST]',
378
-                        'type' => 'string',
379
-                        'required' => false,
380
-                        'validation' => true,
381
-                        'format' => '%s',
382
-                        'css_class' => 'large-text',
383
-                        'rows' => '5',
384
-                        'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
-                    ),
386
-                    'additional_line_item_list' => array(
387
-                        'input' => 'textarea',
388
-                        'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
-                        'type' => 'string',
390
-                        'required' => false,
391
-                        'validation' => true,
392
-                        'format' => '%s',
393
-                        'css_class' => 'large-text',
394
-                        'rows' => '5',
395
-                        'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
-                    ),
397
-                    'payment_list' => array(
398
-                        'input' => 'textarea',
399
-                        'label' => '[PAYMENT_LIST]',
400
-                        'type' => 'string',
401
-                        'required' => true,
402
-                        'validation' => true,
403
-                        'format' => '%s',
404
-                        'css_class' => 'large-text',
405
-                        'rows' => '5',
406
-                        'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
-                    ),
408
-                ),
409
-            ),
410
-        );
411
-    }
412
-
413
-
414
-    /**
415
-     * @see   definition of this method in parent
416
-     * @since 4.5.0
417
-     */
418
-    protected function _set_default_message_types()
419
-    {
420
-        $this->_default_message_types = array('receipt', 'invoice');
421
-    }
422
-
423
-
424
-    /**
425
-     * @see   definition of this method in parent
426
-     * @since 4.5.0
427
-     */
428
-    protected function _set_valid_message_types()
429
-    {
430
-        $this->_valid_message_types = array('receipt', 'invoice');
431
-    }
432
-
433
-
434
-    /**
435
-     * Displays the message in the browser.
436
-     *
437
-     * @since 4.5.0
438
-     * @return string.
439
-     */
440
-    protected function _send_message()
441
-    {
442
-        $this->_template_args = array(
443
-            'page_title' => $this->_subject,
444
-            'base_css' => $this->get_variation(
445
-                $this->_tmp_pack,
446
-                $this->_incoming_message_type->name,
447
-                true,
448
-                'base',
449
-                $this->_variation
450
-            ),
451
-            'print_css' => $this->get_variation(
452
-                $this->_tmp_pack,
453
-                $this->_incoming_message_type->name,
454
-                true,
455
-                'print',
456
-                $this->_variation
457
-            ),
458
-            'main_css' => $this->get_variation(
459
-                $this->_tmp_pack,
460
-                $this->_incoming_message_type->name,
461
-                true,
462
-                'main',
463
-                $this->_variation
464
-            ),
465
-            'main_body' => wpautop(
466
-                apply_filters(
467
-                    'FHEE__EE_Html_messenger___send_message__main_body',
468
-                    $this->_content,
469
-                    $this->_content,
470
-                    $this->_incoming_message_type
471
-                )
472
-            )
473
-        );
474
-        $this->_deregister_wp_hooks();
475
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
-        echo $this->_get_main_template();
477
-        exit();
478
-    }
479
-
480
-
481
-    /**
482
-     * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
-     * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
-     * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
-     *
486
-     * @since 4.5.0
487
-     * @return void
488
-     */
489
-    protected function _deregister_wp_hooks()
490
-    {
491
-        remove_all_actions('wp_head');
492
-        remove_all_actions('wp_footer');
493
-        remove_all_actions('wp_print_footer_scripts');
494
-        remove_all_actions('wp_enqueue_scripts');
495
-        global $wp_scripts, $wp_styles;
496
-        $wp_scripts = $wp_styles = array();
497
-        // just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
-        add_action('wp_footer', 'wp_print_footer_scripts');
499
-        add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
-        add_action('wp_head', 'wp_enqueue_scripts');
501
-    }
502
-
503
-
504
-    /**
505
-     * Overwrite parent _get_main_template for display_html purposes.
506
-     *
507
-     * @since  4.5.0
508
-     * @param bool $preview
509
-     * @return string
510
-     */
511
-    protected function _get_main_template($preview = false)
512
-    {
513
-        $wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
-        // include message type as a template arg
515
-        $this->_template_args['message_type'] = $this->_incoming_message_type;
516
-        return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
-    }
518
-
519
-
520
-    /**
521
-     * @return string
522
-     */
523
-    protected function _preview()
524
-    {
525
-        return $this->_send_message();
526
-    }
527
-
528
-
529
-    protected function _set_admin_settings_fields()
530
-    {
531
-    }
532
-
533
-
534
-    /**
535
-     * add the "powered by EE" credit link to the HTML receipt and invoice
536
-     *
537
-     * @param string $content
538
-     * @param string $content_again
539
-     * @param \EE_message_type $incoming_message_type
540
-     * @return string
541
-     */
542
-    public function add_powered_by_credit_link_to_receipt_and_invoice(
543
-        $content = '',
544
-        $content_again = '',
545
-        EE_message_type $incoming_message_type
546
-    ) {
547
-        if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
-            && apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
-        ) {
550
-            $content .= \EEH_Template::powered_by_event_espresso(
551
-                'aln-cntr',
552
-                '',
553
-                array('utm_content' => 'messages_system')
554
-            )
555
-                . EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
-        }
557
-        return $content;
558
-    }
15
+	/**
16
+	 * The following are the properties that this messenger requires for displaying the html
17
+	 */
18
+	/**
19
+	 * This is the html body generated by the template via the message type.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $_content;
24
+
25
+
26
+	/**
27
+	 * This is for the page title that gets displayed.  (Why use "subject"?  Because the "title" tag in html is
28
+	 * equivalent to the "subject" of the page.
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected $_subject;
33
+
34
+
35
+	/**
36
+	 * EE_Html_messenger constructor.
37
+	 */
38
+	public function __construct()
39
+	{
40
+		// set properties
41
+		$this->name = 'html';
42
+		$this->description = __('This messenger outputs a message to a browser for display.', 'event_espresso');
43
+		$this->label = array(
44
+			'singular' => __('html', 'event_espresso'),
45
+			'plural' => __('html', 'event_espresso'),
46
+		);
47
+		$this->activate_on_install = true;
48
+		// add the "powered by EE" credit link to the HTML receipt and invoice
49
+		add_filter(
50
+			'FHEE__EE_Html_messenger___send_message__main_body',
51
+			array($this, 'add_powered_by_credit_link_to_receipt_and_invoice'),
52
+			10,
53
+			3
54
+		);
55
+		parent::__construct();
56
+	}
57
+
58
+
59
+	/**
60
+	 * HTML Messenger desires execution immediately.
61
+	 *
62
+	 * @see    parent::send_now() for documentation.
63
+	 * @since  4.9.0
64
+	 * @return bool
65
+	 */
66
+	public function send_now()
67
+	{
68
+		return true;
69
+	}
70
+
71
+
72
+	/**
73
+	 * HTML Messenger allows an empty to field.
74
+	 *
75
+	 * @see    parent::allow_empty_to_field() for documentation
76
+	 * @since  4.9.0
77
+	 * @return bool
78
+	 */
79
+	public function allow_empty_to_field()
80
+	{
81
+		return true;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @see abstract declaration in EE_messenger for details.
87
+	 */
88
+	protected function _set_admin_pages()
89
+	{
90
+		$this->admin_registered_pages = array('events_edit' => true);
91
+	}
92
+
93
+
94
+	/**
95
+	 * @see abstract declaration in EE_messenger for details.
96
+	 */
97
+	protected function _set_valid_shortcodes()
98
+	{
99
+		$this->_valid_shortcodes = array();
100
+	}
101
+
102
+
103
+	/**
104
+	 * @see abstract declaration in EE_messenger for details.
105
+	 */
106
+	protected function _set_validator_config()
107
+	{
108
+		$this->_validator_config = array(
109
+			'subject' => array(
110
+				'shortcodes' => array('organization', 'primary_registration_details', 'email', 'transaction'),
111
+			),
112
+			'content' => array(
113
+				'shortcodes' => array(
114
+					'organization',
115
+					'primary_registration_list',
116
+					'primary_registration_details',
117
+					'email',
118
+					'transaction',
119
+					'event_list',
120
+					'payment_list',
121
+					'venue',
122
+					'line_item_list',
123
+					'messenger',
124
+					'ticket_list',
125
+				),
126
+			),
127
+			'event_list' => array(
128
+				'shortcodes' => array(
129
+					'event',
130
+					'ticket_list',
131
+					'venue',
132
+					'primary_registration_details',
133
+					'primary_registration_list',
134
+					'event_author',
135
+				),
136
+				'required' => array('[EVENT_LIST]'),
137
+			),
138
+			'ticket_list' => array(
139
+				'shortcodes' => array(
140
+					'attendee_list',
141
+					'ticket',
142
+					'datetime_list',
143
+					'primary_registration_details',
144
+					'line_item_list',
145
+					'venue',
146
+				),
147
+				'required' => array('[TICKET_LIST]'),
148
+			),
149
+			'ticket_line_item_no_pms' => array(
150
+				'shortcodes' => array('line_item', 'ticket'),
151
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
152
+			),
153
+			'ticket_line_item_pms' => array(
154
+				'shortcodes' => array('line_item', 'ticket', 'line_item_list'),
155
+				'required' => array('[TICKET_LINE_ITEM_LIST]'),
156
+			),
157
+			'price_modifier_line_item_list' => array(
158
+				'shortcodes' => array('line_item'),
159
+				'required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
160
+			),
161
+			'datetime_list' => array(
162
+				'shortcodes' => array('datetime'),
163
+				'required' => array('[DATETIME_LIST]'),
164
+			),
165
+			'attendee_list' => array(
166
+				'shortcodes' => array('attendee'),
167
+				'required' => array('[ATTENDEE_LIST]'),
168
+			),
169
+			'tax_line_item_list' => array(
170
+				'shortcodes' => array('line_item'),
171
+				'required' => array('[TAX_LINE_ITEM_LIST]'),
172
+			),
173
+			'additional_line_item_list' => array(
174
+				'shortcodes' => array('line_item'),
175
+				'required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
176
+			),
177
+			'payment_list' => array(
178
+				'shortcodes' => array('payment'),
179
+				'required' => array('[PAYMENT_LIST_*]'),
180
+			),
181
+		);
182
+	}
183
+
184
+
185
+	/**
186
+	 * This is a method called from EE_messages when this messenger is a generating messenger and the sending messenger
187
+	 * is a different messenger.  Child messengers can set hooks for the sending messenger to callback on if necessary
188
+	 * (i.e. swap out css files or something else).
189
+	 *
190
+	 * @since 4.5.0
191
+	 * @param string $sending_messenger_name the name of the sending messenger so we only set the hooks needed.
192
+	 * @return void
193
+	 */
194
+	public function do_secondary_messenger_hooks($sending_messenger_name)
195
+	{
196
+		if ($sending_messenger_name === 'pdf') {
197
+			add_filter('EE_messenger__get_variation__variation', array($this, 'add_html_css'), 10, 8);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * @param                            $variation_path
204
+	 * @param \EE_Messages_Template_Pack $template_pack
205
+	 * @param                            $messenger_name
206
+	 * @param                            $message_type_name
207
+	 * @param                            $url
208
+	 * @param                            $type
209
+	 * @param                            $variation
210
+	 * @param                            $skip_filters
211
+	 * @return string
212
+	 */
213
+	public function add_html_css(
214
+		$variation_path,
215
+		EE_Messages_Template_Pack $template_pack,
216
+		$messenger_name,
217
+		$message_type_name,
218
+		$url,
219
+		$type,
220
+		$variation,
221
+		$skip_filters
222
+	) {
223
+		$variation = $template_pack->get_variation(
224
+			$this->name,
225
+			$message_type_name,
226
+			$type,
227
+			$variation,
228
+			$url,
229
+			'.css',
230
+			$skip_filters
231
+		);
232
+		return $variation;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Takes care of enqueuing any necessary scripts or styles for the page.  A do_action() so message types using this
238
+	 * messenger can add their own js.
239
+	 *
240
+	 * @return void.
241
+	 */
242
+	public function enqueue_scripts_styles()
243
+	{
244
+		parent::enqueue_scripts_styles();
245
+		do_action('AHEE__EE_Html_messenger__enqueue_scripts_styles');
246
+	}
247
+
248
+
249
+	/**
250
+	 * _set_template_fields
251
+	 * This sets up the fields that a messenger requires for the message to go out.
252
+	 *
253
+	 * @access  protected
254
+	 * @return void
255
+	 */
256
+	protected function _set_template_fields()
257
+	{
258
+		// any extra template fields that are NOT used by the messenger
259
+		// but will get used by a messenger field for shortcode replacement
260
+		// get added to the 'extra' key in an associated array
261
+		// indexed by the messenger field they relate to.
262
+		// This is important for the Messages_admin to know what fields to display to the user.
263
+		// Also, notice that the "values" are equal to the field type
264
+		// that messages admin will use to know what kind of field to display.
265
+		// The values ALSO have one index labeled "shortcode".
266
+		// The values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE])
267
+		// is required in order for this extra field to be displayed.
268
+		//  If the required shortcode isn't part of the shortcodes array
269
+		// then the field is not needed and will not be displayed/parsed.
270
+		$this->_template_fields = array(
271
+			'subject' => array(
272
+				'input' => 'text',
273
+				'label' => __('Page Title', 'event_espresso'),
274
+				'type' => 'string',
275
+				'required' => true,
276
+				'validation' => true,
277
+				'css_class' => 'large-text',
278
+				'format' => '%s',
279
+			),
280
+			'content' => '',
281
+			// left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field.
282
+			'extra' => array(
283
+				'content' => array(
284
+					'main' => array(
285
+						'input' => 'wp_editor',
286
+						'label' => __('Main Content', 'event_espresso'),
287
+						'type' => 'string',
288
+						'required' => true,
289
+						'validation' => true,
290
+						'format' => '%s',
291
+						'rows' => '15',
292
+					),
293
+					'event_list' => array(
294
+						'input' => 'wp_editor',
295
+						'label' => '[EVENT_LIST]',
296
+						'type' => 'string',
297
+						'required' => true,
298
+						'validation' => true,
299
+						'format' => '%s',
300
+						'rows' => '15',
301
+						'shortcodes_required' => array('[EVENT_LIST]'),
302
+					),
303
+					'ticket_list' => array(
304
+						'input' => 'textarea',
305
+						'label' => '[TICKET_LIST]',
306
+						'type' => 'string',
307
+						'required' => true,
308
+						'validation' => true,
309
+						'format' => '%s',
310
+						'css_class' => 'large-text',
311
+						'rows' => '10',
312
+						'shortcodes_required' => array('[TICKET_LIST]'),
313
+					),
314
+					'ticket_line_item_no_pms' => array(
315
+						'input' => 'textarea',
316
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
317
+							'Ticket Line Item List with no Price Modifiers',
318
+							'event_espresso'
319
+						),
320
+						'type' => 'string',
321
+						'required' => false,
322
+						'validation' => true,
323
+						'format' => '%s',
324
+						'css_class' => 'large-text',
325
+						'rows' => '5',
326
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
327
+					),
328
+					'ticket_line_item_pms' => array(
329
+						'input' => 'textarea',
330
+						'label' => '[TICKET_LINE_ITEM_LIST] <br>' . __(
331
+							'Ticket Line Item List with Price Modifiers',
332
+							'event_espresso'
333
+						),
334
+						'type' => 'string',
335
+						'required' => false,
336
+						'validation' => true,
337
+						'format' => '%s',
338
+						'css_class' => 'large-text',
339
+						'rows' => '5',
340
+						'shortcodes_required' => array('[TICKET_LINE_ITEM_LIST]'),
341
+					),
342
+					'price_modifier_line_item_list' => array(
343
+						'input' => 'textarea',
344
+						'label' => '[PRICE_MODIFIER_LINE_ITEM_LIST]',
345
+						'type' => 'string',
346
+						'required' => false,
347
+						'validation' => true,
348
+						'format' => '%s',
349
+						'css_class' => 'large-text',
350
+						'rows' => '5',
351
+						'shortcodes_required' => array('[PRICE_MODIFIER_LINE_ITEM_LIST]'),
352
+					),
353
+					'datetime_list' => array(
354
+						'input' => 'textarea',
355
+						'label' => '[DATETIME_LIST]',
356
+						'type' => 'string',
357
+						'required' => true,
358
+						'validation' => true,
359
+						'format' => '%s',
360
+						'css_class' => 'large-text',
361
+						'rows' => '5',
362
+						'shortcodes_required' => array('[DATETIME_LIST]'),
363
+					),
364
+					'attendee_list' => array(
365
+						'input' => 'textarea',
366
+						'label' => '[ATTENDEE_LIST]',
367
+						'type' => 'string',
368
+						'required' => true,
369
+						'validation' => true,
370
+						'format' => '%s',
371
+						'css_class' => 'large-text',
372
+						'rows' => '5',
373
+						'shortcodes_required' => array('[ATTENDEE_LIST]'),
374
+					),
375
+					'tax_line_item_list' => array(
376
+						'input' => 'textarea',
377
+						'label' => '[TAX_LINE_ITEM_LIST]',
378
+						'type' => 'string',
379
+						'required' => false,
380
+						'validation' => true,
381
+						'format' => '%s',
382
+						'css_class' => 'large-text',
383
+						'rows' => '5',
384
+						'shortcodes_required' => array('[TAX_LINE_ITEM_LIST]'),
385
+					),
386
+					'additional_line_item_list' => array(
387
+						'input' => 'textarea',
388
+						'label' => '[ADDITIONAL_LINE_ITEM_LIST]',
389
+						'type' => 'string',
390
+						'required' => false,
391
+						'validation' => true,
392
+						'format' => '%s',
393
+						'css_class' => 'large-text',
394
+						'rows' => '5',
395
+						'shortcodes_required' => array('[ADDITIONAL_LINE_ITEM_LIST]'),
396
+					),
397
+					'payment_list' => array(
398
+						'input' => 'textarea',
399
+						'label' => '[PAYMENT_LIST]',
400
+						'type' => 'string',
401
+						'required' => true,
402
+						'validation' => true,
403
+						'format' => '%s',
404
+						'css_class' => 'large-text',
405
+						'rows' => '5',
406
+						'shortcodes_required' => array('[PAYMENT_LIST_*]'),
407
+					),
408
+				),
409
+			),
410
+		);
411
+	}
412
+
413
+
414
+	/**
415
+	 * @see   definition of this method in parent
416
+	 * @since 4.5.0
417
+	 */
418
+	protected function _set_default_message_types()
419
+	{
420
+		$this->_default_message_types = array('receipt', 'invoice');
421
+	}
422
+
423
+
424
+	/**
425
+	 * @see   definition of this method in parent
426
+	 * @since 4.5.0
427
+	 */
428
+	protected function _set_valid_message_types()
429
+	{
430
+		$this->_valid_message_types = array('receipt', 'invoice');
431
+	}
432
+
433
+
434
+	/**
435
+	 * Displays the message in the browser.
436
+	 *
437
+	 * @since 4.5.0
438
+	 * @return string.
439
+	 */
440
+	protected function _send_message()
441
+	{
442
+		$this->_template_args = array(
443
+			'page_title' => $this->_subject,
444
+			'base_css' => $this->get_variation(
445
+				$this->_tmp_pack,
446
+				$this->_incoming_message_type->name,
447
+				true,
448
+				'base',
449
+				$this->_variation
450
+			),
451
+			'print_css' => $this->get_variation(
452
+				$this->_tmp_pack,
453
+				$this->_incoming_message_type->name,
454
+				true,
455
+				'print',
456
+				$this->_variation
457
+			),
458
+			'main_css' => $this->get_variation(
459
+				$this->_tmp_pack,
460
+				$this->_incoming_message_type->name,
461
+				true,
462
+				'main',
463
+				$this->_variation
464
+			),
465
+			'main_body' => wpautop(
466
+				apply_filters(
467
+					'FHEE__EE_Html_messenger___send_message__main_body',
468
+					$this->_content,
469
+					$this->_content,
470
+					$this->_incoming_message_type
471
+				)
472
+			)
473
+		);
474
+		$this->_deregister_wp_hooks();
475
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
476
+		echo $this->_get_main_template();
477
+		exit();
478
+	}
479
+
480
+
481
+	/**
482
+	 * The purpose of this function is to de register all actions hooked into wp_head and wp_footer so that it doesn't
483
+	 * interfere with our templates.  If users want to add any custom styles or scripts they must use the
484
+	 * AHEE__EE_Html_messenger__enqueue_scripts_styles hook.
485
+	 *
486
+	 * @since 4.5.0
487
+	 * @return void
488
+	 */
489
+	protected function _deregister_wp_hooks()
490
+	{
491
+		remove_all_actions('wp_head');
492
+		remove_all_actions('wp_footer');
493
+		remove_all_actions('wp_print_footer_scripts');
494
+		remove_all_actions('wp_enqueue_scripts');
495
+		global $wp_scripts, $wp_styles;
496
+		$wp_scripts = $wp_styles = array();
497
+		// just add back in wp_enqueue_scripts and wp_print_footer_scripts cause that's all we want to load.
498
+		add_action('wp_footer', 'wp_print_footer_scripts');
499
+		add_action('wp_print_footer_scripts', '_wp_footer_scripts');
500
+		add_action('wp_head', 'wp_enqueue_scripts');
501
+	}
502
+
503
+
504
+	/**
505
+	 * Overwrite parent _get_main_template for display_html purposes.
506
+	 *
507
+	 * @since  4.5.0
508
+	 * @param bool $preview
509
+	 * @return string
510
+	 */
511
+	protected function _get_main_template($preview = false)
512
+	{
513
+		$wrapper_template = $this->_tmp_pack->get_wrapper($this->name, 'main');
514
+		// include message type as a template arg
515
+		$this->_template_args['message_type'] = $this->_incoming_message_type;
516
+		return EEH_Template::display_template($wrapper_template, $this->_template_args, true);
517
+	}
518
+
519
+
520
+	/**
521
+	 * @return string
522
+	 */
523
+	protected function _preview()
524
+	{
525
+		return $this->_send_message();
526
+	}
527
+
528
+
529
+	protected function _set_admin_settings_fields()
530
+	{
531
+	}
532
+
533
+
534
+	/**
535
+	 * add the "powered by EE" credit link to the HTML receipt and invoice
536
+	 *
537
+	 * @param string $content
538
+	 * @param string $content_again
539
+	 * @param \EE_message_type $incoming_message_type
540
+	 * @return string
541
+	 */
542
+	public function add_powered_by_credit_link_to_receipt_and_invoice(
543
+		$content = '',
544
+		$content_again = '',
545
+		EE_message_type $incoming_message_type
546
+	) {
547
+		if (($incoming_message_type->name === 'invoice' || $incoming_message_type->name === 'receipt')
548
+			&& apply_filters('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', true)
549
+		) {
550
+			$content .= \EEH_Template::powered_by_event_espresso(
551
+				'aln-cntr',
552
+				'',
553
+				array('utm_content' => 'messages_system')
554
+			)
555
+				. EEH_HTML::div(EEH_HTML::p('&nbsp;'));
556
+		}
557
+		return $content;
558
+	}
559 559
 }
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 1 patch
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -15,239 +15,239 @@
 block discarded – undo
15 15
  */
16 16
 class I18nRegistry
17 17
 {
18
-    /**
19
-     * @var DomainInterface
20
-     */
21
-    private $domain;
22
-
23
-    /**
24
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
25
-     *
26
-     * @var array
27
-     */
28
-    private $registered_i18n = array();
29
-
30
-
31
-    /**
32
-     * Used to hold queued translations for the chunks loading in a view.
33
-     *
34
-     * @var array
35
-     */
36
-    private $queued_handle_translations = array();
37
-
38
-    /**
39
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
40
-     *
41
-     * @var array
42
-     */
43
-    private $queued_scripts = array();
44
-
45
-
46
-    /**
47
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
48
-     * translation strings.
49
-     *
50
-     * @var array
51
-     */
52
-    private $i18n_map;
53
-
54
-
55
-    /**
56
-     * I18nRegistry constructor.
57
-     *
58
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
59
-     *                            provided, the class will look for map in root of plugin with filename of
60
-     *                            'translation-map.json'.
61
-     * @param DomainInterface $domain
62
-     */
63
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
64
-    {
65
-        $this->domain = $domain;
66
-        $this->setI18nMap($i18n_map);
67
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
68
-    }
69
-
70
-
71
-    /**
72
-     * Used to register a script that has i18n strings for its $handle
73
-     *
74
-     * @param string $handle The script handle reference.
75
-     * @param string $domain The i18n domain for the strings.
76
-     */
77
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
78
-    {
79
-        if(! isset($this->registered_i18n[$handle])) {
80
-            $this->registered_i18n[ $handle ] = 1;
81
-            $this->queued_scripts[ $handle ] = $domain;
82
-        }
83
-    }
84
-
85
-
86
-
87
-    /**
88
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
89
-     *
90
-     * @param array $handles Array of registered script handles.
91
-     * @return array
92
-     */
93
-    public function queueI18n(array $handles)
94
-    {
95
-        if (empty($this->queued_scripts)) {
96
-            return $handles;
97
-        }
98
-        foreach ($handles as $handle) {
99
-            $this->queueI18nTranslationsForHandle($handle);
100
-        }
101
-        if ($this->queued_handle_translations) {
102
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
103
-                $this->registerInlineScript(
104
-                    $handle,
105
-                    $translations_for_domain['translations'],
106
-                    $translations_for_domain['domain']
107
-                );
108
-                unset($this->queued_handle_translations[$handle]);
109
-            }
110
-        }
111
-        return $handles;
112
-    }
113
-
114
-
115
-    /**
116
-     * Registers inline script with translations for given handle and domain.
117
-     *
118
-     * @param string $handle       Handle used to register javascript file containing translations.
119
-     * @param array  $translations Array of string translations.
120
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
121
-     *                             domain for the javascript.
122
-     */
123
-    protected function registerInlineScript($handle, array $translations, $domain)
124
-    {
125
-        $script = $domain ?
126
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
127
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
128
-        wp_add_inline_script($handle, $script, 'before');
129
-    }
130
-
131
-
132
-    /**
133
-     * Queues up the translation strings for the given handle.
134
-     *
135
-     * @param string $handle The script handle being queued up.
136
-     */
137
-    private function queueI18nTranslationsForHandle($handle)
138
-    {
139
-        if (isset($this->queued_scripts[$handle])) {
140
-            $domain = $this->queued_scripts[$handle];
141
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
142
-            if (count($translations) > 0) {
143
-                $this->queued_handle_translations[$handle] = array(
144
-                    'domain'       => $domain,
145
-                    'translations' => $translations,
146
-                );
147
-            }
148
-            unset($this->queued_scripts[$handle]);
149
-        }
150
-    }
151
-
152
-
153
-    /**
154
-     * Sets the internal i18n_map property.
155
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
156
-     *
157
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
158
-     *                         correspond to.
159
-     */
160
-    private function setI18nMap(array $i18n_map)
161
-    {
162
-        if (empty($i18n_map)) {
163
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
164
-                ? json_decode(
165
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
166
-                        true
167
-                    )
168
-                : array();
169
-        }
170
-        $this->i18n_map = $i18n_map;
171
-    }
172
-
173
-
174
-    /**
175
-     * Get the jed locale data for a given $handle and domain
176
-     *
177
-     * @param string $handle The name for the script handle we want strings returned for.
178
-     * @param string $domain The i18n domain.
179
-     * @return array
180
-     */
181
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
182
-    {
183
-        $translations = $this->getJedLocaleData($domain);
184
-        // get index for adding back after extracting strings for this $chunk.
185
-        $index = $translations[''];
186
-        $translations = $this->getLocaleDataMatchingMap(
187
-            $this->getOriginalStringsForHandleFromMap($handle),
188
-            $translations
189
-        );
190
-        $translations[''] = $index;
191
-        return $translations;
192
-    }
193
-
194
-
195
-    /**
196
-     * Get locale data for given strings from given translations
197
-     *
198
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
199
-     * @param array $translations Translation data to extra strings from.
200
-     * @return array
201
-     */
202
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
203
-    {
204
-        if (empty($string_set)) {
205
-            return array();
206
-        }
207
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
208
-        // slashed also filter falsey values.
209
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
210
-        return array_intersect_key($translations, array_flip($string_set));
211
-    }
212
-
213
-
214
-    /**
215
-     * Get original strings to translate for the given chunk from the map
216
-     *
217
-     * @param string $handle The script handle name to get strings from the map for.
218
-     * @return array
219
-     */
220
-    protected function getOriginalStringsForHandleFromMap($handle)
221
-    {
222
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
223
-    }
224
-
225
-
226
-    /**
227
-     * Returns Jed-formatted localization data.
228
-     *
229
-     * @param  string $domain Translation domain.
230
-     * @return array
231
-     */
232
-    private function getJedLocaleData($domain)
233
-    {
234
-        $translations = get_translations_for_domain($domain);
235
-
236
-        $locale = array(
237
-            '' => array(
238
-                'domain' => $domain,
239
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
240
-            ),
241
-        );
242
-
243
-        if (! empty($translations->headers['Plural-Forms'])) {
244
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
245
-        }
246
-
247
-        foreach ($translations->entries as $msgid => $entry) {
248
-            $locale[$msgid] = $entry->translations;
249
-        }
250
-
251
-        return $locale;
252
-    }
18
+	/**
19
+	 * @var DomainInterface
20
+	 */
21
+	private $domain;
22
+
23
+	/**
24
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private $registered_i18n = array();
29
+
30
+
31
+	/**
32
+	 * Used to hold queued translations for the chunks loading in a view.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	private $queued_handle_translations = array();
37
+
38
+	/**
39
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	private $queued_scripts = array();
44
+
45
+
46
+	/**
47
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
48
+	 * translation strings.
49
+	 *
50
+	 * @var array
51
+	 */
52
+	private $i18n_map;
53
+
54
+
55
+	/**
56
+	 * I18nRegistry constructor.
57
+	 *
58
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
59
+	 *                            provided, the class will look for map in root of plugin with filename of
60
+	 *                            'translation-map.json'.
61
+	 * @param DomainInterface $domain
62
+	 */
63
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
64
+	{
65
+		$this->domain = $domain;
66
+		$this->setI18nMap($i18n_map);
67
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
68
+	}
69
+
70
+
71
+	/**
72
+	 * Used to register a script that has i18n strings for its $handle
73
+	 *
74
+	 * @param string $handle The script handle reference.
75
+	 * @param string $domain The i18n domain for the strings.
76
+	 */
77
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
78
+	{
79
+		if(! isset($this->registered_i18n[$handle])) {
80
+			$this->registered_i18n[ $handle ] = 1;
81
+			$this->queued_scripts[ $handle ] = $domain;
82
+		}
83
+	}
84
+
85
+
86
+
87
+	/**
88
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
89
+	 *
90
+	 * @param array $handles Array of registered script handles.
91
+	 * @return array
92
+	 */
93
+	public function queueI18n(array $handles)
94
+	{
95
+		if (empty($this->queued_scripts)) {
96
+			return $handles;
97
+		}
98
+		foreach ($handles as $handle) {
99
+			$this->queueI18nTranslationsForHandle($handle);
100
+		}
101
+		if ($this->queued_handle_translations) {
102
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
103
+				$this->registerInlineScript(
104
+					$handle,
105
+					$translations_for_domain['translations'],
106
+					$translations_for_domain['domain']
107
+				);
108
+				unset($this->queued_handle_translations[$handle]);
109
+			}
110
+		}
111
+		return $handles;
112
+	}
113
+
114
+
115
+	/**
116
+	 * Registers inline script with translations for given handle and domain.
117
+	 *
118
+	 * @param string $handle       Handle used to register javascript file containing translations.
119
+	 * @param array  $translations Array of string translations.
120
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
121
+	 *                             domain for the javascript.
122
+	 */
123
+	protected function registerInlineScript($handle, array $translations, $domain)
124
+	{
125
+		$script = $domain ?
126
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
127
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
128
+		wp_add_inline_script($handle, $script, 'before');
129
+	}
130
+
131
+
132
+	/**
133
+	 * Queues up the translation strings for the given handle.
134
+	 *
135
+	 * @param string $handle The script handle being queued up.
136
+	 */
137
+	private function queueI18nTranslationsForHandle($handle)
138
+	{
139
+		if (isset($this->queued_scripts[$handle])) {
140
+			$domain = $this->queued_scripts[$handle];
141
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
142
+			if (count($translations) > 0) {
143
+				$this->queued_handle_translations[$handle] = array(
144
+					'domain'       => $domain,
145
+					'translations' => $translations,
146
+				);
147
+			}
148
+			unset($this->queued_scripts[$handle]);
149
+		}
150
+	}
151
+
152
+
153
+	/**
154
+	 * Sets the internal i18n_map property.
155
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
156
+	 *
157
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
158
+	 *                         correspond to.
159
+	 */
160
+	private function setI18nMap(array $i18n_map)
161
+	{
162
+		if (empty($i18n_map)) {
163
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
164
+				? json_decode(
165
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
166
+						true
167
+					)
168
+				: array();
169
+		}
170
+		$this->i18n_map = $i18n_map;
171
+	}
172
+
173
+
174
+	/**
175
+	 * Get the jed locale data for a given $handle and domain
176
+	 *
177
+	 * @param string $handle The name for the script handle we want strings returned for.
178
+	 * @param string $domain The i18n domain.
179
+	 * @return array
180
+	 */
181
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
182
+	{
183
+		$translations = $this->getJedLocaleData($domain);
184
+		// get index for adding back after extracting strings for this $chunk.
185
+		$index = $translations[''];
186
+		$translations = $this->getLocaleDataMatchingMap(
187
+			$this->getOriginalStringsForHandleFromMap($handle),
188
+			$translations
189
+		);
190
+		$translations[''] = $index;
191
+		return $translations;
192
+	}
193
+
194
+
195
+	/**
196
+	 * Get locale data for given strings from given translations
197
+	 *
198
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
199
+	 * @param array $translations Translation data to extra strings from.
200
+	 * @return array
201
+	 */
202
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
203
+	{
204
+		if (empty($string_set)) {
205
+			return array();
206
+		}
207
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
208
+		// slashed also filter falsey values.
209
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
210
+		return array_intersect_key($translations, array_flip($string_set));
211
+	}
212
+
213
+
214
+	/**
215
+	 * Get original strings to translate for the given chunk from the map
216
+	 *
217
+	 * @param string $handle The script handle name to get strings from the map for.
218
+	 * @return array
219
+	 */
220
+	protected function getOriginalStringsForHandleFromMap($handle)
221
+	{
222
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
223
+	}
224
+
225
+
226
+	/**
227
+	 * Returns Jed-formatted localization data.
228
+	 *
229
+	 * @param  string $domain Translation domain.
230
+	 * @return array
231
+	 */
232
+	private function getJedLocaleData($domain)
233
+	{
234
+		$translations = get_translations_for_domain($domain);
235
+
236
+		$locale = array(
237
+			'' => array(
238
+				'domain' => $domain,
239
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
240
+			),
241
+		);
242
+
243
+		if (! empty($translations->headers['Plural-Forms'])) {
244
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
245
+		}
246
+
247
+		foreach ($translations->entries as $msgid => $entry) {
248
+			$locale[$msgid] = $entry->translations;
249
+		}
250
+
251
+		return $locale;
252
+	}
253 253
 }
254 254
\ No newline at end of file
Please login to merge, or discard this patch.