Completed
Branch Gutenberg/event-attendees-bloc... (011228)
by
unknown
66:29 queued 53:26
created
core/services/assets/I18nRegistry.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -14,238 +14,238 @@
 block discarded – undo
14 14
  */
15 15
 class I18nRegistry
16 16
 {
17
-    /**
18
-     * @var DomainInterface
19
-     */
20
-    private $domain;
21
-
22
-    /**
23
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
-     *
25
-     * @var array
26
-     */
27
-    private $registered_i18n = array();
28
-
29
-
30
-    /**
31
-     * Used to hold queued translations for the chunks loading in a view.
32
-     *
33
-     * @var array
34
-     */
35
-    private $queued_handle_translations = array();
36
-
37
-    /**
38
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
39
-     *
40
-     * @var array
41
-     */
42
-    private $queued_scripts = array();
43
-
44
-
45
-    /**
46
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
-     * translation strings.
48
-     *
49
-     * @var array
50
-     */
51
-    private $i18n_map;
52
-
53
-
54
-    /**
55
-     * I18nRegistry constructor.
56
-     *
57
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
-     *                            provided, the class will look for map in root of plugin with filename of
59
-     *                            'translation-map.json'.
60
-     * @param DomainInterface $domain
61
-     */
62
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
-    {
64
-        $this->domain = $domain;
65
-        $this->setI18nMap($i18n_map);
66
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
67
-    }
68
-
69
-
70
-    /**
71
-     * Used to register a script that has i18n strings for its $handle
72
-     *
73
-     * @param string $handle The script handle reference.
74
-     * @param string $domain The i18n domain for the strings.
75
-     */
76
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
77
-    {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
-     *
89
-     * @param array $handles Array of registered script handles.
90
-     * @return array
91
-     */
92
-    public function queueI18n(array $handles)
93
-    {
94
-        if (empty($this->queued_scripts)) {
95
-            return $handles;
96
-        }
97
-        foreach ($handles as $handle) {
98
-            $this->queueI18nTranslationsForHandle($handle);
99
-        }
100
-        if ($this->queued_handle_translations) {
101
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
-                $this->registerInlineScript(
103
-                    $handle,
104
-                    $translations_for_domain['translations'],
105
-                    $translations_for_domain['domain']
106
-                );
107
-            }
108
-        }
109
-        return $handles;
110
-    }
111
-
112
-
113
-    /**
114
-     * Registers inline script with translations for given handle and domain.
115
-     *
116
-     * @param string $handle       Handle used to register javascript file containing translations.
117
-     * @param array  $translations Array of string translations.
118
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
-     *                             domain for the javascript.
120
-     */
121
-    protected function registerInlineScript($handle, array $translations, $domain)
122
-    {
123
-        $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
-        wp_add_inline_script($handle, $script, 'before');
127
-    }
128
-
129
-
130
-    /**
131
-     * Queues up the translation strings for the given handle.
132
-     *
133
-     * @param string $handle The script handle being queued up.
134
-     */
135
-    private function queueI18nTranslationsForHandle($handle)
136
-    {
137
-        if (isset($this->queued_scripts[$handle])) {
138
-            $domain = $this->queued_scripts[$handle];
139
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
-            if (count($translations) > 0) {
141
-                $this->queued_handle_translations[$handle] = array(
142
-                    'domain'       => $domain,
143
-                    'translations' => $translations,
144
-                );
145
-            }
146
-            unset($this->queued_scripts[$handle]);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Sets the internal i18n_map property.
153
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
-     *
155
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
-     *                         correspond to.
157
-     */
158
-    private function setI18nMap(array $i18n_map)
159
-    {
160
-        if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
-                ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
-                        true
165
-                    )
166
-                : array();
167
-        }
168
-        $this->i18n_map = $i18n_map;
169
-    }
170
-
171
-
172
-    /**
173
-     * Get the jed locale data for a given $handle and domain
174
-     *
175
-     * @param string $handle The name for the script handle we want strings returned for.
176
-     * @param string $domain The i18n domain.
177
-     * @return array
178
-     */
179
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
-    {
181
-        $translations = $this->getJedLocaleData($domain);
182
-        // get index for adding back after extracting strings for this $chunk.
183
-        $index = $translations[''];
184
-        $translations = $this->getLocaleDataMatchingMap(
185
-            $this->getOriginalStringsForHandleFromMap($handle),
186
-            $translations
187
-        );
188
-        $translations[''] = $index;
189
-        return $translations;
190
-    }
191
-
192
-
193
-    /**
194
-     * Get locale data for given strings from given translations
195
-     *
196
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
-     * @param array $translations Translation data to extra strings from.
198
-     * @return array
199
-     */
200
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
-    {
202
-        if (empty($string_set)) {
203
-            return array();
204
-        }
205
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
-        // slashed also filter falsey values.
207
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
208
-        return array_intersect_key($translations, array_flip($string_set));
209
-    }
210
-
211
-
212
-    /**
213
-     * Get original strings to translate for the given chunk from the map
214
-     *
215
-     * @param string $handle The script handle name to get strings from the map for.
216
-     * @return array
217
-     */
218
-    protected function getOriginalStringsForHandleFromMap($handle)
219
-    {
220
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
-    }
222
-
223
-
224
-    /**
225
-     * Returns Jed-formatted localization data.
226
-     *
227
-     * @param  string $domain Translation domain.
228
-     * @return array
229
-     */
230
-    private function getJedLocaleData($domain)
231
-    {
232
-        $translations = get_translations_for_domain($domain);
233
-
234
-        $locale = array(
235
-            '' => array(
236
-                'domain' => $domain,
237
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
238
-            ),
239
-        );
240
-
241
-        if (! empty($translations->headers['Plural-Forms'])) {
242
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
-        }
244
-
245
-        foreach ($translations->entries as $msgid => $entry) {
246
-            $locale[$msgid] = $entry->translations;
247
-        }
248
-
249
-        return $locale;
250
-    }
17
+	/**
18
+	 * @var DomainInterface
19
+	 */
20
+	private $domain;
21
+
22
+	/**
23
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private $registered_i18n = array();
28
+
29
+
30
+	/**
31
+	 * Used to hold queued translations for the chunks loading in a view.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $queued_handle_translations = array();
36
+
37
+	/**
38
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $queued_scripts = array();
43
+
44
+
45
+	/**
46
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
+	 * translation strings.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $i18n_map;
52
+
53
+
54
+	/**
55
+	 * I18nRegistry constructor.
56
+	 *
57
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
+	 *                            provided, the class will look for map in root of plugin with filename of
59
+	 *                            'translation-map.json'.
60
+	 * @param DomainInterface $domain
61
+	 */
62
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
+	{
64
+		$this->domain = $domain;
65
+		$this->setI18nMap($i18n_map);
66
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
67
+	}
68
+
69
+
70
+	/**
71
+	 * Used to register a script that has i18n strings for its $handle
72
+	 *
73
+	 * @param string $handle The script handle reference.
74
+	 * @param string $domain The i18n domain for the strings.
75
+	 */
76
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
77
+	{
78
+		if(! isset($this->registered_i18n[$handle])) {
79
+			$this->registered_i18n[ $handle ] = 1;
80
+			$this->queued_scripts[ $handle ] = $domain;
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
+	 *
89
+	 * @param array $handles Array of registered script handles.
90
+	 * @return array
91
+	 */
92
+	public function queueI18n(array $handles)
93
+	{
94
+		if (empty($this->queued_scripts)) {
95
+			return $handles;
96
+		}
97
+		foreach ($handles as $handle) {
98
+			$this->queueI18nTranslationsForHandle($handle);
99
+		}
100
+		if ($this->queued_handle_translations) {
101
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
+				$this->registerInlineScript(
103
+					$handle,
104
+					$translations_for_domain['translations'],
105
+					$translations_for_domain['domain']
106
+				);
107
+			}
108
+		}
109
+		return $handles;
110
+	}
111
+
112
+
113
+	/**
114
+	 * Registers inline script with translations for given handle and domain.
115
+	 *
116
+	 * @param string $handle       Handle used to register javascript file containing translations.
117
+	 * @param array  $translations Array of string translations.
118
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
+	 *                             domain for the javascript.
120
+	 */
121
+	protected function registerInlineScript($handle, array $translations, $domain)
122
+	{
123
+		$script = $domain ?
124
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
+		wp_add_inline_script($handle, $script, 'before');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Queues up the translation strings for the given handle.
132
+	 *
133
+	 * @param string $handle The script handle being queued up.
134
+	 */
135
+	private function queueI18nTranslationsForHandle($handle)
136
+	{
137
+		if (isset($this->queued_scripts[$handle])) {
138
+			$domain = $this->queued_scripts[$handle];
139
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
+			if (count($translations) > 0) {
141
+				$this->queued_handle_translations[$handle] = array(
142
+					'domain'       => $domain,
143
+					'translations' => $translations,
144
+				);
145
+			}
146
+			unset($this->queued_scripts[$handle]);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Sets the internal i18n_map property.
153
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
+	 *
155
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
+	 *                         correspond to.
157
+	 */
158
+	private function setI18nMap(array $i18n_map)
159
+	{
160
+		if (empty($i18n_map)) {
161
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
+				? json_decode(
163
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
+						true
165
+					)
166
+				: array();
167
+		}
168
+		$this->i18n_map = $i18n_map;
169
+	}
170
+
171
+
172
+	/**
173
+	 * Get the jed locale data for a given $handle and domain
174
+	 *
175
+	 * @param string $handle The name for the script handle we want strings returned for.
176
+	 * @param string $domain The i18n domain.
177
+	 * @return array
178
+	 */
179
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
+	{
181
+		$translations = $this->getJedLocaleData($domain);
182
+		// get index for adding back after extracting strings for this $chunk.
183
+		$index = $translations[''];
184
+		$translations = $this->getLocaleDataMatchingMap(
185
+			$this->getOriginalStringsForHandleFromMap($handle),
186
+			$translations
187
+		);
188
+		$translations[''] = $index;
189
+		return $translations;
190
+	}
191
+
192
+
193
+	/**
194
+	 * Get locale data for given strings from given translations
195
+	 *
196
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
+	 * @param array $translations Translation data to extra strings from.
198
+	 * @return array
199
+	 */
200
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
+	{
202
+		if (empty($string_set)) {
203
+			return array();
204
+		}
205
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
+		// slashed also filter falsey values.
207
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
208
+		return array_intersect_key($translations, array_flip($string_set));
209
+	}
210
+
211
+
212
+	/**
213
+	 * Get original strings to translate for the given chunk from the map
214
+	 *
215
+	 * @param string $handle The script handle name to get strings from the map for.
216
+	 * @return array
217
+	 */
218
+	protected function getOriginalStringsForHandleFromMap($handle)
219
+	{
220
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
+	}
222
+
223
+
224
+	/**
225
+	 * Returns Jed-formatted localization data.
226
+	 *
227
+	 * @param  string $domain Translation domain.
228
+	 * @return array
229
+	 */
230
+	private function getJedLocaleData($domain)
231
+	{
232
+		$translations = get_translations_for_domain($domain);
233
+
234
+		$locale = array(
235
+			'' => array(
236
+				'domain' => $domain,
237
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
238
+			),
239
+		);
240
+
241
+		if (! empty($translations->headers['Plural-Forms'])) {
242
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
+		}
244
+
245
+		foreach ($translations->entries as $msgid => $entry) {
246
+			$locale[$msgid] = $entry->translations;
247
+		}
248
+
249
+		return $locale;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 1 patch
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -18,842 +18,842 @@
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-    /**
29
-     * @singleton method used to instantiate class object
30
-     * @access    public
31
-     * @return EE_Payment_Processor instance
32
-     */
33
-    public static function instance()
34
-    {
35
-        // check if class object is instantiated
36
-        if (! self::$_instance instanceof EE_Payment_Processor) {
37
-            self::$_instance = new self();
38
-        }
39
-        return self::$_instance;
40
-    }
41
-
42
-
43
-    /**
44
-     * @return EE_Payment_Processor
45
-     */
46
-    public static function reset()
47
-    {
48
-        self::$_instance = null;
49
-        return self::instance();
50
-    }
51
-
52
-
53
-    /**
54
-     *private constructor to prevent direct creation
55
-     *
56
-     * @Constructor
57
-     * @access private
58
-     */
59
-    private function __construct()
60
-    {
61
-        do_action('AHEE__EE_Payment_Processor__construct');
62
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
-    }
64
-
65
-
66
-    /**
67
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
-     * appropriately. Saves the payment that is generated
69
-     *
70
-     * @param EE_Payment_Method    $payment_method
71
-     * @param EE_Transaction       $transaction
72
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
-     *                                           Leave null if payment is for the full amount owing
74
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
-     *                                           Receive_form_submission() should have
76
-     *                                           already been called on the billing form
77
-     *                                           (ie, its inputs should have their normalized values set).
78
-     * @param string               $return_url   string used mostly by offsite gateways to specify
79
-     *                                           where to go AFTER the offsite gateway
80
-     * @param string               $method       like 'CART', indicates who the client who called this was
81
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
-     * @param boolean              $update_txn   whether or not to call
83
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
-     * @return EE_Payment
86
-     * @throws EE_Error
87
-     * @throws InvalidArgumentException
88
-     * @throws ReflectionException
89
-     * @throws RuntimeException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     */
93
-    public function process_payment(
94
-        EE_Payment_Method $payment_method,
95
-        EE_Transaction $transaction,
96
-        $amount = null,
97
-        $billing_form = null,
98
-        $return_url = null,
99
-        $method = 'CART',
100
-        $by_admin = false,
101
-        $update_txn = true,
102
-        $cancel_url = ''
103
-    ) {
104
-        if ((float) $amount < 0) {
105
-            throw new EE_Error(
106
-                sprintf(
107
-                    __(
108
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
-                        'event_espresso'
110
-                    ),
111
-                    $amount,
112
-                    $transaction->ID()
113
-                )
114
-            );
115
-        }
116
-        // verify payment method
117
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
-            $payment_method,
119
-            true
120
-        );
121
-        // verify transaction
122
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
123
-        $transaction->set_payment_method_ID($payment_method->ID());
124
-        // verify payment method type
125
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
-            $payment = $payment_method->type_obj()->process_payment(
127
-                $transaction,
128
-                min($amount, $transaction->remaining()), // make sure we don't overcharge
129
-                $billing_form,
130
-                $return_url,
131
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
-                $method,
133
-                $by_admin
134
-            );
135
-            // check if payment method uses an off-site gateway
136
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
-                // don't process payments for off-site gateways yet because no payment has occurred yet
138
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
-            }
140
-            return $payment;
141
-        }
142
-        EE_Error::add_error(
143
-            sprintf(
144
-                __(
145
-                    'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
-                    'event_espresso'
147
-                ),
148
-                '<br/>',
149
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
150
-            ),
151
-            __FILE__,
152
-            __FUNCTION__,
153
-            __LINE__
154
-        );
155
-        return null;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param EE_Transaction|int $transaction
161
-     * @param EE_Payment_Method  $payment_method
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     */
168
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
-    {
170
-        /** @type \EE_Transaction $transaction */
171
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
-        $primary_reg = $transaction->primary_registration();
173
-        if (! $primary_reg instanceof EE_Registration) {
174
-            throw new EE_Error(
175
-                sprintf(
176
-                    __(
177
-                        'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
-                        'event_espresso'
179
-                    ),
180
-                    $transaction->ID()
181
-                )
182
-            );
183
-        }
184
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
-            $payment_method,
186
-            true
187
-        );
188
-        $url = add_query_arg(
189
-            array(
190
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
-                'ee_payment_method' => $payment_method->slug(),
192
-            ),
193
-            EE_Registry::instance()->CFG->core->txn_page_url()
194
-        );
195
-        return $url;
196
-    }
197
-
198
-
199
-    /**
200
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
-     * we can easily find what registration the IPN is for and what payment method.
202
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
203
-     * If a payment is found for the IPN info, it is saved.
204
-     *
205
-     * @param array              $_req_data            eg $_REQUEST
206
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
-     * @param boolean            $update_txn           whether or not to call
209
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
-     *                                                 or is processed manually ( false like Mijireh )
212
-     * @throws EE_Error
213
-     * @throws Exception
214
-     * @return EE_Payment
215
-     * @throws \RuntimeException
216
-     * @throws \ReflectionException
217
-     * @throws \InvalidArgumentException
218
-     * @throws InvalidInterfaceException
219
-     * @throws InvalidDataTypeException
220
-     */
221
-    public function process_ipn(
222
-        $_req_data,
223
-        $transaction = null,
224
-        $payment_method = null,
225
-        $update_txn = true,
226
-        $separate_IPN_request = true
227
-    ) {
228
-        EE_Registry::instance()->load_model('Change_Log');
229
-        $_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
-        EE_Processor_Base::set_IPN($separate_IPN_request);
231
-        $obj_for_log = null;
232
-        if ($transaction instanceof EE_Transaction) {
233
-            $obj_for_log = $transaction;
234
-            if ($payment_method instanceof EE_Payment_Method) {
235
-                $obj_for_log = EEM_Payment::instance()->get_one(
236
-                    array(
237
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
-                        'order_by' => array('PAY_timestamp' => 'desc'),
239
-                    )
240
-                );
241
-            }
242
-        } elseif ($payment_method instanceof EE_Payment) {
243
-            $obj_for_log = $payment_method;
244
-        }
245
-        $log = EEM_Change_Log::instance()->log(
246
-            EEM_Change_Log::type_gateway,
247
-            array('IPN data received' => $_req_data),
248
-            $obj_for_log
249
-        );
250
-        try {
251
-            /**
252
-             * @var EE_Payment $payment
253
-             */
254
-            $payment = null;
255
-            if ($transaction && $payment_method) {
256
-                /** @type EE_Transaction $transaction */
257
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
-                /** @type EE_Payment_Method $payment_method */
259
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
-                    try {
262
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
-                        $log->set_object($payment);
264
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
265
-                        EEM_Change_Log::instance()->log(
266
-                            EEM_Change_Log::type_gateway,
267
-                            array(
268
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
269
-                                'current_url' => EEH_URL::current_url(),
270
-                                'payment'     => $e->getPaymentProperties(),
271
-                                'IPN_data'    => $e->getIpnData(),
272
-                            ),
273
-                            $obj_for_log
274
-                        );
275
-                        return $e->getPayment();
276
-                    }
277
-                } else {
278
-                    // not a payment
279
-                    EE_Error::add_error(
280
-                        sprintf(
281
-                            __(
282
-                                'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
-                                'event_espresso'
284
-                            ),
285
-                            '<br/>',
286
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
287
-                        ),
288
-                        __FILE__,
289
-                        __FUNCTION__,
290
-                        __LINE__
291
-                    );
292
-                }
293
-            } else {
294
-                // that's actually pretty ok. The IPN just wasn't able
295
-                // to identify which transaction or payment method this was for
296
-                // give all active payment methods a chance to claim it
297
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
-                foreach ($active_payment_methods as $active_payment_method) {
299
-                    try {
300
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
-                        $payment_method = $active_payment_method;
302
-                        EEM_Change_Log::instance()->log(
303
-                            EEM_Change_Log::type_gateway,
304
-                            array('IPN data' => $_req_data),
305
-                            $payment
306
-                        );
307
-                        break;
308
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
309
-                        EEM_Change_Log::instance()->log(
310
-                            EEM_Change_Log::type_gateway,
311
-                            array(
312
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
313
-                                'current_url' => EEH_URL::current_url(),
314
-                                'payment'     => $e->getPaymentProperties(),
315
-                                'IPN_data'    => $e->getIpnData(),
316
-                            ),
317
-                            $obj_for_log
318
-                        );
319
-                        return $e->getPayment();
320
-                    } catch (EE_Error $e) {
321
-                        // that's fine- it apparently couldn't handle the IPN
322
-                    }
323
-                }
324
-            }
325
-            // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
-            if ($payment instanceof EE_Payment) {
327
-                $payment->save();
328
-                //  update the TXN
329
-                $this->update_txn_based_on_payment(
330
-                    $transaction,
331
-                    $payment,
332
-                    $update_txn,
333
-                    $separate_IPN_request
334
-                );
335
-            } else {
336
-                // we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
-                if ($payment_method) {
338
-                    EEM_Change_Log::instance()->log(
339
-                        EEM_Change_Log::type_gateway,
340
-                        array('IPN data' => $_req_data),
341
-                        $payment_method
342
-                    );
343
-                } elseif ($transaction) {
344
-                    EEM_Change_Log::instance()->log(
345
-                        EEM_Change_Log::type_gateway,
346
-                        array('IPN data' => $_req_data),
347
-                        $transaction
348
-                    );
349
-                }
350
-            }
351
-            return $payment;
352
-        } catch (EE_Error $e) {
353
-            do_action(
354
-                'AHEE__log',
355
-                __FILE__,
356
-                __FUNCTION__,
357
-                sprintf(
358
-                    __(
359
-                        'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
-                        'event_espresso'
361
-                    ),
362
-                    print_r($transaction, true),
363
-                    print_r($_req_data, true),
364
-                    $e->getMessage()
365
-                )
366
-            );
367
-            throw $e;
368
-        }
369
-    }
370
-
371
-
372
-    /**
373
-     * Removes any non-printable illegal characters from the input,
374
-     * which might cause a raucous when trying to insert into the database
375
-     *
376
-     * @param  array $request_data
377
-     * @return array
378
-     */
379
-    protected function _remove_unusable_characters_from_array(array $request_data)
380
-    {
381
-        $return_data = array();
382
-        foreach ($request_data as $key => $value) {
383
-            $return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
-                $value
385
-            );
386
-        }
387
-        return $return_data;
388
-    }
389
-
390
-
391
-    /**
392
-     * Removes any non-printable illegal characters from the input,
393
-     * which might cause a raucous when trying to insert into the database
394
-     *
395
-     * @param string $request_data
396
-     * @return string
397
-     */
398
-    protected function _remove_unusable_characters($request_data)
399
-    {
400
-        return preg_replace('/[^[:print:]]/', '', $request_data);
401
-    }
402
-
403
-
404
-    /**
405
-     * Should be called just before displaying the payment attempt results to the user,
406
-     * when the payment attempt has finished. Some payment methods may have special
407
-     * logic to perform here. For example, if process_payment() happens on a special request
408
-     * and then the user is redirected to a page that displays the payment's status, this
409
-     * should be called while loading the page that displays the payment's status. If the user is
410
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
-     * provider.
412
-     *
413
-     * @param EE_Transaction|int $transaction
414
-     * @param bool               $update_txn whether or not to call
415
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
-     * @return EE_Payment
417
-     * @throws EE_Error
418
-     * @throws InvalidArgumentException
419
-     * @throws ReflectionException
420
-     * @throws RuntimeException
421
-     * @throws InvalidDataTypeException
422
-     * @throws InvalidInterfaceException
423
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
-     */
426
-    public function finalize_payment_for($transaction, $update_txn = true)
427
-    {
428
-        /** @var $transaction EE_Transaction */
429
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
-        $last_payment_method = $transaction->payment_method();
431
-        if ($last_payment_method instanceof EE_Payment_Method) {
432
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
-            return $payment;
435
-        }
436
-        return null;
437
-    }
438
-
439
-
440
-    /**
441
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
-     *
443
-     * @param EE_Payment_Method $payment_method
444
-     * @param EE_Payment        $payment_to_refund
445
-     * @param array             $refund_info
446
-     * @return EE_Payment
447
-     * @throws EE_Error
448
-     * @throws InvalidArgumentException
449
-     * @throws ReflectionException
450
-     * @throws RuntimeException
451
-     * @throws InvalidDataTypeException
452
-     * @throws InvalidInterfaceException
453
-     */
454
-    public function process_refund(
455
-        EE_Payment_Method $payment_method,
456
-        EE_Payment $payment_to_refund,
457
-        array $refund_info = array()
458
-    ) {
459
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
-        }
463
-        return $payment_to_refund;
464
-    }
465
-
466
-
467
-    /**
468
-     * This should be called each time there may have been an update to a
469
-     * payment on a transaction (ie, we asked for a payment to process a
470
-     * payment for a transaction, or we told a payment method about an IPN, or
471
-     * we told a payment method to
472
-     * "finalize_payment_for" (a transaction), or we told a payment method to
473
-     * process a refund. This should handle firing the correct hooks to
474
-     * indicate
475
-     * what exactly happened and updating the transaction appropriately). This
476
-     * could be integrated directly into EE_Transaction upon save, but we want
477
-     * this logic to be separate from 'normal' plain-jane saving and updating
478
-     * of transactions and payments, and to be tied to payment processing.
479
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
-     * of previous code to decide whether or not to save (because the payment passed into
481
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
-     * in which case we only want that payment object for some temporary usage during this request,
483
-     * but we don't want it to be saved).
484
-     *
485
-     * @param EE_Transaction|int $transaction
486
-     * @param EE_Payment         $payment
487
-     * @param boolean            $update_txn
488
-     *                        whether or not to call
489
-     *                        EE_Transaction_Processor::
490
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
491
-     *                        (you can save 1 DB query if you know you're going
492
-     *                        to save it later instead)
493
-     * @param bool               $IPN
494
-     *                        if processing IPNs or other similar payment
495
-     *                        related activities that occur in alternate
496
-     *                        requests than the main one that is processing the
497
-     *                        TXN, then set this to true to check whether the
498
-     *                        TXN is locked before updating
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws ReflectionException
502
-     * @throws RuntimeException
503
-     * @throws InvalidDataTypeException
504
-     * @throws InvalidInterfaceException
505
-     */
506
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
-    {
508
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
-        /** @type EE_Transaction $transaction */
510
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
-        // can we freely update the TXN at this moment?
512
-        if ($IPN && $transaction->is_locked()) {
513
-            // don't update the transaction at this exact moment
514
-            // because the TXN is active in another request
515
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
-                time(),
517
-                $transaction->ID(),
518
-                $payment->ID()
519
-            );
520
-        } else {
521
-            // verify payment and that it has been saved
522
-            if ($payment instanceof EE_Payment && $payment->ID()) {
523
-                if ($payment->payment_method() instanceof EE_Payment_Method
524
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
-                ) {
526
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
-                    // update TXN registrations with payment info
528
-                    $this->process_registration_payments($transaction, $payment);
529
-                }
530
-                $do_action = $payment->just_approved()
531
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
-                    : $do_action;
533
-            } else {
534
-                // send out notifications
535
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
-            }
538
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
-                /** @type EE_Transaction_Payments $transaction_payments */
540
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
-                // set new value for total paid
542
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
543
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
-                if ($update_txn) {
545
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
546
-                }
547
-            }
548
-            // granular hook for others to use.
549
-            do_action($do_action, $transaction, $payment);
550
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
-            // global hook for others to use.
552
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
-        }
554
-    }
555
-
556
-
557
-    /**
558
-     * update registrations REG_paid field after successful payment and link registrations with payment
559
-     *
560
-     * @param EE_Transaction    $transaction
561
-     * @param EE_Payment        $payment
562
-     * @param EE_Registration[] $registrations
563
-     * @throws EE_Error
564
-     * @throws InvalidArgumentException
565
-     * @throws RuntimeException
566
-     * @throws InvalidDataTypeException
567
-     * @throws InvalidInterfaceException
568
-     */
569
-    public function process_registration_payments(
570
-        EE_Transaction $transaction,
571
-        EE_Payment $payment,
572
-        array $registrations = array()
573
-    ) {
574
-        // only process if payment was successful
575
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
576
-            return;
577
-        }
578
-        // EEM_Registration::instance()->show_next_x_db_queries();
579
-        if (empty($registrations)) {
580
-            // find registrations with monies owing that can receive a payment
581
-            $registrations = $transaction->registrations(
582
-                array(
583
-                    array(
584
-                        // only these reg statuses can receive payments
585
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
-                        'REG_final_price'  => array('!=', 0),
587
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
588
-                    ),
589
-                )
590
-            );
591
-        }
592
-        // still nothing ??!??
593
-        if (empty($registrations)) {
594
-            return;
595
-        }
596
-        // todo: break out the following logic into a separate strategy class
597
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
598
-        // todo: which would apply payments using the capitalist "first come first paid" approach
599
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
601
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
-        $refund = $payment->is_a_refund();
603
-        // how much is available to apply to registrations?
604
-        $available_payment_amount = abs($payment->amount());
605
-        foreach ($registrations as $registration) {
606
-            if ($registration instanceof EE_Registration) {
607
-                // nothing left?
608
-                if ($available_payment_amount <= 0) {
609
-                    break;
610
-                }
611
-                if ($refund) {
612
-                    $available_payment_amount = $this->process_registration_refund(
613
-                        $registration,
614
-                        $payment,
615
-                        $available_payment_amount
616
-                    );
617
-                } else {
618
-                    $available_payment_amount = $this->process_registration_payment(
619
-                        $registration,
620
-                        $payment,
621
-                        $available_payment_amount
622
-                    );
623
-                }
624
-            }
625
-        }
626
-        if ($available_payment_amount > 0
627
-            && apply_filters(
628
-                'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
-                false
630
-            )) {
631
-            EE_Error::add_attention(
632
-                sprintf(
633
-                    __(
634
-                        'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
-                        'event_espresso'
636
-                    ),
637
-                    EEH_Template::format_currency($available_payment_amount),
638
-                    implode(', ', array_keys($registrations)),
639
-                    '<br/>',
640
-                    EEH_Template::format_currency($payment->amount())
641
-                ),
642
-                __FILE__,
643
-                __FUNCTION__,
644
-                __LINE__
645
-            );
646
-        }
647
-    }
648
-
649
-
650
-    /**
651
-     * update registration REG_paid field after successful payment and link registration with payment
652
-     *
653
-     * @param EE_Registration $registration
654
-     * @param EE_Payment      $payment
655
-     * @param float           $available_payment_amount
656
-     * @return float
657
-     * @throws EE_Error
658
-     * @throws InvalidArgumentException
659
-     * @throws RuntimeException
660
-     * @throws InvalidDataTypeException
661
-     * @throws InvalidInterfaceException
662
-     */
663
-    public function process_registration_payment(
664
-        EE_Registration $registration,
665
-        EE_Payment $payment,
666
-        $available_payment_amount = 0.00
667
-    ) {
668
-        $owing = $registration->final_price() - $registration->paid();
669
-        if ($owing > 0) {
670
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
671
-            $payment_amount = min($available_payment_amount, $owing);
672
-            // update $available_payment_amount
673
-            $available_payment_amount -= $payment_amount;
674
-            // calculate and set new REG_paid
675
-            $registration->set_paid($registration->paid() + $payment_amount);
676
-            // now save it
677
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
678
-        }
679
-        return $available_payment_amount;
680
-    }
681
-
682
-
683
-    /**
684
-     * update registration REG_paid field after successful payment and link registration with payment
685
-     *
686
-     * @param EE_Registration $registration
687
-     * @param EE_Payment      $payment
688
-     * @param float           $payment_amount
689
-     * @return void
690
-     * @throws EE_Error
691
-     * @throws InvalidArgumentException
692
-     * @throws InvalidDataTypeException
693
-     * @throws InvalidInterfaceException
694
-     */
695
-    protected function _apply_registration_payment(
696
-        EE_Registration $registration,
697
-        EE_Payment $payment,
698
-        $payment_amount = 0.00
699
-    ) {
700
-        // find any existing reg payment records for this registration and payment
701
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
-        );
704
-        // if existing registration payment exists
705
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
-            // then update that record
707
-            $existing_reg_payment->set_amount($payment_amount);
708
-            $existing_reg_payment->save();
709
-        } else {
710
-            // or add new relation between registration and payment and set amount
711
-            $registration->_add_relation_to(
712
-                $payment,
713
-                'Payment',
714
-                array('RPY_amount' => $payment_amount)
715
-            );
716
-            // make it stick
717
-            $registration->save();
718
-        }
719
-    }
720
-
721
-
722
-    /**
723
-     * update registration REG_paid field after refund and link registration with payment
724
-     *
725
-     * @param EE_Registration $registration
726
-     * @param EE_Payment      $payment
727
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
-     * @return float
729
-     * @throws EE_Error
730
-     * @throws InvalidArgumentException
731
-     * @throws RuntimeException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     */
735
-    public function process_registration_refund(
736
-        EE_Registration $registration,
737
-        EE_Payment $payment,
738
-        $available_refund_amount = 0.00
739
-    ) {
740
-        // EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
-        if ($registration->paid() > 0) {
742
-            // ensure $available_refund_amount is NOT negative
743
-            $available_refund_amount = (float) abs($available_refund_amount);
744
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
745
-            $refund_amount = min($available_refund_amount, (float) $registration->paid());
746
-            // update $available_payment_amount
747
-            $available_refund_amount -= $refund_amount;
748
-            // calculate and set new REG_paid
749
-            $registration->set_paid($registration->paid() - $refund_amount);
750
-            // convert payment amount back to a negative value for storage in the db
751
-            $refund_amount = (float) abs($refund_amount) * -1;
752
-            // now save it
753
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
754
-        }
755
-        return $available_refund_amount;
756
-    }
757
-
758
-
759
-    /**
760
-     * Process payments and transaction after payment process completed.
761
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
-     * if this request happens to be processing an IPN,
763
-     * then we will also set the Payment Options Reg Step to completed,
764
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
-     *
766
-     * @param EE_Transaction $transaction
767
-     * @param EE_Payment     $payment
768
-     * @param bool           $IPN
769
-     * @throws EE_Error
770
-     * @throws InvalidArgumentException
771
-     * @throws ReflectionException
772
-     * @throws RuntimeException
773
-     * @throws InvalidDataTypeException
774
-     * @throws InvalidInterfaceException
775
-     */
776
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
-    {
778
-        /** @type EE_Transaction_Processor $transaction_processor */
779
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
-        // is the Payment Options Reg Step completed ?
781
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
-        // if the Payment Options Reg Step is completed...
783
-        $revisit = $payment_options_step_completed === true;
784
-        // then this is kinda sorta a revisit with regards to payments at least
785
-        $transaction_processor->set_revisit($revisit);
786
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
-        if ($IPN
788
-            && $payment_options_step_completed !== true
789
-            && ($payment->is_approved() || $payment->is_pending())
790
-        ) {
791
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
792
-                'payment_options'
793
-            );
794
-        }
795
-        // maybe update status, but don't save transaction just yet
796
-        $transaction->update_status_based_on_total_paid(false);
797
-        // check if 'finalize_registration' step has been completed...
798
-        $finalized = $transaction->reg_step_completed('finalize_registration');
799
-        //  if this is an IPN and the final step has not been initiated
800
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
801
-            // and if it hasn't already been set as being started...
802
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
-        }
804
-        $transaction->save();
805
-        // because the above will return false if the final step was not fully completed, we need to check again...
806
-        if ($IPN && $finalized !== false) {
807
-            // and if we are all good to go, then send out notifications
808
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
-            // ok, now process the transaction according to the payment
810
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
-                $transaction,
812
-                $payment
813
-            );
814
-        }
815
-        // DEBUG LOG
816
-        $payment_method = $payment->payment_method();
817
-        if ($payment_method instanceof EE_Payment_Method) {
818
-            $payment_method_type_obj = $payment_method->type_obj();
819
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
-                $gateway = $payment_method_type_obj->get_gateway();
821
-                if ($gateway instanceof EE_Gateway) {
822
-                    $gateway->log(
823
-                        array(
824
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
-                            'transaction'           => $transaction->model_field_array(),
826
-                            'finalized'             => $finalized,
827
-                            'IPN'                   => $IPN,
828
-                            'deliver_notifications' => has_filter(
829
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
-                            ),
831
-                        ),
832
-                        $payment
833
-                    );
834
-                }
835
-            }
836
-        }
837
-    }
838
-
839
-
840
-    /**
841
-     * Force posts to PayPal to use TLS v1.2. See:
842
-     * https://core.trac.wordpress.org/ticket/36320
843
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
844
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
-     * This will affect PayPal standard, pro, express, and Payflow.
846
-     *
847
-     * @param $handle
848
-     * @param $r
849
-     * @param $url
850
-     */
851
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
-    {
853
-        if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
-            // Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
-            // instead of the constant because it might not be defined
856
-            curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
-        }
858
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+	/**
29
+	 * @singleton method used to instantiate class object
30
+	 * @access    public
31
+	 * @return EE_Payment_Processor instance
32
+	 */
33
+	public static function instance()
34
+	{
35
+		// check if class object is instantiated
36
+		if (! self::$_instance instanceof EE_Payment_Processor) {
37
+			self::$_instance = new self();
38
+		}
39
+		return self::$_instance;
40
+	}
41
+
42
+
43
+	/**
44
+	 * @return EE_Payment_Processor
45
+	 */
46
+	public static function reset()
47
+	{
48
+		self::$_instance = null;
49
+		return self::instance();
50
+	}
51
+
52
+
53
+	/**
54
+	 *private constructor to prevent direct creation
55
+	 *
56
+	 * @Constructor
57
+	 * @access private
58
+	 */
59
+	private function __construct()
60
+	{
61
+		do_action('AHEE__EE_Payment_Processor__construct');
62
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
63
+	}
64
+
65
+
66
+	/**
67
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
68
+	 * appropriately. Saves the payment that is generated
69
+	 *
70
+	 * @param EE_Payment_Method    $payment_method
71
+	 * @param EE_Transaction       $transaction
72
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
73
+	 *                                           Leave null if payment is for the full amount owing
74
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
75
+	 *                                           Receive_form_submission() should have
76
+	 *                                           already been called on the billing form
77
+	 *                                           (ie, its inputs should have their normalized values set).
78
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
79
+	 *                                           where to go AFTER the offsite gateway
80
+	 * @param string               $method       like 'CART', indicates who the client who called this was
81
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
82
+	 * @param boolean              $update_txn   whether or not to call
83
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
84
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
85
+	 * @return EE_Payment
86
+	 * @throws EE_Error
87
+	 * @throws InvalidArgumentException
88
+	 * @throws ReflectionException
89
+	 * @throws RuntimeException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 */
93
+	public function process_payment(
94
+		EE_Payment_Method $payment_method,
95
+		EE_Transaction $transaction,
96
+		$amount = null,
97
+		$billing_form = null,
98
+		$return_url = null,
99
+		$method = 'CART',
100
+		$by_admin = false,
101
+		$update_txn = true,
102
+		$cancel_url = ''
103
+	) {
104
+		if ((float) $amount < 0) {
105
+			throw new EE_Error(
106
+				sprintf(
107
+					__(
108
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
109
+						'event_espresso'
110
+					),
111
+					$amount,
112
+					$transaction->ID()
113
+				)
114
+			);
115
+		}
116
+		// verify payment method
117
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
118
+			$payment_method,
119
+			true
120
+		);
121
+		// verify transaction
122
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
123
+		$transaction->set_payment_method_ID($payment_method->ID());
124
+		// verify payment method type
125
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
126
+			$payment = $payment_method->type_obj()->process_payment(
127
+				$transaction,
128
+				min($amount, $transaction->remaining()), // make sure we don't overcharge
129
+				$billing_form,
130
+				$return_url,
131
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
132
+				$method,
133
+				$by_admin
134
+			);
135
+			// check if payment method uses an off-site gateway
136
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
137
+				// don't process payments for off-site gateways yet because no payment has occurred yet
138
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
139
+			}
140
+			return $payment;
141
+		}
142
+		EE_Error::add_error(
143
+			sprintf(
144
+				__(
145
+					'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
146
+					'event_espresso'
147
+				),
148
+				'<br/>',
149
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
150
+			),
151
+			__FILE__,
152
+			__FUNCTION__,
153
+			__LINE__
154
+		);
155
+		return null;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param EE_Transaction|int $transaction
161
+	 * @param EE_Payment_Method  $payment_method
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 */
168
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
169
+	{
170
+		/** @type \EE_Transaction $transaction */
171
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
172
+		$primary_reg = $transaction->primary_registration();
173
+		if (! $primary_reg instanceof EE_Registration) {
174
+			throw new EE_Error(
175
+				sprintf(
176
+					__(
177
+						'Cannot get IPN URL for transaction with ID %d because it has no primary registration',
178
+						'event_espresso'
179
+					),
180
+					$transaction->ID()
181
+				)
182
+			);
183
+		}
184
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj(
185
+			$payment_method,
186
+			true
187
+		);
188
+		$url = add_query_arg(
189
+			array(
190
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
191
+				'ee_payment_method' => $payment_method->slug(),
192
+			),
193
+			EE_Registry::instance()->CFG->core->txn_page_url()
194
+		);
195
+		return $url;
196
+	}
197
+
198
+
199
+	/**
200
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
201
+	 * we can easily find what registration the IPN is for and what payment method.
202
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
203
+	 * If a payment is found for the IPN info, it is saved.
204
+	 *
205
+	 * @param array              $_req_data            eg $_REQUEST
206
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
207
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
208
+	 * @param boolean            $update_txn           whether or not to call
209
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
210
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
211
+	 *                                                 or is processed manually ( false like Mijireh )
212
+	 * @throws EE_Error
213
+	 * @throws Exception
214
+	 * @return EE_Payment
215
+	 * @throws \RuntimeException
216
+	 * @throws \ReflectionException
217
+	 * @throws \InvalidArgumentException
218
+	 * @throws InvalidInterfaceException
219
+	 * @throws InvalidDataTypeException
220
+	 */
221
+	public function process_ipn(
222
+		$_req_data,
223
+		$transaction = null,
224
+		$payment_method = null,
225
+		$update_txn = true,
226
+		$separate_IPN_request = true
227
+	) {
228
+		EE_Registry::instance()->load_model('Change_Log');
229
+		$_req_data = $this->_remove_unusable_characters_from_array((array) $_req_data);
230
+		EE_Processor_Base::set_IPN($separate_IPN_request);
231
+		$obj_for_log = null;
232
+		if ($transaction instanceof EE_Transaction) {
233
+			$obj_for_log = $transaction;
234
+			if ($payment_method instanceof EE_Payment_Method) {
235
+				$obj_for_log = EEM_Payment::instance()->get_one(
236
+					array(
237
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
238
+						'order_by' => array('PAY_timestamp' => 'desc'),
239
+					)
240
+				);
241
+			}
242
+		} elseif ($payment_method instanceof EE_Payment) {
243
+			$obj_for_log = $payment_method;
244
+		}
245
+		$log = EEM_Change_Log::instance()->log(
246
+			EEM_Change_Log::type_gateway,
247
+			array('IPN data received' => $_req_data),
248
+			$obj_for_log
249
+		);
250
+		try {
251
+			/**
252
+			 * @var EE_Payment $payment
253
+			 */
254
+			$payment = null;
255
+			if ($transaction && $payment_method) {
256
+				/** @type EE_Transaction $transaction */
257
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
258
+				/** @type EE_Payment_Method $payment_method */
259
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
260
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
261
+					try {
262
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
263
+						$log->set_object($payment);
264
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
265
+						EEM_Change_Log::instance()->log(
266
+							EEM_Change_Log::type_gateway,
267
+							array(
268
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
269
+								'current_url' => EEH_URL::current_url(),
270
+								'payment'     => $e->getPaymentProperties(),
271
+								'IPN_data'    => $e->getIpnData(),
272
+							),
273
+							$obj_for_log
274
+						);
275
+						return $e->getPayment();
276
+					}
277
+				} else {
278
+					// not a payment
279
+					EE_Error::add_error(
280
+						sprintf(
281
+							__(
282
+								'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.',
283
+								'event_espresso'
284
+							),
285
+							'<br/>',
286
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
287
+						),
288
+						__FILE__,
289
+						__FUNCTION__,
290
+						__LINE__
291
+					);
292
+				}
293
+			} else {
294
+				// that's actually pretty ok. The IPN just wasn't able
295
+				// to identify which transaction or payment method this was for
296
+				// give all active payment methods a chance to claim it
297
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
298
+				foreach ($active_payment_methods as $active_payment_method) {
299
+					try {
300
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
301
+						$payment_method = $active_payment_method;
302
+						EEM_Change_Log::instance()->log(
303
+							EEM_Change_Log::type_gateway,
304
+							array('IPN data' => $_req_data),
305
+							$payment
306
+						);
307
+						break;
308
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
309
+						EEM_Change_Log::instance()->log(
310
+							EEM_Change_Log::type_gateway,
311
+							array(
312
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
313
+								'current_url' => EEH_URL::current_url(),
314
+								'payment'     => $e->getPaymentProperties(),
315
+								'IPN_data'    => $e->getIpnData(),
316
+							),
317
+							$obj_for_log
318
+						);
319
+						return $e->getPayment();
320
+					} catch (EE_Error $e) {
321
+						// that's fine- it apparently couldn't handle the IPN
322
+					}
323
+				}
324
+			}
325
+			// EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
326
+			if ($payment instanceof EE_Payment) {
327
+				$payment->save();
328
+				//  update the TXN
329
+				$this->update_txn_based_on_payment(
330
+					$transaction,
331
+					$payment,
332
+					$update_txn,
333
+					$separate_IPN_request
334
+				);
335
+			} else {
336
+				// we couldn't find the payment for this IPN... let's try and log at least SOMETHING
337
+				if ($payment_method) {
338
+					EEM_Change_Log::instance()->log(
339
+						EEM_Change_Log::type_gateway,
340
+						array('IPN data' => $_req_data),
341
+						$payment_method
342
+					);
343
+				} elseif ($transaction) {
344
+					EEM_Change_Log::instance()->log(
345
+						EEM_Change_Log::type_gateway,
346
+						array('IPN data' => $_req_data),
347
+						$transaction
348
+					);
349
+				}
350
+			}
351
+			return $payment;
352
+		} catch (EE_Error $e) {
353
+			do_action(
354
+				'AHEE__log',
355
+				__FILE__,
356
+				__FUNCTION__,
357
+				sprintf(
358
+					__(
359
+						'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"',
360
+						'event_espresso'
361
+					),
362
+					print_r($transaction, true),
363
+					print_r($_req_data, true),
364
+					$e->getMessage()
365
+				)
366
+			);
367
+			throw $e;
368
+		}
369
+	}
370
+
371
+
372
+	/**
373
+	 * Removes any non-printable illegal characters from the input,
374
+	 * which might cause a raucous when trying to insert into the database
375
+	 *
376
+	 * @param  array $request_data
377
+	 * @return array
378
+	 */
379
+	protected function _remove_unusable_characters_from_array(array $request_data)
380
+	{
381
+		$return_data = array();
382
+		foreach ($request_data as $key => $value) {
383
+			$return_data[ $this->_remove_unusable_characters($key) ] = $this->_remove_unusable_characters(
384
+				$value
385
+			);
386
+		}
387
+		return $return_data;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Removes any non-printable illegal characters from the input,
393
+	 * which might cause a raucous when trying to insert into the database
394
+	 *
395
+	 * @param string $request_data
396
+	 * @return string
397
+	 */
398
+	protected function _remove_unusable_characters($request_data)
399
+	{
400
+		return preg_replace('/[^[:print:]]/', '', $request_data);
401
+	}
402
+
403
+
404
+	/**
405
+	 * Should be called just before displaying the payment attempt results to the user,
406
+	 * when the payment attempt has finished. Some payment methods may have special
407
+	 * logic to perform here. For example, if process_payment() happens on a special request
408
+	 * and then the user is redirected to a page that displays the payment's status, this
409
+	 * should be called while loading the page that displays the payment's status. If the user is
410
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
411
+	 * provider.
412
+	 *
413
+	 * @param EE_Transaction|int $transaction
414
+	 * @param bool               $update_txn whether or not to call
415
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
416
+	 * @return EE_Payment
417
+	 * @throws EE_Error
418
+	 * @throws InvalidArgumentException
419
+	 * @throws ReflectionException
420
+	 * @throws RuntimeException
421
+	 * @throws InvalidDataTypeException
422
+	 * @throws InvalidInterfaceException
423
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
424
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
425
+	 */
426
+	public function finalize_payment_for($transaction, $update_txn = true)
427
+	{
428
+		/** @var $transaction EE_Transaction */
429
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
430
+		$last_payment_method = $transaction->payment_method();
431
+		if ($last_payment_method instanceof EE_Payment_Method) {
432
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
433
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
434
+			return $payment;
435
+		}
436
+		return null;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
442
+	 *
443
+	 * @param EE_Payment_Method $payment_method
444
+	 * @param EE_Payment        $payment_to_refund
445
+	 * @param array             $refund_info
446
+	 * @return EE_Payment
447
+	 * @throws EE_Error
448
+	 * @throws InvalidArgumentException
449
+	 * @throws ReflectionException
450
+	 * @throws RuntimeException
451
+	 * @throws InvalidDataTypeException
452
+	 * @throws InvalidInterfaceException
453
+	 */
454
+	public function process_refund(
455
+		EE_Payment_Method $payment_method,
456
+		EE_Payment $payment_to_refund,
457
+		array $refund_info = array()
458
+	) {
459
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
460
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
461
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
462
+		}
463
+		return $payment_to_refund;
464
+	}
465
+
466
+
467
+	/**
468
+	 * This should be called each time there may have been an update to a
469
+	 * payment on a transaction (ie, we asked for a payment to process a
470
+	 * payment for a transaction, or we told a payment method about an IPN, or
471
+	 * we told a payment method to
472
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
473
+	 * process a refund. This should handle firing the correct hooks to
474
+	 * indicate
475
+	 * what exactly happened and updating the transaction appropriately). This
476
+	 * could be integrated directly into EE_Transaction upon save, but we want
477
+	 * this logic to be separate from 'normal' plain-jane saving and updating
478
+	 * of transactions and payments, and to be tied to payment processing.
479
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
480
+	 * of previous code to decide whether or not to save (because the payment passed into
481
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
482
+	 * in which case we only want that payment object for some temporary usage during this request,
483
+	 * but we don't want it to be saved).
484
+	 *
485
+	 * @param EE_Transaction|int $transaction
486
+	 * @param EE_Payment         $payment
487
+	 * @param boolean            $update_txn
488
+	 *                        whether or not to call
489
+	 *                        EE_Transaction_Processor::
490
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
491
+	 *                        (you can save 1 DB query if you know you're going
492
+	 *                        to save it later instead)
493
+	 * @param bool               $IPN
494
+	 *                        if processing IPNs or other similar payment
495
+	 *                        related activities that occur in alternate
496
+	 *                        requests than the main one that is processing the
497
+	 *                        TXN, then set this to true to check whether the
498
+	 *                        TXN is locked before updating
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws ReflectionException
502
+	 * @throws RuntimeException
503
+	 * @throws InvalidDataTypeException
504
+	 * @throws InvalidInterfaceException
505
+	 */
506
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
507
+	{
508
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
509
+		/** @type EE_Transaction $transaction */
510
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
511
+		// can we freely update the TXN at this moment?
512
+		if ($IPN && $transaction->is_locked()) {
513
+			// don't update the transaction at this exact moment
514
+			// because the TXN is active in another request
515
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
516
+				time(),
517
+				$transaction->ID(),
518
+				$payment->ID()
519
+			);
520
+		} else {
521
+			// verify payment and that it has been saved
522
+			if ($payment instanceof EE_Payment && $payment->ID()) {
523
+				if ($payment->payment_method() instanceof EE_Payment_Method
524
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
525
+				) {
526
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
527
+					// update TXN registrations with payment info
528
+					$this->process_registration_payments($transaction, $payment);
529
+				}
530
+				$do_action = $payment->just_approved()
531
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
532
+					: $do_action;
533
+			} else {
534
+				// send out notifications
535
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
536
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
537
+			}
538
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
539
+				/** @type EE_Transaction_Payments $transaction_payments */
540
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
541
+				// set new value for total paid
542
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
543
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
544
+				if ($update_txn) {
545
+					$this->_post_payment_processing($transaction, $payment, $IPN);
546
+				}
547
+			}
548
+			// granular hook for others to use.
549
+			do_action($do_action, $transaction, $payment);
550
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
551
+			// global hook for others to use.
552
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
553
+		}
554
+	}
555
+
556
+
557
+	/**
558
+	 * update registrations REG_paid field after successful payment and link registrations with payment
559
+	 *
560
+	 * @param EE_Transaction    $transaction
561
+	 * @param EE_Payment        $payment
562
+	 * @param EE_Registration[] $registrations
563
+	 * @throws EE_Error
564
+	 * @throws InvalidArgumentException
565
+	 * @throws RuntimeException
566
+	 * @throws InvalidDataTypeException
567
+	 * @throws InvalidInterfaceException
568
+	 */
569
+	public function process_registration_payments(
570
+		EE_Transaction $transaction,
571
+		EE_Payment $payment,
572
+		array $registrations = array()
573
+	) {
574
+		// only process if payment was successful
575
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
576
+			return;
577
+		}
578
+		// EEM_Registration::instance()->show_next_x_db_queries();
579
+		if (empty($registrations)) {
580
+			// find registrations with monies owing that can receive a payment
581
+			$registrations = $transaction->registrations(
582
+				array(
583
+					array(
584
+						// only these reg statuses can receive payments
585
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
586
+						'REG_final_price'  => array('!=', 0),
587
+						'REG_final_price*' => array('!=', 'REG_paid', true),
588
+					),
589
+				)
590
+			);
591
+		}
592
+		// still nothing ??!??
593
+		if (empty($registrations)) {
594
+			return;
595
+		}
596
+		// todo: break out the following logic into a separate strategy class
597
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
598
+		// todo: which would apply payments using the capitalist "first come first paid" approach
599
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
600
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
601
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
602
+		$refund = $payment->is_a_refund();
603
+		// how much is available to apply to registrations?
604
+		$available_payment_amount = abs($payment->amount());
605
+		foreach ($registrations as $registration) {
606
+			if ($registration instanceof EE_Registration) {
607
+				// nothing left?
608
+				if ($available_payment_amount <= 0) {
609
+					break;
610
+				}
611
+				if ($refund) {
612
+					$available_payment_amount = $this->process_registration_refund(
613
+						$registration,
614
+						$payment,
615
+						$available_payment_amount
616
+					);
617
+				} else {
618
+					$available_payment_amount = $this->process_registration_payment(
619
+						$registration,
620
+						$payment,
621
+						$available_payment_amount
622
+					);
623
+				}
624
+			}
625
+		}
626
+		if ($available_payment_amount > 0
627
+			&& apply_filters(
628
+				'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications',
629
+				false
630
+			)) {
631
+			EE_Error::add_attention(
632
+				sprintf(
633
+					__(
634
+						'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
635
+						'event_espresso'
636
+					),
637
+					EEH_Template::format_currency($available_payment_amount),
638
+					implode(', ', array_keys($registrations)),
639
+					'<br/>',
640
+					EEH_Template::format_currency($payment->amount())
641
+				),
642
+				__FILE__,
643
+				__FUNCTION__,
644
+				__LINE__
645
+			);
646
+		}
647
+	}
648
+
649
+
650
+	/**
651
+	 * update registration REG_paid field after successful payment and link registration with payment
652
+	 *
653
+	 * @param EE_Registration $registration
654
+	 * @param EE_Payment      $payment
655
+	 * @param float           $available_payment_amount
656
+	 * @return float
657
+	 * @throws EE_Error
658
+	 * @throws InvalidArgumentException
659
+	 * @throws RuntimeException
660
+	 * @throws InvalidDataTypeException
661
+	 * @throws InvalidInterfaceException
662
+	 */
663
+	public function process_registration_payment(
664
+		EE_Registration $registration,
665
+		EE_Payment $payment,
666
+		$available_payment_amount = 0.00
667
+	) {
668
+		$owing = $registration->final_price() - $registration->paid();
669
+		if ($owing > 0) {
670
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
671
+			$payment_amount = min($available_payment_amount, $owing);
672
+			// update $available_payment_amount
673
+			$available_payment_amount -= $payment_amount;
674
+			// calculate and set new REG_paid
675
+			$registration->set_paid($registration->paid() + $payment_amount);
676
+			// now save it
677
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
678
+		}
679
+		return $available_payment_amount;
680
+	}
681
+
682
+
683
+	/**
684
+	 * update registration REG_paid field after successful payment and link registration with payment
685
+	 *
686
+	 * @param EE_Registration $registration
687
+	 * @param EE_Payment      $payment
688
+	 * @param float           $payment_amount
689
+	 * @return void
690
+	 * @throws EE_Error
691
+	 * @throws InvalidArgumentException
692
+	 * @throws InvalidDataTypeException
693
+	 * @throws InvalidInterfaceException
694
+	 */
695
+	protected function _apply_registration_payment(
696
+		EE_Registration $registration,
697
+		EE_Payment $payment,
698
+		$payment_amount = 0.00
699
+	) {
700
+		// find any existing reg payment records for this registration and payment
701
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
702
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
703
+		);
704
+		// if existing registration payment exists
705
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
706
+			// then update that record
707
+			$existing_reg_payment->set_amount($payment_amount);
708
+			$existing_reg_payment->save();
709
+		} else {
710
+			// or add new relation between registration and payment and set amount
711
+			$registration->_add_relation_to(
712
+				$payment,
713
+				'Payment',
714
+				array('RPY_amount' => $payment_amount)
715
+			);
716
+			// make it stick
717
+			$registration->save();
718
+		}
719
+	}
720
+
721
+
722
+	/**
723
+	 * update registration REG_paid field after refund and link registration with payment
724
+	 *
725
+	 * @param EE_Registration $registration
726
+	 * @param EE_Payment      $payment
727
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
728
+	 * @return float
729
+	 * @throws EE_Error
730
+	 * @throws InvalidArgumentException
731
+	 * @throws RuntimeException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 */
735
+	public function process_registration_refund(
736
+		EE_Registration $registration,
737
+		EE_Payment $payment,
738
+		$available_refund_amount = 0.00
739
+	) {
740
+		// EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
741
+		if ($registration->paid() > 0) {
742
+			// ensure $available_refund_amount is NOT negative
743
+			$available_refund_amount = (float) abs($available_refund_amount);
744
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
745
+			$refund_amount = min($available_refund_amount, (float) $registration->paid());
746
+			// update $available_payment_amount
747
+			$available_refund_amount -= $refund_amount;
748
+			// calculate and set new REG_paid
749
+			$registration->set_paid($registration->paid() - $refund_amount);
750
+			// convert payment amount back to a negative value for storage in the db
751
+			$refund_amount = (float) abs($refund_amount) * -1;
752
+			// now save it
753
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
754
+		}
755
+		return $available_refund_amount;
756
+	}
757
+
758
+
759
+	/**
760
+	 * Process payments and transaction after payment process completed.
761
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
762
+	 * if this request happens to be processing an IPN,
763
+	 * then we will also set the Payment Options Reg Step to completed,
764
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
765
+	 *
766
+	 * @param EE_Transaction $transaction
767
+	 * @param EE_Payment     $payment
768
+	 * @param bool           $IPN
769
+	 * @throws EE_Error
770
+	 * @throws InvalidArgumentException
771
+	 * @throws ReflectionException
772
+	 * @throws RuntimeException
773
+	 * @throws InvalidDataTypeException
774
+	 * @throws InvalidInterfaceException
775
+	 */
776
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
777
+	{
778
+		/** @type EE_Transaction_Processor $transaction_processor */
779
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
780
+		// is the Payment Options Reg Step completed ?
781
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
782
+		// if the Payment Options Reg Step is completed...
783
+		$revisit = $payment_options_step_completed === true;
784
+		// then this is kinda sorta a revisit with regards to payments at least
785
+		$transaction_processor->set_revisit($revisit);
786
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
787
+		if ($IPN
788
+			&& $payment_options_step_completed !== true
789
+			&& ($payment->is_approved() || $payment->is_pending())
790
+		) {
791
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
792
+				'payment_options'
793
+			);
794
+		}
795
+		// maybe update status, but don't save transaction just yet
796
+		$transaction->update_status_based_on_total_paid(false);
797
+		// check if 'finalize_registration' step has been completed...
798
+		$finalized = $transaction->reg_step_completed('finalize_registration');
799
+		//  if this is an IPN and the final step has not been initiated
800
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
801
+			// and if it hasn't already been set as being started...
802
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
803
+		}
804
+		$transaction->save();
805
+		// because the above will return false if the final step was not fully completed, we need to check again...
806
+		if ($IPN && $finalized !== false) {
807
+			// and if we are all good to go, then send out notifications
808
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
809
+			// ok, now process the transaction according to the payment
810
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
811
+				$transaction,
812
+				$payment
813
+			);
814
+		}
815
+		// DEBUG LOG
816
+		$payment_method = $payment->payment_method();
817
+		if ($payment_method instanceof EE_Payment_Method) {
818
+			$payment_method_type_obj = $payment_method->type_obj();
819
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
820
+				$gateway = $payment_method_type_obj->get_gateway();
821
+				if ($gateway instanceof EE_Gateway) {
822
+					$gateway->log(
823
+						array(
824
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
825
+							'transaction'           => $transaction->model_field_array(),
826
+							'finalized'             => $finalized,
827
+							'IPN'                   => $IPN,
828
+							'deliver_notifications' => has_filter(
829
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
830
+							),
831
+						),
832
+						$payment
833
+					);
834
+				}
835
+			}
836
+		}
837
+	}
838
+
839
+
840
+	/**
841
+	 * Force posts to PayPal to use TLS v1.2. See:
842
+	 * https://core.trac.wordpress.org/ticket/36320
843
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
844
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
845
+	 * This will affect PayPal standard, pro, express, and Payflow.
846
+	 *
847
+	 * @param $handle
848
+	 * @param $r
849
+	 * @param $url
850
+	 */
851
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
852
+	{
853
+		if (strpos($url, 'https://') !== false && strpos($url, '.paypal.com') !== false) {
854
+			// Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
855
+			// instead of the constant because it might not be defined
856
+			curl_setopt($handle, CURLOPT_SSLVERSION, 6);
857
+		}
858
+	}
859 859
 }
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 1 patch
Indentation   +1121 added lines, -1121 removed lines patch added patch discarded remove patch
@@ -37,31 +37,31 @@  discard block
 block discarded – undo
37 37
  * @param string $action_or_filter
38 38
  */
39 39
 function deprecated_espresso_action_or_filter_doing_it_wrong(
40
-    $deprecated_filter,
41
-    $replacement,
42
-    $replacement_location,
43
-    $version_deprecated,
44
-    $version_applies,
45
-    $action_or_filter = 'action'
40
+	$deprecated_filter,
41
+	$replacement,
42
+	$replacement_location,
43
+	$version_deprecated,
44
+	$version_applies,
45
+	$action_or_filter = 'action'
46 46
 ) {
47
-    $action_or_filter = $action_or_filter === 'action'
48
-        ? esc_html__('action', 'event_espresso')
49
-        : esc_html__('filter', 'event_espresso');
50
-    EE_Error::doing_it_wrong(
51
-        $deprecated_filter,
52
-        sprintf(
53
-            __(
54
-                'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
55
-                'event_espresso'
56
-            ),
57
-            $action_or_filter,
58
-            $replacement,
59
-            $replacement_location,
60
-            '<br />'
61
-        ),
62
-        $version_deprecated,
63
-        $version_applies
64
-    );
47
+	$action_or_filter = $action_or_filter === 'action'
48
+		? esc_html__('action', 'event_espresso')
49
+		: esc_html__('filter', 'event_espresso');
50
+	EE_Error::doing_it_wrong(
51
+		$deprecated_filter,
52
+		sprintf(
53
+			__(
54
+				'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
55
+				'event_espresso'
56
+			),
57
+			$action_or_filter,
58
+			$replacement,
59
+			$replacement_location,
60
+			'<br />'
61
+		),
62
+		$version_deprecated,
63
+		$version_applies
64
+	);
65 65
 }
66 66
 
67 67
 /**
@@ -73,90 +73,90 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout)
75 75
 {
76
-    // list of old filters
77
-    $deprecated_filters = array(
78
-        'update_registration_details' => true,
79
-        'process_payment'             => true,
80
-        'finalize_registration'       => true,
81
-        'and_proceed_to_payment'      => true,
82
-        'proceed_to'                  => true,
83
-    );
84
-    // loop thru and call doing_it_wrong() or remove any that aren't being used
85
-    foreach ($deprecated_filters as $deprecated_filter => $on) {
86
-        // was this filter called ?
87
-        if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
88
-            // only display doing_it_wrong() notice to Event Admins during non-AJAX requests
89
-            if (EE_Registry::instance()->CAP->current_user_can(
90
-                    'ee_read_ee',
91
-                    'hide_doing_it_wrong_for_deprecated_SPCO_filter'
92
-                ) && ! defined('DOING_AJAX')) {
93
-                EE_Error::doing_it_wrong(
94
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
95
-                    sprintf(
96
-                        __(
97
-                            'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
98
-                            'event_espresso'
99
-                        ),
100
-                        'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
101
-                        '<br />',
102
-                        'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
103
-                        '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
104
-                    ),
105
-                    '4.6.10'
106
-                );
107
-            }
108
-        } else {
109
-            unset($deprecated_filters[ $deprecated_filter ]);
110
-        }
111
-    }
112
-    if (! empty($deprecated_filters)) {
113
-
114
-        if ($checkout->current_step->slug(
115
-            ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
116
-            $submit_button_text = apply_filters(
117
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
118
-                $submit_button_text
119
-            );
120
-        } elseif ($checkout->current_step->slug(
121
-            ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
122
-            $submit_button_text = apply_filters(
123
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
124
-                $submit_button_text
125
-            );
126
-        } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
127
-            ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
128
-            $submit_button_text = apply_filters(
129
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
130
-                $submit_button_text
131
-            );
132
-        }
133
-        if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
134
-            if ($checkout->payment_required() && $checkout->next_step->slug(
135
-                ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
136
-                $submit_button_text .= apply_filters(
137
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
138
-                    $submit_button_text
139
-                );
140
-            }
141
-            if ($checkout->next_step->slug(
142
-                ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
143
-                $submit_button_text = apply_filters(
144
-                                          'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
145
-                                          $submit_button_text
146
-                                      ) . $checkout->next_step->name();
147
-            }
148
-        }
149
-
150
-    }
151
-    return $submit_button_text;
76
+	// list of old filters
77
+	$deprecated_filters = array(
78
+		'update_registration_details' => true,
79
+		'process_payment'             => true,
80
+		'finalize_registration'       => true,
81
+		'and_proceed_to_payment'      => true,
82
+		'proceed_to'                  => true,
83
+	);
84
+	// loop thru and call doing_it_wrong() or remove any that aren't being used
85
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
86
+		// was this filter called ?
87
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
88
+			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
89
+			if (EE_Registry::instance()->CAP->current_user_can(
90
+					'ee_read_ee',
91
+					'hide_doing_it_wrong_for_deprecated_SPCO_filter'
92
+				) && ! defined('DOING_AJAX')) {
93
+				EE_Error::doing_it_wrong(
94
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
95
+					sprintf(
96
+						__(
97
+							'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
98
+							'event_espresso'
99
+						),
100
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
101
+						'<br />',
102
+						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
103
+						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
104
+					),
105
+					'4.6.10'
106
+				);
107
+			}
108
+		} else {
109
+			unset($deprecated_filters[ $deprecated_filter ]);
110
+		}
111
+	}
112
+	if (! empty($deprecated_filters)) {
113
+
114
+		if ($checkout->current_step->slug(
115
+			) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
116
+			$submit_button_text = apply_filters(
117
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
118
+				$submit_button_text
119
+			);
120
+		} elseif ($checkout->current_step->slug(
121
+			) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
122
+			$submit_button_text = apply_filters(
123
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
124
+				$submit_button_text
125
+			);
126
+		} elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
127
+			) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
128
+			$submit_button_text = apply_filters(
129
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
130
+				$submit_button_text
131
+			);
132
+		}
133
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
134
+			if ($checkout->payment_required() && $checkout->next_step->slug(
135
+				) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
136
+				$submit_button_text .= apply_filters(
137
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
138
+					$submit_button_text
139
+				);
140
+			}
141
+			if ($checkout->next_step->slug(
142
+				) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
143
+				$submit_button_text = apply_filters(
144
+										  'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
145
+										  $submit_button_text
146
+									  ) . $checkout->next_step->name();
147
+			}
148
+		}
149
+
150
+	}
151
+	return $submit_button_text;
152 152
 
153 153
 }
154 154
 
155 155
 add_filter(
156
-    'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
157
-    'ee_deprecated__registration_checkout__button_text',
158
-    10,
159
-    2
156
+	'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
157
+	'ee_deprecated__registration_checkout__button_text',
158
+	10,
159
+	2
160 160
 );
161 161
 
162 162
 
@@ -168,54 +168,54 @@  discard block
 block discarded – undo
168 168
  */
169 169
 function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates)
170 170
 {
171
-    $action_ref = null;
172
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
173
-        ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
174
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
175
-        ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
176
-    if ($action_ref) {
177
-
178
-        EE_Error::doing_it_wrong(
179
-            $action_ref,
180
-            sprintf(
181
-                __(
182
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
183
-                    'event_espresso'
184
-                ),
185
-                '<br />',
186
-                '/core/business/EE_Transaction_Processor.class.php',
187
-                'AHEE__EE_Transaction_Processor__finalize',
188
-                'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
189
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
190
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
191
-            ),
192
-            '4.6.0'
193
-        );
194
-        switch ($action_ref) {
195
-            case 'AHEE__EE_Transaction__finalize__new_transaction' :
196
-                do_action(
197
-                    'AHEE__EE_Transaction__finalize__new_transaction',
198
-                    $checkout->transaction,
199
-                    $checkout->admin_request
200
-                );
201
-                break;
202
-            case 'AHEE__EE_Transaction__finalize__all_transaction' :
203
-                do_action(
204
-                    'AHEE__EE_Transaction__finalize__new_transaction',
205
-                    $checkout->transaction,
206
-                    array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
207
-                    $checkout->admin_request
208
-                );
209
-                break;
210
-        }
211
-    }
171
+	$action_ref = null;
172
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
173
+		? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
174
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
175
+		? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
176
+	if ($action_ref) {
177
+
178
+		EE_Error::doing_it_wrong(
179
+			$action_ref,
180
+			sprintf(
181
+				__(
182
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
183
+					'event_espresso'
184
+				),
185
+				'<br />',
186
+				'/core/business/EE_Transaction_Processor.class.php',
187
+				'AHEE__EE_Transaction_Processor__finalize',
188
+				'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
189
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
190
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
191
+			),
192
+			'4.6.0'
193
+		);
194
+		switch ($action_ref) {
195
+			case 'AHEE__EE_Transaction__finalize__new_transaction' :
196
+				do_action(
197
+					'AHEE__EE_Transaction__finalize__new_transaction',
198
+					$checkout->transaction,
199
+					$checkout->admin_request
200
+				);
201
+				break;
202
+			case 'AHEE__EE_Transaction__finalize__all_transaction' :
203
+				do_action(
204
+					'AHEE__EE_Transaction__finalize__new_transaction',
205
+					$checkout->transaction,
206
+					array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
207
+					$checkout->admin_request
208
+				);
209
+				break;
210
+		}
211
+	}
212 212
 }
213 213
 
214 214
 add_action(
215
-    'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
216
-    'ee_deprecated_finalize_transaction',
217
-    10,
218
-    2
215
+	'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
216
+	'ee_deprecated_finalize_transaction',
217
+	10,
218
+	2
219 219
 );
220 220
 /**
221 221
  * ee_deprecated_finalize_registration
@@ -224,35 +224,35 @@  discard block
 block discarded – undo
224 224
  */
225 225
 function ee_deprecated_finalize_registration(EE_Registration $registration)
226 226
 {
227
-    $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
228
-        ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
229
-    if ($action_ref) {
230
-        EE_Error::doing_it_wrong(
231
-            $action_ref,
232
-            sprintf(
233
-                __(
234
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
235
-                    'event_espresso'
236
-                ),
237
-                '<br />',
238
-                '/core/business/EE_Registration_Processor.class.php',
239
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
240
-            ),
241
-            '4.6.0'
242
-        );
243
-        do_action(
244
-            'AHEE__EE_Registration__finalize__update_and_new_reg',
245
-            $registration,
246
-            (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
247
-        );
248
-    }
227
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
228
+		? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
229
+	if ($action_ref) {
230
+		EE_Error::doing_it_wrong(
231
+			$action_ref,
232
+			sprintf(
233
+				__(
234
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
235
+					'event_espresso'
236
+				),
237
+				'<br />',
238
+				'/core/business/EE_Registration_Processor.class.php',
239
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
240
+			),
241
+			'4.6.0'
242
+		);
243
+		do_action(
244
+			'AHEE__EE_Registration__finalize__update_and_new_reg',
245
+			$registration,
246
+			(is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
247
+		);
248
+	}
249 249
 }
250 250
 
251 251
 add_action(
252
-    'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
253
-    'ee_deprecated_finalize_registration',
254
-    10,
255
-    1
252
+	'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
253
+	'ee_deprecated_finalize_registration',
254
+	10,
255
+	1
256 256
 );
257 257
 
258 258
 
@@ -262,44 +262,44 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function ee_deprecated_hooks()
264 264
 {
265
-    /**
266
-     * @var          $hooks       array where keys are hook names, and their values are array{
267
-     * @type string  $version     when deprecated
268
-     * @type string  $alternative saying what to use instead
269
-     * @type boolean $still_works whether or not the hook still works
270
-     *        }
271
-     */
272
-    $hooks = array(
273
-        'AHEE__EE_System___do_setup_validations' => array(
274
-            'version'     => '4.6.0',
275
-            'alternative' => __(
276
-                'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
277
-                'event_espresso'
278
-            ),
279
-            'still_works' => false,
280
-        ),
281
-    );
282
-    foreach ($hooks as $name => $deprecation_info) {
283
-        if (has_action($name)) {
284
-            EE_Error::doing_it_wrong(
285
-                $name,
286
-                sprintf(
287
-                    __('This filter is deprecated. %1$s%2$s', 'event_espresso'),
288
-                    $deprecation_info['still_works'] ? __(
289
-                        'It *may* work as an attempt to build in backwards compatibility.',
290
-                        'event_espresso'
291
-                    ) : __('It has been completely removed.', 'event_espresso'),
292
-                    isset($deprecation_info['alternative'])
293
-                        ? $deprecation_info['alternative']
294
-                        : __(
295
-                        'Please read the current EE4 documentation further or contact Support.',
296
-                        'event_espresso'
297
-                    )
298
-                ),
299
-                isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
300
-            );
301
-        }
302
-    }
265
+	/**
266
+	 * @var          $hooks       array where keys are hook names, and their values are array{
267
+	 * @type string  $version     when deprecated
268
+	 * @type string  $alternative saying what to use instead
269
+	 * @type boolean $still_works whether or not the hook still works
270
+	 *        }
271
+	 */
272
+	$hooks = array(
273
+		'AHEE__EE_System___do_setup_validations' => array(
274
+			'version'     => '4.6.0',
275
+			'alternative' => __(
276
+				'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
277
+				'event_espresso'
278
+			),
279
+			'still_works' => false,
280
+		),
281
+	);
282
+	foreach ($hooks as $name => $deprecation_info) {
283
+		if (has_action($name)) {
284
+			EE_Error::doing_it_wrong(
285
+				$name,
286
+				sprintf(
287
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
288
+					$deprecation_info['still_works'] ? __(
289
+						'It *may* work as an attempt to build in backwards compatibility.',
290
+						'event_espresso'
291
+					) : __('It has been completely removed.', 'event_espresso'),
292
+					isset($deprecation_info['alternative'])
293
+						? $deprecation_info['alternative']
294
+						: __(
295
+						'Please read the current EE4 documentation further or contact Support.',
296
+						'event_espresso'
297
+					)
298
+				),
299
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
300
+			);
301
+		}
302
+	}
303 303
 }
304 304
 
305 305
 add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
@@ -314,34 +314,34 @@  discard block
 block discarded – undo
314 314
  */
315 315
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
316 316
 {
317
-    $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
318
-              || has_action(
319
-                  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
320
-              );
321
-    if ($in_use) {
322
-        $msg = __(
323
-            'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
324
-            . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
325
-            . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
326
-            . 'to add other actions after a form submission has been received.',
327
-            'event_espresso'
328
-        );
329
-        EE_Error::doing_it_wrong(
330
-            __CLASS__ . '::' . __FUNCTION__,
331
-            $msg,
332
-            '4.8.32.rc.000'
333
-        );
334
-        // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
335
-        if (is_admin() && ! defined('DOING_AJAX')) {
336
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
337
-        }
338
-    }
339
-    return $in_use;
317
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
318
+			  || has_action(
319
+				  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
320
+			  );
321
+	if ($in_use) {
322
+		$msg = __(
323
+			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
324
+			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
325
+			. 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
326
+			. 'to add other actions after a form submission has been received.',
327
+			'event_espresso'
328
+		);
329
+		EE_Error::doing_it_wrong(
330
+			__CLASS__ . '::' . __FUNCTION__,
331
+			$msg,
332
+			'4.8.32.rc.000'
333
+		);
334
+		// it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
335
+		if (is_admin() && ! defined('DOING_AJAX')) {
336
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
337
+		}
338
+	}
339
+	return $in_use;
340 340
 }
341 341
 
342 342
 add_action(
343
-    'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
344
-    'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
343
+	'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
344
+	'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
345 345
 );
346 346
 
347 347
 /**
@@ -353,77 +353,77 @@  discard block
 block discarded – undo
353 353
  */
354 354
 function ee_deprecated_update_attendee_registration_form_old($admin_page)
355 355
 {
356
-    // check if the old hooks are in use. If not, do the default
357
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
358
-        || ! $admin_page instanceof EE_Admin_Page) {
359
-        return;
360
-    }
361
-    $req_data = $admin_page->get_request_data();
362
-    $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
363
-    $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
364
-    $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
365
-    if (! $REG_ID || ! $qstns) {
366
-        EE_Error::add_error(
367
-            __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
368
-            __FILE__,
369
-            __FUNCTION__,
370
-            __LINE__
371
-        );
372
-    }
373
-    $success = true;
374
-
375
-    // allow others to get in on this awesome fun   :D
376
-    do_action(
377
-        'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
378
-        $REG_ID,
379
-        $qstns
380
-    );
381
-    // loop thru questions... FINALLY!!!
382
-
383
-    foreach ($qstns as $QST_ID => $qstn) {
384
-        // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
385
-        if (! is_array($qstn)) {
386
-            $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
387
-            continue;
388
-        }
389
-
390
-
391
-        foreach ($qstn as $ANS_ID => $ANS_value) {
392
-            // get answer
393
-            $query_params = array(
394
-                0 => array(
395
-                    'ANS_ID' => $ANS_ID,
396
-                    'REG_ID' => $REG_ID,
397
-                    'QST_ID' => $QST_ID,
398
-                ),
399
-            );
400
-            $answer = EEM_Answer::instance()->get_one($query_params);
401
-            // this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
402
-            if (! $answer instanceof EE_Answer) {
403
-                $set_values = array(
404
-                    'QST_ID'    => $QST_ID,
405
-                    'REG_ID'    => $REG_ID,
406
-                    'ANS_value' => $qstn,
407
-                );
408
-                $success = EEM_Answer::instance()->insert($set_values);
409
-                continue 2;
410
-            }
411
-
412
-            $answer->set('ANS_value', $ANS_value);
413
-            $success = $answer->save();
414
-        }
415
-    }
416
-    $what = __('Registration Form', 'event_espresso');
417
-    $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
418
-    $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
419
-    exit;
356
+	// check if the old hooks are in use. If not, do the default
357
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
358
+		|| ! $admin_page instanceof EE_Admin_Page) {
359
+		return;
360
+	}
361
+	$req_data = $admin_page->get_request_data();
362
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
363
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
364
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
365
+	if (! $REG_ID || ! $qstns) {
366
+		EE_Error::add_error(
367
+			__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
368
+			__FILE__,
369
+			__FUNCTION__,
370
+			__LINE__
371
+		);
372
+	}
373
+	$success = true;
374
+
375
+	// allow others to get in on this awesome fun   :D
376
+	do_action(
377
+		'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
378
+		$REG_ID,
379
+		$qstns
380
+	);
381
+	// loop thru questions... FINALLY!!!
382
+
383
+	foreach ($qstns as $QST_ID => $qstn) {
384
+		// if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
385
+		if (! is_array($qstn)) {
386
+			$success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
387
+			continue;
388
+		}
389
+
390
+
391
+		foreach ($qstn as $ANS_ID => $ANS_value) {
392
+			// get answer
393
+			$query_params = array(
394
+				0 => array(
395
+					'ANS_ID' => $ANS_ID,
396
+					'REG_ID' => $REG_ID,
397
+					'QST_ID' => $QST_ID,
398
+				),
399
+			);
400
+			$answer = EEM_Answer::instance()->get_one($query_params);
401
+			// this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
402
+			if (! $answer instanceof EE_Answer) {
403
+				$set_values = array(
404
+					'QST_ID'    => $QST_ID,
405
+					'REG_ID'    => $REG_ID,
406
+					'ANS_value' => $qstn,
407
+				);
408
+				$success = EEM_Answer::instance()->insert($set_values);
409
+				continue 2;
410
+			}
411
+
412
+			$answer->set('ANS_value', $ANS_value);
413
+			$success = $answer->save();
414
+		}
415
+	}
416
+	$what = __('Registration Form', 'event_espresso');
417
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
418
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
419
+	exit;
420 420
 }
421 421
 
422 422
 add_action(
423
-    'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
424
-    'ee_deprecated_update_attendee_registration_form_old',
425
-    10,
426
-    1
423
+	'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
424
+	'ee_deprecated_update_attendee_registration_form_old',
425
+	10,
426
+	1
427 427
 );
428 428
 /**
429 429
  * Render the registration admin page's custom questions area in the old fashion
@@ -439,50 +439,50 @@  discard block
 block discarded – undo
439 439
  */
440 440
 function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration)
441 441
 {
442
-    // check if the old hooks are in use. If not, do the default
443
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
444
-        || ! $admin_page instanceof EE_Admin_Page) {
445
-        return $do_default_action;
446
-    }
447
-    add_filter(
448
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
449
-        array($admin_page, 'form_before_question_group'),
450
-        10,
451
-        1
452
-    );
453
-    add_filter(
454
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
455
-        array($admin_page, 'form_after_question_group'),
456
-        10,
457
-        1
458
-    );
459
-    add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
460
-    add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
461
-
462
-    $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
463
-        $registration,
464
-        $registration->get(
465
-            'EVT_ID'
466
-        )
467
-    );
468
-
469
-    EE_Registry::instance()->load_helper('Form_Fields');
470
-    $template_args = array(
471
-        'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
472
-        'reg_questions_form_action' => 'edit_registration',
473
-        'REG_ID'                    => $registration->ID(),
474
-    );
475
-    $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
476
-    echo EEH_Template::display_template($template_path, $template_args, true);
477
-    // indicate that we should not do the default admin page code
478
-    return false;
442
+	// check if the old hooks are in use. If not, do the default
443
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
444
+		|| ! $admin_page instanceof EE_Admin_Page) {
445
+		return $do_default_action;
446
+	}
447
+	add_filter(
448
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
449
+		array($admin_page, 'form_before_question_group'),
450
+		10,
451
+		1
452
+	);
453
+	add_filter(
454
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
455
+		array($admin_page, 'form_after_question_group'),
456
+		10,
457
+		1
458
+	);
459
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
460
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
461
+
462
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
463
+		$registration,
464
+		$registration->get(
465
+			'EVT_ID'
466
+		)
467
+	);
468
+
469
+	EE_Registry::instance()->load_helper('Form_Fields');
470
+	$template_args = array(
471
+		'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
472
+		'reg_questions_form_action' => 'edit_registration',
473
+		'REG_ID'                    => $registration->ID(),
474
+	);
475
+	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
476
+	echo EEH_Template::display_template($template_path, $template_args, true);
477
+	// indicate that we should not do the default admin page code
478
+	return false;
479 479
 }
480 480
 
481 481
 add_action(
482
-    'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
483
-    'ee_deprecated_reg_questions_meta_box_old',
484
-    10,
485
-    3
482
+	'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
483
+	'ee_deprecated_reg_questions_meta_box_old',
484
+	10,
485
+	3
486 486
 );
487 487
 
488 488
 
@@ -499,42 +499,42 @@  discard block
 block discarded – undo
499 499
 class EE_Message_Template_Defaults extends EE_Base
500 500
 {
501 501
 
502
-    /**
503
-     * EE_Message_Template_Defaults constructor.
504
-     *
505
-     * @param EE_messages $messages
506
-     * @param             $messenger_name
507
-     * @param             $message_type_name
508
-     * @param int         $GRP_ID
509
-     * @return EE_Messages_Template_Defaults
510
-     */
511
-    public function __construct(
512
-        EE_messages $messages,
513
-        $messenger_name,
514
-        $message_type_name,
515
-        $GRP_ID = 0
516
-    ) {
517
-        EE_Error::doing_it_wrong(
518
-            __FUNCTION__,
519
-            __(
520
-                'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
521
-                'event_espresso'
522
-            ),
523
-            '4.9.0'
524
-        );
525
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
526
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
527
-        $messenger = $message_resource_manager->get_messenger($messenger_name);
528
-        $message_type = $message_resource_manager->get_message_type($message_type_name);
529
-        return EE_Registry::instance()->load_lib(
530
-            'Messages_Template_Defaults',
531
-            array(
532
-                $GRP_ID,
533
-                $messenger,
534
-                $message_type,
535
-            )
536
-        );
537
-    }
502
+	/**
503
+	 * EE_Message_Template_Defaults constructor.
504
+	 *
505
+	 * @param EE_messages $messages
506
+	 * @param             $messenger_name
507
+	 * @param             $message_type_name
508
+	 * @param int         $GRP_ID
509
+	 * @return EE_Messages_Template_Defaults
510
+	 */
511
+	public function __construct(
512
+		EE_messages $messages,
513
+		$messenger_name,
514
+		$message_type_name,
515
+		$GRP_ID = 0
516
+	) {
517
+		EE_Error::doing_it_wrong(
518
+			__FUNCTION__,
519
+			__(
520
+				'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
521
+				'event_espresso'
522
+			),
523
+			'4.9.0'
524
+		);
525
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
526
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
527
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
528
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
529
+		return EE_Registry::instance()->load_lib(
530
+			'Messages_Template_Defaults',
531
+			array(
532
+				$GRP_ID,
533
+				$messenger,
534
+				$message_type,
535
+			)
536
+		);
537
+	}
538 538
 }
539 539
 
540 540
 
@@ -552,525 +552,525 @@  discard block
 block discarded – undo
552 552
 class EE_messages
553 553
 {
554 554
 
555
-    /** @type EE_messenger[] */
556
-    protected $_active_messengers = array();
557
-
558
-    /** @type array */
559
-    protected $_active_message_types = array();
560
-
561
-    /** @type EE_message_type[] */
562
-    protected $_installed_message_types = array();
563
-
564
-    /** @type EE_messenger */
565
-    protected $_messenger;
566
-
567
-    /** @type EE_message_type */
568
-    protected $_message_type;
569
-
570
-    /** @type array */
571
-    protected $_contexts = array();
572
-
573
-    /** @type EE_Message_Resource_Manager $_message_resource_manager */
574
-    protected $_message_resource_manager;
575
-
576
-
577
-    /**
578
-     * EE_messages constructor.
579
-     *
580
-     * @deprecated 4.9.0
581
-     */
582
-    public function __construct()
583
-    {
584
-    }
585
-
586
-
587
-    /**
588
-     * @param string $method
589
-     */
590
-    public function _class_is_deprecated($method)
591
-    {
592
-        EE_Error::doing_it_wrong(
593
-            'EE_messages::' . $method,
594
-            __('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
595
-            '4.9.0',
596
-            '4.10.0.p'
597
-        );
598
-        // Please use EE_Message_Resource_Manager instead
599
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
600
-    }
601
-
602
-
603
-    /**
604
-     * @deprecated 4.9.0
605
-     * @param string $messenger_name
606
-     * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
607
-     */
608
-    public function ensure_messenger_is_active($messenger_name)
609
-    {
610
-        // EE_messages has been deprecated
611
-        $this->_class_is_deprecated(__FUNCTION__);
612
-        return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
613
-    }
614
-
615
-
616
-    /**
617
-     * @deprecated 4.9.0
618
-     * @param string $message_type message type name
619
-     * @param        $messenger
620
-     * @return bool true if it got activated (or was active) and false if not.
621
-     * @throws \EE_Error
622
-     */
623
-    public function ensure_message_type_is_active($message_type, $messenger)
624
-    {
625
-        // EE_messages has been deprecated
626
-        $this->_class_is_deprecated(__FUNCTION__);
627
-        return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
628
-    }
629
-
630
-
631
-    /**
632
-     * @deprecated 4.9.0
633
-     * @param string $messenger_name
634
-     * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
635
-     *                                             If included we do NOT setup the default message types (assuming they
636
-     *                                             are already setup.)
637
-     * @return boolean an array of generated templates or false if nothing generated/activated.
638
-     */
639
-    public function activate_messenger($messenger_name, $mts_to_activate = array())
640
-    {
641
-        // EE_messages has been deprecated
642
-        $this->_class_is_deprecated(__FUNCTION__);
643
-        return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
644
-    }
645
-
646
-
647
-    /**
648
-     * @deprecated 4.9.0
649
-     * @param EE_messenger    $messenger    messenger used in trigger
650
-     * @param EE_message_type $message_type message type used in trigger
651
-     *
652
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
653
-     */
654
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
655
-    {
656
-        // EE_messages has been deprecated
657
-        $this->_class_is_deprecated(__FUNCTION__);
658
-        return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
659
-    }
660
-
661
-
662
-    /**
663
-     * @deprecated 4.9.0
664
-     * @param string $messenger
665
-     * @return EE_messenger | null
666
-     */
667
-    public function get_messenger_if_active($messenger)
668
-    {
669
-        // EE_messages has been deprecated
670
-        $this->_class_is_deprecated(__FUNCTION__);
671
-        return $this->_message_resource_manager->get_active_messenger($messenger);
672
-    }
673
-
674
-
675
-    /**
676
-     * @deprecated 4.9.0
677
-     * @param EE_Message $message
678
-     * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
679
-     *                  available.
680
-     *                  Eg. Valid Messenger and Message Type:
681
-     *                  array(
682
-     *                  'messenger' => new EE_Email_messenger(),
683
-     *                  'message_type' => new EE_Registration_Approved_message_type()
684
-     *                  )
685
-     *                  Valid Messenger and Invalid Message Type:
686
-     *                  array(
687
-     *                  'messenger' => new EE_Email_messenger(),
688
-     *                  'message_type' => null
689
-     *                  )
690
-     */
691
-    public function validate_for_use(EE_Message $message)
692
-    {
693
-        // EE_messages has been deprecated
694
-        $this->_class_is_deprecated(__FUNCTION__);
695
-        return array(
696
-            'messenger'    => $message->messenger_object(),
697
-            'message_type' => $message->message_type_object(),
698
-        );
699
-    }
700
-
701
-
702
-    /**
703
-     * @deprecated 4.9.0
704
-     * @param  string $type                 What type of message are we sending (corresponds to message types)
705
-     * @param  mixed  $vars                 Data being sent for parsing in the message
706
-     * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
707
-     *                                      Otherwise we cycle through all active messengers.
708
-     * @param string  $generating_messenger if included then this messenger is used for generating the message
709
-     *                                      templates (but not for sending).
710
-     * @param string  $context              If included then only a message type for a specific context will be
711
-     *                                      generated.
712
-     * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
713
-     *                                      EE_messages objects which might be used by the trigger to setup a batch
714
-     *                                      message (typically html messenger uses it).
715
-     * @return bool
716
-     */
717
-    public function send_message(
718
-        $type,
719
-        $vars,
720
-        $sending_messenger = '',
721
-        $generating_messenger = '',
722
-        $context = '',
723
-        $send = true
724
-    ) {
725
-        // EE_messages has been deprecated
726
-        $this->_class_is_deprecated(__FUNCTION__);
727
-        /** @type EE_Messages_Processor $processor */
728
-        $processor = EE_Registry::instance()->load_lib('Messages_Processor');
729
-        $error = false;
730
-        // try to intelligently determine what method we'll call based on the incoming data.
731
-        // if generating and sending are different then generate and send immediately.
732
-        if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
733
-            // in the legacy system, when generating and sending were different, that means all the
734
-            // vars are already in the request object.  So let's just use that.
735
-            try {
736
-                /** @type EE_Message_To_Generate_From_Request $mtg */
737
-                $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
738
-                $processor->generate_and_send_now($mtg);
739
-            } catch (EE_Error $e) {
740
-                $error_msg = __(
741
-                    'Please note that a system message failed to send due to a technical issue.',
742
-                    'event_espresso'
743
-                );
744
-                // add specific message for developers if WP_DEBUG in on
745
-                $error_msg .= '||' . $e->getMessage();
746
-                EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
747
-                $error = true;
748
-            }
749
-        } else {
750
-            $processor->generate_for_all_active_messengers($type, $vars, $send);
751
-            // let's find out if there were any errors and how many successfully were queued.
752
-            $count_errors = $processor->get_queue()->count_STS_in_queue(
753
-                array(EEM_Message::status_failed, EEM_Message::status_debug_only)
754
-            );
755
-            $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
756
-            $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
757
-            $count_errors = $count_errors + $count_retry;
758
-            if ($count_errors > 0) {
759
-                $error = true;
760
-                if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
761
-                    $message = sprintf(
762
-                        __(
763
-                            'There were %d errors and %d messages successfully queued for generation and sending',
764
-                            'event_espresso'
765
-                        ),
766
-                        $count_errors,
767
-                        $count_queued
768
-                    );
769
-                } elseif ($count_errors > 1 && $count_queued === 1) {
770
-                    $message = sprintf(
771
-                        __(
772
-                            'There were %d errors and %d message successfully queued for generation.',
773
-                            'event_espresso'
774
-                        ),
775
-                        $count_errors,
776
-                        $count_queued
777
-                    );
778
-                } elseif ($count_errors === 1 && $count_queued > 1) {
779
-                    $message = sprintf(
780
-                        __(
781
-                            'There was %d error and %d messages successfully queued for generation.',
782
-                            'event_espresso'
783
-                        ),
784
-                        $count_errors,
785
-                        $count_queued
786
-                    );
787
-                } else {
788
-                    $message = sprintf(
789
-                        __(
790
-                            'There was %d message that failed to be queued for generation.',
791
-                            'event_espresso'
792
-                        ),
793
-                        $count_errors
794
-                    );
795
-                }
796
-                EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
797
-            } else {
798
-                if ($count_queued === 1) {
799
-                    $message = sprintf(
800
-                        __(
801
-                            '%d message successfully queued for generation.',
802
-                            'event_espresso'
803
-                        ),
804
-                        $count_queued
805
-                    );
806
-                } else {
807
-                    $message = sprintf(
808
-                        __(
809
-                            '%d messages were successfully queued for generation.',
810
-                            'event_espresso'
811
-                        ),
812
-                        $count_queued
813
-                    );
814
-                }
815
-                EE_Error::add_success($message);
816
-            }
817
-        }
818
-        // if no error then return the generated message(s).
819
-        if (! $error && ! $send) {
820
-            $generated_queue = $processor->generate_queue(false);
821
-            // get message and return.
822
-            $generated_queue->get_message_repository()->rewind();
823
-            $messages = array();
824
-            while ($generated_queue->get_message_repository()->valid()) {
825
-                $message = $generated_queue->get_message_repository()->current();
826
-                if ($message instanceof EE_Message) {
827
-                    // set properties that might be expected by add-ons (backward compat)
828
-                    $message->content = $message->content();
829
-                    $message->template_pack = $message->get_template_pack();
830
-                    $message->template_variation = $message->get_template_pack_variation();
831
-                    $messages[] = $message;
832
-                }
833
-                $generated_queue->get_message_repository()->next();
834
-            }
835
-            return $messages;
836
-        }
837
-        return $error ? false
838
-            : true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
839
-    }
840
-
841
-
842
-    /**
843
-     * @deprecated 4.9.0
844
-     * @param  string $type      This should correspond with a valid message type
845
-     * @param  string $context   This should correspond with a valid context for the message type
846
-     * @param  string $messenger This should correspond with a valid messenger.
847
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
848
-     *                           preview
849
-     * @return string          The body of the message.
850
-     */
851
-    public function preview_message($type, $context, $messenger, $send = false)
852
-    {
853
-        // EE_messages has been deprecated
854
-        $this->_class_is_deprecated(__FUNCTION__);
855
-        return EED_Messages::preview_message($type, $context, $messenger, $send);
856
-    }
857
-
858
-
859
-    /**
860
-     * @since      4.5.0
861
-     * @deprecated 4.9.0   Moved to EED_Messages Module
862
-     * @param string   $messenger    a string matching a valid active messenger in the system
863
-     * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
864
-     *                               required to send along the message type to the messenger because this is used for
865
-     *                               determining what specific variations might be loaded for the generated message.
866
-     * @param stdClass $message      a stdClass object in the format expected by the messenger.
867
-     *
868
-     * @return bool          success or fail.
869
-     */
870
-    public function send_message_with_messenger_only($messenger, $message_type, $message)
871
-    {
872
-        // EE_messages has been deprecated
873
-        $this->_class_is_deprecated(__FUNCTION__);
874
-        // setup for sending to new method.
875
-        /** @type EE_Messages_Queue $queue */
876
-        $queue = EE_Registry::instance()->load_lib('Messages_Queue');
877
-        // make sure we have a proper message object
878
-        if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
879
-            $msg = EE_Message_Factory::create(
880
-                array(
881
-                    'MSG_messenger'    => $messenger,
882
-                    'MSG_message_type' => $message_type,
883
-                    'MSG_content'      => $message->content,
884
-                    'MSG_subject'      => $message->subject,
885
-                )
886
-            );
887
-        } else {
888
-            $msg = $message;
889
-        }
890
-        if (! $msg instanceof EE_Message) {
891
-            return false;
892
-        }
893
-        // make sure any content in a content property (if not empty) is set on the MSG_content.
894
-        if (! empty($msg->content)) {
895
-            $msg->set('MSG_content', $msg->content);
896
-        }
897
-        $queue->add($msg);
898
-        return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
899
-    }
900
-
901
-
902
-    /**
903
-     * @deprecated 4.9.0
904
-     * @param         $messenger
905
-     * @param  string $message_type message type that the templates are being created for
906
-     * @param int     $GRP_ID
907
-     * @param bool    $is_global
908
-     * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
909
-     *                      returned.
910
-     * @throws \EE_Error
911
-     */
912
-    public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
913
-    {
914
-        // EE_messages has been deprecated
915
-        $this->_class_is_deprecated(__FUNCTION__);
916
-        EE_Registry::instance()->load_helper('MSG_Template');
917
-        return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
918
-    }
919
-
920
-
921
-    /**
922
-     * @deprecated 4.9.0
923
-     * @param  string $messenger_name    name of EE_messenger
924
-     * @param  string $message_type_name name of EE_message_type
925
-     * @return array
926
-     */
927
-    public function get_fields($messenger_name, $message_type_name)
928
-    {
929
-        // EE_messages has been deprecated
930
-        $this->_class_is_deprecated(__FUNCTION__);
931
-        EE_Registry::instance()->load_helper('MSG_Template');
932
-        return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
933
-    }
934
-
935
-
936
-    /**
937
-     * @deprecated 4.9.0
938
-     * @access     public
939
-     * @param string $type                we can indicate just returning installed message types
940
-     *                                    or messengers (or both) via this parameter.
941
-     * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
942
-     * @return array                    multidimensional array of messenger and message_type objects
943
-     *                                    (messengers index, and message_type index);
944
-     */
945
-    public function get_installed($type = 'all', $skip_cache = false)
946
-    {
947
-        // EE_messages has been deprecated
948
-        $this->_class_is_deprecated(__FUNCTION__);
949
-        if ($skip_cache) {
950
-            $this->_message_resource_manager->reset_active_messengers_and_message_types();
951
-        }
952
-        switch ($type) {
953
-            case 'messengers' :
954
-                return array(
955
-                    'messenger' => $this->_message_resource_manager->installed_messengers(),
956
-                );
957
-                break;
958
-            case 'message_types' :
959
-                return array(
960
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
961
-                );
962
-                break;
963
-            case 'all' :
964
-            default :
965
-                return array(
966
-                    'messenger'    => $this->_message_resource_manager->installed_messengers(),
967
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
968
-                );
969
-                break;
970
-        }
971
-    }
972
-
973
-
974
-    /**
975
-     * @deprecated 4.9.0
976
-     * @return \EE_messenger[]
977
-     */
978
-    public function get_active_messengers()
979
-    {
980
-        // EE_messages has been deprecated
981
-        $this->_class_is_deprecated(__FUNCTION__);
982
-        return $this->_message_resource_manager->active_messengers();
983
-    }
984
-
985
-
986
-    /**
987
-     * @deprecated 4.9.0
988
-     * @return array array of message_type references (string)
989
-     */
990
-    public function get_active_message_types()
991
-    {
992
-        // EE_messages has been deprecated
993
-        $this->_class_is_deprecated(__FUNCTION__);
994
-        return $this->_message_resource_manager->list_of_active_message_types();
995
-    }
996
-
997
-
998
-    /**
999
-     * @deprecated 4.9.0
1000
-     * @return EE_message_type[]
1001
-     */
1002
-    public function get_active_message_type_objects()
1003
-    {
1004
-        // EE_messages has been deprecated
1005
-        $this->_class_is_deprecated(__FUNCTION__);
1006
-        return $this->_message_resource_manager->get_active_message_type_objects();
1007
-    }
1008
-
1009
-
1010
-    /**
1011
-     * @deprecated 4.9.0
1012
-     * @since      4.5.0
1013
-     * @param string $messenger The messenger being checked
1014
-     * @return EE_message_type[]    (or empty array if none present)
1015
-     */
1016
-    public function get_active_message_types_per_messenger($messenger)
1017
-    {
1018
-        // EE_messages has been deprecated
1019
-        $this->_class_is_deprecated(__FUNCTION__);
1020
-        return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * @deprecated 4.9.0
1026
-     * @param string $messenger    The string should correspond to the messenger (message types are
1027
-     * @param string $message_type The string should correspond to a message type.
1028
-     * @return EE_message_type|null
1029
-     */
1030
-    public function get_active_message_type($messenger, $message_type)
1031
-    {
1032
-        // EE_messages has been deprecated
1033
-        $this->_class_is_deprecated(__FUNCTION__);
1034
-        return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * @deprecated 4.9.0
1040
-     * @return array|\EE_message_type[]
1041
-     */
1042
-    public function get_installed_message_types()
1043
-    {
1044
-        // EE_messages has been deprecated
1045
-        $this->_class_is_deprecated(__FUNCTION__);
1046
-        return $this->_message_resource_manager->installed_message_types();
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * @deprecated 4.9.0
1052
-     * @return array
1053
-     */
1054
-    public function get_installed_messengers()
1055
-    {
1056
-        // EE_messages has been deprecated
1057
-        $this->_class_is_deprecated(__FUNCTION__);
1058
-        return $this->_message_resource_manager->installed_messengers();
1059
-    }
1060
-
1061
-
1062
-    /**
1063
-     * @deprecated 4.9.0
1064
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1065
-     *                           message type.
1066
-     * @return array
1067
-     */
1068
-    public function get_all_contexts($slugs_only = true)
1069
-    {
1070
-        // EE_messages has been deprecated
1071
-        $this->_class_is_deprecated(__FUNCTION__);
1072
-        return $this->_message_resource_manager->get_all_contexts($slugs_only);
1073
-    }
555
+	/** @type EE_messenger[] */
556
+	protected $_active_messengers = array();
557
+
558
+	/** @type array */
559
+	protected $_active_message_types = array();
560
+
561
+	/** @type EE_message_type[] */
562
+	protected $_installed_message_types = array();
563
+
564
+	/** @type EE_messenger */
565
+	protected $_messenger;
566
+
567
+	/** @type EE_message_type */
568
+	protected $_message_type;
569
+
570
+	/** @type array */
571
+	protected $_contexts = array();
572
+
573
+	/** @type EE_Message_Resource_Manager $_message_resource_manager */
574
+	protected $_message_resource_manager;
575
+
576
+
577
+	/**
578
+	 * EE_messages constructor.
579
+	 *
580
+	 * @deprecated 4.9.0
581
+	 */
582
+	public function __construct()
583
+	{
584
+	}
585
+
586
+
587
+	/**
588
+	 * @param string $method
589
+	 */
590
+	public function _class_is_deprecated($method)
591
+	{
592
+		EE_Error::doing_it_wrong(
593
+			'EE_messages::' . $method,
594
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
595
+			'4.9.0',
596
+			'4.10.0.p'
597
+		);
598
+		// Please use EE_Message_Resource_Manager instead
599
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
600
+	}
601
+
602
+
603
+	/**
604
+	 * @deprecated 4.9.0
605
+	 * @param string $messenger_name
606
+	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
607
+	 */
608
+	public function ensure_messenger_is_active($messenger_name)
609
+	{
610
+		// EE_messages has been deprecated
611
+		$this->_class_is_deprecated(__FUNCTION__);
612
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @deprecated 4.9.0
618
+	 * @param string $message_type message type name
619
+	 * @param        $messenger
620
+	 * @return bool true if it got activated (or was active) and false if not.
621
+	 * @throws \EE_Error
622
+	 */
623
+	public function ensure_message_type_is_active($message_type, $messenger)
624
+	{
625
+		// EE_messages has been deprecated
626
+		$this->_class_is_deprecated(__FUNCTION__);
627
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
628
+	}
629
+
630
+
631
+	/**
632
+	 * @deprecated 4.9.0
633
+	 * @param string $messenger_name
634
+	 * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
635
+	 *                                             If included we do NOT setup the default message types (assuming they
636
+	 *                                             are already setup.)
637
+	 * @return boolean an array of generated templates or false if nothing generated/activated.
638
+	 */
639
+	public function activate_messenger($messenger_name, $mts_to_activate = array())
640
+	{
641
+		// EE_messages has been deprecated
642
+		$this->_class_is_deprecated(__FUNCTION__);
643
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
644
+	}
645
+
646
+
647
+	/**
648
+	 * @deprecated 4.9.0
649
+	 * @param EE_messenger    $messenger    messenger used in trigger
650
+	 * @param EE_message_type $message_type message type used in trigger
651
+	 *
652
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
653
+	 */
654
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
655
+	{
656
+		// EE_messages has been deprecated
657
+		$this->_class_is_deprecated(__FUNCTION__);
658
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
659
+	}
660
+
661
+
662
+	/**
663
+	 * @deprecated 4.9.0
664
+	 * @param string $messenger
665
+	 * @return EE_messenger | null
666
+	 */
667
+	public function get_messenger_if_active($messenger)
668
+	{
669
+		// EE_messages has been deprecated
670
+		$this->_class_is_deprecated(__FUNCTION__);
671
+		return $this->_message_resource_manager->get_active_messenger($messenger);
672
+	}
673
+
674
+
675
+	/**
676
+	 * @deprecated 4.9.0
677
+	 * @param EE_Message $message
678
+	 * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
679
+	 *                  available.
680
+	 *                  Eg. Valid Messenger and Message Type:
681
+	 *                  array(
682
+	 *                  'messenger' => new EE_Email_messenger(),
683
+	 *                  'message_type' => new EE_Registration_Approved_message_type()
684
+	 *                  )
685
+	 *                  Valid Messenger and Invalid Message Type:
686
+	 *                  array(
687
+	 *                  'messenger' => new EE_Email_messenger(),
688
+	 *                  'message_type' => null
689
+	 *                  )
690
+	 */
691
+	public function validate_for_use(EE_Message $message)
692
+	{
693
+		// EE_messages has been deprecated
694
+		$this->_class_is_deprecated(__FUNCTION__);
695
+		return array(
696
+			'messenger'    => $message->messenger_object(),
697
+			'message_type' => $message->message_type_object(),
698
+		);
699
+	}
700
+
701
+
702
+	/**
703
+	 * @deprecated 4.9.0
704
+	 * @param  string $type                 What type of message are we sending (corresponds to message types)
705
+	 * @param  mixed  $vars                 Data being sent for parsing in the message
706
+	 * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
707
+	 *                                      Otherwise we cycle through all active messengers.
708
+	 * @param string  $generating_messenger if included then this messenger is used for generating the message
709
+	 *                                      templates (but not for sending).
710
+	 * @param string  $context              If included then only a message type for a specific context will be
711
+	 *                                      generated.
712
+	 * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
713
+	 *                                      EE_messages objects which might be used by the trigger to setup a batch
714
+	 *                                      message (typically html messenger uses it).
715
+	 * @return bool
716
+	 */
717
+	public function send_message(
718
+		$type,
719
+		$vars,
720
+		$sending_messenger = '',
721
+		$generating_messenger = '',
722
+		$context = '',
723
+		$send = true
724
+	) {
725
+		// EE_messages has been deprecated
726
+		$this->_class_is_deprecated(__FUNCTION__);
727
+		/** @type EE_Messages_Processor $processor */
728
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
729
+		$error = false;
730
+		// try to intelligently determine what method we'll call based on the incoming data.
731
+		// if generating and sending are different then generate and send immediately.
732
+		if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
733
+			// in the legacy system, when generating and sending were different, that means all the
734
+			// vars are already in the request object.  So let's just use that.
735
+			try {
736
+				/** @type EE_Message_To_Generate_From_Request $mtg */
737
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
738
+				$processor->generate_and_send_now($mtg);
739
+			} catch (EE_Error $e) {
740
+				$error_msg = __(
741
+					'Please note that a system message failed to send due to a technical issue.',
742
+					'event_espresso'
743
+				);
744
+				// add specific message for developers if WP_DEBUG in on
745
+				$error_msg .= '||' . $e->getMessage();
746
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
747
+				$error = true;
748
+			}
749
+		} else {
750
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
751
+			// let's find out if there were any errors and how many successfully were queued.
752
+			$count_errors = $processor->get_queue()->count_STS_in_queue(
753
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
754
+			);
755
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
756
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
757
+			$count_errors = $count_errors + $count_retry;
758
+			if ($count_errors > 0) {
759
+				$error = true;
760
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
761
+					$message = sprintf(
762
+						__(
763
+							'There were %d errors and %d messages successfully queued for generation and sending',
764
+							'event_espresso'
765
+						),
766
+						$count_errors,
767
+						$count_queued
768
+					);
769
+				} elseif ($count_errors > 1 && $count_queued === 1) {
770
+					$message = sprintf(
771
+						__(
772
+							'There were %d errors and %d message successfully queued for generation.',
773
+							'event_espresso'
774
+						),
775
+						$count_errors,
776
+						$count_queued
777
+					);
778
+				} elseif ($count_errors === 1 && $count_queued > 1) {
779
+					$message = sprintf(
780
+						__(
781
+							'There was %d error and %d messages successfully queued for generation.',
782
+							'event_espresso'
783
+						),
784
+						$count_errors,
785
+						$count_queued
786
+					);
787
+				} else {
788
+					$message = sprintf(
789
+						__(
790
+							'There was %d message that failed to be queued for generation.',
791
+							'event_espresso'
792
+						),
793
+						$count_errors
794
+					);
795
+				}
796
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
797
+			} else {
798
+				if ($count_queued === 1) {
799
+					$message = sprintf(
800
+						__(
801
+							'%d message successfully queued for generation.',
802
+							'event_espresso'
803
+						),
804
+						$count_queued
805
+					);
806
+				} else {
807
+					$message = sprintf(
808
+						__(
809
+							'%d messages were successfully queued for generation.',
810
+							'event_espresso'
811
+						),
812
+						$count_queued
813
+					);
814
+				}
815
+				EE_Error::add_success($message);
816
+			}
817
+		}
818
+		// if no error then return the generated message(s).
819
+		if (! $error && ! $send) {
820
+			$generated_queue = $processor->generate_queue(false);
821
+			// get message and return.
822
+			$generated_queue->get_message_repository()->rewind();
823
+			$messages = array();
824
+			while ($generated_queue->get_message_repository()->valid()) {
825
+				$message = $generated_queue->get_message_repository()->current();
826
+				if ($message instanceof EE_Message) {
827
+					// set properties that might be expected by add-ons (backward compat)
828
+					$message->content = $message->content();
829
+					$message->template_pack = $message->get_template_pack();
830
+					$message->template_variation = $message->get_template_pack_variation();
831
+					$messages[] = $message;
832
+				}
833
+				$generated_queue->get_message_repository()->next();
834
+			}
835
+			return $messages;
836
+		}
837
+		return $error ? false
838
+			: true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
839
+	}
840
+
841
+
842
+	/**
843
+	 * @deprecated 4.9.0
844
+	 * @param  string $type      This should correspond with a valid message type
845
+	 * @param  string $context   This should correspond with a valid context for the message type
846
+	 * @param  string $messenger This should correspond with a valid messenger.
847
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
848
+	 *                           preview
849
+	 * @return string          The body of the message.
850
+	 */
851
+	public function preview_message($type, $context, $messenger, $send = false)
852
+	{
853
+		// EE_messages has been deprecated
854
+		$this->_class_is_deprecated(__FUNCTION__);
855
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
856
+	}
857
+
858
+
859
+	/**
860
+	 * @since      4.5.0
861
+	 * @deprecated 4.9.0   Moved to EED_Messages Module
862
+	 * @param string   $messenger    a string matching a valid active messenger in the system
863
+	 * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
864
+	 *                               required to send along the message type to the messenger because this is used for
865
+	 *                               determining what specific variations might be loaded for the generated message.
866
+	 * @param stdClass $message      a stdClass object in the format expected by the messenger.
867
+	 *
868
+	 * @return bool          success or fail.
869
+	 */
870
+	public function send_message_with_messenger_only($messenger, $message_type, $message)
871
+	{
872
+		// EE_messages has been deprecated
873
+		$this->_class_is_deprecated(__FUNCTION__);
874
+		// setup for sending to new method.
875
+		/** @type EE_Messages_Queue $queue */
876
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
877
+		// make sure we have a proper message object
878
+		if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
879
+			$msg = EE_Message_Factory::create(
880
+				array(
881
+					'MSG_messenger'    => $messenger,
882
+					'MSG_message_type' => $message_type,
883
+					'MSG_content'      => $message->content,
884
+					'MSG_subject'      => $message->subject,
885
+				)
886
+			);
887
+		} else {
888
+			$msg = $message;
889
+		}
890
+		if (! $msg instanceof EE_Message) {
891
+			return false;
892
+		}
893
+		// make sure any content in a content property (if not empty) is set on the MSG_content.
894
+		if (! empty($msg->content)) {
895
+			$msg->set('MSG_content', $msg->content);
896
+		}
897
+		$queue->add($msg);
898
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
899
+	}
900
+
901
+
902
+	/**
903
+	 * @deprecated 4.9.0
904
+	 * @param         $messenger
905
+	 * @param  string $message_type message type that the templates are being created for
906
+	 * @param int     $GRP_ID
907
+	 * @param bool    $is_global
908
+	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
909
+	 *                      returned.
910
+	 * @throws \EE_Error
911
+	 */
912
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
913
+	{
914
+		// EE_messages has been deprecated
915
+		$this->_class_is_deprecated(__FUNCTION__);
916
+		EE_Registry::instance()->load_helper('MSG_Template');
917
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
918
+	}
919
+
920
+
921
+	/**
922
+	 * @deprecated 4.9.0
923
+	 * @param  string $messenger_name    name of EE_messenger
924
+	 * @param  string $message_type_name name of EE_message_type
925
+	 * @return array
926
+	 */
927
+	public function get_fields($messenger_name, $message_type_name)
928
+	{
929
+		// EE_messages has been deprecated
930
+		$this->_class_is_deprecated(__FUNCTION__);
931
+		EE_Registry::instance()->load_helper('MSG_Template');
932
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
933
+	}
934
+
935
+
936
+	/**
937
+	 * @deprecated 4.9.0
938
+	 * @access     public
939
+	 * @param string $type                we can indicate just returning installed message types
940
+	 *                                    or messengers (or both) via this parameter.
941
+	 * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
942
+	 * @return array                    multidimensional array of messenger and message_type objects
943
+	 *                                    (messengers index, and message_type index);
944
+	 */
945
+	public function get_installed($type = 'all', $skip_cache = false)
946
+	{
947
+		// EE_messages has been deprecated
948
+		$this->_class_is_deprecated(__FUNCTION__);
949
+		if ($skip_cache) {
950
+			$this->_message_resource_manager->reset_active_messengers_and_message_types();
951
+		}
952
+		switch ($type) {
953
+			case 'messengers' :
954
+				return array(
955
+					'messenger' => $this->_message_resource_manager->installed_messengers(),
956
+				);
957
+				break;
958
+			case 'message_types' :
959
+				return array(
960
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
961
+				);
962
+				break;
963
+			case 'all' :
964
+			default :
965
+				return array(
966
+					'messenger'    => $this->_message_resource_manager->installed_messengers(),
967
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
968
+				);
969
+				break;
970
+		}
971
+	}
972
+
973
+
974
+	/**
975
+	 * @deprecated 4.9.0
976
+	 * @return \EE_messenger[]
977
+	 */
978
+	public function get_active_messengers()
979
+	{
980
+		// EE_messages has been deprecated
981
+		$this->_class_is_deprecated(__FUNCTION__);
982
+		return $this->_message_resource_manager->active_messengers();
983
+	}
984
+
985
+
986
+	/**
987
+	 * @deprecated 4.9.0
988
+	 * @return array array of message_type references (string)
989
+	 */
990
+	public function get_active_message_types()
991
+	{
992
+		// EE_messages has been deprecated
993
+		$this->_class_is_deprecated(__FUNCTION__);
994
+		return $this->_message_resource_manager->list_of_active_message_types();
995
+	}
996
+
997
+
998
+	/**
999
+	 * @deprecated 4.9.0
1000
+	 * @return EE_message_type[]
1001
+	 */
1002
+	public function get_active_message_type_objects()
1003
+	{
1004
+		// EE_messages has been deprecated
1005
+		$this->_class_is_deprecated(__FUNCTION__);
1006
+		return $this->_message_resource_manager->get_active_message_type_objects();
1007
+	}
1008
+
1009
+
1010
+	/**
1011
+	 * @deprecated 4.9.0
1012
+	 * @since      4.5.0
1013
+	 * @param string $messenger The messenger being checked
1014
+	 * @return EE_message_type[]    (or empty array if none present)
1015
+	 */
1016
+	public function get_active_message_types_per_messenger($messenger)
1017
+	{
1018
+		// EE_messages has been deprecated
1019
+		$this->_class_is_deprecated(__FUNCTION__);
1020
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * @deprecated 4.9.0
1026
+	 * @param string $messenger    The string should correspond to the messenger (message types are
1027
+	 * @param string $message_type The string should correspond to a message type.
1028
+	 * @return EE_message_type|null
1029
+	 */
1030
+	public function get_active_message_type($messenger, $message_type)
1031
+	{
1032
+		// EE_messages has been deprecated
1033
+		$this->_class_is_deprecated(__FUNCTION__);
1034
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * @deprecated 4.9.0
1040
+	 * @return array|\EE_message_type[]
1041
+	 */
1042
+	public function get_installed_message_types()
1043
+	{
1044
+		// EE_messages has been deprecated
1045
+		$this->_class_is_deprecated(__FUNCTION__);
1046
+		return $this->_message_resource_manager->installed_message_types();
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * @deprecated 4.9.0
1052
+	 * @return array
1053
+	 */
1054
+	public function get_installed_messengers()
1055
+	{
1056
+		// EE_messages has been deprecated
1057
+		$this->_class_is_deprecated(__FUNCTION__);
1058
+		return $this->_message_resource_manager->installed_messengers();
1059
+	}
1060
+
1061
+
1062
+	/**
1063
+	 * @deprecated 4.9.0
1064
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1065
+	 *                           message type.
1066
+	 * @return array
1067
+	 */
1068
+	public function get_all_contexts($slugs_only = true)
1069
+	{
1070
+		// EE_messages has been deprecated
1071
+		$this->_class_is_deprecated(__FUNCTION__);
1072
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
1073
+	}
1074 1074
 
1075 1075
 
1076 1076
 }
@@ -1129,88 +1129,88 @@  discard block
 block discarded – undo
1129 1129
 
1130 1130
 
1131 1131
 add_filter(
1132
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1133
-    function ($event_list_iframe_css) {
1134
-        if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1135
-            return $event_list_iframe_css;
1136
-        }
1137
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1138
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1139
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1141
-            '4.9.14',
1142
-            '5.0.0',
1143
-            'filter'
1144
-        );
1145
-        return apply_filters(
1146
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1147
-            $event_list_iframe_css
1148
-        );
1149
-    }
1132
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1133
+	function ($event_list_iframe_css) {
1134
+		if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1135
+			return $event_list_iframe_css;
1136
+		}
1137
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1138
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1139
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1141
+			'4.9.14',
1142
+			'5.0.0',
1143
+			'filter'
1144
+		);
1145
+		return apply_filters(
1146
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1147
+			$event_list_iframe_css
1148
+		);
1149
+	}
1150 1150
 );
1151 1151
 add_filter(
1152
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1153
-    function ($event_list_iframe_js) {
1154
-        if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1155
-            return $event_list_iframe_js;
1156
-        }
1157
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1158
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1159
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1161
-            '4.9.14',
1162
-            '5.0.0',
1163
-            'filter'
1164
-        );
1165
-        return apply_filters(
1166
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1167
-            $event_list_iframe_js
1168
-        );
1169
-    }
1152
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1153
+	function ($event_list_iframe_js) {
1154
+		if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1155
+			return $event_list_iframe_js;
1156
+		}
1157
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1158
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1159
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1161
+			'4.9.14',
1162
+			'5.0.0',
1163
+			'filter'
1164
+		);
1165
+		return apply_filters(
1166
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1167
+			$event_list_iframe_js
1168
+		);
1169
+	}
1170 1170
 );
1171 1171
 add_action(
1172
-    'AHEE__EE_Capabilities__addCaps__complete',
1173
-    function ($capabilities_map) {
1174
-        if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1175
-            return;
1176
-        }
1177
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1178
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1179
-            'AHEE__EE_Capabilities__addCaps__complete',
1180
-            '\EE_Capabilities::addCaps()',
1181
-            '4.9.42',
1182
-            '5.0.0'
1183
-        );
1184
-        do_action(
1185
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1186
-            $capabilities_map
1187
-        );
1188
-    }
1172
+	'AHEE__EE_Capabilities__addCaps__complete',
1173
+	function ($capabilities_map) {
1174
+		if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1175
+			return;
1176
+		}
1177
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1178
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1179
+			'AHEE__EE_Capabilities__addCaps__complete',
1180
+			'\EE_Capabilities::addCaps()',
1181
+			'4.9.42',
1182
+			'5.0.0'
1183
+		);
1184
+		do_action(
1185
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1186
+			$capabilities_map
1187
+		);
1188
+	}
1189 1189
 );
1190 1190
 
1191 1191
 add_filter(
1192
-    'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1193
-    function ($existing_attendee, $registration, $attendee_data) {
1194
-        if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1195
-            return $existing_attendee;
1196
-        }
1197
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1198
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1199
-            'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
-            '\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1201
-            '4.9.34',
1202
-            '5.0.0',
1203
-            'filter'
1204
-        );
1205
-        return apply_filters(
1206
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1207
-            $existing_attendee,
1208
-            $registration,
1209
-            $attendee_data
1210
-        );
1211
-    },
1212
-    10,
1213
-    3
1192
+	'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1193
+	function ($existing_attendee, $registration, $attendee_data) {
1194
+		if (! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1195
+			return $existing_attendee;
1196
+		}
1197
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1198
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1199
+			'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
+			'\EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1201
+			'4.9.34',
1202
+			'5.0.0',
1203
+			'filter'
1204
+		);
1205
+		return apply_filters(
1206
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1207
+			$existing_attendee,
1208
+			$registration,
1209
+			$attendee_data
1210
+		);
1211
+	},
1212
+	10,
1213
+	3
1214 1214
 );
1215 1215
 
1216 1216
 /**
@@ -1221,88 +1221,88 @@  discard block
 block discarded – undo
1221 1221
 class EE_Event_List_Query extends WP_Query
1222 1222
 {
1223 1223
 
1224
-    private $title;
1225
-
1226
-    private $css_class;
1227
-
1228
-    private $category_slug;
1229
-
1230
-    /**
1231
-     * EE_Event_List_Query constructor.
1232
-     *
1233
-     * @param array $args
1234
-     */
1235
-    public function __construct($args = array())
1236
-    {
1237
-        \EE_Error::doing_it_wrong(
1238
-            __METHOD__,
1239
-            __(
1240
-                'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1241
-                'event_espresso'
1242
-            ),
1243
-            '4.9.27',
1244
-            '5.0.0'
1245
-        );
1246
-        $this->title = isset($args['title']) ? $args['title'] : '';
1247
-        $this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1248
-        $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1249
-        $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1250
-        // the current "page" we are viewing
1251
-        $paged = max(1, get_query_var('paged'));
1252
-        // Force these args
1253
-        $args = array_merge(
1254
-            $args,
1255
-            array(
1256
-                'post_type'              => 'espresso_events',
1257
-                'posts_per_page'         => $limit,
1258
-                'update_post_term_cache' => false,
1259
-                'update_post_meta_cache' => false,
1260
-                'paged'                  => $paged,
1261
-                'offset'                 => ($paged - 1) * $limit,
1262
-            )
1263
-        );
1264
-        // run the query
1265
-        parent::__construct($args);
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     * event_list_title
1271
-     *
1272
-     * @param string $event_list_title
1273
-     * @return string
1274
-     */
1275
-    public function event_list_title($event_list_title = '')
1276
-    {
1277
-        if (! empty($this->title)) {
1278
-            return $this->title;
1279
-        }
1280
-        return $event_list_title;
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * event_list_css
1286
-     *
1287
-     * @param string $event_list_css
1288
-     * @return string
1289
-     */
1290
-    public function event_list_css($event_list_css = '')
1291
-    {
1292
-        $event_list_css .= ! empty($event_list_css)
1293
-            ? ' '
1294
-            : '';
1295
-        $event_list_css .= ! empty($this->css_class)
1296
-            ? $this->css_class
1297
-            : '';
1298
-        $event_list_css .= ! empty($event_list_css)
1299
-            ? ' '
1300
-            : '';
1301
-        $event_list_css .= ! empty($this->category_slug)
1302
-            ? $this->category_slug
1303
-            : '';
1304
-        return $event_list_css;
1305
-    }
1224
+	private $title;
1225
+
1226
+	private $css_class;
1227
+
1228
+	private $category_slug;
1229
+
1230
+	/**
1231
+	 * EE_Event_List_Query constructor.
1232
+	 *
1233
+	 * @param array $args
1234
+	 */
1235
+	public function __construct($args = array())
1236
+	{
1237
+		\EE_Error::doing_it_wrong(
1238
+			__METHOD__,
1239
+			__(
1240
+				'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1241
+				'event_espresso'
1242
+			),
1243
+			'4.9.27',
1244
+			'5.0.0'
1245
+		);
1246
+		$this->title = isset($args['title']) ? $args['title'] : '';
1247
+		$this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1248
+		$this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1249
+		$limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1250
+		// the current "page" we are viewing
1251
+		$paged = max(1, get_query_var('paged'));
1252
+		// Force these args
1253
+		$args = array_merge(
1254
+			$args,
1255
+			array(
1256
+				'post_type'              => 'espresso_events',
1257
+				'posts_per_page'         => $limit,
1258
+				'update_post_term_cache' => false,
1259
+				'update_post_meta_cache' => false,
1260
+				'paged'                  => $paged,
1261
+				'offset'                 => ($paged - 1) * $limit,
1262
+			)
1263
+		);
1264
+		// run the query
1265
+		parent::__construct($args);
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 * event_list_title
1271
+	 *
1272
+	 * @param string $event_list_title
1273
+	 * @return string
1274
+	 */
1275
+	public function event_list_title($event_list_title = '')
1276
+	{
1277
+		if (! empty($this->title)) {
1278
+			return $this->title;
1279
+		}
1280
+		return $event_list_title;
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * event_list_css
1286
+	 *
1287
+	 * @param string $event_list_css
1288
+	 * @return string
1289
+	 */
1290
+	public function event_list_css($event_list_css = '')
1291
+	{
1292
+		$event_list_css .= ! empty($event_list_css)
1293
+			? ' '
1294
+			: '';
1295
+		$event_list_css .= ! empty($this->css_class)
1296
+			? $this->css_class
1297
+			: '';
1298
+		$event_list_css .= ! empty($event_list_css)
1299
+			? ' '
1300
+			: '';
1301
+		$event_list_css .= ! empty($this->category_slug)
1302
+			? $this->category_slug
1303
+			: '';
1304
+		return $event_list_css;
1305
+	}
1306 1306
 
1307 1307
 }
1308 1308
 
@@ -1319,66 +1319,66 @@  discard block
 block discarded – undo
1319 1319
 {
1320 1320
 
1321 1321
 
1322
-    /**
1323
-     *    class constructor
1324
-     *
1325
-     * @deprecated 4.9.59.p
1326
-     */
1327
-    public function __construct()
1328
-    {
1329
-        EE_Error::doing_it_wrong(
1330
-            __METHOD__,
1331
-            sprintf(
1332
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1333
-                __CLASS__,
1334
-                'EventEspresso\core\services\licensing\LicenseServices'
1335
-            ),
1336
-            '4.9.59.p'
1337
-        );
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * The purpose of this function is to display information about Event Espresso data collection
1343
-     * and a optin selection for extra data collecting by users.
1344
-     *
1345
-     * @param bool $extra
1346
-     * @return string html.
1347
-     * @deprecated 4.9.59.p
1348
-     */
1349
-    public static function espresso_data_collection_optin_text($extra = true)
1350
-    {
1351
-        EE_Error::doing_it_wrong(
1352
-            __METHOD__,
1353
-            sprintf(
1354
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1355
-                __METHOD__,
1356
-                'EventEspresso\core\domain\services\Stats::optinText'
1357
-            ),
1358
-            '4.9.59.p'
1359
-        );
1360
-        Stats::optinText($extra);
1361
-    }
1362
-
1363
-    /**
1364
-     * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1365
-     *
1366
-     * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1367
-     *                          identify plugins. Defaults to core update
1368
-     * @return boolean           True if update available, false if not.
1369
-     * @deprecated 4.9.59.p
1370
-     */
1371
-    public static function is_update_available($basename = '')
1372
-    {
1373
-        EE_Error::doing_it_wrong(
1374
-            __METHOD__,
1375
-            sprintf(
1376
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1377
-                __METHOD__,
1378
-                'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable'
1379
-            ),
1380
-            '4.9.59.p'
1381
-        );
1382
-        return LicenseService::isUpdateAvailable($basename);
1383
-    }
1322
+	/**
1323
+	 *    class constructor
1324
+	 *
1325
+	 * @deprecated 4.9.59.p
1326
+	 */
1327
+	public function __construct()
1328
+	{
1329
+		EE_Error::doing_it_wrong(
1330
+			__METHOD__,
1331
+			sprintf(
1332
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1333
+				__CLASS__,
1334
+				'EventEspresso\core\services\licensing\LicenseServices'
1335
+			),
1336
+			'4.9.59.p'
1337
+		);
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * The purpose of this function is to display information about Event Espresso data collection
1343
+	 * and a optin selection for extra data collecting by users.
1344
+	 *
1345
+	 * @param bool $extra
1346
+	 * @return string html.
1347
+	 * @deprecated 4.9.59.p
1348
+	 */
1349
+	public static function espresso_data_collection_optin_text($extra = true)
1350
+	{
1351
+		EE_Error::doing_it_wrong(
1352
+			__METHOD__,
1353
+			sprintf(
1354
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1355
+				__METHOD__,
1356
+				'EventEspresso\core\domain\services\Stats::optinText'
1357
+			),
1358
+			'4.9.59.p'
1359
+		);
1360
+		Stats::optinText($extra);
1361
+	}
1362
+
1363
+	/**
1364
+	 * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1365
+	 *
1366
+	 * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1367
+	 *                          identify plugins. Defaults to core update
1368
+	 * @return boolean           True if update available, false if not.
1369
+	 * @deprecated 4.9.59.p
1370
+	 */
1371
+	public static function is_update_available($basename = '')
1372
+	{
1373
+		EE_Error::doing_it_wrong(
1374
+			__METHOD__,
1375
+			sprintf(
1376
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1377
+				__METHOD__,
1378
+				'EventEspresso\core\services\licensing\LicenseService::isUpdateAvailable'
1379
+			),
1380
+			'4.9.59.p'
1381
+		);
1382
+		return LicenseService::isUpdateAvailable($basename);
1383
+	}
1384 1384
 }
1385 1385
\ No newline at end of file
Please login to merge, or discard this patch.
templates/reg_admin_details_main_meta_box_reg_questions.template.php 3 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <div id="admin-primary-mbox-questions-dv" class="admin-primary-mbox-dv">
2 2
     <p>
3 3
         <?php _e(
4
-            'This displays the custom questions and answers for this registrant.  Please note that any answers to system questions have been saved with the contact record.  You can edit those answers via the "View/Edit this Contact" link in the Contact Details metabox in the sidebar.',
5
-            'event_espresso'
6
-        ); ?></p>
4
+			'This displays the custom questions and answers for this registrant.  Please note that any answers to system questions have been saved with the contact record.  You can edit those answers via the "View/Edit this Contact" link in the Contact Details metabox in the sidebar.',
5
+			'event_espresso'
6
+		); ?></p>
7 7
 
8 8
     <form name="reg-admin-attendee-questions-frm" id="reg-admin-attendee-questions-frm"
9 9
           action="<?php echo REG_ADMIN_URL; ?>" method="post">
@@ -16,19 +16,19 @@  discard block
 block discarded – undo
16 16
         <?php echo $att_questions; ?>
17 17
         <?php if (! empty($att_questions)) : ?>
18 18
             <?php if (EE_Registry::instance()->CAP->current_user_can(
19
-                'ee_edit_registration',
20
-                'edit-reg-questions-mbox',
21
-                $REG_ID
22
-            )) : ?>
19
+				'ee_edit_registration',
20
+				'edit-reg-questions-mbox',
21
+				$REG_ID
22
+			)) : ?>
23 23
             <input id="reg-admin-attendee-questions-submit" class="button-primary" value="Update Registration Questions"
24 24
                    type="submit"/>
25 25
             <?php endif; ?>
26 26
         <?php else : ?>
27 27
             <p class="ee-attention">
28 28
                 <?php _e(
29
-                    'There were no custom questions asked for this registration.',
30
-                    'event_espresso'
31
-                ); ?></p>
29
+					'There were no custom questions asked for this registration.',
30
+					'event_espresso'
31
+				); ?></p>
32 32
         <?php endif; ?>
33 33
 
34 34
     </form>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@
 block discarded – undo
7 7
 
8 8
     <form name="reg-admin-attendee-questions-frm" id="reg-admin-attendee-questions-frm"
9 9
           action="<?php echo REG_ADMIN_URL; ?>" method="post">
10
-        <?php wp_nonce_field($reg_questions_form_action . '_nonce', $reg_questions_form_action . '_nonce'); ?>
10
+        <?php wp_nonce_field($reg_questions_form_action.'_nonce', $reg_questions_form_action.'_nonce'); ?>
11 11
         <input type="hidden" name="page" value="<?php echo REG_PG_SLUG; ?>"/>
12 12
         <input type="hidden" name="action" value="<?php echo $reg_questions_form_action; ?>"/>
13 13
         <input type="hidden" name="_REG_ID" value="<?php echo $REG_ID; ?>"/>
14 14
         <input type="hidden" name="espresso_ajax" id="espresso-ajax" value="0"/>
15 15
         <input type="hidden" name="noheader" id="reg-admin-noheader-inp" value="true"/>
16 16
         <?php echo $att_questions; ?>
17
-        <?php if (! empty($att_questions)) : ?>
17
+        <?php if ( ! empty($att_questions)) : ?>
18 18
             <?php if (EE_Registry::instance()->CAP->current_user_can(
19 19
                 'ee_edit_registration',
20 20
                 'edit-reg-questions-mbox',
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,12 +23,15 @@
 block discarded – undo
23 23
             <input id="reg-admin-attendee-questions-submit" class="button-primary" value="Update Registration Questions"
24 24
                    type="submit"/>
25 25
             <?php endif; ?>
26
-        <?php else : ?>
26
+        <?php else {
27
+	: ?>
27 28
             <p class="ee-attention">
28 29
                 <?php _e(
29 30
                     'There were no custom questions asked for this registration.',
30 31
                     'event_espresso'
31
-                ); ?></p>
32
+                );
33
+}
34
+?></p>
32 35
         <?php endif; ?>
33 36
 
34 37
     </form>
Please login to merge, or discard this patch.
registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -15,168 +15,168 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Registration_Custom_Questions_Form extends EE_Form_Section_Proper
17 17
 {
18
-    /**
19
-     *
20
-     * @var EE_Registration
21
-     */
22
-    protected $_registration = null;
18
+	/**
19
+	 *
20
+	 * @var EE_Registration
21
+	 */
22
+	protected $_registration = null;
23 23
 
24
-    /**
25
-     *
26
-     * @param EE_Registration $reg
27
-     * @param array $options
28
-     */
29
-    public function __construct(EE_Registration $reg, $options = array())
30
-    {
31
-        $this->_registration = $reg;
32
-        if (! isset($options['layout_strategy'])) {
33
-            $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34
-        }
35
-        if (! isset($options['html_id'])) {
36
-            $options['html_id'] = 'reg-admin-attendee-questions-frm';
37
-        }
38
-        $this->build_form_from_registration();
39
-        parent::__construct($options);
40
-    }
24
+	/**
25
+	 *
26
+	 * @param EE_Registration $reg
27
+	 * @param array $options
28
+	 */
29
+	public function __construct(EE_Registration $reg, $options = array())
30
+	{
31
+		$this->_registration = $reg;
32
+		if (! isset($options['layout_strategy'])) {
33
+			$options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34
+		}
35
+		if (! isset($options['html_id'])) {
36
+			$options['html_id'] = 'reg-admin-attendee-questions-frm';
37
+		}
38
+		$this->build_form_from_registration();
39
+		parent::__construct($options);
40
+	}
41 41
 
42 42
 
43
-    /**
44
-     * Gets the registration object this form is about
45
-     * @return EE_Registration
46
-     */
47
-    public function get_registration()
48
-    {
49
-        return $this->_registration;
50
-    }
43
+	/**
44
+	 * Gets the registration object this form is about
45
+	 * @return EE_Registration
46
+	 */
47
+	public function get_registration()
48
+	{
49
+		return $this->_registration;
50
+	}
51 51
 
52
-    public function build_form_from_registration()
53
-    {
54
-        $reg = $this->get_registration();
55
-        if (! $reg instanceof EE_Registration) {
56
-            throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57
-        }
58
-        // we want to get all their question groups
59
-        $question_groups = EEM_Question_Group::instance()->get_all(
60
-            array(
61
-                array(
62
-                    'Event_Question_Group.EVT_ID' => $reg->event_ID(),
63
-                    'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64
-                    'OR' => array(
65
-                        'Question.QST_system*blank' =>  '',
66
-                        'Question.QST_system*null' => array( 'IS_NULL' )
67
-                    )
68
-                ),
69
-                'order_by' => array( 'QSG_order' => 'ASC' )
70
-            )
71
-        );
72
-        // get each question groups questions
73
-        foreach ($question_groups as $question_group) {
74
-            if ($question_group instanceof EE_Question_Group) {
75
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
76
-                    $question_group,
77
-                    $reg
78
-                );
79
-            }
80
-        }
81
-    }
52
+	public function build_form_from_registration()
53
+	{
54
+		$reg = $this->get_registration();
55
+		if (! $reg instanceof EE_Registration) {
56
+			throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57
+		}
58
+		// we want to get all their question groups
59
+		$question_groups = EEM_Question_Group::instance()->get_all(
60
+			array(
61
+				array(
62
+					'Event_Question_Group.EVT_ID' => $reg->event_ID(),
63
+					'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64
+					'OR' => array(
65
+						'Question.QST_system*blank' =>  '',
66
+						'Question.QST_system*null' => array( 'IS_NULL' )
67
+					)
68
+				),
69
+				'order_by' => array( 'QSG_order' => 'ASC' )
70
+			)
71
+		);
72
+		// get each question groups questions
73
+		foreach ($question_groups as $question_group) {
74
+			if ($question_group instanceof EE_Question_Group) {
75
+				$this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
76
+					$question_group,
77
+					$reg
78
+				);
79
+			}
80
+		}
81
+	}
82 82
 
83 83
 
84 84
 
85
-    /**
86
-     *
87
-     * @param EE_Question_Group $question_group
88
-     * @param EE_Registration   $registration
89
-     * @return \EE_Form_Section_Proper
90
-     * @throws \EE_Error
91
-     */
92
-    public function build_subform_from_question_group($question_group, $registration)
93
-    {
94
-        if (! $question_group instanceof EE_Question_Group ||
95
-            ! $registration instanceof EE_Registration) {
96
-            throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97
-        }
98
-        $parts_of_subsection = array(
99
-            'title' => new EE_Form_Section_HTML(
100
-                EEH_HTML::h5(
101
-                    $question_group->name(),
102
-                    $question_group->identifier(),
103
-                    'espresso-question-group-title-h5 section-title'
104
-                )
105
-            )
106
-        );
107
-        $questions = $question_group->questions(
108
-            array(
109
-                array(
110
-                    'OR' => array(
111
-                        'QST_system*blank' => '',
112
-                        'QST_system*null' => array( 'IS_NULL' )
113
-                    )
114
-                )
115
-            )
116
-        );
117
-        foreach ($questions as $question) {
118
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
119
-        }
120
-        if (EE_Registry::instance()->CAP->current_user_can(
121
-            'ee_edit_registration',
122
-            'edit-reg-questions-mbox',
123
-            $this->_registration->ID()
124
-        )) {
125
-            $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
-                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" title="' . esc_attr__('click to edit question', 'event_espresso') . '">
85
+	/**
86
+	 *
87
+	 * @param EE_Question_Group $question_group
88
+	 * @param EE_Registration   $registration
89
+	 * @return \EE_Form_Section_Proper
90
+	 * @throws \EE_Error
91
+	 */
92
+	public function build_subform_from_question_group($question_group, $registration)
93
+	{
94
+		if (! $question_group instanceof EE_Question_Group ||
95
+			! $registration instanceof EE_Registration) {
96
+			throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97
+		}
98
+		$parts_of_subsection = array(
99
+			'title' => new EE_Form_Section_HTML(
100
+				EEH_HTML::h5(
101
+					$question_group->name(),
102
+					$question_group->identifier(),
103
+					'espresso-question-group-title-h5 section-title'
104
+				)
105
+			)
106
+		);
107
+		$questions = $question_group->questions(
108
+			array(
109
+				array(
110
+					'OR' => array(
111
+						'QST_system*blank' => '',
112
+						'QST_system*null' => array( 'IS_NULL' )
113
+					)
114
+				)
115
+			)
116
+		);
117
+		foreach ($questions as $question) {
118
+			$parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
119
+		}
120
+		if (EE_Registry::instance()->CAP->current_user_can(
121
+			'ee_edit_registration',
122
+			'edit-reg-questions-mbox',
123
+			$this->_registration->ID()
124
+		)) {
125
+			$parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
+				'<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" title="' . esc_attr__('click to edit question', 'event_espresso') . '">
127 127
 		  			<span class="reg-admin-edit-question-group-spn lt-grey-txt">' . __('edit the above question group', 'event_espresso') . '</span>
128 128
 		  			<div class="dashicons dashicons-edit"></div>
129 129
 		  		</a></td></tr>'
130
-            );
131
-        }
132
-        return new EE_Form_Section_Proper(
133
-            array(
134
-                'subsections' => $parts_of_subsection,
135
-                'html_class' => 'question-group-questions',
136
-            )
137
-        );
138
-    }
130
+			);
131
+		}
132
+		return new EE_Form_Section_Proper(
133
+			array(
134
+				'subsections' => $parts_of_subsection,
135
+				'html_class' => 'question-group-questions',
136
+			)
137
+		);
138
+	}
139 139
 
140
-    /**
141
-     * Overrides parent so if inputs were disabled, we leave those with their defaults
142
-     * from the answers in the DB
143
-     * @param array $req_data like $_POST
144
-     * @return void
145
-     */
146
-    protected function _normalize($req_data)
147
-    {
148
-        $this->_received_submission = true;
149
-        $this->_validation_errors = array();
150
-        foreach ($this->get_validatable_subsections() as $subsection) {
151
-            if ($subsection->form_data_present_in($req_data)) {
152
-                try {
153
-                    $subsection->_normalize($req_data);
154
-                } catch (EE_Validation_Error $e) {
155
-                    $subsection->add_validation_error($e);
156
-                }
157
-            }
158
-        }
159
-    }
140
+	/**
141
+	 * Overrides parent so if inputs were disabled, we leave those with their defaults
142
+	 * from the answers in the DB
143
+	 * @param array $req_data like $_POST
144
+	 * @return void
145
+	 */
146
+	protected function _normalize($req_data)
147
+	{
148
+		$this->_received_submission = true;
149
+		$this->_validation_errors = array();
150
+		foreach ($this->get_validatable_subsections() as $subsection) {
151
+			if ($subsection->form_data_present_in($req_data)) {
152
+				try {
153
+					$subsection->_normalize($req_data);
154
+				} catch (EE_Validation_Error $e) {
155
+					$subsection->add_validation_error($e);
156
+				}
157
+			}
158
+		}
159
+	}
160 160
 
161 161
 
162 162
 
163
-    /**
164
-     * Performs validation on this form section and its subsections. For each subsection,
165
-     * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection.
166
-     * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method,
167
-     * calling parent::_validate() first.
168
-     */
169
-    protected function _validate()
170
-    {
171
-        foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172
-            if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173
-                if (method_exists($this, '_validate_'.$subsection_name)) {
174
-                    call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
175
-                }
176
-                $subsection->_validate();
177
-            } elseif ($subsection instanceof EE_Form_Section_Proper) {
178
-                $subsection->_received_submission = true;
179
-            }
180
-        }
181
-    }
163
+	/**
164
+	 * Performs validation on this form section and its subsections. For each subsection,
165
+	 * calls _validate_{subsection_name} on THIS form (if the function exists) and passes it the subsection, then calls _validate on that subsection.
166
+	 * If you need to perform validation on the form as a whole (considering multiple) you would be best to override this _validate method,
167
+	 * calling parent::_validate() first.
168
+	 */
169
+	protected function _validate()
170
+	{
171
+		foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172
+			if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173
+				if (method_exists($this, '_validate_'.$subsection_name)) {
174
+					call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
175
+				}
176
+				$subsection->_validate();
177
+			} elseif ($subsection instanceof EE_Form_Section_Proper) {
178
+				$subsection->_received_submission = true;
179
+			}
180
+		}
181
+	}
182 182
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     public function __construct(EE_Registration $reg, $options = array())
30 30
     {
31 31
         $this->_registration = $reg;
32
-        if (! isset($options['layout_strategy'])) {
32
+        if ( ! isset($options['layout_strategy'])) {
33 33
             $options['layout_strategy'] = new EE_Admin_Two_Column_Layout();
34 34
         }
35
-        if (! isset($options['html_id'])) {
35
+        if ( ! isset($options['html_id'])) {
36 36
             $options['html_id'] = 'reg-admin-attendee-questions-frm';
37 37
         }
38 38
         $this->build_form_from_registration();
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     public function build_form_from_registration()
53 53
     {
54 54
         $reg = $this->get_registration();
55
-        if (! $reg instanceof EE_Registration) {
55
+        if ( ! $reg instanceof EE_Registration) {
56 56
             throw new EE_Error(__('We cannot build the registration custom questions form because there is no registration set on it yet', 'event_espresso'));
57 57
         }
58 58
         // we want to get all their question groups
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
                     'Event_Question_Group.EQG_primary' => $reg->count() == 1 ? true : false,
64 64
                     'OR' => array(
65 65
                         'Question.QST_system*blank' =>  '',
66
-                        'Question.QST_system*null' => array( 'IS_NULL' )
66
+                        'Question.QST_system*null' => array('IS_NULL')
67 67
                     )
68 68
                 ),
69
-                'order_by' => array( 'QSG_order' => 'ASC' )
69
+                'order_by' => array('QSG_order' => 'ASC')
70 70
             )
71 71
         );
72 72
         // get each question groups questions
73 73
         foreach ($question_groups as $question_group) {
74 74
             if ($question_group instanceof EE_Question_Group) {
75
-                $this->_subsections[ $question_group->ID() ] = $this->build_subform_from_question_group(
75
+                $this->_subsections[$question_group->ID()] = $this->build_subform_from_question_group(
76 76
                     $question_group,
77 77
                     $reg
78 78
                 );
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function build_subform_from_question_group($question_group, $registration)
93 93
     {
94
-        if (! $question_group instanceof EE_Question_Group ||
94
+        if ( ! $question_group instanceof EE_Question_Group ||
95 95
             ! $registration instanceof EE_Registration) {
96 96
             throw new EE_Error(__('A valid question group and registration must be passed to EE_Registration_Custom_Question_Form', 'event_espresso'));
97 97
         }
@@ -109,13 +109,13 @@  discard block
 block discarded – undo
109 109
                 array(
110 110
                     'OR' => array(
111 111
                         'QST_system*blank' => '',
112
-                        'QST_system*null' => array( 'IS_NULL' )
112
+                        'QST_system*null' => array('IS_NULL')
113 113
                     )
114 114
                 )
115 115
             )
116 116
         );
117 117
         foreach ($questions as $question) {
118
-            $parts_of_subsection[ $question->ID() ] = $question->generate_form_input($registration);
118
+            $parts_of_subsection[$question->ID()] = $question->generate_form_input($registration);
119 119
         }
120 120
         if (EE_Registry::instance()->CAP->current_user_can(
121 121
             'ee_edit_registration',
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
             $this->_registration->ID()
124 124
         )) {
125 125
             $parts_of_subsection['edit_link'] = new EE_Form_Section_HTML(
126
-                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" title="' . esc_attr__('click to edit question', 'event_espresso') . '">
127
-		  			<span class="reg-admin-edit-question-group-spn lt-grey-txt">' . __('edit the above question group', 'event_espresso') . '</span>
126
+                '<tr><th/><td class="reg-admin-edit-attendee-question-td"><a class="reg-admin-edit-attendee-question-lnk" href="#" title="'.esc_attr__('click to edit question', 'event_espresso').'">
127
+		  			<span class="reg-admin-edit-question-group-spn lt-grey-txt">' . __('edit the above question group', 'event_espresso').'</span>
128 128
 		  			<div class="dashicons dashicons-edit"></div>
129 129
 		  		</a></td></tr>'
130 130
             );
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) {
172 172
             if ($subsection->form_data_present_in(array_merge($_GET, $_POST))) {
173 173
                 if (method_exists($this, '_validate_'.$subsection_name)) {
174
-                    call_user_func_array(array($this,'_validate_'.$subsection_name), array($subsection));
174
+                    call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection));
175 175
                 }
176 176
                 $subsection->_validate();
177 177
             } elseif ($subsection instanceof EE_Form_Section_Proper) {
Please login to merge, or discard this patch.
core/EE_Error.core.php 2 patches
Indentation   +1126 added lines, -1126 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 // if you're a dev and want to receive all errors via email
11 11
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
12 12
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
13
-    set_error_handler(array('EE_Error', 'error_handler'));
14
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
13
+	set_error_handler(array('EE_Error', 'error_handler'));
14
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
15 15
 }
16 16
 
17 17
 
@@ -25,251 +25,251 @@  discard block
 block discarded – undo
25 25
 class EE_Error extends Exception
26 26
 {
27 27
 
28
-    const OPTIONS_KEY_NOTICES = 'ee_notices';
29
-
30
-
31
-    /**
32
-     * name of the file to log exceptions to
33
-     *
34
-     * @var string
35
-     */
36
-    private static $_exception_log_file = 'espresso_error_log.txt';
37
-
38
-    /**
39
-     *    stores details for all exception
40
-     *
41
-     * @var array
42
-     */
43
-    private static $_all_exceptions = array();
44
-
45
-    /**
46
-     *    tracks number of errors
47
-     *
48
-     * @var int
49
-     */
50
-    private static $_error_count = 0;
51
-
52
-    /**
53
-     * @var array $_espresso_notices
54
-     */
55
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
-
57
-
58
-    /**
59
-     * @override default exception handling
60
-     * @param string         $message
61
-     * @param int            $code
62
-     * @param Exception|null $previous
63
-     */
64
-    public function __construct($message, $code = 0, Exception $previous = null)
65
-    {
66
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
67
-            parent::__construct($message, $code);
68
-        } else {
69
-            parent::__construct($message, $code, $previous);
70
-        }
71
-    }
72
-
73
-
74
-    /**
75
-     *    error_handler
76
-     *
77
-     * @param $code
78
-     * @param $message
79
-     * @param $file
80
-     * @param $line
81
-     * @return void
82
-     */
83
-    public static function error_handler($code, $message, $file, $line)
84
-    {
85
-        $type = EE_Error::error_type($code);
86
-        $site = site_url();
87
-        switch ($site) {
88
-            case 'http://ee4.eventespresso.com/':
89
-            case 'http://ee4decaf.eventespresso.com/':
90
-            case 'http://ee4hf.eventespresso.com/':
91
-            case 'http://ee4a.eventespresso.com/':
92
-            case 'http://ee4ad.eventespresso.com/':
93
-            case 'http://ee4b.eventespresso.com/':
94
-            case 'http://ee4bd.eventespresso.com/':
95
-            case 'http://ee4d.eventespresso.com/':
96
-            case 'http://ee4dd.eventespresso.com/':
97
-                $to = '[email protected]';
98
-                break;
99
-            default:
100
-                $to = get_option('admin_email');
101
-        }
102
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
103
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
104
-        if (function_exists('wp_mail')) {
105
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
106
-            wp_mail($to, $subject, $msg);
107
-        }
108
-        echo '<div id="message" class="espresso-notices error"><p>';
109
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
110
-        echo '<br /></p></div>';
111
-    }
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-    /**
162
-     *    fatal_error_handler
163
-     *
164
-     * @return void
165
-     */
166
-    public static function fatal_error_handler()
167
-    {
168
-        $last_error = error_get_last();
169
-        if ($last_error['type'] === E_ERROR) {
170
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
171
-        }
172
-    }
173
-
174
-
175
-    /**
176
-     * _format_error
177
-     *
178
-     * @param $code
179
-     * @param $message
180
-     * @param $file
181
-     * @param $line
182
-     * @return string
183
-     */
184
-    private static function _format_error($code, $message, $file, $line)
185
-    {
186
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
187
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
188
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
189
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
191
-        $html .= '</tbody></table>';
192
-        return $html;
193
-    }
194
-
195
-
196
-    /**
197
-     * set_content_type
198
-     *
199
-     * @param $content_type
200
-     * @return string
201
-     */
202
-    public static function set_content_type($content_type)
203
-    {
204
-        return 'text/html';
205
-    }
206
-
207
-
208
-    /**
209
-     * @return void
210
-     * @throws EE_Error
211
-     * @throws ReflectionException
212
-     */
213
-    public function get_error()
214
-    {
215
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
216
-            throw $this;
217
-        }
218
-        // get separate user and developer messages if they exist
219
-        $msg = explode('||', $this->getMessage());
220
-        $user_msg = $msg[0];
221
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
222
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
223
-        // add details to _all_exceptions array
224
-        $x_time = time();
225
-        self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
226
-        self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
227
-        self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
228
-        self::$_all_exceptions[ $x_time ]['msg'] = $msg;
229
-        self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
230
-        self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
231
-        self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
232
-        self::$_error_count++;
233
-        // add_action( 'shutdown', array( $this, 'display_errors' ));
234
-        $this->display_errors();
235
-    }
236
-
237
-
238
-    /**
239
-     * @param bool   $check_stored
240
-     * @param string $type_to_check
241
-     * @return bool
242
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
243
-     * @throws \InvalidArgumentException
244
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
245
-     * @throws InvalidInterfaceException
246
-     */
247
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
248
-    {
249
-        $has_error = isset(self::$_espresso_notices[ $type_to_check ])
250
-                     && ! empty(self::$_espresso_notices[ $type_to_check ])
251
-            ? true
252
-            : false;
253
-        if ($check_stored && ! $has_error) {
254
-            $notices = EE_Error::getStoredNotices();
255
-            foreach ($notices as $type => $notice) {
256
-                if ($type === $type_to_check && $notice) {
257
-                    return true;
258
-                }
259
-            }
260
-        }
261
-        return $has_error;
262
-    }
263
-
264
-
265
-    /**
266
-     * @echo string
267
-     * @throws \ReflectionException
268
-     */
269
-    public function display_errors()
270
-    {
271
-        $trace_details = '';
272
-        $output = '
28
+	const OPTIONS_KEY_NOTICES = 'ee_notices';
29
+
30
+
31
+	/**
32
+	 * name of the file to log exceptions to
33
+	 *
34
+	 * @var string
35
+	 */
36
+	private static $_exception_log_file = 'espresso_error_log.txt';
37
+
38
+	/**
39
+	 *    stores details for all exception
40
+	 *
41
+	 * @var array
42
+	 */
43
+	private static $_all_exceptions = array();
44
+
45
+	/**
46
+	 *    tracks number of errors
47
+	 *
48
+	 * @var int
49
+	 */
50
+	private static $_error_count = 0;
51
+
52
+	/**
53
+	 * @var array $_espresso_notices
54
+	 */
55
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
56
+
57
+
58
+	/**
59
+	 * @override default exception handling
60
+	 * @param string         $message
61
+	 * @param int            $code
62
+	 * @param Exception|null $previous
63
+	 */
64
+	public function __construct($message, $code = 0, Exception $previous = null)
65
+	{
66
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
67
+			parent::__construct($message, $code);
68
+		} else {
69
+			parent::__construct($message, $code, $previous);
70
+		}
71
+	}
72
+
73
+
74
+	/**
75
+	 *    error_handler
76
+	 *
77
+	 * @param $code
78
+	 * @param $message
79
+	 * @param $file
80
+	 * @param $line
81
+	 * @return void
82
+	 */
83
+	public static function error_handler($code, $message, $file, $line)
84
+	{
85
+		$type = EE_Error::error_type($code);
86
+		$site = site_url();
87
+		switch ($site) {
88
+			case 'http://ee4.eventespresso.com/':
89
+			case 'http://ee4decaf.eventespresso.com/':
90
+			case 'http://ee4hf.eventespresso.com/':
91
+			case 'http://ee4a.eventespresso.com/':
92
+			case 'http://ee4ad.eventespresso.com/':
93
+			case 'http://ee4b.eventespresso.com/':
94
+			case 'http://ee4bd.eventespresso.com/':
95
+			case 'http://ee4d.eventespresso.com/':
96
+			case 'http://ee4dd.eventespresso.com/':
97
+				$to = '[email protected]';
98
+				break;
99
+			default:
100
+				$to = get_option('admin_email');
101
+		}
102
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
103
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
104
+		if (function_exists('wp_mail')) {
105
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
106
+			wp_mail($to, $subject, $msg);
107
+		}
108
+		echo '<div id="message" class="espresso-notices error"><p>';
109
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
110
+		echo '<br /></p></div>';
111
+	}
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+	/**
162
+	 *    fatal_error_handler
163
+	 *
164
+	 * @return void
165
+	 */
166
+	public static function fatal_error_handler()
167
+	{
168
+		$last_error = error_get_last();
169
+		if ($last_error['type'] === E_ERROR) {
170
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
171
+		}
172
+	}
173
+
174
+
175
+	/**
176
+	 * _format_error
177
+	 *
178
+	 * @param $code
179
+	 * @param $message
180
+	 * @param $file
181
+	 * @param $line
182
+	 * @return string
183
+	 */
184
+	private static function _format_error($code, $message, $file, $line)
185
+	{
186
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
187
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
188
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
189
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
191
+		$html .= '</tbody></table>';
192
+		return $html;
193
+	}
194
+
195
+
196
+	/**
197
+	 * set_content_type
198
+	 *
199
+	 * @param $content_type
200
+	 * @return string
201
+	 */
202
+	public static function set_content_type($content_type)
203
+	{
204
+		return 'text/html';
205
+	}
206
+
207
+
208
+	/**
209
+	 * @return void
210
+	 * @throws EE_Error
211
+	 * @throws ReflectionException
212
+	 */
213
+	public function get_error()
214
+	{
215
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
216
+			throw $this;
217
+		}
218
+		// get separate user and developer messages if they exist
219
+		$msg = explode('||', $this->getMessage());
220
+		$user_msg = $msg[0];
221
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
222
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
223
+		// add details to _all_exceptions array
224
+		$x_time = time();
225
+		self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
226
+		self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
227
+		self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
228
+		self::$_all_exceptions[ $x_time ]['msg'] = $msg;
229
+		self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
230
+		self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
231
+		self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
232
+		self::$_error_count++;
233
+		// add_action( 'shutdown', array( $this, 'display_errors' ));
234
+		$this->display_errors();
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param bool   $check_stored
240
+	 * @param string $type_to_check
241
+	 * @return bool
242
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
243
+	 * @throws \InvalidArgumentException
244
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
245
+	 * @throws InvalidInterfaceException
246
+	 */
247
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
248
+	{
249
+		$has_error = isset(self::$_espresso_notices[ $type_to_check ])
250
+					 && ! empty(self::$_espresso_notices[ $type_to_check ])
251
+			? true
252
+			: false;
253
+		if ($check_stored && ! $has_error) {
254
+			$notices = EE_Error::getStoredNotices();
255
+			foreach ($notices as $type => $notice) {
256
+				if ($type === $type_to_check && $notice) {
257
+					return true;
258
+				}
259
+			}
260
+		}
261
+		return $has_error;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @echo string
267
+	 * @throws \ReflectionException
268
+	 */
269
+	public function display_errors()
270
+	{
271
+		$trace_details = '';
272
+		$output = '
273 273
 <style type="text/css">
274 274
 	#ee-error-message {
275 275
 		max-width:90% !important;
@@ -325,21 +325,21 @@  discard block
 block discarded – undo
325 325
 	}
326 326
 </style>
327 327
 <div id="ee-error-message" class="error">';
328
-        if (! WP_DEBUG) {
329
-            $output .= '
328
+		if (! WP_DEBUG) {
329
+			$output .= '
330 330
 	<p>';
331
-        }
332
-        // cycle thru errors
333
-        foreach (self::$_all_exceptions as $time => $ex) {
334
-            $error_code = '';
335
-            // process trace info
336
-            if (empty($ex['trace'])) {
337
-                $trace_details .= __(
338
-                    'Sorry, but no trace information was available for this exception.',
339
-                    'event_espresso'
340
-                );
341
-            } else {
342
-                $trace_details .= '
331
+		}
332
+		// cycle thru errors
333
+		foreach (self::$_all_exceptions as $time => $ex) {
334
+			$error_code = '';
335
+			// process trace info
336
+			if (empty($ex['trace'])) {
337
+				$trace_details .= __(
338
+					'Sorry, but no trace information was available for this exception.',
339
+					'event_espresso'
340
+				);
341
+			} else {
342
+				$trace_details .= '
343 343
 			<div id="ee-trace-details">
344 344
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
345 345
 				<tr>
@@ -349,43 +349,43 @@  discard block
 block discarded – undo
349 349
 					<th scope="col" align="left">Class</th>
350 350
 					<th scope="col" align="left">Method( arguments )</th>
351 351
 				</tr>';
352
-                $last_on_stack = count($ex['trace']) - 1;
353
-                // reverse array so that stack is in proper chronological order
354
-                $sorted_trace = array_reverse($ex['trace']);
355
-                foreach ($sorted_trace as $nmbr => $trace) {
356
-                    $file = isset($trace['file']) ? $trace['file'] : '';
357
-                    $class = isset($trace['class']) ? $trace['class'] : '';
358
-                    $type = isset($trace['type']) ? $trace['type'] : '';
359
-                    $function = isset($trace['function']) ? $trace['function'] : '';
360
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
361
-                    $line = isset($trace['line']) ? $trace['line'] : '';
362
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
363
-                    if (empty($file) && ! empty($class)) {
364
-                        $a = new ReflectionClass($class);
365
-                        $file = $a->getFileName();
366
-                        if (empty($line) && ! empty($function)) {
367
-                            try {
368
-                                // if $function is a closure, this throws an exception
369
-                                $b = new ReflectionMethod($class, $function);
370
-                                $line = $b->getStartLine();
371
-                            } catch (Exception $closure_exception) {
372
-                                $line = 'unknown';
373
-                            }
374
-                        }
375
-                    }
376
-                    if ($nmbr === $last_on_stack) {
377
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
378
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
379
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
380
-                    }
381
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
382
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
383
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
384
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
385
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
386
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
387
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
388
-                    $trace_details .= '
352
+				$last_on_stack = count($ex['trace']) - 1;
353
+				// reverse array so that stack is in proper chronological order
354
+				$sorted_trace = array_reverse($ex['trace']);
355
+				foreach ($sorted_trace as $nmbr => $trace) {
356
+					$file = isset($trace['file']) ? $trace['file'] : '';
357
+					$class = isset($trace['class']) ? $trace['class'] : '';
358
+					$type = isset($trace['type']) ? $trace['type'] : '';
359
+					$function = isset($trace['function']) ? $trace['function'] : '';
360
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
361
+					$line = isset($trace['line']) ? $trace['line'] : '';
362
+					$zebra = ($nmbr % 2) ? ' odd' : '';
363
+					if (empty($file) && ! empty($class)) {
364
+						$a = new ReflectionClass($class);
365
+						$file = $a->getFileName();
366
+						if (empty($line) && ! empty($function)) {
367
+							try {
368
+								// if $function is a closure, this throws an exception
369
+								$b = new ReflectionMethod($class, $function);
370
+								$line = $b->getStartLine();
371
+							} catch (Exception $closure_exception) {
372
+								$line = 'unknown';
373
+							}
374
+						}
375
+					}
376
+					if ($nmbr === $last_on_stack) {
377
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
378
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
379
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
380
+					}
381
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
382
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
383
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
384
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
385
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
386
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
387
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
388
+					$trace_details .= '
389 389
 					<tr>
390 390
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
391 391
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -393,626 +393,626 @@  discard block
 block discarded – undo
393 393
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
394 394
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
395 395
 					</tr>';
396
-                }
397
-                $trace_details .= '
396
+				}
397
+				$trace_details .= '
398 398
 			 </table>
399 399
 			</div>';
400
-            }
401
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
402
-            // add generic non-identifying messages for non-privileged users
403
-            if (! WP_DEBUG) {
404
-                $output .= '<span class="ee-error-user-msg-spn">'
405
-                           . trim($ex['msg'])
406
-                           . '</span> &nbsp; <sup>'
407
-                           . $ex['code']
408
-                           . '</sup><br />';
409
-            } else {
410
-                // or helpful developer messages if debugging is on
411
-                $output .= '
400
+			}
401
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
402
+			// add generic non-identifying messages for non-privileged users
403
+			if (! WP_DEBUG) {
404
+				$output .= '<span class="ee-error-user-msg-spn">'
405
+						   . trim($ex['msg'])
406
+						   . '</span> &nbsp; <sup>'
407
+						   . $ex['code']
408
+						   . '</sup><br />';
409
+			} else {
410
+				// or helpful developer messages if debugging is on
411
+				$output .= '
412 412
 		<div class="ee-error-dev-msg-dv">
413 413
 			<p class="ee-error-dev-msg-pg">
414 414
 				<strong class="ee-error-dev-msg-str">An '
415
-                           . $ex['name']
416
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
417
-                           . $ex['code']
418
-                           . '</span><br />
415
+						   . $ex['name']
416
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
417
+						   . $ex['code']
418
+						   . '</span><br />
419 419
 				<span class="big-text">"'
420
-                           . trim($ex['msg'])
421
-                           . '"</span><br/>
420
+						   . trim($ex['msg'])
421
+						   . '"</span><br/>
422 422
 				<a id="display-ee-error-trace-'
423
-                           . self::$_error_count
424
-                           . $time
425
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
426
-                           . self::$_error_count
427
-                           . $time
428
-                           . '">
423
+						   . self::$_error_count
424
+						   . $time
425
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
426
+						   . self::$_error_count
427
+						   . $time
428
+						   . '">
429 429
 					'
430
-                           . __('click to view backtrace and class/method details', 'event_espresso')
431
-                           . '
430
+						   . __('click to view backtrace and class/method details', 'event_espresso')
431
+						   . '
432 432
 				</a><br />
433 433
 				<span class="small-text lt-grey-text">'
434
-                           . $ex['file']
435
-                           . ' &nbsp; ( line no: '
436
-                           . $ex['line']
437
-                           . ' )</span>
434
+						   . $ex['file']
435
+						   . ' &nbsp; ( line no: '
436
+						   . $ex['line']
437
+						   . ' )</span>
438 438
 			</p>
439 439
 			<div id="ee-error-trace-'
440
-                           . self::$_error_count
441
-                           . $time
442
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
440
+						   . self::$_error_count
441
+						   . $time
442
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
443 443
 				'
444
-                           . $trace_details;
445
-                if (! empty($class)) {
446
-                    $output .= '
444
+						   . $trace_details;
445
+				if (! empty($class)) {
446
+					$output .= '
447 447
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
448 448
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
449 449
 						<h3>Class Details</h3>';
450
-                    $a = new ReflectionClass($class);
451
-                    $output .= '
450
+					$a = new ReflectionClass($class);
451
+					$output .= '
452 452
 						<pre>' . $a . '</pre>
453 453
 					</div>
454 454
 				</div>';
455
-                }
456
-                $output .= '
455
+				}
456
+				$output .= '
457 457
 			</div>
458 458
 		</div>
459 459
 		<br />';
460
-            }
461
-            $this->write_to_error_log($time, $ex);
462
-        }
463
-        // remove last linebreak
464
-        $output = substr($output, 0, -6);
465
-        if (! WP_DEBUG) {
466
-            $output .= '
460
+			}
461
+			$this->write_to_error_log($time, $ex);
462
+		}
463
+		// remove last linebreak
464
+		$output = substr($output, 0, -6);
465
+		if (! WP_DEBUG) {
466
+			$output .= '
467 467
 	</p>';
468
-        }
469
-        $output .= '
468
+		}
469
+		$output .= '
470 470
 </div>';
471
-        $output .= self::_print_scripts(true);
472
-        if (defined('DOING_AJAX')) {
473
-            echo wp_json_encode(array('error' => $output));
474
-            exit();
475
-        }
476
-        echo $output;
477
-        die();
478
-    }
479
-
480
-
481
-    /**
482
-     *    generate string from exception trace args
483
-     *
484
-     * @param array $arguments
485
-     * @param bool  $array
486
-     * @return string
487
-     */
488
-    private function _convert_args_to_string($arguments = array(), $array = false)
489
-    {
490
-        $arg_string = '';
491
-        if (! empty($arguments)) {
492
-            $args = array();
493
-            foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
495
-                    if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
497
-                    } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
-                    } elseif ($arg === null) {
500
-                        $args[] = ' NULL';
501
-                    } elseif (is_bool($arg)) {
502
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
503
-                    } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
505
-                    } elseif (is_resource($arg)) {
506
-                        $args[] = get_resource_type($arg);
507
-                    } else {
508
-                        $args[] = $arg;
509
-                    }
510
-                }
511
-            }
512
-            $arg_string = implode(', ', $args);
513
-        }
514
-        if ($array) {
515
-            $arg_string .= ' )';
516
-        }
517
-        return $arg_string;
518
-    }
519
-
520
-
521
-    /**
522
-     *    add error message
523
-     *
524
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
525
-     *                            separate messages for user || dev
526
-     * @param        string $file the file that the error occurred in - just use __FILE__
527
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
528
-     * @param        string $line the line number where the error occurred - just use __LINE__
529
-     * @return        void
530
-     */
531
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
532
-    {
533
-        self::_add_notice('errors', $msg, $file, $func, $line);
534
-        self::$_error_count++;
535
-    }
536
-
537
-
538
-    /**
539
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
540
-     * adds an error
541
-     *
542
-     * @param string $msg
543
-     * @param string $file
544
-     * @param string $func
545
-     * @param string $line
546
-     * @throws EE_Error
547
-     */
548
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
549
-    {
550
-        if (WP_DEBUG) {
551
-            throw new EE_Error($msg);
552
-        }
553
-        EE_Error::add_error($msg, $file, $func, $line);
554
-    }
555
-
556
-
557
-    /**
558
-     *    add success message
559
-     *
560
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
561
-     *                            separate messages for user || dev
562
-     * @param        string $file the file that the error occurred in - just use __FILE__
563
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
564
-     * @param        string $line the line number where the error occurred - just use __LINE__
565
-     * @return        void
566
-     */
567
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
568
-    {
569
-        self::_add_notice('success', $msg, $file, $func, $line);
570
-    }
571
-
572
-
573
-    /**
574
-     *    add attention message
575
-     *
576
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
577
-     *                            separate messages for user || dev
578
-     * @param        string $file the file that the error occurred in - just use __FILE__
579
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
580
-     * @param        string $line the line number where the error occurred - just use __LINE__
581
-     * @return        void
582
-     */
583
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
584
-    {
585
-        self::_add_notice('attention', $msg, $file, $func, $line);
586
-    }
587
-
588
-
589
-    /**
590
-     * @param string $type whether the message is for a success or error notification
591
-     * @param string $msg  the message to display to users or developers
592
-     *                     - adding a double pipe || (OR) creates separate messages for user || dev
593
-     * @param string $file the file that the error occurred in - just use __FILE__
594
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
595
-     * @param string $line the line number where the error occurred - just use __LINE__
596
-     * @return void
597
-     */
598
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
599
-    {
600
-        if (empty($msg)) {
601
-            EE_Error::doing_it_wrong(
602
-                'EE_Error::add_' . $type . '()',
603
-                sprintf(
604
-                    __(
605
-                        'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
606
-                        'event_espresso'
607
-                    ),
608
-                    $type,
609
-                    $file,
610
-                    $line
611
-                ),
612
-                EVENT_ESPRESSO_VERSION
613
-            );
614
-        }
615
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
616
-            EE_Error::doing_it_wrong(
617
-                'EE_Error::add_error()',
618
-                __(
619
-                    'You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
620
-                    'event_espresso'
621
-                ),
622
-                EVENT_ESPRESSO_VERSION
623
-            );
624
-        }
625
-        // get separate user and developer messages if they exist
626
-        $msg = explode('||', $msg);
627
-        $user_msg = $msg[0];
628
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
629
-        /**
630
-         * Do an action so other code can be triggered when a notice is created
631
-         *
632
-         * @param string $type     can be 'errors', 'attention', or 'success'
633
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
634
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
635
-         * @param string $file     file where error was generated
636
-         * @param string $func     function where error was generated
637
-         * @param string $line     line where error was generated
638
-         */
639
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
640
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
641
-        // add notice if message exists
642
-        if (! empty($msg)) {
643
-            // get error code
644
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
645
-            if (WP_DEBUG && $type === 'errors') {
646
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
647
-            }
648
-            // add notice. Index by code if it's not blank
649
-            if ($notice_code) {
650
-                self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
651
-            } else {
652
-                self::$_espresso_notices[ $type ][] = $msg;
653
-            }
654
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
655
-        }
656
-    }
657
-
658
-
659
-    /**
660
-     * in some case it may be necessary to overwrite the existing success messages
661
-     *
662
-     * @return        void
663
-     */
664
-    public static function overwrite_success()
665
-    {
666
-        self::$_espresso_notices['success'] = false;
667
-    }
668
-
669
-
670
-    /**
671
-     * in some case it may be necessary to overwrite the existing attention messages
672
-     *
673
-     * @return void
674
-     */
675
-    public static function overwrite_attention()
676
-    {
677
-        self::$_espresso_notices['attention'] = false;
678
-    }
679
-
680
-
681
-    /**
682
-     * in some case it may be necessary to overwrite the existing error messages
683
-     *
684
-     * @return void
685
-     */
686
-    public static function overwrite_errors()
687
-    {
688
-        self::$_espresso_notices['errors'] = false;
689
-    }
690
-
691
-
692
-    /**
693
-     * @return void
694
-     */
695
-    public static function reset_notices()
696
-    {
697
-        self::$_espresso_notices['success'] = false;
698
-        self::$_espresso_notices['attention'] = false;
699
-        self::$_espresso_notices['errors'] = false;
700
-    }
701
-
702
-
703
-    /**
704
-     * @return int
705
-     */
706
-    public static function has_notices()
707
-    {
708
-        $has_notices = 0;
709
-        // check for success messages
710
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
711
-            ? 3
712
-            : $has_notices;
713
-        // check for attention messages
714
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
715
-            ? 2
716
-            : $has_notices;
717
-        // check for error messages
718
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
719
-            ? 1
720
-            : $has_notices;
721
-        return $has_notices;
722
-    }
723
-
724
-
725
-    /**
726
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
727
-     *
728
-     * @since 4.9.0
729
-     * @return array
730
-     */
731
-    public static function get_vanilla_notices()
732
-    {
733
-        return array(
734
-            'success'   => isset(self::$_espresso_notices['success'])
735
-                ? self::$_espresso_notices['success']
736
-                : array(),
737
-            'attention' => isset(self::$_espresso_notices['attention'])
738
-                ? self::$_espresso_notices['attention']
739
-                : array(),
740
-            'errors'    => isset(self::$_espresso_notices['errors'])
741
-                ? self::$_espresso_notices['errors']
742
-                : array(),
743
-        );
744
-    }
745
-
746
-
747
-    /**
748
-     * @return array
749
-     * @throws InvalidArgumentException
750
-     * @throws InvalidDataTypeException
751
-     * @throws InvalidInterfaceException
752
-     */
753
-    public static function getStoredNotices()
754
-    {
755
-        if ($user_id = get_current_user_id()) {
756
-            // get notices for logged in user
757
-            $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
758
-            return is_array($notices) ? $notices : array();
759
-        }
760
-        if (EE_Session::isLoadedAndActive()) {
761
-            // get notices for user currently engaged in a session
762
-            $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
763
-            return is_array($session_data) ? $session_data : array();
764
-        }
765
-        // get global notices and hope they apply to the current site visitor
766
-        $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
767
-        return is_array($notices) ? $notices : array();
768
-    }
769
-
770
-
771
-    /**
772
-     * @param array $notices
773
-     * @return bool
774
-     * @throws InvalidArgumentException
775
-     * @throws InvalidDataTypeException
776
-     * @throws InvalidInterfaceException
777
-     */
778
-    public static function storeNotices(array $notices)
779
-    {
780
-        if ($user_id = get_current_user_id()) {
781
-            // store notices for logged in user
782
-            return (bool) update_user_option(
783
-                $user_id,
784
-                EE_Error::OPTIONS_KEY_NOTICES,
785
-                $notices
786
-            );
787
-        }
788
-        if (EE_Session::isLoadedAndActive()) {
789
-            // store notices for user currently engaged in a session
790
-            return EE_Session::instance()->set_session_data(
791
-                array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
792
-            );
793
-        }
794
-        // store global notices and hope they apply to the same site visitor on the next request
795
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
796
-    }
797
-
798
-
799
-    /**
800
-     * @return bool|TRUE
801
-     * @throws InvalidArgumentException
802
-     * @throws InvalidDataTypeException
803
-     * @throws InvalidInterfaceException
804
-     */
805
-    public static function clearNotices()
806
-    {
807
-        if ($user_id = get_current_user_id()) {
808
-            // clear notices for logged in user
809
-            return (bool) update_user_option(
810
-                $user_id,
811
-                EE_Error::OPTIONS_KEY_NOTICES,
812
-                array()
813
-            );
814
-        }
815
-        if (EE_Session::isLoadedAndActive()) {
816
-            // clear notices for user currently engaged in a session
817
-            return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
818
-        }
819
-        // clear global notices and hope none belonged to some for some other site visitor
820
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
821
-    }
822
-
823
-
824
-    /**
825
-     * saves notices to the db for retrieval on next request
826
-     *
827
-     * @return void
828
-     * @throws InvalidArgumentException
829
-     * @throws InvalidDataTypeException
830
-     * @throws InvalidInterfaceException
831
-     */
832
-    public static function stashNoticesBeforeRedirect()
833
-    {
834
-        EE_Error::get_notices(false, true);
835
-    }
836
-
837
-
838
-    /**
839
-     * compile all error or success messages into one string
840
-     *
841
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
842
-     * @param boolean $format_output            whether or not to format the messages for display in the WP admin
843
-     * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
844
-     *                                          - ONLY do this just before redirecting
845
-     * @param boolean $remove_empty             whether or not to unset empty messages
846
-     * @return array
847
-     * @throws InvalidArgumentException
848
-     * @throws InvalidDataTypeException
849
-     * @throws InvalidInterfaceException
850
-     */
851
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
852
-    {
853
-        $success_messages = '';
854
-        $attention_messages = '';
855
-        $error_messages = '';
856
-        // either save notices to the db
857
-        if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
858
-            self::$_espresso_notices = array_merge(
859
-                EE_Error::getStoredNotices(),
860
-                self::$_espresso_notices
861
-            );
862
-            EE_Error::storeNotices(self::$_espresso_notices);
863
-            return array();
864
-        }
865
-        $print_scripts = EE_Error::combineExistingAndNewNotices();
866
-        // check for success messages
867
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
868
-            // combine messages
869
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
870
-            $print_scripts = true;
871
-        }
872
-        // check for attention messages
873
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
874
-            // combine messages
875
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
876
-            $print_scripts = true;
877
-        }
878
-        // check for error messages
879
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
880
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
881
-                ? __('The following errors have occurred:<br />', 'event_espresso')
882
-                : __('An error has occurred:<br />', 'event_espresso');
883
-            // combine messages
884
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
885
-            $print_scripts = true;
886
-        }
887
-        if ($format_output) {
888
-            $notices = EE_Error::formatNoticesOutput(
889
-                $success_messages,
890
-                $attention_messages,
891
-                $error_messages
892
-            );
893
-        } else {
894
-            $notices = array(
895
-                'success'   => $success_messages,
896
-                'attention' => $attention_messages,
897
-                'errors'    => $error_messages,
898
-            );
899
-            if ($remove_empty) {
900
-                // remove empty notices
901
-                foreach ($notices as $type => $notice) {
902
-                    if (empty($notice)) {
903
-                        unset($notices[ $type ]);
904
-                    }
905
-                }
906
-            }
907
-        }
908
-        if ($print_scripts) {
909
-            self::_print_scripts();
910
-        }
911
-        return $notices;
912
-    }
913
-
914
-
915
-    /**
916
-     * @return bool
917
-     * @throws InvalidArgumentException
918
-     * @throws InvalidDataTypeException
919
-     * @throws InvalidInterfaceException
920
-     */
921
-    private static function combineExistingAndNewNotices()
922
-    {
923
-        $print_scripts = false;
924
-        // grab any notices that have been previously saved
925
-        $notices = EE_Error::getStoredNotices();
926
-        if (! empty($notices)) {
927
-            foreach ($notices as $type => $notice) {
928
-                if (is_array($notice) && ! empty($notice)) {
929
-                    // make sure that existing notice type is an array
930
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
931
-                                                        && ! empty(self::$_espresso_notices[ $type ])
932
-                        ? self::$_espresso_notices[ $type ]
933
-                        : array();
934
-                    // add newly created notices to existing ones
935
-                    self::$_espresso_notices[ $type ] += $notice;
936
-                    $print_scripts = true;
937
-                }
938
-            }
939
-            // now clear any stored notices
940
-            EE_Error::clearNotices();
941
-        }
942
-        return $print_scripts;
943
-    }
944
-
945
-
946
-    /**
947
-     * @param string $success_messages
948
-     * @param string $attention_messages
949
-     * @param string $error_messages
950
-     * @return string
951
-     */
952
-    private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
953
-    {
954
-        $notices = '<div id="espresso-notices">';
955
-        $close = is_admin()
956
-            ? ''
957
-            : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
958
-        if ($success_messages !== '') {
959
-            $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
960
-            $css_class = is_admin() ? 'updated fade' : 'success fade-away';
961
-            // showMessage( $success_messages );
962
-            $notices .= '<div id="' . $css_id . '" '
963
-                        . 'class="espresso-notices ' . $css_class . '" '
964
-                        . 'style="display:none;">'
965
-                        . '<p>' . $success_messages . '</p>'
966
-                        . $close
967
-                        . '</div>';
968
-        }
969
-        if ($attention_messages !== '') {
970
-            $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
971
-            $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
972
-            // showMessage( $error_messages, TRUE );
973
-            $notices .= '<div id="' . $css_id . '" '
974
-                        . 'class="espresso-notices ' . $css_class . '" '
975
-                        . 'style="display:none;">'
976
-                        . '<p>' . $attention_messages . '</p>'
977
-                        . $close
978
-                        . '</div>';
979
-        }
980
-        if ($error_messages !== '') {
981
-            $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
982
-            $css_class = is_admin() ? 'error' : 'error fade-away';
983
-            // showMessage( $error_messages, TRUE );
984
-            $notices .= '<div id="' . $css_id . '" '
985
-                        . 'class="espresso-notices ' . $css_class . '" '
986
-                        . 'style="display:none;">'
987
-                        . '<p>' . $error_messages . '</p>'
988
-                        . $close
989
-                        . '</div>';
990
-        }
991
-        $notices .= '</div>';
992
-        return $notices;
993
-    }
994
-
995
-
996
-    /**
997
-     * _print_scripts
998
-     *
999
-     * @param    bool $force_print
1000
-     * @return    string
1001
-     */
1002
-    private static function _print_scripts($force_print = false)
1003
-    {
1004
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1005
-            if (wp_script_is('ee_error_js', 'registered')) {
1006
-                wp_enqueue_style('espresso_default');
1007
-                wp_enqueue_style('espresso_custom_css');
1008
-                wp_enqueue_script('ee_error_js');
1009
-            }
1010
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1011
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1012
-                return '';
1013
-            }
1014
-        } else {
1015
-            return '
471
+		$output .= self::_print_scripts(true);
472
+		if (defined('DOING_AJAX')) {
473
+			echo wp_json_encode(array('error' => $output));
474
+			exit();
475
+		}
476
+		echo $output;
477
+		die();
478
+	}
479
+
480
+
481
+	/**
482
+	 *    generate string from exception trace args
483
+	 *
484
+	 * @param array $arguments
485
+	 * @param bool  $array
486
+	 * @return string
487
+	 */
488
+	private function _convert_args_to_string($arguments = array(), $array = false)
489
+	{
490
+		$arg_string = '';
491
+		if (! empty($arguments)) {
492
+			$args = array();
493
+			foreach ($arguments as $arg) {
494
+				if (! empty($arg)) {
495
+					if (is_string($arg)) {
496
+						$args[] = " '" . $arg . "'";
497
+					} elseif (is_array($arg)) {
498
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
499
+					} elseif ($arg === null) {
500
+						$args[] = ' NULL';
501
+					} elseif (is_bool($arg)) {
502
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
503
+					} elseif (is_object($arg)) {
504
+						$args[] = ' OBJECT ' . get_class($arg);
505
+					} elseif (is_resource($arg)) {
506
+						$args[] = get_resource_type($arg);
507
+					} else {
508
+						$args[] = $arg;
509
+					}
510
+				}
511
+			}
512
+			$arg_string = implode(', ', $args);
513
+		}
514
+		if ($array) {
515
+			$arg_string .= ' )';
516
+		}
517
+		return $arg_string;
518
+	}
519
+
520
+
521
+	/**
522
+	 *    add error message
523
+	 *
524
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
525
+	 *                            separate messages for user || dev
526
+	 * @param        string $file the file that the error occurred in - just use __FILE__
527
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
528
+	 * @param        string $line the line number where the error occurred - just use __LINE__
529
+	 * @return        void
530
+	 */
531
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
532
+	{
533
+		self::_add_notice('errors', $msg, $file, $func, $line);
534
+		self::$_error_count++;
535
+	}
536
+
537
+
538
+	/**
539
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
540
+	 * adds an error
541
+	 *
542
+	 * @param string $msg
543
+	 * @param string $file
544
+	 * @param string $func
545
+	 * @param string $line
546
+	 * @throws EE_Error
547
+	 */
548
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
549
+	{
550
+		if (WP_DEBUG) {
551
+			throw new EE_Error($msg);
552
+		}
553
+		EE_Error::add_error($msg, $file, $func, $line);
554
+	}
555
+
556
+
557
+	/**
558
+	 *    add success message
559
+	 *
560
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
561
+	 *                            separate messages for user || dev
562
+	 * @param        string $file the file that the error occurred in - just use __FILE__
563
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
564
+	 * @param        string $line the line number where the error occurred - just use __LINE__
565
+	 * @return        void
566
+	 */
567
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
568
+	{
569
+		self::_add_notice('success', $msg, $file, $func, $line);
570
+	}
571
+
572
+
573
+	/**
574
+	 *    add attention message
575
+	 *
576
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
577
+	 *                            separate messages for user || dev
578
+	 * @param        string $file the file that the error occurred in - just use __FILE__
579
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
580
+	 * @param        string $line the line number where the error occurred - just use __LINE__
581
+	 * @return        void
582
+	 */
583
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
584
+	{
585
+		self::_add_notice('attention', $msg, $file, $func, $line);
586
+	}
587
+
588
+
589
+	/**
590
+	 * @param string $type whether the message is for a success or error notification
591
+	 * @param string $msg  the message to display to users or developers
592
+	 *                     - adding a double pipe || (OR) creates separate messages for user || dev
593
+	 * @param string $file the file that the error occurred in - just use __FILE__
594
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
595
+	 * @param string $line the line number where the error occurred - just use __LINE__
596
+	 * @return void
597
+	 */
598
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
599
+	{
600
+		if (empty($msg)) {
601
+			EE_Error::doing_it_wrong(
602
+				'EE_Error::add_' . $type . '()',
603
+				sprintf(
604
+					__(
605
+						'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
606
+						'event_espresso'
607
+					),
608
+					$type,
609
+					$file,
610
+					$line
611
+				),
612
+				EVENT_ESPRESSO_VERSION
613
+			);
614
+		}
615
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
616
+			EE_Error::doing_it_wrong(
617
+				'EE_Error::add_error()',
618
+				__(
619
+					'You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
620
+					'event_espresso'
621
+				),
622
+				EVENT_ESPRESSO_VERSION
623
+			);
624
+		}
625
+		// get separate user and developer messages if they exist
626
+		$msg = explode('||', $msg);
627
+		$user_msg = $msg[0];
628
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
629
+		/**
630
+		 * Do an action so other code can be triggered when a notice is created
631
+		 *
632
+		 * @param string $type     can be 'errors', 'attention', or 'success'
633
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
634
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
635
+		 * @param string $file     file where error was generated
636
+		 * @param string $func     function where error was generated
637
+		 * @param string $line     line where error was generated
638
+		 */
639
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
640
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
641
+		// add notice if message exists
642
+		if (! empty($msg)) {
643
+			// get error code
644
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
645
+			if (WP_DEBUG && $type === 'errors') {
646
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
647
+			}
648
+			// add notice. Index by code if it's not blank
649
+			if ($notice_code) {
650
+				self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
651
+			} else {
652
+				self::$_espresso_notices[ $type ][] = $msg;
653
+			}
654
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
655
+		}
656
+	}
657
+
658
+
659
+	/**
660
+	 * in some case it may be necessary to overwrite the existing success messages
661
+	 *
662
+	 * @return        void
663
+	 */
664
+	public static function overwrite_success()
665
+	{
666
+		self::$_espresso_notices['success'] = false;
667
+	}
668
+
669
+
670
+	/**
671
+	 * in some case it may be necessary to overwrite the existing attention messages
672
+	 *
673
+	 * @return void
674
+	 */
675
+	public static function overwrite_attention()
676
+	{
677
+		self::$_espresso_notices['attention'] = false;
678
+	}
679
+
680
+
681
+	/**
682
+	 * in some case it may be necessary to overwrite the existing error messages
683
+	 *
684
+	 * @return void
685
+	 */
686
+	public static function overwrite_errors()
687
+	{
688
+		self::$_espresso_notices['errors'] = false;
689
+	}
690
+
691
+
692
+	/**
693
+	 * @return void
694
+	 */
695
+	public static function reset_notices()
696
+	{
697
+		self::$_espresso_notices['success'] = false;
698
+		self::$_espresso_notices['attention'] = false;
699
+		self::$_espresso_notices['errors'] = false;
700
+	}
701
+
702
+
703
+	/**
704
+	 * @return int
705
+	 */
706
+	public static function has_notices()
707
+	{
708
+		$has_notices = 0;
709
+		// check for success messages
710
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
711
+			? 3
712
+			: $has_notices;
713
+		// check for attention messages
714
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
715
+			? 2
716
+			: $has_notices;
717
+		// check for error messages
718
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
719
+			? 1
720
+			: $has_notices;
721
+		return $has_notices;
722
+	}
723
+
724
+
725
+	/**
726
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
727
+	 *
728
+	 * @since 4.9.0
729
+	 * @return array
730
+	 */
731
+	public static function get_vanilla_notices()
732
+	{
733
+		return array(
734
+			'success'   => isset(self::$_espresso_notices['success'])
735
+				? self::$_espresso_notices['success']
736
+				: array(),
737
+			'attention' => isset(self::$_espresso_notices['attention'])
738
+				? self::$_espresso_notices['attention']
739
+				: array(),
740
+			'errors'    => isset(self::$_espresso_notices['errors'])
741
+				? self::$_espresso_notices['errors']
742
+				: array(),
743
+		);
744
+	}
745
+
746
+
747
+	/**
748
+	 * @return array
749
+	 * @throws InvalidArgumentException
750
+	 * @throws InvalidDataTypeException
751
+	 * @throws InvalidInterfaceException
752
+	 */
753
+	public static function getStoredNotices()
754
+	{
755
+		if ($user_id = get_current_user_id()) {
756
+			// get notices for logged in user
757
+			$notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
758
+			return is_array($notices) ? $notices : array();
759
+		}
760
+		if (EE_Session::isLoadedAndActive()) {
761
+			// get notices for user currently engaged in a session
762
+			$session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
763
+			return is_array($session_data) ? $session_data : array();
764
+		}
765
+		// get global notices and hope they apply to the current site visitor
766
+		$notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
767
+		return is_array($notices) ? $notices : array();
768
+	}
769
+
770
+
771
+	/**
772
+	 * @param array $notices
773
+	 * @return bool
774
+	 * @throws InvalidArgumentException
775
+	 * @throws InvalidDataTypeException
776
+	 * @throws InvalidInterfaceException
777
+	 */
778
+	public static function storeNotices(array $notices)
779
+	{
780
+		if ($user_id = get_current_user_id()) {
781
+			// store notices for logged in user
782
+			return (bool) update_user_option(
783
+				$user_id,
784
+				EE_Error::OPTIONS_KEY_NOTICES,
785
+				$notices
786
+			);
787
+		}
788
+		if (EE_Session::isLoadedAndActive()) {
789
+			// store notices for user currently engaged in a session
790
+			return EE_Session::instance()->set_session_data(
791
+				array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
792
+			);
793
+		}
794
+		// store global notices and hope they apply to the same site visitor on the next request
795
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
796
+	}
797
+
798
+
799
+	/**
800
+	 * @return bool|TRUE
801
+	 * @throws InvalidArgumentException
802
+	 * @throws InvalidDataTypeException
803
+	 * @throws InvalidInterfaceException
804
+	 */
805
+	public static function clearNotices()
806
+	{
807
+		if ($user_id = get_current_user_id()) {
808
+			// clear notices for logged in user
809
+			return (bool) update_user_option(
810
+				$user_id,
811
+				EE_Error::OPTIONS_KEY_NOTICES,
812
+				array()
813
+			);
814
+		}
815
+		if (EE_Session::isLoadedAndActive()) {
816
+			// clear notices for user currently engaged in a session
817
+			return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
818
+		}
819
+		// clear global notices and hope none belonged to some for some other site visitor
820
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
821
+	}
822
+
823
+
824
+	/**
825
+	 * saves notices to the db for retrieval on next request
826
+	 *
827
+	 * @return void
828
+	 * @throws InvalidArgumentException
829
+	 * @throws InvalidDataTypeException
830
+	 * @throws InvalidInterfaceException
831
+	 */
832
+	public static function stashNoticesBeforeRedirect()
833
+	{
834
+		EE_Error::get_notices(false, true);
835
+	}
836
+
837
+
838
+	/**
839
+	 * compile all error or success messages into one string
840
+	 *
841
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
842
+	 * @param boolean $format_output            whether or not to format the messages for display in the WP admin
843
+	 * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
844
+	 *                                          - ONLY do this just before redirecting
845
+	 * @param boolean $remove_empty             whether or not to unset empty messages
846
+	 * @return array
847
+	 * @throws InvalidArgumentException
848
+	 * @throws InvalidDataTypeException
849
+	 * @throws InvalidInterfaceException
850
+	 */
851
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
852
+	{
853
+		$success_messages = '';
854
+		$attention_messages = '';
855
+		$error_messages = '';
856
+		// either save notices to the db
857
+		if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
858
+			self::$_espresso_notices = array_merge(
859
+				EE_Error::getStoredNotices(),
860
+				self::$_espresso_notices
861
+			);
862
+			EE_Error::storeNotices(self::$_espresso_notices);
863
+			return array();
864
+		}
865
+		$print_scripts = EE_Error::combineExistingAndNewNotices();
866
+		// check for success messages
867
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
868
+			// combine messages
869
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
870
+			$print_scripts = true;
871
+		}
872
+		// check for attention messages
873
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
874
+			// combine messages
875
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
876
+			$print_scripts = true;
877
+		}
878
+		// check for error messages
879
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
880
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
881
+				? __('The following errors have occurred:<br />', 'event_espresso')
882
+				: __('An error has occurred:<br />', 'event_espresso');
883
+			// combine messages
884
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
885
+			$print_scripts = true;
886
+		}
887
+		if ($format_output) {
888
+			$notices = EE_Error::formatNoticesOutput(
889
+				$success_messages,
890
+				$attention_messages,
891
+				$error_messages
892
+			);
893
+		} else {
894
+			$notices = array(
895
+				'success'   => $success_messages,
896
+				'attention' => $attention_messages,
897
+				'errors'    => $error_messages,
898
+			);
899
+			if ($remove_empty) {
900
+				// remove empty notices
901
+				foreach ($notices as $type => $notice) {
902
+					if (empty($notice)) {
903
+						unset($notices[ $type ]);
904
+					}
905
+				}
906
+			}
907
+		}
908
+		if ($print_scripts) {
909
+			self::_print_scripts();
910
+		}
911
+		return $notices;
912
+	}
913
+
914
+
915
+	/**
916
+	 * @return bool
917
+	 * @throws InvalidArgumentException
918
+	 * @throws InvalidDataTypeException
919
+	 * @throws InvalidInterfaceException
920
+	 */
921
+	private static function combineExistingAndNewNotices()
922
+	{
923
+		$print_scripts = false;
924
+		// grab any notices that have been previously saved
925
+		$notices = EE_Error::getStoredNotices();
926
+		if (! empty($notices)) {
927
+			foreach ($notices as $type => $notice) {
928
+				if (is_array($notice) && ! empty($notice)) {
929
+					// make sure that existing notice type is an array
930
+					self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
931
+														&& ! empty(self::$_espresso_notices[ $type ])
932
+						? self::$_espresso_notices[ $type ]
933
+						: array();
934
+					// add newly created notices to existing ones
935
+					self::$_espresso_notices[ $type ] += $notice;
936
+					$print_scripts = true;
937
+				}
938
+			}
939
+			// now clear any stored notices
940
+			EE_Error::clearNotices();
941
+		}
942
+		return $print_scripts;
943
+	}
944
+
945
+
946
+	/**
947
+	 * @param string $success_messages
948
+	 * @param string $attention_messages
949
+	 * @param string $error_messages
950
+	 * @return string
951
+	 */
952
+	private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
953
+	{
954
+		$notices = '<div id="espresso-notices">';
955
+		$close = is_admin()
956
+			? ''
957
+			: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
958
+		if ($success_messages !== '') {
959
+			$css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
960
+			$css_class = is_admin() ? 'updated fade' : 'success fade-away';
961
+			// showMessage( $success_messages );
962
+			$notices .= '<div id="' . $css_id . '" '
963
+						. 'class="espresso-notices ' . $css_class . '" '
964
+						. 'style="display:none;">'
965
+						. '<p>' . $success_messages . '</p>'
966
+						. $close
967
+						. '</div>';
968
+		}
969
+		if ($attention_messages !== '') {
970
+			$css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
971
+			$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
972
+			// showMessage( $error_messages, TRUE );
973
+			$notices .= '<div id="' . $css_id . '" '
974
+						. 'class="espresso-notices ' . $css_class . '" '
975
+						. 'style="display:none;">'
976
+						. '<p>' . $attention_messages . '</p>'
977
+						. $close
978
+						. '</div>';
979
+		}
980
+		if ($error_messages !== '') {
981
+			$css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
982
+			$css_class = is_admin() ? 'error' : 'error fade-away';
983
+			// showMessage( $error_messages, TRUE );
984
+			$notices .= '<div id="' . $css_id . '" '
985
+						. 'class="espresso-notices ' . $css_class . '" '
986
+						. 'style="display:none;">'
987
+						. '<p>' . $error_messages . '</p>'
988
+						. $close
989
+						. '</div>';
990
+		}
991
+		$notices .= '</div>';
992
+		return $notices;
993
+	}
994
+
995
+
996
+	/**
997
+	 * _print_scripts
998
+	 *
999
+	 * @param    bool $force_print
1000
+	 * @return    string
1001
+	 */
1002
+	private static function _print_scripts($force_print = false)
1003
+	{
1004
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1005
+			if (wp_script_is('ee_error_js', 'registered')) {
1006
+				wp_enqueue_style('espresso_default');
1007
+				wp_enqueue_style('espresso_custom_css');
1008
+				wp_enqueue_script('ee_error_js');
1009
+			}
1010
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1011
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1012
+				return '';
1013
+			}
1014
+		} else {
1015
+			return '
1016 1016
 <script>
1017 1017
 /* <![CDATA[ */
1018 1018
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1022,221 +1022,221 @@  discard block
 block discarded – undo
1022 1022
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1023 1023
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1024 1024
 ';
1025
-        }
1026
-        return '';
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * @return void
1032
-     */
1033
-    public static function enqueue_error_scripts()
1034
-    {
1035
-        self::_print_scripts();
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * create error code from filepath, function name,
1041
-     * and line number where exception or error was thrown
1042
-     *
1043
-     * @param string $file
1044
-     * @param string $func
1045
-     * @param string $line
1046
-     * @return string
1047
-     */
1048
-    public static function generate_error_code($file = '', $func = '', $line = '')
1049
-    {
1050
-        $file = explode('.', basename($file));
1051
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1052
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1053
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1054
-        return $error_code;
1055
-    }
1056
-
1057
-
1058
-    /**
1059
-     * write exception details to log file
1060
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1061
-     *
1062
-     * @param int   $time
1063
-     * @param array $ex
1064
-     * @param bool  $clear
1065
-     * @return void
1066
-     */
1067
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1068
-    {
1069
-        if (empty($ex)) {
1070
-            return;
1071
-        }
1072
-        if (! $time) {
1073
-            $time = time();
1074
-        }
1075
-        $exception_log = '----------------------------------------------------------------------------------------'
1076
-                         . PHP_EOL;
1077
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1078
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1079
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1080
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1081
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1082
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1083
-        $exception_log .= $ex['string'] . PHP_EOL;
1084
-        $exception_log .= '----------------------------------------------------------------------------------------'
1085
-                          . PHP_EOL;
1086
-        try {
1087
-            error_log($exception_log);
1088
-        } catch (EE_Error $e) {
1089
-            EE_Error::add_error(
1090
-                sprintf(
1091
-                    __(
1092
-                        'Event Espresso error logging could not be setup because: %s',
1093
-                        'event_espresso'
1094
-                    ),
1095
-                    $e->getMessage()
1096
-                )
1097
-            );
1098
-        }
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1104
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1105
-     * but the code execution is done in a manner that could lead to unexpected results
1106
-     * (i.e. running to early, or too late in WP or EE loading process).
1107
-     * A good test for knowing whether to use this method is:
1108
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1109
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1110
-     * 2. If this is loaded before something else, it won't break anything,
1111
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1112
-     *
1113
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1114
-     * @param string $function      The function that was called
1115
-     * @param string $message       A message explaining what has been done incorrectly
1116
-     * @param string $version       The version of Event Espresso where the error was added
1117
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1118
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1119
-     *                              but not have any notices appear until a later version. This allows developers
1120
-     *                              extra time to update their code before notices appear.
1121
-     * @param int    $error_type
1122
-     */
1123
-    public static function doing_it_wrong(
1124
-        $function,
1125
-        $message,
1126
-        $version,
1127
-        $applies_when = '',
1128
-        $error_type = null
1129
-    ) {
1130
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1131
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1132
-        }
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * Like get_notices, but returns an array of all the notices of the given type.
1138
-     *
1139
-     * @return array {
1140
-     * @type array $success   all the success messages
1141
-     * @type array $errors    all the error messages
1142
-     * @type array $attention all the attention messages
1143
-     * }
1144
-     */
1145
-    public static function get_raw_notices()
1146
-    {
1147
-        return self::$_espresso_notices;
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * @deprecated 4.9.27
1153
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1154
-     * @param string $pan_message  the message to be stored persistently until dismissed
1155
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1156
-     * @return void
1157
-     * @throws InvalidDataTypeException
1158
-     */
1159
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1160
-    {
1161
-        new PersistentAdminNotice(
1162
-            $pan_name,
1163
-            $pan_message,
1164
-            $force_update
1165
-        );
1166
-        EE_Error::doing_it_wrong(
1167
-            __METHOD__,
1168
-            sprintf(
1169
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1170
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1171
-            ),
1172
-            '4.9.27'
1173
-        );
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * @deprecated 4.9.27
1179
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1180
-     * @param bool   $purge
1181
-     * @param bool   $return
1182
-     * @throws DomainException
1183
-     * @throws InvalidInterfaceException
1184
-     * @throws InvalidDataTypeException
1185
-     * @throws ServiceNotFoundException
1186
-     * @throws InvalidArgumentException
1187
-     */
1188
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1189
-    {
1190
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1191
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1192
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1193
-        );
1194
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1195
-        EE_Error::doing_it_wrong(
1196
-            __METHOD__,
1197
-            sprintf(
1198
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1199
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1200
-            ),
1201
-            '4.9.27'
1202
-        );
1203
-    }
1204
-
1205
-
1206
-    /**
1207
-     * @deprecated 4.9.27
1208
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1209
-     * @param  string $pan_message the message to be stored persistently until dismissed
1210
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1211
-     */
1212
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1213
-    {
1214
-        EE_Error::doing_it_wrong(
1215
-            __METHOD__,
1216
-            sprintf(
1217
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1218
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1219
-            ),
1220
-            '4.9.27'
1221
-        );
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * @deprecated 4.9.27
1227
-     * @param string $return_url
1228
-     */
1229
-    public static function get_persistent_admin_notices($return_url = '')
1230
-    {
1231
-        EE_Error::doing_it_wrong(
1232
-            __METHOD__,
1233
-            sprintf(
1234
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1235
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1236
-            ),
1237
-            '4.9.27'
1238
-        );
1239
-    }
1025
+		}
1026
+		return '';
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * @return void
1032
+	 */
1033
+	public static function enqueue_error_scripts()
1034
+	{
1035
+		self::_print_scripts();
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * create error code from filepath, function name,
1041
+	 * and line number where exception or error was thrown
1042
+	 *
1043
+	 * @param string $file
1044
+	 * @param string $func
1045
+	 * @param string $line
1046
+	 * @return string
1047
+	 */
1048
+	public static function generate_error_code($file = '', $func = '', $line = '')
1049
+	{
1050
+		$file = explode('.', basename($file));
1051
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1052
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1053
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1054
+		return $error_code;
1055
+	}
1056
+
1057
+
1058
+	/**
1059
+	 * write exception details to log file
1060
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1061
+	 *
1062
+	 * @param int   $time
1063
+	 * @param array $ex
1064
+	 * @param bool  $clear
1065
+	 * @return void
1066
+	 */
1067
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1068
+	{
1069
+		if (empty($ex)) {
1070
+			return;
1071
+		}
1072
+		if (! $time) {
1073
+			$time = time();
1074
+		}
1075
+		$exception_log = '----------------------------------------------------------------------------------------'
1076
+						 . PHP_EOL;
1077
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1078
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1079
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1080
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1081
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1082
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1083
+		$exception_log .= $ex['string'] . PHP_EOL;
1084
+		$exception_log .= '----------------------------------------------------------------------------------------'
1085
+						  . PHP_EOL;
1086
+		try {
1087
+			error_log($exception_log);
1088
+		} catch (EE_Error $e) {
1089
+			EE_Error::add_error(
1090
+				sprintf(
1091
+					__(
1092
+						'Event Espresso error logging could not be setup because: %s',
1093
+						'event_espresso'
1094
+					),
1095
+					$e->getMessage()
1096
+				)
1097
+			);
1098
+		}
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1104
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1105
+	 * but the code execution is done in a manner that could lead to unexpected results
1106
+	 * (i.e. running to early, or too late in WP or EE loading process).
1107
+	 * A good test for knowing whether to use this method is:
1108
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1109
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1110
+	 * 2. If this is loaded before something else, it won't break anything,
1111
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1112
+	 *
1113
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1114
+	 * @param string $function      The function that was called
1115
+	 * @param string $message       A message explaining what has been done incorrectly
1116
+	 * @param string $version       The version of Event Espresso where the error was added
1117
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1118
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1119
+	 *                              but not have any notices appear until a later version. This allows developers
1120
+	 *                              extra time to update their code before notices appear.
1121
+	 * @param int    $error_type
1122
+	 */
1123
+	public static function doing_it_wrong(
1124
+		$function,
1125
+		$message,
1126
+		$version,
1127
+		$applies_when = '',
1128
+		$error_type = null
1129
+	) {
1130
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1131
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1132
+		}
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * Like get_notices, but returns an array of all the notices of the given type.
1138
+	 *
1139
+	 * @return array {
1140
+	 * @type array $success   all the success messages
1141
+	 * @type array $errors    all the error messages
1142
+	 * @type array $attention all the attention messages
1143
+	 * }
1144
+	 */
1145
+	public static function get_raw_notices()
1146
+	{
1147
+		return self::$_espresso_notices;
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * @deprecated 4.9.27
1153
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1154
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1155
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1156
+	 * @return void
1157
+	 * @throws InvalidDataTypeException
1158
+	 */
1159
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1160
+	{
1161
+		new PersistentAdminNotice(
1162
+			$pan_name,
1163
+			$pan_message,
1164
+			$force_update
1165
+		);
1166
+		EE_Error::doing_it_wrong(
1167
+			__METHOD__,
1168
+			sprintf(
1169
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1170
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1171
+			),
1172
+			'4.9.27'
1173
+		);
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * @deprecated 4.9.27
1179
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1180
+	 * @param bool   $purge
1181
+	 * @param bool   $return
1182
+	 * @throws DomainException
1183
+	 * @throws InvalidInterfaceException
1184
+	 * @throws InvalidDataTypeException
1185
+	 * @throws ServiceNotFoundException
1186
+	 * @throws InvalidArgumentException
1187
+	 */
1188
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1189
+	{
1190
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1191
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1192
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1193
+		);
1194
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1195
+		EE_Error::doing_it_wrong(
1196
+			__METHOD__,
1197
+			sprintf(
1198
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1199
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1200
+			),
1201
+			'4.9.27'
1202
+		);
1203
+	}
1204
+
1205
+
1206
+	/**
1207
+	 * @deprecated 4.9.27
1208
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1209
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1210
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1211
+	 */
1212
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1213
+	{
1214
+		EE_Error::doing_it_wrong(
1215
+			__METHOD__,
1216
+			sprintf(
1217
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1218
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1219
+			),
1220
+			'4.9.27'
1221
+		);
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * @deprecated 4.9.27
1227
+	 * @param string $return_url
1228
+	 */
1229
+	public static function get_persistent_admin_notices($return_url = '')
1230
+	{
1231
+		EE_Error::doing_it_wrong(
1232
+			__METHOD__,
1233
+			sprintf(
1234
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1235
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1236
+			),
1237
+			'4.9.27'
1238
+		);
1239
+	}
1240 1240
 }
1241 1241
 
1242 1242
 // end of Class EE_Exceptions
@@ -1249,27 +1249,27 @@  discard block
 block discarded – undo
1249 1249
  */
1250 1250
 function espresso_error_enqueue_scripts()
1251 1251
 {
1252
-    // js for error handling
1253
-    wp_register_script(
1254
-        'espresso_core',
1255
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1256
-        array('jquery'),
1257
-        EVENT_ESPRESSO_VERSION,
1258
-        false
1259
-    );
1260
-    wp_register_script(
1261
-        'ee_error_js',
1262
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1263
-        array('espresso_core'),
1264
-        EVENT_ESPRESSO_VERSION,
1265
-        false
1266
-    );
1252
+	// js for error handling
1253
+	wp_register_script(
1254
+		'espresso_core',
1255
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1256
+		array('jquery'),
1257
+		EVENT_ESPRESSO_VERSION,
1258
+		false
1259
+	);
1260
+	wp_register_script(
1261
+		'ee_error_js',
1262
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1263
+		array('espresso_core'),
1264
+		EVENT_ESPRESSO_VERSION,
1265
+		false
1266
+	);
1267 1267
 }
1268 1268
 
1269 1269
 if (is_admin()) {
1270
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1270
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1271 1271
 } else {
1272
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1272
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 5);
1273 1273
 }
1274 1274
 
1275 1275
 
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
             default:
100 100
                 $to = get_option('admin_email');
101 101
         }
102
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
103 103
         $msg = EE_Error::_format_error($type, $message, $file, $line);
104 104
         if (function_exists('wp_mail')) {
105 105
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
106 106
             wp_mail($to, $subject, $msg);
107 107
         }
108 108
         echo '<div id="message" class="espresso-notices error"><p>';
109
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
110 110
         echo '<br /></p></div>';
111 111
     }
112 112
 
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
223 223
         // add details to _all_exceptions array
224 224
         $x_time = time();
225
-        self::$_all_exceptions[ $x_time ]['name'] = get_class($this);
226
-        self::$_all_exceptions[ $x_time ]['file'] = $this->getFile();
227
-        self::$_all_exceptions[ $x_time ]['line'] = $this->getLine();
228
-        self::$_all_exceptions[ $x_time ]['msg'] = $msg;
229
-        self::$_all_exceptions[ $x_time ]['code'] = $this->getCode();
230
-        self::$_all_exceptions[ $x_time ]['trace'] = $this->getTrace();
231
-        self::$_all_exceptions[ $x_time ]['string'] = $this->getTraceAsString();
225
+        self::$_all_exceptions[$x_time]['name'] = get_class($this);
226
+        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
227
+        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
228
+        self::$_all_exceptions[$x_time]['msg'] = $msg;
229
+        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
230
+        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
231
+        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
232 232
         self::$_error_count++;
233 233
         // add_action( 'shutdown', array( $this, 'display_errors' ));
234 234
         $this->display_errors();
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
      */
247 247
     public static function has_error($check_stored = false, $type_to_check = 'errors')
248 248
     {
249
-        $has_error = isset(self::$_espresso_notices[ $type_to_check ])
250
-                     && ! empty(self::$_espresso_notices[ $type_to_check ])
249
+        $has_error = isset(self::$_espresso_notices[$type_to_check])
250
+                     && ! empty(self::$_espresso_notices[$type_to_check])
251 251
             ? true
252 252
             : false;
253 253
         if ($check_stored && ! $has_error) {
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	}
326 326
 </style>
327 327
 <div id="ee-error-message" class="error">';
328
-        if (! WP_DEBUG) {
328
+        if ( ! WP_DEBUG) {
329 329
             $output .= '
330 330
 	<p>';
331 331
         }
@@ -384,14 +384,14 @@  discard block
 block discarded – undo
384 384
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
385 385
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
386 386
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
387
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
387
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
388 388
                     $trace_details .= '
389 389
 					<tr>
390
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
391
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
392
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
393
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
394
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
390
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
391
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
392
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
393
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
394
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
395 395
 					</tr>';
396 396
                 }
397 397
                 $trace_details .= '
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
             }
401 401
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
402 402
             // add generic non-identifying messages for non-privileged users
403
-            if (! WP_DEBUG) {
403
+            if ( ! WP_DEBUG) {
404 404
                 $output .= '<span class="ee-error-user-msg-spn">'
405 405
                            . trim($ex['msg'])
406 406
                            . '</span> &nbsp; <sup>'
@@ -442,14 +442,14 @@  discard block
 block discarded – undo
442 442
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
443 443
 				'
444 444
                            . $trace_details;
445
-                if (! empty($class)) {
445
+                if ( ! empty($class)) {
446 446
                     $output .= '
447 447
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
448 448
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
449 449
 						<h3>Class Details</h3>';
450 450
                     $a = new ReflectionClass($class);
451 451
                     $output .= '
452
-						<pre>' . $a . '</pre>
452
+						<pre>' . $a.'</pre>
453 453
 					</div>
454 454
 				</div>';
455 455
                 }
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         }
463 463
         // remove last linebreak
464 464
         $output = substr($output, 0, -6);
465
-        if (! WP_DEBUG) {
465
+        if ( ! WP_DEBUG) {
466 466
             $output .= '
467 467
 	</p>';
468 468
         }
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
     private function _convert_args_to_string($arguments = array(), $array = false)
489 489
     {
490 490
         $arg_string = '';
491
-        if (! empty($arguments)) {
491
+        if ( ! empty($arguments)) {
492 492
             $args = array();
493 493
             foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
494
+                if ( ! empty($arg)) {
495 495
                     if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
496
+                        $args[] = " '".$arg."'";
497 497
                     } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
498
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
499 499
                     } elseif ($arg === null) {
500 500
                         $args[] = ' NULL';
501 501
                     } elseif (is_bool($arg)) {
502 502
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
503 503
                     } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
504
+                        $args[] = ' OBJECT '.get_class($arg);
505 505
                     } elseif (is_resource($arg)) {
506 506
                         $args[] = get_resource_type($arg);
507 507
                     } else {
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
     {
600 600
         if (empty($msg)) {
601 601
             EE_Error::doing_it_wrong(
602
-                'EE_Error::add_' . $type . '()',
602
+                'EE_Error::add_'.$type.'()',
603 603
                 sprintf(
604 604
                     __(
605 605
                         'Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
@@ -639,17 +639,17 @@  discard block
 block discarded – undo
639 639
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
640 640
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
641 641
         // add notice if message exists
642
-        if (! empty($msg)) {
642
+        if ( ! empty($msg)) {
643 643
             // get error code
644 644
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
645 645
             if (WP_DEBUG && $type === 'errors') {
646
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
646
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
647 647
             }
648 648
             // add notice. Index by code if it's not blank
649 649
             if ($notice_code) {
650
-                self::$_espresso_notices[ $type ][ $notice_code ] = $msg;
650
+                self::$_espresso_notices[$type][$notice_code] = $msg;
651 651
             } else {
652
-                self::$_espresso_notices[ $type ][] = $msg;
652
+                self::$_espresso_notices[$type][] = $msg;
653 653
             }
654 654
             add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
655 655
         }
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
                 // remove empty notices
901 901
                 foreach ($notices as $type => $notice) {
902 902
                     if (empty($notice)) {
903
-                        unset($notices[ $type ]);
903
+                        unset($notices[$type]);
904 904
                     }
905 905
                 }
906 906
             }
@@ -923,16 +923,16 @@  discard block
 block discarded – undo
923 923
         $print_scripts = false;
924 924
         // grab any notices that have been previously saved
925 925
         $notices = EE_Error::getStoredNotices();
926
-        if (! empty($notices)) {
926
+        if ( ! empty($notices)) {
927 927
             foreach ($notices as $type => $notice) {
928 928
                 if (is_array($notice) && ! empty($notice)) {
929 929
                     // make sure that existing notice type is an array
930
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
931
-                                                        && ! empty(self::$_espresso_notices[ $type ])
932
-                        ? self::$_espresso_notices[ $type ]
930
+                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
931
+                                                        && ! empty(self::$_espresso_notices[$type])
932
+                        ? self::$_espresso_notices[$type]
933 933
                         : array();
934 934
                     // add newly created notices to existing ones
935
-                    self::$_espresso_notices[ $type ] += $notice;
935
+                    self::$_espresso_notices[$type] += $notice;
936 936
                     $print_scripts = true;
937 937
                 }
938 938
             }
@@ -959,10 +959,10 @@  discard block
 block discarded – undo
959 959
             $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
960 960
             $css_class = is_admin() ? 'updated fade' : 'success fade-away';
961 961
             // showMessage( $success_messages );
962
-            $notices .= '<div id="' . $css_id . '" '
963
-                        . 'class="espresso-notices ' . $css_class . '" '
962
+            $notices .= '<div id="'.$css_id.'" '
963
+                        . 'class="espresso-notices '.$css_class.'" '
964 964
                         . 'style="display:none;">'
965
-                        . '<p>' . $success_messages . '</p>'
965
+                        . '<p>'.$success_messages.'</p>'
966 966
                         . $close
967 967
                         . '</div>';
968 968
         }
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
             $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
971 971
             $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
972 972
             // showMessage( $error_messages, TRUE );
973
-            $notices .= '<div id="' . $css_id . '" '
974
-                        . 'class="espresso-notices ' . $css_class . '" '
973
+            $notices .= '<div id="'.$css_id.'" '
974
+                        . 'class="espresso-notices '.$css_class.'" '
975 975
                         . 'style="display:none;">'
976
-                        . '<p>' . $attention_messages . '</p>'
976
+                        . '<p>'.$attention_messages.'</p>'
977 977
                         . $close
978 978
                         . '</div>';
979 979
         }
@@ -981,10 +981,10 @@  discard block
 block discarded – undo
981 981
             $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
982 982
             $css_class = is_admin() ? 'error' : 'error fade-away';
983 983
             // showMessage( $error_messages, TRUE );
984
-            $notices .= '<div id="' . $css_id . '" '
985
-                        . 'class="espresso-notices ' . $css_class . '" '
984
+            $notices .= '<div id="'.$css_id.'" '
985
+                        . 'class="espresso-notices '.$css_class.'" '
986 986
                         . 'style="display:none;">'
987
-                        . '<p>' . $error_messages . '</p>'
987
+                        . '<p>'.$error_messages.'</p>'
988 988
                         . $close
989 989
                         . '</div>';
990 990
         }
@@ -1001,7 +1001,7 @@  discard block
 block discarded – undo
1001 1001
      */
1002 1002
     private static function _print_scripts($force_print = false)
1003 1003
     {
1004
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1004
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1005 1005
             if (wp_script_is('ee_error_js', 'registered')) {
1006 1006
                 wp_enqueue_style('espresso_default');
1007 1007
                 wp_enqueue_style('espresso_custom_css');
@@ -1015,12 +1015,12 @@  discard block
 block discarded – undo
1015 1015
             return '
1016 1016
 <script>
1017 1017
 /* <![CDATA[ */
1018
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1018
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1019 1019
 /* ]]> */
1020 1020
 </script>
1021
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1022
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1023
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1021
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1022
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1023
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1024 1024
 ';
1025 1025
         }
1026 1026
         return '';
@@ -1049,8 +1049,8 @@  discard block
 block discarded – undo
1049 1049
     {
1050 1050
         $file = explode('.', basename($file));
1051 1051
         $error_code = ! empty($file[0]) ? $file[0] : '';
1052
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1053
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1052
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1053
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1054 1054
         return $error_code;
1055 1055
     }
1056 1056
 
@@ -1069,18 +1069,18 @@  discard block
 block discarded – undo
1069 1069
         if (empty($ex)) {
1070 1070
             return;
1071 1071
         }
1072
-        if (! $time) {
1072
+        if ( ! $time) {
1073 1073
             $time = time();
1074 1074
         }
1075 1075
         $exception_log = '----------------------------------------------------------------------------------------'
1076 1076
                          . PHP_EOL;
1077
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1078
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1079
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1080
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1081
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1082
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1083
-        $exception_log .= $ex['string'] . PHP_EOL;
1077
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1078
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1079
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1080
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1081
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1082
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1083
+        $exception_log .= $ex['string'].PHP_EOL;
1084 1084
         $exception_log .= '----------------------------------------------------------------------------------------'
1085 1085
                           . PHP_EOL;
1086 1086
         try {
@@ -1252,14 +1252,14 @@  discard block
 block discarded – undo
1252 1252
     // js for error handling
1253 1253
     wp_register_script(
1254 1254
         'espresso_core',
1255
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1255
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1256 1256
         array('jquery'),
1257 1257
         EVENT_ESPRESSO_VERSION,
1258 1258
         false
1259 1259
     );
1260 1260
     wp_register_script(
1261 1261
         'ee_error_js',
1262
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1262
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1263 1263
         array('espresso_core'),
1264 1264
         EVENT_ESPRESSO_VERSION,
1265 1265
         false
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3829 added lines, -3829 removed lines patch added patch discarded remove patch
@@ -19,2404 +19,2404 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    private static $_reg_status;
38
-
39
-    /**
40
-     * Form for displaying the custom questions for this registration.
41
-     * This gets used a few times throughout the request so its best to cache it
42
-     *
43
-     * @var EE_Registration_Custom_Questions_Form
44
-     */
45
-    protected $_reg_custom_questions_form = null;
46
-
47
-
48
-    /**
49
-     *        constructor
50
-     *
51
-     * @Constructor
52
-     * @access public
53
-     * @param bool $routing
54
-     * @return Registrations_Admin_Page
55
-     */
56
-    public function __construct($routing = true)
57
-    {
58
-        parent::__construct($routing);
59
-        add_action('wp_loaded', array($this, 'wp_loaded'));
60
-    }
61
-
62
-
63
-    public function wp_loaded()
64
-    {
65
-        // when adding a new registration...
66
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67
-            EE_System::do_not_cache();
68
-            if (! isset($this->_req_data['processing_registration'])
69
-                || absint($this->_req_data['processing_registration']) !== 1
70
-            ) {
71
-                // and it's NOT the attendee information reg step
72
-                // force cookie expiration by setting time to last week
73
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
74
-                // and update the global
75
-                $_COOKIE['ee_registration_added'] = 0;
76
-            }
77
-        }
78
-    }
79
-
80
-
81
-    protected function _init_page_props()
82
-    {
83
-        $this->page_slug = REG_PG_SLUG;
84
-        $this->_admin_base_url = REG_ADMIN_URL;
85
-        $this->_admin_base_path = REG_ADMIN;
86
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
87
-        $this->_cpt_routes = array(
88
-            'add_new_attendee' => 'espresso_attendees',
89
-            'edit_attendee'    => 'espresso_attendees',
90
-            'insert_attendee'  => 'espresso_attendees',
91
-            'update_attendee'  => 'espresso_attendees',
92
-        );
93
-        $this->_cpt_model_names = array(
94
-            'add_new_attendee' => 'EEM_Attendee',
95
-            'edit_attendee'    => 'EEM_Attendee',
96
-        );
97
-        $this->_cpt_edit_routes = array(
98
-            'espresso_attendees' => 'edit_attendee',
99
-        );
100
-        $this->_pagenow_map = array(
101
-            'add_new_attendee' => 'post-new.php',
102
-            'edit_attendee'    => 'post.php',
103
-            'trash'            => 'post.php',
104
-        );
105
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
106
-        // add filters so that the comment urls don't take users to a confusing 404 page
107
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
108
-    }
109
-
110
-
111
-    public function clear_comment_link($link, $comment, $args)
112
-    {
113
-        // gotta make sure this only happens on this route
114
-        $post_type = get_post_type($comment->comment_post_ID);
115
-        if ($post_type === 'espresso_attendees') {
116
-            return '#commentsdiv';
117
-        }
118
-        return $link;
119
-    }
120
-
121
-
122
-    protected function _ajax_hooks()
123
-    {
124
-        // todo: all hooks for registrations ajax goes in here
125
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
126
-    }
127
-
128
-
129
-    protected function _define_page_props()
130
-    {
131
-        $this->_admin_page_title = $this->page_label;
132
-        $this->_labels = array(
133
-            'buttons'                      => array(
134
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
135
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
136
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
137
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
138
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
139
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
140
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
141
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
142
-            ),
143
-            'publishbox'                   => array(
144
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
145
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
146
-            ),
147
-            'hide_add_button_on_cpt_route' => array(
148
-                'edit_attendee' => true,
149
-            ),
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     *        grab url requests and route them
156
-     *
157
-     * @access private
158
-     * @return void
159
-     */
160
-    public function _set_page_routes()
161
-    {
162
-        $this->_get_registration_status_array();
163
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
164
-            ? $this->_req_data['_REG_ID'] : 0;
165
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
166
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
167
-            : $reg_id;
168
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
169
-            ? $this->_req_data['ATT_ID'] : 0;
170
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
171
-            ? $this->_req_data['post']
172
-            : $att_id;
173
-        $this->_page_routes = array(
174
-            'default'                             => array(
175
-                'func'       => '_registrations_overview_list_table',
176
-                'capability' => 'ee_read_registrations',
177
-            ),
178
-            'view_registration'                   => array(
179
-                'func'       => '_registration_details',
180
-                'capability' => 'ee_read_registration',
181
-                'obj_id'     => $reg_id,
182
-            ),
183
-            'edit_registration'                   => array(
184
-                'func'               => '_update_attendee_registration_form',
185
-                'noheader'           => true,
186
-                'headers_sent_route' => 'view_registration',
187
-                'capability'         => 'ee_edit_registration',
188
-                'obj_id'             => $reg_id,
189
-                '_REG_ID'            => $reg_id,
190
-            ),
191
-            'trash_registrations'                 => array(
192
-                'func'       => '_trash_or_restore_registrations',
193
-                'args'       => array('trash' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_delete_registrations',
196
-            ),
197
-            'restore_registrations'               => array(
198
-                'func'       => '_trash_or_restore_registrations',
199
-                'args'       => array('trash' => false),
200
-                'noheader'   => true,
201
-                'capability' => 'ee_delete_registrations',
202
-            ),
203
-            'delete_registrations'                => array(
204
-                'func'       => '_delete_registrations',
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'new_registration'                    => array(
209
-                'func'       => 'new_registration',
210
-                'capability' => 'ee_edit_registrations',
211
-            ),
212
-            'process_reg_step'                    => array(
213
-                'func'       => 'process_reg_step',
214
-                'noheader'   => true,
215
-                'capability' => 'ee_edit_registrations',
216
-            ),
217
-            'redirect_to_txn'                     => array(
218
-                'func'       => 'redirect_to_txn',
219
-                'noheader'   => true,
220
-                'capability' => 'ee_edit_registrations',
221
-            ),
222
-            'change_reg_status'                   => array(
223
-                'func'       => '_change_reg_status',
224
-                'noheader'   => true,
225
-                'capability' => 'ee_edit_registration',
226
-                'obj_id'     => $reg_id,
227
-            ),
228
-            'approve_registration'                => array(
229
-                'func'       => 'approve_registration',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registration',
232
-                'obj_id'     => $reg_id,
233
-            ),
234
-            'approve_and_notify_registration'     => array(
235
-                'func'       => 'approve_registration',
236
-                'noheader'   => true,
237
-                'args'       => array(true),
238
-                'capability' => 'ee_edit_registration',
239
-                'obj_id'     => $reg_id,
240
-            ),
241
-            'approve_registrations'               => array(
242
-                'func'       => 'bulk_action_on_registrations',
243
-                'noheader'   => true,
244
-                'capability' => 'ee_edit_registrations',
245
-                'args'       => array('approve'),
246
-            ),
247
-            'approve_and_notify_registrations'    => array(
248
-                'func'       => 'bulk_action_on_registrations',
249
-                'noheader'   => true,
250
-                'capability' => 'ee_edit_registrations',
251
-                'args'       => array('approve', true),
252
-            ),
253
-            'decline_registration'                => array(
254
-                'func'       => 'decline_registration',
255
-                'noheader'   => true,
256
-                'capability' => 'ee_edit_registration',
257
-                'obj_id'     => $reg_id,
258
-            ),
259
-            'decline_and_notify_registration'     => array(
260
-                'func'       => 'decline_registration',
261
-                'noheader'   => true,
262
-                'args'       => array(true),
263
-                'capability' => 'ee_edit_registration',
264
-                'obj_id'     => $reg_id,
265
-            ),
266
-            'decline_registrations'               => array(
267
-                'func'       => 'bulk_action_on_registrations',
268
-                'noheader'   => true,
269
-                'capability' => 'ee_edit_registrations',
270
-                'args'       => array('decline'),
271
-            ),
272
-            'decline_and_notify_registrations'    => array(
273
-                'func'       => 'bulk_action_on_registrations',
274
-                'noheader'   => true,
275
-                'capability' => 'ee_edit_registrations',
276
-                'args'       => array('decline', true),
277
-            ),
278
-            'pending_registration'                => array(
279
-                'func'       => 'pending_registration',
280
-                'noheader'   => true,
281
-                'capability' => 'ee_edit_registration',
282
-                'obj_id'     => $reg_id,
283
-            ),
284
-            'pending_and_notify_registration'     => array(
285
-                'func'       => 'pending_registration',
286
-                'noheader'   => true,
287
-                'args'       => array(true),
288
-                'capability' => 'ee_edit_registration',
289
-                'obj_id'     => $reg_id,
290
-            ),
291
-            'pending_registrations'               => array(
292
-                'func'       => 'bulk_action_on_registrations',
293
-                'noheader'   => true,
294
-                'capability' => 'ee_edit_registrations',
295
-                'args'       => array('pending'),
296
-            ),
297
-            'pending_and_notify_registrations'    => array(
298
-                'func'       => 'bulk_action_on_registrations',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-                'args'       => array('pending', true),
302
-            ),
303
-            'no_approve_registration'             => array(
304
-                'func'       => 'not_approve_registration',
305
-                'noheader'   => true,
306
-                'capability' => 'ee_edit_registration',
307
-                'obj_id'     => $reg_id,
308
-            ),
309
-            'no_approve_and_notify_registration'  => array(
310
-                'func'       => 'not_approve_registration',
311
-                'noheader'   => true,
312
-                'args'       => array(true),
313
-                'capability' => 'ee_edit_registration',
314
-                'obj_id'     => $reg_id,
315
-            ),
316
-            'no_approve_registrations'            => array(
317
-                'func'       => 'bulk_action_on_registrations',
318
-                'noheader'   => true,
319
-                'capability' => 'ee_edit_registrations',
320
-                'args'       => array('not_approve'),
321
-            ),
322
-            'no_approve_and_notify_registrations' => array(
323
-                'func'       => 'bulk_action_on_registrations',
324
-                'noheader'   => true,
325
-                'capability' => 'ee_edit_registrations',
326
-                'args'       => array('not_approve', true),
327
-            ),
328
-            'cancel_registration'                 => array(
329
-                'func'       => 'cancel_registration',
330
-                'noheader'   => true,
331
-                'capability' => 'ee_edit_registration',
332
-                'obj_id'     => $reg_id,
333
-            ),
334
-            'cancel_and_notify_registration'      => array(
335
-                'func'       => 'cancel_registration',
336
-                'noheader'   => true,
337
-                'args'       => array(true),
338
-                'capability' => 'ee_edit_registration',
339
-                'obj_id'     => $reg_id,
340
-            ),
341
-            'cancel_registrations'                => array(
342
-                'func'       => 'bulk_action_on_registrations',
343
-                'noheader'   => true,
344
-                'capability' => 'ee_edit_registrations',
345
-                'args'       => array('cancel'),
346
-            ),
347
-            'cancel_and_notify_registrations'     => array(
348
-                'func'       => 'bulk_action_on_registrations',
349
-                'noheader'   => true,
350
-                'capability' => 'ee_edit_registrations',
351
-                'args'       => array('cancel', true),
352
-            ),
353
-            'wait_list_registration'              => array(
354
-                'func'       => 'wait_list_registration',
355
-                'noheader'   => true,
356
-                'capability' => 'ee_edit_registration',
357
-                'obj_id'     => $reg_id,
358
-            ),
359
-            'wait_list_and_notify_registration'   => array(
360
-                'func'       => 'wait_list_registration',
361
-                'noheader'   => true,
362
-                'args'       => array(true),
363
-                'capability' => 'ee_edit_registration',
364
-                'obj_id'     => $reg_id,
365
-            ),
366
-            'contact_list'                        => array(
367
-                'func'       => '_attendee_contact_list_table',
368
-                'capability' => 'ee_read_contacts',
369
-            ),
370
-            'add_new_attendee'                    => array(
371
-                'func' => '_create_new_cpt_item',
372
-                'args' => array(
373
-                    'new_attendee' => true,
374
-                    'capability'   => 'ee_edit_contacts',
375
-                ),
376
-            ),
377
-            'edit_attendee'                       => array(
378
-                'func'       => '_edit_cpt_item',
379
-                'capability' => 'ee_edit_contacts',
380
-                'obj_id'     => $att_id,
381
-            ),
382
-            'duplicate_attendee'                  => array(
383
-                'func'       => '_duplicate_attendee',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_contacts',
386
-                'obj_id'     => $att_id,
387
-            ),
388
-            'insert_attendee'                     => array(
389
-                'func'       => '_insert_or_update_attendee',
390
-                'args'       => array(
391
-                    'new_attendee' => true,
392
-                ),
393
-                'noheader'   => true,
394
-                'capability' => 'ee_edit_contacts',
395
-            ),
396
-            'update_attendee'                     => array(
397
-                'func'       => '_insert_or_update_attendee',
398
-                'args'       => array(
399
-                    'new_attendee' => false,
400
-                ),
401
-                'noheader'   => true,
402
-                'capability' => 'ee_edit_contacts',
403
-                'obj_id'     => $att_id,
404
-            ),
405
-            'trash_attendees'                     => array(
406
-                'func'       => '_trash_or_restore_attendees',
407
-                'args'       => array(
408
-                    'trash' => 'true',
409
-                ),
410
-                'noheader'   => true,
411
-                'capability' => 'ee_delete_contacts',
412
-            ),
413
-            'trash_attendee'                      => array(
414
-                'func'       => '_trash_or_restore_attendees',
415
-                'args'       => array(
416
-                    'trash' => true,
417
-                ),
418
-                'noheader'   => true,
419
-                'capability' => 'ee_delete_contacts',
420
-                'obj_id'     => $att_id,
421
-            ),
422
-            'restore_attendees'                   => array(
423
-                'func'       => '_trash_or_restore_attendees',
424
-                'args'       => array(
425
-                    'trash' => false,
426
-                ),
427
-                'noheader'   => true,
428
-                'capability' => 'ee_delete_contacts',
429
-                'obj_id'     => $att_id,
430
-            ),
431
-            'resend_registration'                 => array(
432
-                'func'       => '_resend_registration',
433
-                'noheader'   => true,
434
-                'capability' => 'ee_send_message',
435
-            ),
436
-            'registrations_report'                => array(
437
-                'func'       => '_registrations_report',
438
-                'noheader'   => true,
439
-                'capability' => 'ee_read_registrations',
440
-            ),
441
-            'contact_list_export'                 => array(
442
-                'func'       => '_contact_list_export',
443
-                'noheader'   => true,
444
-                'capability' => 'export',
445
-            ),
446
-            'contact_list_report'                 => array(
447
-                'func'       => '_contact_list_report',
448
-                'noheader'   => true,
449
-                'capability' => 'ee_read_contacts',
450
-            ),
451
-        );
452
-    }
453
-
454
-
455
-    protected function _set_page_config()
456
-    {
457
-        $this->_page_config = array(
458
-            'default'           => array(
459
-                'nav'           => array(
460
-                    'label' => esc_html__('Overview', 'event_espresso'),
461
-                    'order' => 5,
462
-                ),
463
-                'help_tabs'     => array(
464
-                    'registrations_overview_help_tab'                       => array(
465
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
466
-                        'filename' => 'registrations_overview',
467
-                    ),
468
-                    'registrations_overview_table_column_headings_help_tab' => array(
469
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
470
-                        'filename' => 'registrations_overview_table_column_headings',
471
-                    ),
472
-                    'registrations_overview_filters_help_tab'               => array(
473
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
474
-                        'filename' => 'registrations_overview_filters',
475
-                    ),
476
-                    'registrations_overview_views_help_tab'                 => array(
477
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
478
-                        'filename' => 'registrations_overview_views',
479
-                    ),
480
-                    'registrations_regoverview_other_help_tab'              => array(
481
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
482
-                        'filename' => 'registrations_overview_other',
483
-                    ),
484
-                ),
485
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
486
-                'qtips'         => array('Registration_List_Table_Tips'),
487
-                'list_table'    => 'EE_Registrations_List_Table',
488
-                'require_nonce' => false,
489
-            ),
490
-            'view_registration' => array(
491
-                'nav'           => array(
492
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
493
-                    'order'      => 15,
494
-                    'url'        => isset($this->_req_data['_REG_ID'])
495
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
496
-                        : $this->_admin_base_url,
497
-                    'persistent' => false,
498
-                ),
499
-                'help_tabs'     => array(
500
-                    'registrations_details_help_tab'                    => array(
501
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
502
-                        'filename' => 'registrations_details',
503
-                    ),
504
-                    'registrations_details_table_help_tab'              => array(
505
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
506
-                        'filename' => 'registrations_details_table',
507
-                    ),
508
-                    'registrations_details_form_answers_help_tab'       => array(
509
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
510
-                        'filename' => 'registrations_details_form_answers',
511
-                    ),
512
-                    'registrations_details_registrant_details_help_tab' => array(
513
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
514
-                        'filename' => 'registrations_details_registrant_details',
515
-                    ),
516
-                ),
517
-                'help_tour'     => array('Registration_Details_Help_Tour'),
518
-                'metaboxes'     => array_merge(
519
-                    $this->_default_espresso_metaboxes,
520
-                    array('_registration_details_metaboxes')
521
-                ),
522
-                'require_nonce' => false,
523
-            ),
524
-            'new_registration'  => array(
525
-                'nav'           => array(
526
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
527
-                    'url'        => '#',
528
-                    'order'      => 15,
529
-                    'persistent' => false,
530
-                ),
531
-                'metaboxes'     => $this->_default_espresso_metaboxes,
532
-                'labels'        => array(
533
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
534
-                ),
535
-                'require_nonce' => false,
536
-            ),
537
-            'add_new_attendee'  => array(
538
-                'nav'           => array(
539
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
540
-                    'order'      => 15,
541
-                    'persistent' => false,
542
-                ),
543
-                'metaboxes'     => array_merge(
544
-                    $this->_default_espresso_metaboxes,
545
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
546
-                ),
547
-                'require_nonce' => false,
548
-            ),
549
-            'edit_attendee'     => array(
550
-                'nav'           => array(
551
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
552
-                    'order'      => 15,
553
-                    'persistent' => false,
554
-                    'url'        => isset($this->_req_data['ATT_ID'])
555
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
556
-                        : $this->_admin_base_url,
557
-                ),
558
-                'metaboxes'     => array('attendee_editor_metaboxes'),
559
-                'require_nonce' => false,
560
-            ),
561
-            'contact_list'      => array(
562
-                'nav'           => array(
563
-                    'label' => esc_html__('Contact List', 'event_espresso'),
564
-                    'order' => 20,
565
-                ),
566
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
567
-                'help_tabs'     => array(
568
-                    'registrations_contact_list_help_tab'                       => array(
569
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
570
-                        'filename' => 'registrations_contact_list',
571
-                    ),
572
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
573
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
574
-                        'filename' => 'registrations_contact_list_table_column_headings',
575
-                    ),
576
-                    'registrations_contact_list_views_help_tab'                 => array(
577
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
578
-                        'filename' => 'registrations_contact_list_views',
579
-                    ),
580
-                    'registrations_contact_list_other_help_tab'                 => array(
581
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
582
-                        'filename' => 'registrations_contact_list_other',
583
-                    ),
584
-                ),
585
-                'help_tour'     => array('Contact_List_Help_Tour'),
586
-                'metaboxes'     => array(),
587
-                'require_nonce' => false,
588
-            ),
589
-            // override default cpt routes
590
-            'create_new'        => '',
591
-            'edit'              => '',
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * The below methods aren't used by this class currently
598
-     */
599
-    protected function _add_screen_options()
600
-    {
601
-    }
602
-
603
-
604
-    protected function _add_feature_pointers()
605
-    {
606
-    }
607
-
608
-
609
-    public function admin_init()
610
-    {
611
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
612
-            'click "Update Registration Questions" to save your changes',
613
-            'event_espresso'
614
-        );
615
-    }
616
-
617
-
618
-    public function admin_notices()
619
-    {
620
-    }
621
-
622
-
623
-    public function admin_footer_scripts()
624
-    {
625
-    }
626
-
627
-
628
-    /**
629
-     *        get list of registration statuses
630
-     *
631
-     * @access private
632
-     * @return void
633
-     * @throws EE_Error
634
-     */
635
-    private function _get_registration_status_array()
636
-    {
637
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
638
-    }
639
-
640
-
641
-    protected function _add_screen_options_default()
642
-    {
643
-        $this->_per_page_screen_option();
644
-    }
645
-
646
-
647
-    protected function _add_screen_options_contact_list()
648
-    {
649
-        $page_title = $this->_admin_page_title;
650
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
651
-        $this->_per_page_screen_option();
652
-        $this->_admin_page_title = $page_title;
653
-    }
654
-
655
-
656
-    public function load_scripts_styles()
657
-    {
658
-        // style
659
-        wp_register_style(
660
-            'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
662
-            array('ee-admin-css'),
663
-            EVENT_ESPRESSO_VERSION
664
-        );
665
-        wp_enqueue_style('espresso_reg');
666
-        // script
667
-        wp_register_script(
668
-            'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
670
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671
-            EVENT_ESPRESSO_VERSION,
672
-            true
673
-        );
674
-        wp_enqueue_script('espresso_reg');
675
-    }
676
-
677
-
678
-    public function load_scripts_styles_edit_attendee()
679
-    {
680
-        // stuff to only show up on our attendee edit details page.
681
-        $attendee_details_translations = array(
682
-            'att_publish_text' => sprintf(
683
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
684
-                $this->_cpt_model_obj->get_datetime('ATT_created')
685
-            ),
686
-        );
687
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
688
-        wp_enqueue_script('jquery-validate');
689
-    }
690
-
691
-
692
-    public function load_scripts_styles_view_registration()
693
-    {
694
-        // styles
695
-        wp_enqueue_style('espresso-ui-theme');
696
-        // scripts
697
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
698
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
699
-    }
700
-
701
-
702
-    public function load_scripts_styles_contact_list()
703
-    {
704
-        wp_dequeue_style('espresso_reg');
705
-        wp_register_style(
706
-            'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
708
-            array('ee-admin-css'),
709
-            EVENT_ESPRESSO_VERSION
710
-        );
711
-        wp_enqueue_style('espresso_att');
712
-    }
713
-
714
-
715
-    public function load_scripts_styles_new_registration()
716
-    {
717
-        wp_register_script(
718
-            'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
720
-            array('underscore', 'jquery'),
721
-            EVENT_ESPRESSO_VERSION,
722
-            true
723
-        );
724
-        wp_enqueue_script('ee-spco-for-admin');
725
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
726
-        EE_Form_Section_Proper::wp_enqueue_scripts();
727
-        EED_Ticket_Selector::load_tckt_slctr_assets();
728
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
729
-    }
730
-
731
-
732
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
733
-    {
734
-        add_filter('FHEE_load_EE_messages', '__return_true');
735
-    }
736
-
737
-
738
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
739
-    {
740
-        add_filter('FHEE_load_EE_messages', '__return_true');
741
-    }
742
-
743
-
744
-    protected function _set_list_table_views_default()
745
-    {
746
-        // for notification related bulk actions we need to make sure only active messengers have an option.
747
-        EED_Messages::set_autoloaders();
748
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
749
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
750
-        $active_mts = $message_resource_manager->list_of_active_message_types();
751
-        // key= bulk_action_slug, value= message type.
752
-        $match_array = array(
753
-            'approve_registrations'    => 'registration',
754
-            'decline_registrations'    => 'declined_registration',
755
-            'pending_registrations'    => 'pending_approval',
756
-            'no_approve_registrations' => 'not_approved_registration',
757
-            'cancel_registrations'     => 'cancelled_registration',
758
-        );
759
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
760
-            'ee_send_message',
761
-            'batch_send_messages'
762
-        );
763
-        /** setup reg status bulk actions **/
764
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
765
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
766
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
767
-                'Approve and Notify Registrations',
768
-                'event_espresso'
769
-            );
770
-        }
771
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
772
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
773
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
774
-                'Decline and Notify Registrations',
775
-                'event_espresso'
776
-            );
777
-        }
778
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
779
-            'Set Registrations to Pending Payment',
780
-            'event_espresso'
781
-        );
782
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
783
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
784
-                'Set Registrations to Pending Payment and Notify',
785
-                'event_espresso'
786
-            );
787
-        }
788
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
789
-            'Set Registrations to Not Approved',
790
-            'event_espresso'
791
-        );
792
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
793
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
794
-                'Set Registrations to Not Approved and Notify',
795
-                'event_espresso'
796
-            );
797
-        }
798
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
799
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
800
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
801
-                'Cancel Registrations and Notify',
802
-                'event_espresso'
803
-            );
804
-        }
805
-        $def_reg_status_actions = apply_filters(
806
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
807
-            $def_reg_status_actions,
808
-            $active_mts,
809
-            $can_send
810
-        );
811
-
812
-        $this->_views = array(
813
-            'all'   => array(
814
-                'slug'        => 'all',
815
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
816
-                'count'       => 0,
817
-                'bulk_action' => array_merge(
818
-                    $def_reg_status_actions,
819
-                    array(
820
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
821
-                    )
822
-                ),
823
-            ),
824
-            'month' => array(
825
-                'slug'        => 'month',
826
-                'label'       => esc_html__('This Month', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge(
829
-                    $def_reg_status_actions,
830
-                    array(
831
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
832
-                    )
833
-                ),
834
-            ),
835
-            'today' => array(
836
-                'slug'        => 'today',
837
-                'label'       => sprintf(
838
-                    esc_html__('Today - %s', 'event_espresso'),
839
-                    date('M d, Y', current_time('timestamp'))
840
-                ),
841
-                'count'       => 0,
842
-                'bulk_action' => array_merge(
843
-                    $def_reg_status_actions,
844
-                    array(
845
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
-                    )
847
-                ),
848
-            ),
849
-        );
850
-        if (EE_Registry::instance()->CAP->current_user_can(
851
-            'ee_delete_registrations',
852
-            'espresso_registrations_delete_registration'
853
-        )) {
854
-            $this->_views['incomplete'] = array(
855
-                'slug'        => 'incomplete',
856
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
857
-                'count'       => 0,
858
-                'bulk_action' => array(
859
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
860
-                ),
861
-            );
862
-            $this->_views['trash'] = array(
863
-                'slug'        => 'trash',
864
-                'label'       => esc_html__('Trash', 'event_espresso'),
865
-                'count'       => 0,
866
-                'bulk_action' => array(
867
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
868
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
869
-                ),
870
-            );
871
-        }
872
-    }
873
-
874
-
875
-    protected function _set_list_table_views_contact_list()
876
-    {
877
-        $this->_views = array(
878
-            'in_use' => array(
879
-                'slug'        => 'in_use',
880
-                'label'       => esc_html__('In Use', 'event_espresso'),
881
-                'count'       => 0,
882
-                'bulk_action' => array(
883
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
884
-                ),
885
-            ),
886
-        );
887
-        if (EE_Registry::instance()->CAP->current_user_can(
888
-            'ee_delete_contacts',
889
-            'espresso_registrations_trash_attendees'
890
-        )
891
-        ) {
892
-            $this->_views['trash'] = array(
893
-                'slug'        => 'trash',
894
-                'label'       => esc_html__('Trash', 'event_espresso'),
895
-                'count'       => 0,
896
-                'bulk_action' => array(
897
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
-                ),
899
-            );
900
-        }
901
-    }
902
-
903
-
904
-    protected function _registration_legend_items()
905
-    {
906
-        $fc_items = array(
907
-            'star-icon'        => array(
908
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
-            ),
911
-            'view_details'     => array(
912
-                'class' => 'dashicons dashicons-clipboard',
913
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
-            ),
915
-            'edit_attendee'    => array(
916
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
-            ),
919
-            'view_transaction' => array(
920
-                'class' => 'dashicons dashicons-cart',
921
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
-            ),
923
-            'view_invoice'     => array(
924
-                'class' => 'dashicons dashicons-media-spreadsheet',
925
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
-            ),
927
-        );
928
-        if (EE_Registry::instance()->CAP->current_user_can(
929
-            'ee_send_message',
930
-            'espresso_registrations_resend_registration'
931
-        )) {
932
-            $fc_items['resend_registration'] = array(
933
-                'class' => 'dashicons dashicons-email-alt',
934
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
-            );
936
-        } else {
937
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
-        }
939
-        if (EE_Registry::instance()->CAP->current_user_can(
940
-            'ee_read_global_messages',
941
-            'view_filtered_messages'
942
-        )) {
943
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
-                $fc_items['view_related_messages'] = array(
946
-                    'class' => $related_for_icon['css_class'],
947
-                    'desc'  => $related_for_icon['label'],
948
-                );
949
-            }
950
-        }
951
-        $sc_items = array(
952
-            'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_approved,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_pending_payment,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_wait_list,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_incomplete,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_not_approved,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_declined,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-            'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
-                'desc'  => EEH_Template::pretty_status(
1003
-                    EEM_Registration::status_id_cancelled,
1004
-                    false,
1005
-                    'sentence'
1006
-                ),
1007
-            ),
1008
-        );
1009
-        return array_merge($fc_items, $sc_items);
1010
-    }
1011
-
1012
-
1013
-
1014
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1015
-    /**
1016
-     * @throws \EE_Error
1017
-     */
1018
-    protected function _registrations_overview_list_table()
1019
-    {
1020
-        $this->_template_args['admin_page_header'] = '';
1021
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1022
-            ? absint($this->_req_data['event_id'])
1023
-            : 0;
1024
-        $ATT_ID = ! empty($this->_req_data['ATT_ID'])
1025
-            ? absint($this->_req_data['ATT_ID'])
1026
-            : 0;
1027
-        if ($ATT_ID) {
1028
-            $attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
-            if ($attendee instanceof EE_Attendee) {
1030
-                $this->_template_args['admin_page_header'] = sprintf(
1031
-                    esc_html__(
1032
-                        '%1$s Viewing registrations for %2$s%3$s',
1033
-                        'event_espresso'
1034
-                    ),
1035
-                    '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
-                        array(
1038
-                            'action' => 'edit_attendee',
1039
-                            'post'   => $ATT_ID,
1040
-                        ),
1041
-                        REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1043
-                    '</h3>'
1044
-                );
1045
-            }
1046
-        }
1047
-        if ($EVT_ID) {
1048
-            if (EE_Registry::instance()->CAP->current_user_can(
1049
-                'ee_edit_registrations',
1050
-                'espresso_registrations_new_registration',
1051
-                $EVT_ID
1052
-            )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
-                    'new_registration',
1055
-                    'add-registrant',
1056
-                    array('event_id' => $EVT_ID),
1057
-                    'add-new-h2'
1058
-                );
1059
-            }
1060
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
-            if ($event instanceof EE_Event) {
1062
-                $this->_template_args['admin_page_header'] = sprintf(
1063
-                    esc_html__(
1064
-                        '%s Viewing registrations for the event: %s%s',
1065
-                        'event_espresso'
1066
-                    ),
1067
-                    '<h3 style="line-height:1.5em;">',
1068
-                    '<br /><a href="'
1069
-                    . EE_Admin_Page::add_query_args_and_nonce(
1070
-                        array(
1071
-                            'action' => 'edit',
1072
-                            'post'   => $event->ID(),
1073
-                        ),
1074
-                        EVENTS_ADMIN_URL
1075
-                    )
1076
-                    . '">&nbsp;'
1077
-                    . $event->get('EVT_name')
1078
-                    . '&nbsp;</a>&nbsp;',
1079
-                    '</h3>'
1080
-                );
1081
-            }
1082
-            $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
-                $this->_template_args['admin_page_header'] = substr(
1086
-                    $this->_template_args['admin_page_header'],
1087
-                    0,
1088
-                    -5
1089
-                );
1090
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1095
-            }
1096
-        }
1097
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
-        $this->display_admin_list_table_page_with_no_sidebar();
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * This sets the _registration property for the registration details screen
1104
-     *
1105
-     * @access private
1106
-     * @return bool
1107
-     * @throws EE_Error
1108
-     * @throws InvalidArgumentException
1109
-     * @throws InvalidDataTypeException
1110
-     * @throws InvalidInterfaceException
1111
-     */
1112
-    private function _set_registration_object()
1113
-    {
1114
-        // get out if we've already set the object
1115
-        if ($this->_registration instanceof EE_Registration) {
1116
-            return true;
1117
-        }
1118
-        $REG = EEM_Registration::instance();
1119
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
-            return true;
1122
-        } else {
1123
-            $error_msg = sprintf(
1124
-                esc_html__(
1125
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
-                    'event_espresso'
1127
-                ),
1128
-                $REG_ID
1129
-            );
1130
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
-            $this->_registration = null;
1132
-            return false;
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Used to retrieve registrations for the list table.
1139
-     *
1140
-     * @param int  $per_page
1141
-     * @param bool $count
1142
-     * @param bool $this_month
1143
-     * @param bool $today
1144
-     * @return EE_Registration[]|int
1145
-     * @throws EE_Error
1146
-     * @throws InvalidArgumentException
1147
-     * @throws InvalidDataTypeException
1148
-     * @throws InvalidInterfaceException
1149
-     */
1150
-    public function get_registrations(
1151
-        $per_page = 10,
1152
-        $count = false,
1153
-        $this_month = false,
1154
-        $today = false
1155
-    ) {
1156
-        if ($this_month) {
1157
-            $this->_req_data['status'] = 'month';
1158
-        }
1159
-        if ($today) {
1160
-            $this->_req_data['status'] = 'today';
1161
-        }
1162
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
-        /**
1164
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
-         *
1166
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1167
-         * @see  EEM_Base::get_all()
1168
-         */
1169
-        $query_params['group_by'] = '';
1170
-
1171
-        return $count
1172
-            ? EEM_Registration::instance()->count($query_params)
1173
-            /** @type EE_Registration[] */
1174
-            : EEM_Registration::instance()->get_all($query_params);
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1180
-     * Note: this listens to values on the request for some of the query parameters.
1181
-     *
1182
-     * @param array $request
1183
-     * @param int   $per_page
1184
-     * @param bool  $count
1185
-     * @return array
1186
-     * @throws EE_Error
1187
-     */
1188
-    protected function _get_registration_query_parameters(
1189
-        $request = array(),
1190
-        $per_page = 10,
1191
-        $count = false
1192
-    ) {
1193
-
1194
-        $query_params = array(
1195
-            0                          => $this->_get_where_conditions_for_registrations_query(
1196
-                $request
1197
-            ),
1198
-            'caps'                     => EEM_Registration::caps_read_admin,
1199
-            'default_where_conditions' => 'this_model_only',
1200
-        );
1201
-        if (! $count) {
1202
-            $query_params = array_merge(
1203
-                $query_params,
1204
-                $this->_get_orderby_for_registrations_query(),
1205
-                $this->_get_limit($per_page)
1206
-            );
1207
-        }
1208
-
1209
-        return $query_params;
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * This will add ATT_ID to the provided $where array for EE model query parameters.
1215
-     *
1216
-     * @param array $request usually the same as $this->_req_data but not necessarily
1217
-     * @return array
1218
-     */
1219
-    protected function addAttendeeIdToWhereConditions(array $request)
1220
-    {
1221
-        $where = array();
1222
-        if (! empty($request['ATT_ID'])) {
1223
-            $where['ATT_ID'] = absint($request['ATT_ID']);
1224
-        }
1225
-        return $where;
1226
-    }
1227
-
1228
-
1229
-    /**
1230
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1231
-     *
1232
-     * @param array $request usually the same as $this->_req_data but not necessarily
1233
-     * @return array
1234
-     */
1235
-    protected function _add_event_id_to_where_conditions(array $request)
1236
-    {
1237
-        $where = array();
1238
-        if (! empty($request['event_id'])) {
1239
-            $where['EVT_ID'] = absint($request['event_id']);
1240
-        }
1241
-        return $where;
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1247
-     *
1248
-     * @param array $request usually the same as $this->_req_data but not necessarily
1249
-     * @return array
1250
-     */
1251
-    protected function _add_category_id_to_where_conditions(array $request)
1252
-    {
1253
-        $where = array();
1254
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1255
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1256
-        }
1257
-        return $where;
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1263
-     *
1264
-     * @param array $request usually the same as $this->_req_data but not necessarily
1265
-     * @return array
1266
-     */
1267
-    protected function _add_datetime_id_to_where_conditions(array $request)
1268
-    {
1269
-        $where = array();
1270
-        if (! empty($request['datetime_id'])) {
1271
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1272
-        }
1273
-        if (! empty($request['DTT_ID'])) {
1274
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1275
-        }
1276
-        return $where;
1277
-    }
1278
-
1279
-
1280
-    /**
1281
-     * Adds the correct registration status to the where conditions for the registrations query.
1282
-     *
1283
-     * @param array $request usually the same as $this->_req_data but not necessarily
1284
-     * @return array
1285
-     */
1286
-    protected function _add_registration_status_to_where_conditions(array $request)
1287
-    {
1288
-        $where = array();
1289
-        $view = EEH_Array::is_set($request, 'status', '');
1290
-        $registration_status = ! empty($request['_reg_status'])
1291
-            ? sanitize_text_field($request['_reg_status'])
1292
-            : '';
1293
-
1294
-        /*
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	private static $_reg_status;
38
+
39
+	/**
40
+	 * Form for displaying the custom questions for this registration.
41
+	 * This gets used a few times throughout the request so its best to cache it
42
+	 *
43
+	 * @var EE_Registration_Custom_Questions_Form
44
+	 */
45
+	protected $_reg_custom_questions_form = null;
46
+
47
+
48
+	/**
49
+	 *        constructor
50
+	 *
51
+	 * @Constructor
52
+	 * @access public
53
+	 * @param bool $routing
54
+	 * @return Registrations_Admin_Page
55
+	 */
56
+	public function __construct($routing = true)
57
+	{
58
+		parent::__construct($routing);
59
+		add_action('wp_loaded', array($this, 'wp_loaded'));
60
+	}
61
+
62
+
63
+	public function wp_loaded()
64
+	{
65
+		// when adding a new registration...
66
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67
+			EE_System::do_not_cache();
68
+			if (! isset($this->_req_data['processing_registration'])
69
+				|| absint($this->_req_data['processing_registration']) !== 1
70
+			) {
71
+				// and it's NOT the attendee information reg step
72
+				// force cookie expiration by setting time to last week
73
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
74
+				// and update the global
75
+				$_COOKIE['ee_registration_added'] = 0;
76
+			}
77
+		}
78
+	}
79
+
80
+
81
+	protected function _init_page_props()
82
+	{
83
+		$this->page_slug = REG_PG_SLUG;
84
+		$this->_admin_base_url = REG_ADMIN_URL;
85
+		$this->_admin_base_path = REG_ADMIN;
86
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
87
+		$this->_cpt_routes = array(
88
+			'add_new_attendee' => 'espresso_attendees',
89
+			'edit_attendee'    => 'espresso_attendees',
90
+			'insert_attendee'  => 'espresso_attendees',
91
+			'update_attendee'  => 'espresso_attendees',
92
+		);
93
+		$this->_cpt_model_names = array(
94
+			'add_new_attendee' => 'EEM_Attendee',
95
+			'edit_attendee'    => 'EEM_Attendee',
96
+		);
97
+		$this->_cpt_edit_routes = array(
98
+			'espresso_attendees' => 'edit_attendee',
99
+		);
100
+		$this->_pagenow_map = array(
101
+			'add_new_attendee' => 'post-new.php',
102
+			'edit_attendee'    => 'post.php',
103
+			'trash'            => 'post.php',
104
+		);
105
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
106
+		// add filters so that the comment urls don't take users to a confusing 404 page
107
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
108
+	}
109
+
110
+
111
+	public function clear_comment_link($link, $comment, $args)
112
+	{
113
+		// gotta make sure this only happens on this route
114
+		$post_type = get_post_type($comment->comment_post_ID);
115
+		if ($post_type === 'espresso_attendees') {
116
+			return '#commentsdiv';
117
+		}
118
+		return $link;
119
+	}
120
+
121
+
122
+	protected function _ajax_hooks()
123
+	{
124
+		// todo: all hooks for registrations ajax goes in here
125
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
126
+	}
127
+
128
+
129
+	protected function _define_page_props()
130
+	{
131
+		$this->_admin_page_title = $this->page_label;
132
+		$this->_labels = array(
133
+			'buttons'                      => array(
134
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
135
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
136
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
137
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
138
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
139
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
140
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
141
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
142
+			),
143
+			'publishbox'                   => array(
144
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
145
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
146
+			),
147
+			'hide_add_button_on_cpt_route' => array(
148
+				'edit_attendee' => true,
149
+			),
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 *        grab url requests and route them
156
+	 *
157
+	 * @access private
158
+	 * @return void
159
+	 */
160
+	public function _set_page_routes()
161
+	{
162
+		$this->_get_registration_status_array();
163
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
164
+			? $this->_req_data['_REG_ID'] : 0;
165
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
166
+			? $this->_req_data['reg_status_change_form']['REG_ID']
167
+			: $reg_id;
168
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
169
+			? $this->_req_data['ATT_ID'] : 0;
170
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
171
+			? $this->_req_data['post']
172
+			: $att_id;
173
+		$this->_page_routes = array(
174
+			'default'                             => array(
175
+				'func'       => '_registrations_overview_list_table',
176
+				'capability' => 'ee_read_registrations',
177
+			),
178
+			'view_registration'                   => array(
179
+				'func'       => '_registration_details',
180
+				'capability' => 'ee_read_registration',
181
+				'obj_id'     => $reg_id,
182
+			),
183
+			'edit_registration'                   => array(
184
+				'func'               => '_update_attendee_registration_form',
185
+				'noheader'           => true,
186
+				'headers_sent_route' => 'view_registration',
187
+				'capability'         => 'ee_edit_registration',
188
+				'obj_id'             => $reg_id,
189
+				'_REG_ID'            => $reg_id,
190
+			),
191
+			'trash_registrations'                 => array(
192
+				'func'       => '_trash_or_restore_registrations',
193
+				'args'       => array('trash' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_delete_registrations',
196
+			),
197
+			'restore_registrations'               => array(
198
+				'func'       => '_trash_or_restore_registrations',
199
+				'args'       => array('trash' => false),
200
+				'noheader'   => true,
201
+				'capability' => 'ee_delete_registrations',
202
+			),
203
+			'delete_registrations'                => array(
204
+				'func'       => '_delete_registrations',
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'new_registration'                    => array(
209
+				'func'       => 'new_registration',
210
+				'capability' => 'ee_edit_registrations',
211
+			),
212
+			'process_reg_step'                    => array(
213
+				'func'       => 'process_reg_step',
214
+				'noheader'   => true,
215
+				'capability' => 'ee_edit_registrations',
216
+			),
217
+			'redirect_to_txn'                     => array(
218
+				'func'       => 'redirect_to_txn',
219
+				'noheader'   => true,
220
+				'capability' => 'ee_edit_registrations',
221
+			),
222
+			'change_reg_status'                   => array(
223
+				'func'       => '_change_reg_status',
224
+				'noheader'   => true,
225
+				'capability' => 'ee_edit_registration',
226
+				'obj_id'     => $reg_id,
227
+			),
228
+			'approve_registration'                => array(
229
+				'func'       => 'approve_registration',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registration',
232
+				'obj_id'     => $reg_id,
233
+			),
234
+			'approve_and_notify_registration'     => array(
235
+				'func'       => 'approve_registration',
236
+				'noheader'   => true,
237
+				'args'       => array(true),
238
+				'capability' => 'ee_edit_registration',
239
+				'obj_id'     => $reg_id,
240
+			),
241
+			'approve_registrations'               => array(
242
+				'func'       => 'bulk_action_on_registrations',
243
+				'noheader'   => true,
244
+				'capability' => 'ee_edit_registrations',
245
+				'args'       => array('approve'),
246
+			),
247
+			'approve_and_notify_registrations'    => array(
248
+				'func'       => 'bulk_action_on_registrations',
249
+				'noheader'   => true,
250
+				'capability' => 'ee_edit_registrations',
251
+				'args'       => array('approve', true),
252
+			),
253
+			'decline_registration'                => array(
254
+				'func'       => 'decline_registration',
255
+				'noheader'   => true,
256
+				'capability' => 'ee_edit_registration',
257
+				'obj_id'     => $reg_id,
258
+			),
259
+			'decline_and_notify_registration'     => array(
260
+				'func'       => 'decline_registration',
261
+				'noheader'   => true,
262
+				'args'       => array(true),
263
+				'capability' => 'ee_edit_registration',
264
+				'obj_id'     => $reg_id,
265
+			),
266
+			'decline_registrations'               => array(
267
+				'func'       => 'bulk_action_on_registrations',
268
+				'noheader'   => true,
269
+				'capability' => 'ee_edit_registrations',
270
+				'args'       => array('decline'),
271
+			),
272
+			'decline_and_notify_registrations'    => array(
273
+				'func'       => 'bulk_action_on_registrations',
274
+				'noheader'   => true,
275
+				'capability' => 'ee_edit_registrations',
276
+				'args'       => array('decline', true),
277
+			),
278
+			'pending_registration'                => array(
279
+				'func'       => 'pending_registration',
280
+				'noheader'   => true,
281
+				'capability' => 'ee_edit_registration',
282
+				'obj_id'     => $reg_id,
283
+			),
284
+			'pending_and_notify_registration'     => array(
285
+				'func'       => 'pending_registration',
286
+				'noheader'   => true,
287
+				'args'       => array(true),
288
+				'capability' => 'ee_edit_registration',
289
+				'obj_id'     => $reg_id,
290
+			),
291
+			'pending_registrations'               => array(
292
+				'func'       => 'bulk_action_on_registrations',
293
+				'noheader'   => true,
294
+				'capability' => 'ee_edit_registrations',
295
+				'args'       => array('pending'),
296
+			),
297
+			'pending_and_notify_registrations'    => array(
298
+				'func'       => 'bulk_action_on_registrations',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+				'args'       => array('pending', true),
302
+			),
303
+			'no_approve_registration'             => array(
304
+				'func'       => 'not_approve_registration',
305
+				'noheader'   => true,
306
+				'capability' => 'ee_edit_registration',
307
+				'obj_id'     => $reg_id,
308
+			),
309
+			'no_approve_and_notify_registration'  => array(
310
+				'func'       => 'not_approve_registration',
311
+				'noheader'   => true,
312
+				'args'       => array(true),
313
+				'capability' => 'ee_edit_registration',
314
+				'obj_id'     => $reg_id,
315
+			),
316
+			'no_approve_registrations'            => array(
317
+				'func'       => 'bulk_action_on_registrations',
318
+				'noheader'   => true,
319
+				'capability' => 'ee_edit_registrations',
320
+				'args'       => array('not_approve'),
321
+			),
322
+			'no_approve_and_notify_registrations' => array(
323
+				'func'       => 'bulk_action_on_registrations',
324
+				'noheader'   => true,
325
+				'capability' => 'ee_edit_registrations',
326
+				'args'       => array('not_approve', true),
327
+			),
328
+			'cancel_registration'                 => array(
329
+				'func'       => 'cancel_registration',
330
+				'noheader'   => true,
331
+				'capability' => 'ee_edit_registration',
332
+				'obj_id'     => $reg_id,
333
+			),
334
+			'cancel_and_notify_registration'      => array(
335
+				'func'       => 'cancel_registration',
336
+				'noheader'   => true,
337
+				'args'       => array(true),
338
+				'capability' => 'ee_edit_registration',
339
+				'obj_id'     => $reg_id,
340
+			),
341
+			'cancel_registrations'                => array(
342
+				'func'       => 'bulk_action_on_registrations',
343
+				'noheader'   => true,
344
+				'capability' => 'ee_edit_registrations',
345
+				'args'       => array('cancel'),
346
+			),
347
+			'cancel_and_notify_registrations'     => array(
348
+				'func'       => 'bulk_action_on_registrations',
349
+				'noheader'   => true,
350
+				'capability' => 'ee_edit_registrations',
351
+				'args'       => array('cancel', true),
352
+			),
353
+			'wait_list_registration'              => array(
354
+				'func'       => 'wait_list_registration',
355
+				'noheader'   => true,
356
+				'capability' => 'ee_edit_registration',
357
+				'obj_id'     => $reg_id,
358
+			),
359
+			'wait_list_and_notify_registration'   => array(
360
+				'func'       => 'wait_list_registration',
361
+				'noheader'   => true,
362
+				'args'       => array(true),
363
+				'capability' => 'ee_edit_registration',
364
+				'obj_id'     => $reg_id,
365
+			),
366
+			'contact_list'                        => array(
367
+				'func'       => '_attendee_contact_list_table',
368
+				'capability' => 'ee_read_contacts',
369
+			),
370
+			'add_new_attendee'                    => array(
371
+				'func' => '_create_new_cpt_item',
372
+				'args' => array(
373
+					'new_attendee' => true,
374
+					'capability'   => 'ee_edit_contacts',
375
+				),
376
+			),
377
+			'edit_attendee'                       => array(
378
+				'func'       => '_edit_cpt_item',
379
+				'capability' => 'ee_edit_contacts',
380
+				'obj_id'     => $att_id,
381
+			),
382
+			'duplicate_attendee'                  => array(
383
+				'func'       => '_duplicate_attendee',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_contacts',
386
+				'obj_id'     => $att_id,
387
+			),
388
+			'insert_attendee'                     => array(
389
+				'func'       => '_insert_or_update_attendee',
390
+				'args'       => array(
391
+					'new_attendee' => true,
392
+				),
393
+				'noheader'   => true,
394
+				'capability' => 'ee_edit_contacts',
395
+			),
396
+			'update_attendee'                     => array(
397
+				'func'       => '_insert_or_update_attendee',
398
+				'args'       => array(
399
+					'new_attendee' => false,
400
+				),
401
+				'noheader'   => true,
402
+				'capability' => 'ee_edit_contacts',
403
+				'obj_id'     => $att_id,
404
+			),
405
+			'trash_attendees'                     => array(
406
+				'func'       => '_trash_or_restore_attendees',
407
+				'args'       => array(
408
+					'trash' => 'true',
409
+				),
410
+				'noheader'   => true,
411
+				'capability' => 'ee_delete_contacts',
412
+			),
413
+			'trash_attendee'                      => array(
414
+				'func'       => '_trash_or_restore_attendees',
415
+				'args'       => array(
416
+					'trash' => true,
417
+				),
418
+				'noheader'   => true,
419
+				'capability' => 'ee_delete_contacts',
420
+				'obj_id'     => $att_id,
421
+			),
422
+			'restore_attendees'                   => array(
423
+				'func'       => '_trash_or_restore_attendees',
424
+				'args'       => array(
425
+					'trash' => false,
426
+				),
427
+				'noheader'   => true,
428
+				'capability' => 'ee_delete_contacts',
429
+				'obj_id'     => $att_id,
430
+			),
431
+			'resend_registration'                 => array(
432
+				'func'       => '_resend_registration',
433
+				'noheader'   => true,
434
+				'capability' => 'ee_send_message',
435
+			),
436
+			'registrations_report'                => array(
437
+				'func'       => '_registrations_report',
438
+				'noheader'   => true,
439
+				'capability' => 'ee_read_registrations',
440
+			),
441
+			'contact_list_export'                 => array(
442
+				'func'       => '_contact_list_export',
443
+				'noheader'   => true,
444
+				'capability' => 'export',
445
+			),
446
+			'contact_list_report'                 => array(
447
+				'func'       => '_contact_list_report',
448
+				'noheader'   => true,
449
+				'capability' => 'ee_read_contacts',
450
+			),
451
+		);
452
+	}
453
+
454
+
455
+	protected function _set_page_config()
456
+	{
457
+		$this->_page_config = array(
458
+			'default'           => array(
459
+				'nav'           => array(
460
+					'label' => esc_html__('Overview', 'event_espresso'),
461
+					'order' => 5,
462
+				),
463
+				'help_tabs'     => array(
464
+					'registrations_overview_help_tab'                       => array(
465
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
466
+						'filename' => 'registrations_overview',
467
+					),
468
+					'registrations_overview_table_column_headings_help_tab' => array(
469
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
470
+						'filename' => 'registrations_overview_table_column_headings',
471
+					),
472
+					'registrations_overview_filters_help_tab'               => array(
473
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
474
+						'filename' => 'registrations_overview_filters',
475
+					),
476
+					'registrations_overview_views_help_tab'                 => array(
477
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
478
+						'filename' => 'registrations_overview_views',
479
+					),
480
+					'registrations_regoverview_other_help_tab'              => array(
481
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
482
+						'filename' => 'registrations_overview_other',
483
+					),
484
+				),
485
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
486
+				'qtips'         => array('Registration_List_Table_Tips'),
487
+				'list_table'    => 'EE_Registrations_List_Table',
488
+				'require_nonce' => false,
489
+			),
490
+			'view_registration' => array(
491
+				'nav'           => array(
492
+					'label'      => esc_html__('REG Details', 'event_espresso'),
493
+					'order'      => 15,
494
+					'url'        => isset($this->_req_data['_REG_ID'])
495
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
496
+						: $this->_admin_base_url,
497
+					'persistent' => false,
498
+				),
499
+				'help_tabs'     => array(
500
+					'registrations_details_help_tab'                    => array(
501
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
502
+						'filename' => 'registrations_details',
503
+					),
504
+					'registrations_details_table_help_tab'              => array(
505
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
506
+						'filename' => 'registrations_details_table',
507
+					),
508
+					'registrations_details_form_answers_help_tab'       => array(
509
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
510
+						'filename' => 'registrations_details_form_answers',
511
+					),
512
+					'registrations_details_registrant_details_help_tab' => array(
513
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
514
+						'filename' => 'registrations_details_registrant_details',
515
+					),
516
+				),
517
+				'help_tour'     => array('Registration_Details_Help_Tour'),
518
+				'metaboxes'     => array_merge(
519
+					$this->_default_espresso_metaboxes,
520
+					array('_registration_details_metaboxes')
521
+				),
522
+				'require_nonce' => false,
523
+			),
524
+			'new_registration'  => array(
525
+				'nav'           => array(
526
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
527
+					'url'        => '#',
528
+					'order'      => 15,
529
+					'persistent' => false,
530
+				),
531
+				'metaboxes'     => $this->_default_espresso_metaboxes,
532
+				'labels'        => array(
533
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
534
+				),
535
+				'require_nonce' => false,
536
+			),
537
+			'add_new_attendee'  => array(
538
+				'nav'           => array(
539
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
540
+					'order'      => 15,
541
+					'persistent' => false,
542
+				),
543
+				'metaboxes'     => array_merge(
544
+					$this->_default_espresso_metaboxes,
545
+					array('_publish_post_box', 'attendee_editor_metaboxes')
546
+				),
547
+				'require_nonce' => false,
548
+			),
549
+			'edit_attendee'     => array(
550
+				'nav'           => array(
551
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
552
+					'order'      => 15,
553
+					'persistent' => false,
554
+					'url'        => isset($this->_req_data['ATT_ID'])
555
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
556
+						: $this->_admin_base_url,
557
+				),
558
+				'metaboxes'     => array('attendee_editor_metaboxes'),
559
+				'require_nonce' => false,
560
+			),
561
+			'contact_list'      => array(
562
+				'nav'           => array(
563
+					'label' => esc_html__('Contact List', 'event_espresso'),
564
+					'order' => 20,
565
+				),
566
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
567
+				'help_tabs'     => array(
568
+					'registrations_contact_list_help_tab'                       => array(
569
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
570
+						'filename' => 'registrations_contact_list',
571
+					),
572
+					'registrations_contact-list_table_column_headings_help_tab' => array(
573
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
574
+						'filename' => 'registrations_contact_list_table_column_headings',
575
+					),
576
+					'registrations_contact_list_views_help_tab'                 => array(
577
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
578
+						'filename' => 'registrations_contact_list_views',
579
+					),
580
+					'registrations_contact_list_other_help_tab'                 => array(
581
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
582
+						'filename' => 'registrations_contact_list_other',
583
+					),
584
+				),
585
+				'help_tour'     => array('Contact_List_Help_Tour'),
586
+				'metaboxes'     => array(),
587
+				'require_nonce' => false,
588
+			),
589
+			// override default cpt routes
590
+			'create_new'        => '',
591
+			'edit'              => '',
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * The below methods aren't used by this class currently
598
+	 */
599
+	protected function _add_screen_options()
600
+	{
601
+	}
602
+
603
+
604
+	protected function _add_feature_pointers()
605
+	{
606
+	}
607
+
608
+
609
+	public function admin_init()
610
+	{
611
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
612
+			'click "Update Registration Questions" to save your changes',
613
+			'event_espresso'
614
+		);
615
+	}
616
+
617
+
618
+	public function admin_notices()
619
+	{
620
+	}
621
+
622
+
623
+	public function admin_footer_scripts()
624
+	{
625
+	}
626
+
627
+
628
+	/**
629
+	 *        get list of registration statuses
630
+	 *
631
+	 * @access private
632
+	 * @return void
633
+	 * @throws EE_Error
634
+	 */
635
+	private function _get_registration_status_array()
636
+	{
637
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
638
+	}
639
+
640
+
641
+	protected function _add_screen_options_default()
642
+	{
643
+		$this->_per_page_screen_option();
644
+	}
645
+
646
+
647
+	protected function _add_screen_options_contact_list()
648
+	{
649
+		$page_title = $this->_admin_page_title;
650
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
651
+		$this->_per_page_screen_option();
652
+		$this->_admin_page_title = $page_title;
653
+	}
654
+
655
+
656
+	public function load_scripts_styles()
657
+	{
658
+		// style
659
+		wp_register_style(
660
+			'espresso_reg',
661
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
662
+			array('ee-admin-css'),
663
+			EVENT_ESPRESSO_VERSION
664
+		);
665
+		wp_enqueue_style('espresso_reg');
666
+		// script
667
+		wp_register_script(
668
+			'espresso_reg',
669
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
670
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671
+			EVENT_ESPRESSO_VERSION,
672
+			true
673
+		);
674
+		wp_enqueue_script('espresso_reg');
675
+	}
676
+
677
+
678
+	public function load_scripts_styles_edit_attendee()
679
+	{
680
+		// stuff to only show up on our attendee edit details page.
681
+		$attendee_details_translations = array(
682
+			'att_publish_text' => sprintf(
683
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
684
+				$this->_cpt_model_obj->get_datetime('ATT_created')
685
+			),
686
+		);
687
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
688
+		wp_enqueue_script('jquery-validate');
689
+	}
690
+
691
+
692
+	public function load_scripts_styles_view_registration()
693
+	{
694
+		// styles
695
+		wp_enqueue_style('espresso-ui-theme');
696
+		// scripts
697
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
698
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
699
+	}
700
+
701
+
702
+	public function load_scripts_styles_contact_list()
703
+	{
704
+		wp_dequeue_style('espresso_reg');
705
+		wp_register_style(
706
+			'espresso_att',
707
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
708
+			array('ee-admin-css'),
709
+			EVENT_ESPRESSO_VERSION
710
+		);
711
+		wp_enqueue_style('espresso_att');
712
+	}
713
+
714
+
715
+	public function load_scripts_styles_new_registration()
716
+	{
717
+		wp_register_script(
718
+			'ee-spco-for-admin',
719
+			REG_ASSETS_URL . 'spco_for_admin.js',
720
+			array('underscore', 'jquery'),
721
+			EVENT_ESPRESSO_VERSION,
722
+			true
723
+		);
724
+		wp_enqueue_script('ee-spco-for-admin');
725
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
726
+		EE_Form_Section_Proper::wp_enqueue_scripts();
727
+		EED_Ticket_Selector::load_tckt_slctr_assets();
728
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
729
+	}
730
+
731
+
732
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
733
+	{
734
+		add_filter('FHEE_load_EE_messages', '__return_true');
735
+	}
736
+
737
+
738
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
739
+	{
740
+		add_filter('FHEE_load_EE_messages', '__return_true');
741
+	}
742
+
743
+
744
+	protected function _set_list_table_views_default()
745
+	{
746
+		// for notification related bulk actions we need to make sure only active messengers have an option.
747
+		EED_Messages::set_autoloaders();
748
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
749
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
750
+		$active_mts = $message_resource_manager->list_of_active_message_types();
751
+		// key= bulk_action_slug, value= message type.
752
+		$match_array = array(
753
+			'approve_registrations'    => 'registration',
754
+			'decline_registrations'    => 'declined_registration',
755
+			'pending_registrations'    => 'pending_approval',
756
+			'no_approve_registrations' => 'not_approved_registration',
757
+			'cancel_registrations'     => 'cancelled_registration',
758
+		);
759
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
760
+			'ee_send_message',
761
+			'batch_send_messages'
762
+		);
763
+		/** setup reg status bulk actions **/
764
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
765
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
766
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
767
+				'Approve and Notify Registrations',
768
+				'event_espresso'
769
+			);
770
+		}
771
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
772
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
773
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
774
+				'Decline and Notify Registrations',
775
+				'event_espresso'
776
+			);
777
+		}
778
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
779
+			'Set Registrations to Pending Payment',
780
+			'event_espresso'
781
+		);
782
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
783
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
784
+				'Set Registrations to Pending Payment and Notify',
785
+				'event_espresso'
786
+			);
787
+		}
788
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
789
+			'Set Registrations to Not Approved',
790
+			'event_espresso'
791
+		);
792
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
793
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
794
+				'Set Registrations to Not Approved and Notify',
795
+				'event_espresso'
796
+			);
797
+		}
798
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
799
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
800
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
801
+				'Cancel Registrations and Notify',
802
+				'event_espresso'
803
+			);
804
+		}
805
+		$def_reg_status_actions = apply_filters(
806
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
807
+			$def_reg_status_actions,
808
+			$active_mts,
809
+			$can_send
810
+		);
811
+
812
+		$this->_views = array(
813
+			'all'   => array(
814
+				'slug'        => 'all',
815
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
816
+				'count'       => 0,
817
+				'bulk_action' => array_merge(
818
+					$def_reg_status_actions,
819
+					array(
820
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
821
+					)
822
+				),
823
+			),
824
+			'month' => array(
825
+				'slug'        => 'month',
826
+				'label'       => esc_html__('This Month', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge(
829
+					$def_reg_status_actions,
830
+					array(
831
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
832
+					)
833
+				),
834
+			),
835
+			'today' => array(
836
+				'slug'        => 'today',
837
+				'label'       => sprintf(
838
+					esc_html__('Today - %s', 'event_espresso'),
839
+					date('M d, Y', current_time('timestamp'))
840
+				),
841
+				'count'       => 0,
842
+				'bulk_action' => array_merge(
843
+					$def_reg_status_actions,
844
+					array(
845
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
+					)
847
+				),
848
+			),
849
+		);
850
+		if (EE_Registry::instance()->CAP->current_user_can(
851
+			'ee_delete_registrations',
852
+			'espresso_registrations_delete_registration'
853
+		)) {
854
+			$this->_views['incomplete'] = array(
855
+				'slug'        => 'incomplete',
856
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
857
+				'count'       => 0,
858
+				'bulk_action' => array(
859
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
860
+				),
861
+			);
862
+			$this->_views['trash'] = array(
863
+				'slug'        => 'trash',
864
+				'label'       => esc_html__('Trash', 'event_espresso'),
865
+				'count'       => 0,
866
+				'bulk_action' => array(
867
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
868
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
869
+				),
870
+			);
871
+		}
872
+	}
873
+
874
+
875
+	protected function _set_list_table_views_contact_list()
876
+	{
877
+		$this->_views = array(
878
+			'in_use' => array(
879
+				'slug'        => 'in_use',
880
+				'label'       => esc_html__('In Use', 'event_espresso'),
881
+				'count'       => 0,
882
+				'bulk_action' => array(
883
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
884
+				),
885
+			),
886
+		);
887
+		if (EE_Registry::instance()->CAP->current_user_can(
888
+			'ee_delete_contacts',
889
+			'espresso_registrations_trash_attendees'
890
+		)
891
+		) {
892
+			$this->_views['trash'] = array(
893
+				'slug'        => 'trash',
894
+				'label'       => esc_html__('Trash', 'event_espresso'),
895
+				'count'       => 0,
896
+				'bulk_action' => array(
897
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
+				),
899
+			);
900
+		}
901
+	}
902
+
903
+
904
+	protected function _registration_legend_items()
905
+	{
906
+		$fc_items = array(
907
+			'star-icon'        => array(
908
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
+			),
911
+			'view_details'     => array(
912
+				'class' => 'dashicons dashicons-clipboard',
913
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
+			),
915
+			'edit_attendee'    => array(
916
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
+			),
919
+			'view_transaction' => array(
920
+				'class' => 'dashicons dashicons-cart',
921
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
+			),
923
+			'view_invoice'     => array(
924
+				'class' => 'dashicons dashicons-media-spreadsheet',
925
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
+			),
927
+		);
928
+		if (EE_Registry::instance()->CAP->current_user_can(
929
+			'ee_send_message',
930
+			'espresso_registrations_resend_registration'
931
+		)) {
932
+			$fc_items['resend_registration'] = array(
933
+				'class' => 'dashicons dashicons-email-alt',
934
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
+			);
936
+		} else {
937
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
+		}
939
+		if (EE_Registry::instance()->CAP->current_user_can(
940
+			'ee_read_global_messages',
941
+			'view_filtered_messages'
942
+		)) {
943
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
+				$fc_items['view_related_messages'] = array(
946
+					'class' => $related_for_icon['css_class'],
947
+					'desc'  => $related_for_icon['label'],
948
+				);
949
+			}
950
+		}
951
+		$sc_items = array(
952
+			'approved_status'   => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_approved,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'pending_status'    => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_pending_payment,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'wait_list'         => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_wait_list,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'incomplete_status' => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_incomplete,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'not_approved'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_not_approved,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'declined_status'   => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_declined,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+			'cancelled_status'  => array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
+				'desc'  => EEH_Template::pretty_status(
1003
+					EEM_Registration::status_id_cancelled,
1004
+					false,
1005
+					'sentence'
1006
+				),
1007
+			),
1008
+		);
1009
+		return array_merge($fc_items, $sc_items);
1010
+	}
1011
+
1012
+
1013
+
1014
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1015
+	/**
1016
+	 * @throws \EE_Error
1017
+	 */
1018
+	protected function _registrations_overview_list_table()
1019
+	{
1020
+		$this->_template_args['admin_page_header'] = '';
1021
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1022
+			? absint($this->_req_data['event_id'])
1023
+			: 0;
1024
+		$ATT_ID = ! empty($this->_req_data['ATT_ID'])
1025
+			? absint($this->_req_data['ATT_ID'])
1026
+			: 0;
1027
+		if ($ATT_ID) {
1028
+			$attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
+			if ($attendee instanceof EE_Attendee) {
1030
+				$this->_template_args['admin_page_header'] = sprintf(
1031
+					esc_html__(
1032
+						'%1$s Viewing registrations for %2$s%3$s',
1033
+						'event_espresso'
1034
+					),
1035
+					'<h3 style="line-height:1.5em;">',
1036
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
+						array(
1038
+							'action' => 'edit_attendee',
1039
+							'post'   => $ATT_ID,
1040
+						),
1041
+						REG_ADMIN_URL
1042
+					) . '">' . $attendee->full_name() . '</a>',
1043
+					'</h3>'
1044
+				);
1045
+			}
1046
+		}
1047
+		if ($EVT_ID) {
1048
+			if (EE_Registry::instance()->CAP->current_user_can(
1049
+				'ee_edit_registrations',
1050
+				'espresso_registrations_new_registration',
1051
+				$EVT_ID
1052
+			)) {
1053
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
+					'new_registration',
1055
+					'add-registrant',
1056
+					array('event_id' => $EVT_ID),
1057
+					'add-new-h2'
1058
+				);
1059
+			}
1060
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
+			if ($event instanceof EE_Event) {
1062
+				$this->_template_args['admin_page_header'] = sprintf(
1063
+					esc_html__(
1064
+						'%s Viewing registrations for the event: %s%s',
1065
+						'event_espresso'
1066
+					),
1067
+					'<h3 style="line-height:1.5em;">',
1068
+					'<br /><a href="'
1069
+					. EE_Admin_Page::add_query_args_and_nonce(
1070
+						array(
1071
+							'action' => 'edit',
1072
+							'post'   => $event->ID(),
1073
+						),
1074
+						EVENTS_ADMIN_URL
1075
+					)
1076
+					. '">&nbsp;'
1077
+					. $event->get('EVT_name')
1078
+					. '&nbsp;</a>&nbsp;',
1079
+					'</h3>'
1080
+				);
1081
+			}
1082
+			$DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
+				$this->_template_args['admin_page_header'] = substr(
1086
+					$this->_template_args['admin_page_header'],
1087
+					0,
1088
+					-5
1089
+				);
1090
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1093
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1095
+			}
1096
+		}
1097
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
+		$this->display_admin_list_table_page_with_no_sidebar();
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * This sets the _registration property for the registration details screen
1104
+	 *
1105
+	 * @access private
1106
+	 * @return bool
1107
+	 * @throws EE_Error
1108
+	 * @throws InvalidArgumentException
1109
+	 * @throws InvalidDataTypeException
1110
+	 * @throws InvalidInterfaceException
1111
+	 */
1112
+	private function _set_registration_object()
1113
+	{
1114
+		// get out if we've already set the object
1115
+		if ($this->_registration instanceof EE_Registration) {
1116
+			return true;
1117
+		}
1118
+		$REG = EEM_Registration::instance();
1119
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
+			return true;
1122
+		} else {
1123
+			$error_msg = sprintf(
1124
+				esc_html__(
1125
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
+					'event_espresso'
1127
+				),
1128
+				$REG_ID
1129
+			);
1130
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
+			$this->_registration = null;
1132
+			return false;
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Used to retrieve registrations for the list table.
1139
+	 *
1140
+	 * @param int  $per_page
1141
+	 * @param bool $count
1142
+	 * @param bool $this_month
1143
+	 * @param bool $today
1144
+	 * @return EE_Registration[]|int
1145
+	 * @throws EE_Error
1146
+	 * @throws InvalidArgumentException
1147
+	 * @throws InvalidDataTypeException
1148
+	 * @throws InvalidInterfaceException
1149
+	 */
1150
+	public function get_registrations(
1151
+		$per_page = 10,
1152
+		$count = false,
1153
+		$this_month = false,
1154
+		$today = false
1155
+	) {
1156
+		if ($this_month) {
1157
+			$this->_req_data['status'] = 'month';
1158
+		}
1159
+		if ($today) {
1160
+			$this->_req_data['status'] = 'today';
1161
+		}
1162
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
+		/**
1164
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
+		 *
1166
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1167
+		 * @see  EEM_Base::get_all()
1168
+		 */
1169
+		$query_params['group_by'] = '';
1170
+
1171
+		return $count
1172
+			? EEM_Registration::instance()->count($query_params)
1173
+			/** @type EE_Registration[] */
1174
+			: EEM_Registration::instance()->get_all($query_params);
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1180
+	 * Note: this listens to values on the request for some of the query parameters.
1181
+	 *
1182
+	 * @param array $request
1183
+	 * @param int   $per_page
1184
+	 * @param bool  $count
1185
+	 * @return array
1186
+	 * @throws EE_Error
1187
+	 */
1188
+	protected function _get_registration_query_parameters(
1189
+		$request = array(),
1190
+		$per_page = 10,
1191
+		$count = false
1192
+	) {
1193
+
1194
+		$query_params = array(
1195
+			0                          => $this->_get_where_conditions_for_registrations_query(
1196
+				$request
1197
+			),
1198
+			'caps'                     => EEM_Registration::caps_read_admin,
1199
+			'default_where_conditions' => 'this_model_only',
1200
+		);
1201
+		if (! $count) {
1202
+			$query_params = array_merge(
1203
+				$query_params,
1204
+				$this->_get_orderby_for_registrations_query(),
1205
+				$this->_get_limit($per_page)
1206
+			);
1207
+		}
1208
+
1209
+		return $query_params;
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * This will add ATT_ID to the provided $where array for EE model query parameters.
1215
+	 *
1216
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1217
+	 * @return array
1218
+	 */
1219
+	protected function addAttendeeIdToWhereConditions(array $request)
1220
+	{
1221
+		$where = array();
1222
+		if (! empty($request['ATT_ID'])) {
1223
+			$where['ATT_ID'] = absint($request['ATT_ID']);
1224
+		}
1225
+		return $where;
1226
+	}
1227
+
1228
+
1229
+	/**
1230
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1231
+	 *
1232
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1233
+	 * @return array
1234
+	 */
1235
+	protected function _add_event_id_to_where_conditions(array $request)
1236
+	{
1237
+		$where = array();
1238
+		if (! empty($request['event_id'])) {
1239
+			$where['EVT_ID'] = absint($request['event_id']);
1240
+		}
1241
+		return $where;
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1247
+	 *
1248
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1249
+	 * @return array
1250
+	 */
1251
+	protected function _add_category_id_to_where_conditions(array $request)
1252
+	{
1253
+		$where = array();
1254
+		if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1255
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1256
+		}
1257
+		return $where;
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1263
+	 *
1264
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1265
+	 * @return array
1266
+	 */
1267
+	protected function _add_datetime_id_to_where_conditions(array $request)
1268
+	{
1269
+		$where = array();
1270
+		if (! empty($request['datetime_id'])) {
1271
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1272
+		}
1273
+		if (! empty($request['DTT_ID'])) {
1274
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1275
+		}
1276
+		return $where;
1277
+	}
1278
+
1279
+
1280
+	/**
1281
+	 * Adds the correct registration status to the where conditions for the registrations query.
1282
+	 *
1283
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1284
+	 * @return array
1285
+	 */
1286
+	protected function _add_registration_status_to_where_conditions(array $request)
1287
+	{
1288
+		$where = array();
1289
+		$view = EEH_Array::is_set($request, 'status', '');
1290
+		$registration_status = ! empty($request['_reg_status'])
1291
+			? sanitize_text_field($request['_reg_status'])
1292
+			: '';
1293
+
1294
+		/*
1295 1295
          * If filtering by registration status, then we show registrations matching that status.
1296 1296
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1297 1297
          * UNLESS viewing trashed registrations.
1298 1298
          */
1299
-        if (! empty($registration_status)) {
1300
-            $where['STS_ID'] = $registration_status;
1301
-        } else {
1302
-            // make sure we exclude incomplete registrations, but only if not trashed.
1303
-            if ($view === 'trash') {
1304
-                $where['REG_deleted'] = true;
1305
-            } elseif ($view === 'incomplete') {
1306
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1307
-            } else {
1308
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1309
-            }
1310
-        }
1311
-        return $where;
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Adds any provided date restraints to the where conditions for the registrations query.
1317
-     *
1318
-     * @param array $request usually the same as $this->_req_data but not necessarily
1319
-     * @return array
1320
-     * @throws EE_Error
1321
-     * @throws InvalidArgumentException
1322
-     * @throws InvalidDataTypeException
1323
-     * @throws InvalidInterfaceException
1324
-     */
1325
-    protected function _add_date_to_where_conditions(array $request)
1326
-    {
1327
-        $where = array();
1328
-        $view = EEH_Array::is_set($request, 'status', '');
1329
-        $month_range = ! empty($request['month_range'])
1330
-            ? sanitize_text_field($request['month_range'])
1331
-            : '';
1332
-        $retrieve_for_today = $view === 'today';
1333
-        $retrieve_for_this_month = $view === 'month';
1334
-
1335
-        if ($retrieve_for_today) {
1336
-            $now = date('Y-m-d', current_time('timestamp'));
1337
-            $where['REG_date'] = array(
1338
-                'BETWEEN',
1339
-                array(
1340
-                    EEM_Registration::instance()->convert_datetime_for_query(
1341
-                        'REG_date',
1342
-                        $now . ' 00:00:00',
1343
-                        'Y-m-d H:i:s'
1344
-                    ),
1345
-                    EEM_Registration::instance()->convert_datetime_for_query(
1346
-                        'REG_date',
1347
-                        $now . ' 23:59:59',
1348
-                        'Y-m-d H:i:s'
1349
-                    ),
1350
-                ),
1351
-            );
1352
-        } elseif ($retrieve_for_this_month) {
1353
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1354
-            $days_this_month = date('t', current_time('timestamp'));
1355
-            $where['REG_date'] = array(
1356
-                'BETWEEN',
1357
-                array(
1358
-                    EEM_Registration::instance()->convert_datetime_for_query(
1359
-                        'REG_date',
1360
-                        $current_year_and_month . '-01 00:00:00',
1361
-                        'Y-m-d H:i:s'
1362
-                    ),
1363
-                    EEM_Registration::instance()->convert_datetime_for_query(
1364
-                        'REG_date',
1365
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1366
-                        'Y-m-d H:i:s'
1367
-                    ),
1368
-                ),
1369
-            );
1370
-        } elseif ($month_range) {
1371
-            $pieces = explode(' ', $month_range, 3);
1372
-            $month_requested = ! empty($pieces[0])
1373
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1374
-                : '';
1375
-            $year_requested = ! empty($pieces[1])
1376
-                ? $pieces[1]
1377
-                : '';
1378
-            // if there is not a month or year then we can't go further
1379
-            if ($month_requested && $year_requested) {
1380
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1381
-                $where['REG_date'] = array(
1382
-                    'BETWEEN',
1383
-                    array(
1384
-                        EEM_Registration::instance()->convert_datetime_for_query(
1385
-                            'REG_date',
1386
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1387
-                            'Y-m-d H:i:s'
1388
-                        ),
1389
-                        EEM_Registration::instance()->convert_datetime_for_query(
1390
-                            'REG_date',
1391
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1392
-                            'Y-m-d H:i:s'
1393
-                        ),
1394
-                    ),
1395
-                );
1396
-            }
1397
-        }
1398
-        return $where;
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     * Adds any provided search restraints to the where conditions for the registrations query
1404
-     *
1405
-     * @param array $request usually the same as $this->_req_data but not necessarily
1406
-     * @return array
1407
-     */
1408
-    protected function _add_search_to_where_conditions(array $request)
1409
-    {
1410
-        $where = array();
1411
-        if (! empty($request['s'])) {
1412
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1413
-            $where['OR*search_conditions'] = array(
1414
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1415
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1416
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1417
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1418
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1419
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1420
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1421
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1422
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1423
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1424
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1425
-                'REG_final_price'                         => array('LIKE', $search_string),
1426
-                'REG_code'                                => array('LIKE', $search_string),
1427
-                'REG_count'                               => array('LIKE', $search_string),
1428
-                'REG_group_size'                          => array('LIKE', $search_string),
1429
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1430
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1431
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1432
-            );
1433
-        }
1434
-        return $where;
1435
-    }
1436
-
1437
-
1438
-    /**
1439
-     * Sets up the where conditions for the registrations query.
1440
-     *
1441
-     * @param array $request
1442
-     * @return array
1443
-     * @throws EE_Error
1444
-     */
1445
-    protected function _get_where_conditions_for_registrations_query($request)
1446
-    {
1447
-        return apply_filters(
1448
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1449
-            array_merge(
1450
-                $this->addAttendeeIdToWhereConditions($request),
1451
-                $this->_add_event_id_to_where_conditions($request),
1452
-                $this->_add_category_id_to_where_conditions($request),
1453
-                $this->_add_datetime_id_to_where_conditions($request),
1454
-                $this->_add_registration_status_to_where_conditions($request),
1455
-                $this->_add_date_to_where_conditions($request),
1456
-                $this->_add_search_to_where_conditions($request)
1457
-            ),
1458
-            $request
1459
-        );
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * Sets up the orderby for the registrations query.
1465
-     *
1466
-     * @return array
1467
-     */
1468
-    protected function _get_orderby_for_registrations_query()
1469
-    {
1470
-        $orderby_field = ! empty($this->_req_data['orderby'])
1471
-            ? sanitize_text_field($this->_req_data['orderby'])
1472
-            : '_REG_date';
1473
-        switch ($orderby_field) {
1474
-            case '_REG_ID':
1475
-                $orderby = array('REG_ID');
1476
-                break;
1477
-            case '_Reg_status':
1478
-                $orderby = array('STS_ID');
1479
-                break;
1480
-            case 'ATT_fname':
1481
-                $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1482
-                break;
1483
-            case 'ATT_lname':
1484
-                $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1485
-                break;
1486
-            case 'event_name':
1487
-                $orderby = array('Event.EVT_name');
1488
-                break;
1489
-            case 'DTT_EVT_start':
1490
-                $orderby = array('Event.Datetime.DTT_EVT_start');
1491
-                break;
1492
-            case '_REG_date':
1493
-                $orderby = array('REG_date');
1494
-                break;
1495
-            default:
1496
-                $orderby = array($orderby_field);
1497
-                break;
1498
-        }
1499
-
1500
-        // order
1501
-        $order = ! empty($this->_req_data['order'])
1502
-            ? sanitize_text_field($this->_req_data['order'])
1503
-            : 'DESC';
1504
-        $orderby = array_combine(
1505
-            $orderby,
1506
-            array_fill(0, count($orderby), $order)
1507
-        );
1508
-        // because there are many registrations with the same date, define
1509
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
1510
-        if (empty($orderby['REG_ID'])) {
1511
-            $orderby['REG_ID'] = $order;
1512
-        }
1513
-
1514
-        $orderby = apply_filters(
1515
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1516
-            $orderby,
1517
-            $this->_req_data
1518
-        );
1519
-
1520
-        return array('order_by' => $orderby);
1521
-    }
1522
-
1523
-
1524
-    /**
1525
-     * Sets up the limit for the registrations query.
1526
-     *
1527
-     * @param $per_page
1528
-     * @return array
1529
-     */
1530
-    protected function _get_limit($per_page)
1531
-    {
1532
-        $current_page = ! empty($this->_req_data['paged'])
1533
-            ? absint($this->_req_data['paged'])
1534
-            : 1;
1535
-        $per_page = ! empty($this->_req_data['perpage'])
1536
-            ? $this->_req_data['perpage']
1537
-            : $per_page;
1538
-
1539
-        // -1 means return all results so get out if that's set.
1540
-        if ((int) $per_page === -1) {
1541
-            return array();
1542
-        }
1543
-        $per_page = absint($per_page);
1544
-        $offset = ($current_page - 1) * $per_page;
1545
-        return array('limit' => array($offset, $per_page));
1546
-    }
1547
-
1548
-
1549
-    public function get_registration_status_array()
1550
-    {
1551
-        return self::$_reg_status;
1552
-    }
1553
-
1554
-
1555
-
1556
-
1557
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1558
-    /**
1559
-     *        generates HTML for the View Registration Details Admin page
1560
-     *
1561
-     * @access protected
1562
-     * @return void
1563
-     * @throws DomainException
1564
-     * @throws EE_Error
1565
-     * @throws InvalidArgumentException
1566
-     * @throws InvalidDataTypeException
1567
-     * @throws InvalidInterfaceException
1568
-     * @throws EntityNotFoundException
1569
-     */
1570
-    protected function _registration_details()
1571
-    {
1572
-        $this->_template_args = array();
1573
-        $this->_set_registration_object();
1574
-        if (is_object($this->_registration)) {
1575
-            $transaction = $this->_registration->transaction()
1576
-                ? $this->_registration->transaction()
1577
-                : EE_Transaction::new_instance();
1578
-            $this->_session = $transaction->session_data();
1579
-            $event_id = $this->_registration->event_ID();
1580
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1581
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1582
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1583
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1584
-            $this->_template_args['grand_total'] = $transaction->total();
1585
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1586
-            // link back to overview
1587
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1588
-            $this->_template_args['registration'] = $this->_registration;
1589
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1590
-                array(
1591
-                    'action'   => 'default',
1592
-                    'event_id' => $event_id,
1593
-                ),
1594
-                REG_ADMIN_URL
1595
-            );
1596
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1597
-                array(
1598
-                    'action' => 'default',
1599
-                    'EVT_ID' => $event_id,
1600
-                    'page'   => 'espresso_transactions',
1601
-                ),
1602
-                admin_url('admin.php')
1603
-            );
1604
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1605
-                array(
1606
-                    'page'   => 'espresso_events',
1607
-                    'action' => 'edit',
1608
-                    'post'   => $event_id,
1609
-                ),
1610
-                admin_url('admin.php')
1611
-            );
1612
-            // next and previous links
1613
-            $next_reg = $this->_registration->next(
1614
-                null,
1615
-                array(),
1616
-                'REG_ID'
1617
-            );
1618
-            $this->_template_args['next_registration'] = $next_reg
1619
-                ? $this->_next_link(
1620
-                    EE_Admin_Page::add_query_args_and_nonce(
1621
-                        array(
1622
-                            'action'  => 'view_registration',
1623
-                            '_REG_ID' => $next_reg['REG_ID'],
1624
-                        ),
1625
-                        REG_ADMIN_URL
1626
-                    ),
1627
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1628
-                )
1629
-                : '';
1630
-            $previous_reg = $this->_registration->previous(
1631
-                null,
1632
-                array(),
1633
-                'REG_ID'
1634
-            );
1635
-            $this->_template_args['previous_registration'] = $previous_reg
1636
-                ? $this->_previous_link(
1637
-                    EE_Admin_Page::add_query_args_and_nonce(
1638
-                        array(
1639
-                            'action'  => 'view_registration',
1640
-                            '_REG_ID' => $previous_reg['REG_ID'],
1641
-                        ),
1642
-                        REG_ADMIN_URL
1643
-                    ),
1644
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1645
-                )
1646
-                : '';
1647
-            // grab header
1648
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1649
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1650
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1651
-                $template_path,
1652
-                $this->_template_args,
1653
-                true
1654
-            );
1655
-        } else {
1656
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1657
-        }
1658
-        // the details template wrapper
1659
-        $this->display_admin_page_with_sidebar();
1660
-    }
1661
-
1662
-
1663
-    protected function _registration_details_metaboxes()
1664
-    {
1665
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1666
-        $this->_set_registration_object();
1667
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1668
-        add_meta_box(
1669
-            'edit-reg-status-mbox',
1670
-            esc_html__('Registration Status', 'event_espresso'),
1671
-            array($this, 'set_reg_status_buttons_metabox'),
1672
-            $this->wp_page_slug,
1673
-            'normal',
1674
-            'high'
1675
-        );
1676
-        add_meta_box(
1677
-            'edit-reg-details-mbox',
1678
-            esc_html__('Registration Details', 'event_espresso'),
1679
-            array($this, '_reg_details_meta_box'),
1680
-            $this->wp_page_slug,
1681
-            'normal',
1682
-            'high'
1683
-        );
1684
-        if ($attendee instanceof EE_Attendee
1685
-            && EE_Registry::instance()->CAP->current_user_can(
1686
-                'ee_read_registration',
1687
-                'edit-reg-questions-mbox',
1688
-                $this->_registration->ID()
1689
-            )
1690
-        ) {
1691
-            add_meta_box(
1692
-                'edit-reg-questions-mbox',
1693
-                esc_html__('Registration Form Answers', 'event_espresso'),
1694
-                array($this, '_reg_questions_meta_box'),
1695
-                $this->wp_page_slug,
1696
-                'normal',
1697
-                'high'
1698
-            );
1699
-        }
1700
-        add_meta_box(
1701
-            'edit-reg-registrant-mbox',
1702
-            esc_html__('Contact Details', 'event_espresso'),
1703
-            array($this, '_reg_registrant_side_meta_box'),
1704
-            $this->wp_page_slug,
1705
-            'side',
1706
-            'high'
1707
-        );
1708
-        if ($this->_registration->group_size() > 1) {
1709
-            add_meta_box(
1710
-                'edit-reg-attendees-mbox',
1711
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1712
-                array($this, '_reg_attendees_meta_box'),
1713
-                $this->wp_page_slug,
1714
-                'normal',
1715
-                'high'
1716
-            );
1717
-        }
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     * set_reg_status_buttons_metabox
1723
-     *
1724
-     * @access protected
1725
-     * @return string
1726
-     * @throws \EE_Error
1727
-     */
1728
-    public function set_reg_status_buttons_metabox()
1729
-    {
1730
-        $this->_set_registration_object();
1731
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1732
-        echo $change_reg_status_form->form_open(
1733
-            self::add_query_args_and_nonce(
1734
-                array(
1735
-                    'action' => 'change_reg_status',
1736
-                ),
1737
-                REG_ADMIN_URL
1738
-            )
1739
-        );
1740
-        echo $change_reg_status_form->get_html();
1741
-        echo $change_reg_status_form->form_close();
1742
-    }
1743
-
1744
-
1745
-    /**
1746
-     * @return EE_Form_Section_Proper
1747
-     * @throws EE_Error
1748
-     * @throws InvalidArgumentException
1749
-     * @throws InvalidDataTypeException
1750
-     * @throws InvalidInterfaceException
1751
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1752
-     */
1753
-    protected function _generate_reg_status_change_form()
1754
-    {
1755
-        $reg_status_change_form_array = array(
1756
-            'name'            => 'reg_status_change_form',
1757
-            'html_id'         => 'reg-status-change-form',
1758
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1759
-            'subsections'     => array(
1760
-                'return'             => new EE_Hidden_Input(
1761
-                    array(
1762
-                        'name'    => 'return',
1763
-                        'default' => 'view_registration',
1764
-                    )
1765
-                ),
1766
-                'REG_ID'             => new EE_Hidden_Input(
1767
-                    array(
1768
-                        'name'    => 'REG_ID',
1769
-                        'default' => $this->_registration->ID(),
1770
-                    )
1771
-                ),
1772
-                'current_status'     => new EE_Form_Section_HTML(
1773
-                    EEH_HTML::tr(
1774
-                        EEH_HTML::th(
1775
-                            EEH_HTML::label(
1776
-                                EEH_HTML::strong(
1777
-                                    esc_html__('Current Registration Status', 'event_espresso')
1778
-                                )
1779
-                            )
1780
-                        )
1781
-                        . EEH_HTML::td(
1782
-                            EEH_HTML::strong(
1783
-                                $this->_registration->pretty_status(),
1784
-                                '',
1785
-                                'status-' . $this->_registration->status_ID(),
1786
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1787
-                            )
1788
-                        )
1789
-                    )
1790
-                )
1791
-            )
1792
-        );
1793
-        if (EE_Registry::instance()->CAP->current_user_can(
1794
-            'ee_edit_registration',
1795
-            'toggle_registration_status',
1796
-            $this->_registration->ID()
1797
-        )) {
1798
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1799
-                $this->_get_reg_statuses(),
1800
-                array(
1801
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1802
-                    'default'         => $this->_registration->status_ID(),
1803
-                )
1804
-            );
1805
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1806
-                array(
1807
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1808
-                    'default'         => false,
1809
-                    'html_help_text'  => esc_html__(
1810
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1811
-                        'event_espresso'
1812
-                    )
1813
-                )
1814
-            );
1815
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1816
-                array(
1817
-                    'html_class'      => 'button-primary',
1818
-                    'html_label_text' => '&nbsp;',
1819
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1820
-                )
1821
-            );
1822
-        }
1823
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * Returns an array of all the buttons for the various statuses and switch status actions
1829
-     *
1830
-     * @return array
1831
-     * @throws EE_Error
1832
-     * @throws InvalidArgumentException
1833
-     * @throws InvalidDataTypeException
1834
-     * @throws InvalidInterfaceException
1835
-     * @throws EntityNotFoundException
1836
-     */
1837
-    protected function _get_reg_statuses()
1838
-    {
1839
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1840
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1841
-        // get current reg status
1842
-        $current_status = $this->_registration->status_ID();
1843
-        // is registration for free event? This will determine whether to display the pending payment option
1844
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1845
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1846
-        ) {
1847
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1848
-        }
1849
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1855
-     *
1856
-     * @param bool $status REG status given for changing registrations to.
1857
-     * @param bool $notify Whether to send messages notifications or not.
1858
-     * @return array (array with reg_id(s) updated and whether update was successful.
1859
-     * @throws EE_Error
1860
-     * @throws InvalidArgumentException
1861
-     * @throws InvalidDataTypeException
1862
-     * @throws InvalidInterfaceException
1863
-     * @throws ReflectionException
1864
-     * @throws RuntimeException
1865
-     * @throws EntityNotFoundException
1866
-     */
1867
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1868
-    {
1869
-        if (isset($this->_req_data['reg_status_change_form'])) {
1870
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1871
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1872
-                : array();
1873
-        } else {
1874
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1875
-                ? (array) $this->_req_data['_REG_ID']
1876
-                : array();
1877
-        }
1878
-        // sanitize $REG_IDs
1879
-        $REG_IDs = array_map('absint', $REG_IDs);
1880
-        // and remove empty entries
1881
-        $REG_IDs = array_filter($REG_IDs);
1882
-
1883
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1884
-
1885
-        /**
1886
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1887
-         * Currently this value is used downstream by the _process_resend_registration method.
1888
-         *
1889
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1890
-         * @param bool                     $status           The status registrations were changed to.
1891
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1892
-         * @param Registrations_Admin_Page $admin_page_object
1893
-         */
1894
-        $this->_req_data['_REG_ID'] = apply_filters(
1895
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1896
-            $result['REG_ID'],
1897
-            $status,
1898
-            $result['success'],
1899
-            $this
1900
-        );
1901
-
1902
-        // notify?
1903
-        if ($notify
1904
-            && $result['success']
1905
-            && ! empty($this->_req_data['_REG_ID'])
1906
-            && EE_Registry::instance()->CAP->current_user_can(
1907
-                'ee_send_message',
1908
-                'espresso_registrations_resend_registration'
1909
-            )
1910
-        ) {
1911
-            $this->_process_resend_registration();
1912
-        }
1913
-        return $result;
1914
-    }
1915
-
1916
-
1917
-    /**
1918
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1919
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1920
-     *
1921
-     * @param array  $REG_IDs
1922
-     * @param string $status
1923
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1924
-     *                        slug sent with setting the registration status.
1925
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1926
-     * @throws EE_Error
1927
-     * @throws InvalidArgumentException
1928
-     * @throws InvalidDataTypeException
1929
-     * @throws InvalidInterfaceException
1930
-     * @throws ReflectionException
1931
-     * @throws RuntimeException
1932
-     * @throws EntityNotFoundException
1933
-     */
1934
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1935
-    {
1936
-        $success = false;
1937
-        // typecast $REG_IDs
1938
-        $REG_IDs = (array) $REG_IDs;
1939
-        if (! empty($REG_IDs)) {
1940
-            $success = true;
1941
-            // set default status if none is passed
1942
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1943
-            $status_context = $notify
1944
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1945
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1946
-            // loop through REG_ID's and change status
1947
-            foreach ($REG_IDs as $REG_ID) {
1948
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1949
-                if ($registration instanceof EE_Registration) {
1950
-                    $registration->set_status(
1951
-                        $status,
1952
-                        false,
1953
-                        new Context(
1954
-                            $status_context,
1955
-                            esc_html__(
1956
-                                'Manually triggered status change on a Registration Admin Page route.',
1957
-                                'event_espresso'
1958
-                            )
1959
-                        )
1960
-                    );
1961
-                    $result = $registration->save();
1962
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1963
-                    $success = $result !== false ? $success : false;
1964
-                }
1965
-            }
1966
-        }
1967
-
1968
-        // return $success and processed registrations
1969
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1970
-    }
1971
-
1972
-
1973
-    /**
1974
-     * Common logic for setting up success message and redirecting to appropriate route
1975
-     *
1976
-     * @param  string $STS_ID status id for the registration changed to
1977
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1978
-     * @return void
1979
-     * @throws EE_Error
1980
-     */
1981
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1982
-    {
1983
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1984
-            : array('success' => false);
1985
-        $success = isset($result['success']) && $result['success'];
1986
-        // setup success message
1987
-        if ($success) {
1988
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1989
-                $msg = sprintf(
1990
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1991
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1992
-                );
1993
-            } else {
1994
-                $msg = sprintf(
1995
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1996
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1997
-                );
1998
-            }
1999
-            EE_Error::add_success($msg);
2000
-        } else {
2001
-            EE_Error::add_error(
2002
-                esc_html__(
2003
-                    'Something went wrong, and the status was not changed',
2004
-                    'event_espresso'
2005
-                ),
2006
-                __FILE__,
2007
-                __LINE__,
2008
-                __FUNCTION__
2009
-            );
2010
-        }
2011
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2012
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2013
-        } else {
2014
-            $route = array('action' => 'default');
2015
-        }
2016
-        // unset nonces
2017
-        foreach ($this->_req_data as $ref => $value) {
2018
-            if (strpos($ref, 'nonce') !== false) {
2019
-                unset($this->_req_data[ $ref ]);
2020
-                continue;
2021
-            }
2022
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2023
-            $this->_req_data[ $ref ] = $value;
2024
-        }
2025
-        // merge request vars so that the reloaded list table contains any existing filter query params
2026
-        $route = array_merge($this->_req_data, $route);
2027
-        $this->_redirect_after_action($success, '', '', $route, true);
2028
-    }
2029
-
2030
-
2031
-    /**
2032
-     * incoming reg status change from reg details page.
2033
-     *
2034
-     * @return void
2035
-     */
2036
-    protected function _change_reg_status()
2037
-    {
2038
-        $this->_req_data['return'] = 'view_registration';
2039
-        // set notify based on whether the send notifications toggle is set or not
2040
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2041
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2042
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2043
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2044
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2045
-            case EEM_Registration::status_id_approved:
2046
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2047
-                $this->approve_registration($notify);
2048
-                break;
2049
-            case EEM_Registration::status_id_pending_payment:
2050
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2051
-                $this->pending_registration($notify);
2052
-                break;
2053
-            case EEM_Registration::status_id_not_approved:
2054
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2055
-                $this->not_approve_registration($notify);
2056
-                break;
2057
-            case EEM_Registration::status_id_declined:
2058
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2059
-                $this->decline_registration($notify);
2060
-                break;
2061
-            case EEM_Registration::status_id_cancelled:
2062
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2063
-                $this->cancel_registration($notify);
2064
-                break;
2065
-            case EEM_Registration::status_id_wait_list:
2066
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2067
-                $this->wait_list_registration($notify);
2068
-                break;
2069
-            case EEM_Registration::status_id_incomplete:
2070
-            default:
2071
-                $result['success'] = false;
2072
-                unset($this->_req_data['return']);
2073
-                $this->_reg_status_change_return('', false);
2074
-                break;
2075
-        }
2076
-    }
2077
-
2078
-
2079
-    /**
2080
-     * Callback for bulk action routes.
2081
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2082
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2083
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2084
-     * when an action is happening on just a single registration).
2085
-     *
2086
-     * @param      $action
2087
-     * @param bool $notify
2088
-     */
2089
-    protected function bulk_action_on_registrations($action, $notify = false)
2090
-    {
2091
-        do_action(
2092
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2093
-            $this,
2094
-            $action,
2095
-            $notify
2096
-        );
2097
-        $method = $action . '_registration';
2098
-        if (method_exists($this, $method)) {
2099
-            $this->$method($notify);
2100
-        }
2101
-    }
2102
-
2103
-
2104
-    /**
2105
-     * approve_registration
2106
-     *
2107
-     * @access protected
2108
-     * @param bool $notify whether or not to notify the registrant about their approval.
2109
-     * @return void
2110
-     */
2111
-    protected function approve_registration($notify = false)
2112
-    {
2113
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2114
-    }
2115
-
2116
-
2117
-    /**
2118
-     *        decline_registration
2119
-     *
2120
-     * @access protected
2121
-     * @param bool $notify whether or not to notify the registrant about their status change.
2122
-     * @return void
2123
-     */
2124
-    protected function decline_registration($notify = false)
2125
-    {
2126
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2127
-    }
2128
-
2129
-
2130
-    /**
2131
-     *        cancel_registration
2132
-     *
2133
-     * @access protected
2134
-     * @param bool $notify whether or not to notify the registrant about their status change.
2135
-     * @return void
2136
-     */
2137
-    protected function cancel_registration($notify = false)
2138
-    {
2139
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2140
-    }
2141
-
2142
-
2143
-    /**
2144
-     *        not_approve_registration
2145
-     *
2146
-     * @access protected
2147
-     * @param bool $notify whether or not to notify the registrant about their status change.
2148
-     * @return void
2149
-     */
2150
-    protected function not_approve_registration($notify = false)
2151
-    {
2152
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2153
-    }
2154
-
2155
-
2156
-    /**
2157
-     *        decline_registration
2158
-     *
2159
-     * @access protected
2160
-     * @param bool $notify whether or not to notify the registrant about their status change.
2161
-     * @return void
2162
-     */
2163
-    protected function pending_registration($notify = false)
2164
-    {
2165
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2166
-    }
2167
-
2168
-
2169
-    /**
2170
-     * waitlist_registration
2171
-     *
2172
-     * @access protected
2173
-     * @param bool $notify whether or not to notify the registrant about their status change.
2174
-     * @return void
2175
-     */
2176
-    protected function wait_list_registration($notify = false)
2177
-    {
2178
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2179
-    }
2180
-
2181
-
2182
-    /**
2183
-     *        generates HTML for the Registration main meta box
2184
-     *
2185
-     * @access public
2186
-     * @return void
2187
-     * @throws DomainException
2188
-     * @throws EE_Error
2189
-     * @throws InvalidArgumentException
2190
-     * @throws InvalidDataTypeException
2191
-     * @throws InvalidInterfaceException
2192
-     * @throws ReflectionException
2193
-     * @throws EntityNotFoundException
2194
-     */
2195
-    public function _reg_details_meta_box()
2196
-    {
2197
-        EEH_Autoloader::register_line_item_display_autoloaders();
2198
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2199
-        EE_Registry::instance()->load_helper('Line_Item');
2200
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2201
-            : EE_Transaction::new_instance();
2202
-        $this->_session = $transaction->session_data();
2203
-        $filters = new EE_Line_Item_Filter_Collection();
2204
-        // $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2205
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2206
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2207
-            $filters,
2208
-            $transaction->total_line_item()
2209
-        );
2210
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2211
-        $line_item_display = new EE_Line_Item_Display(
2212
-            'reg_admin_table',
2213
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2214
-        );
2215
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2216
-            $filtered_line_item_tree,
2217
-            array('EE_Registration' => $this->_registration)
2218
-        );
2219
-        $attendee = $this->_registration->attendee();
2220
-        if (EE_Registry::instance()->CAP->current_user_can(
2221
-            'ee_read_transaction',
2222
-            'espresso_transactions_view_transaction'
2223
-        )) {
2224
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2225
-                EE_Admin_Page::add_query_args_and_nonce(
2226
-                    array(
2227
-                        'action' => 'view_transaction',
2228
-                        'TXN_ID' => $transaction->ID(),
2229
-                    ),
2230
-                    TXN_ADMIN_URL
2231
-                ),
2232
-                esc_html__(' View Transaction', 'event_espresso'),
2233
-                'button secondary-button right',
2234
-                'dashicons dashicons-cart'
2235
-            );
2236
-        } else {
2237
-            $this->_template_args['view_transaction_button'] = '';
2238
-        }
2239
-        if ($attendee instanceof EE_Attendee
2240
-            && EE_Registry::instance()->CAP->current_user_can(
2241
-                'ee_send_message',
2242
-                'espresso_registrations_resend_registration'
2243
-            )
2244
-        ) {
2245
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2246
-                EE_Admin_Page::add_query_args_and_nonce(
2247
-                    array(
2248
-                        'action'      => 'resend_registration',
2249
-                        '_REG_ID'     => $this->_registration->ID(),
2250
-                        'redirect_to' => 'view_registration',
2251
-                    ),
2252
-                    REG_ADMIN_URL
2253
-                ),
2254
-                esc_html__(' Resend Registration', 'event_espresso'),
2255
-                'button secondary-button right',
2256
-                'dashicons dashicons-email-alt'
2257
-            );
2258
-        } else {
2259
-            $this->_template_args['resend_registration_button'] = '';
2260
-        }
2261
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2262
-        $payment = $transaction->get_first_related('Payment');
2263
-        $payment = ! $payment instanceof EE_Payment
2264
-            ? EE_Payment::new_instance()
2265
-            : $payment;
2266
-        $payment_method = $payment->get_first_related('Payment_Method');
2267
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2268
-            ? EE_Payment_Method::new_instance()
2269
-            : $payment_method;
2270
-        $reg_details = array(
2271
-            'payment_method'       => $payment_method->name(),
2272
-            'response_msg'         => $payment->gateway_response(),
2273
-            'registration_id'      => $this->_registration->get('REG_code'),
2274
-            'registration_session' => $this->_registration->session_ID(),
2275
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2276
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2277
-        );
2278
-        if (isset($reg_details['registration_id'])) {
2279
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2280
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2281
-                'Registration ID',
2282
-                'event_espresso'
2283
-            );
2284
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2285
-        }
2286
-        if (isset($reg_details['payment_method'])) {
2287
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2288
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2289
-                'Most Recent Payment Method',
2290
-                'event_espresso'
2291
-            );
2292
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2293
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2294
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2295
-                'Payment method response',
2296
-                'event_espresso'
2297
-            );
2298
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2299
-        }
2300
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2301
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2302
-            'Registration Session',
2303
-            'event_espresso'
2304
-        );
2305
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2306
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2307
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2308
-            'Registration placed from IP',
2309
-            'event_espresso'
2310
-        );
2311
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2312
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2313
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2314
-            'Registrant User Agent',
2315
-            'event_espresso'
2316
-        );
2317
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2318
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2319
-            array(
2320
-                'action'   => 'default',
2321
-                'event_id' => $this->_registration->event_ID(),
2322
-            ),
2323
-            REG_ADMIN_URL
2324
-        );
2325
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2326
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2327
-        $template_path =
2328
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2329
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * generates HTML for the Registration Questions meta box.
2335
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2336
-     * otherwise uses new forms system
2337
-     *
2338
-     * @access public
2339
-     * @return void
2340
-     * @throws DomainException
2341
-     * @throws EE_Error
2342
-     */
2343
-    public function _reg_questions_meta_box()
2344
-    {
2345
-        // allow someone to override this method entirely
2346
-        if (apply_filters(
2347
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2348
-            true,
2349
-            $this,
2350
-            $this->_registration
2351
-        )) {
2352
-            $form = $this->_get_reg_custom_questions_form(
2353
-                $this->_registration->ID()
2354
-            );
2355
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2356
-                ? $form->get_html_and_js()
2357
-                : '';
2358
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2359
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2360
-            $template_path =
2361
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2362
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2363
-        }
2364
-    }
2365
-
2366
-
2367
-    /**
2368
-     * form_before_question_group
2369
-     *
2370
-     * @deprecated    as of 4.8.32.rc.000
2371
-     * @access        public
2372
-     * @param        string $output
2373
-     * @return        string
2374
-     */
2375
-    public function form_before_question_group($output)
2376
-    {
2377
-        EE_Error::doing_it_wrong(
2378
-            __CLASS__ . '::' . __FUNCTION__,
2379
-            esc_html__(
2380
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2381
-                'event_espresso'
2382
-            ),
2383
-            '4.8.32.rc.000'
2384
-        );
2385
-        return '
1299
+		if (! empty($registration_status)) {
1300
+			$where['STS_ID'] = $registration_status;
1301
+		} else {
1302
+			// make sure we exclude incomplete registrations, but only if not trashed.
1303
+			if ($view === 'trash') {
1304
+				$where['REG_deleted'] = true;
1305
+			} elseif ($view === 'incomplete') {
1306
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1307
+			} else {
1308
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1309
+			}
1310
+		}
1311
+		return $where;
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1317
+	 *
1318
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1319
+	 * @return array
1320
+	 * @throws EE_Error
1321
+	 * @throws InvalidArgumentException
1322
+	 * @throws InvalidDataTypeException
1323
+	 * @throws InvalidInterfaceException
1324
+	 */
1325
+	protected function _add_date_to_where_conditions(array $request)
1326
+	{
1327
+		$where = array();
1328
+		$view = EEH_Array::is_set($request, 'status', '');
1329
+		$month_range = ! empty($request['month_range'])
1330
+			? sanitize_text_field($request['month_range'])
1331
+			: '';
1332
+		$retrieve_for_today = $view === 'today';
1333
+		$retrieve_for_this_month = $view === 'month';
1334
+
1335
+		if ($retrieve_for_today) {
1336
+			$now = date('Y-m-d', current_time('timestamp'));
1337
+			$where['REG_date'] = array(
1338
+				'BETWEEN',
1339
+				array(
1340
+					EEM_Registration::instance()->convert_datetime_for_query(
1341
+						'REG_date',
1342
+						$now . ' 00:00:00',
1343
+						'Y-m-d H:i:s'
1344
+					),
1345
+					EEM_Registration::instance()->convert_datetime_for_query(
1346
+						'REG_date',
1347
+						$now . ' 23:59:59',
1348
+						'Y-m-d H:i:s'
1349
+					),
1350
+				),
1351
+			);
1352
+		} elseif ($retrieve_for_this_month) {
1353
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1354
+			$days_this_month = date('t', current_time('timestamp'));
1355
+			$where['REG_date'] = array(
1356
+				'BETWEEN',
1357
+				array(
1358
+					EEM_Registration::instance()->convert_datetime_for_query(
1359
+						'REG_date',
1360
+						$current_year_and_month . '-01 00:00:00',
1361
+						'Y-m-d H:i:s'
1362
+					),
1363
+					EEM_Registration::instance()->convert_datetime_for_query(
1364
+						'REG_date',
1365
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1366
+						'Y-m-d H:i:s'
1367
+					),
1368
+				),
1369
+			);
1370
+		} elseif ($month_range) {
1371
+			$pieces = explode(' ', $month_range, 3);
1372
+			$month_requested = ! empty($pieces[0])
1373
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1374
+				: '';
1375
+			$year_requested = ! empty($pieces[1])
1376
+				? $pieces[1]
1377
+				: '';
1378
+			// if there is not a month or year then we can't go further
1379
+			if ($month_requested && $year_requested) {
1380
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1381
+				$where['REG_date'] = array(
1382
+					'BETWEEN',
1383
+					array(
1384
+						EEM_Registration::instance()->convert_datetime_for_query(
1385
+							'REG_date',
1386
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1387
+							'Y-m-d H:i:s'
1388
+						),
1389
+						EEM_Registration::instance()->convert_datetime_for_query(
1390
+							'REG_date',
1391
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1392
+							'Y-m-d H:i:s'
1393
+						),
1394
+					),
1395
+				);
1396
+			}
1397
+		}
1398
+		return $where;
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 * Adds any provided search restraints to the where conditions for the registrations query
1404
+	 *
1405
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1406
+	 * @return array
1407
+	 */
1408
+	protected function _add_search_to_where_conditions(array $request)
1409
+	{
1410
+		$where = array();
1411
+		if (! empty($request['s'])) {
1412
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1413
+			$where['OR*search_conditions'] = array(
1414
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1415
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1416
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1417
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1418
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1419
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1420
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1421
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1422
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1423
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1424
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1425
+				'REG_final_price'                         => array('LIKE', $search_string),
1426
+				'REG_code'                                => array('LIKE', $search_string),
1427
+				'REG_count'                               => array('LIKE', $search_string),
1428
+				'REG_group_size'                          => array('LIKE', $search_string),
1429
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1430
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1431
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1432
+			);
1433
+		}
1434
+		return $where;
1435
+	}
1436
+
1437
+
1438
+	/**
1439
+	 * Sets up the where conditions for the registrations query.
1440
+	 *
1441
+	 * @param array $request
1442
+	 * @return array
1443
+	 * @throws EE_Error
1444
+	 */
1445
+	protected function _get_where_conditions_for_registrations_query($request)
1446
+	{
1447
+		return apply_filters(
1448
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1449
+			array_merge(
1450
+				$this->addAttendeeIdToWhereConditions($request),
1451
+				$this->_add_event_id_to_where_conditions($request),
1452
+				$this->_add_category_id_to_where_conditions($request),
1453
+				$this->_add_datetime_id_to_where_conditions($request),
1454
+				$this->_add_registration_status_to_where_conditions($request),
1455
+				$this->_add_date_to_where_conditions($request),
1456
+				$this->_add_search_to_where_conditions($request)
1457
+			),
1458
+			$request
1459
+		);
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * Sets up the orderby for the registrations query.
1465
+	 *
1466
+	 * @return array
1467
+	 */
1468
+	protected function _get_orderby_for_registrations_query()
1469
+	{
1470
+		$orderby_field = ! empty($this->_req_data['orderby'])
1471
+			? sanitize_text_field($this->_req_data['orderby'])
1472
+			: '_REG_date';
1473
+		switch ($orderby_field) {
1474
+			case '_REG_ID':
1475
+				$orderby = array('REG_ID');
1476
+				break;
1477
+			case '_Reg_status':
1478
+				$orderby = array('STS_ID');
1479
+				break;
1480
+			case 'ATT_fname':
1481
+				$orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1482
+				break;
1483
+			case 'ATT_lname':
1484
+				$orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1485
+				break;
1486
+			case 'event_name':
1487
+				$orderby = array('Event.EVT_name');
1488
+				break;
1489
+			case 'DTT_EVT_start':
1490
+				$orderby = array('Event.Datetime.DTT_EVT_start');
1491
+				break;
1492
+			case '_REG_date':
1493
+				$orderby = array('REG_date');
1494
+				break;
1495
+			default:
1496
+				$orderby = array($orderby_field);
1497
+				break;
1498
+		}
1499
+
1500
+		// order
1501
+		$order = ! empty($this->_req_data['order'])
1502
+			? sanitize_text_field($this->_req_data['order'])
1503
+			: 'DESC';
1504
+		$orderby = array_combine(
1505
+			$orderby,
1506
+			array_fill(0, count($orderby), $order)
1507
+		);
1508
+		// because there are many registrations with the same date, define
1509
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
1510
+		if (empty($orderby['REG_ID'])) {
1511
+			$orderby['REG_ID'] = $order;
1512
+		}
1513
+
1514
+		$orderby = apply_filters(
1515
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1516
+			$orderby,
1517
+			$this->_req_data
1518
+		);
1519
+
1520
+		return array('order_by' => $orderby);
1521
+	}
1522
+
1523
+
1524
+	/**
1525
+	 * Sets up the limit for the registrations query.
1526
+	 *
1527
+	 * @param $per_page
1528
+	 * @return array
1529
+	 */
1530
+	protected function _get_limit($per_page)
1531
+	{
1532
+		$current_page = ! empty($this->_req_data['paged'])
1533
+			? absint($this->_req_data['paged'])
1534
+			: 1;
1535
+		$per_page = ! empty($this->_req_data['perpage'])
1536
+			? $this->_req_data['perpage']
1537
+			: $per_page;
1538
+
1539
+		// -1 means return all results so get out if that's set.
1540
+		if ((int) $per_page === -1) {
1541
+			return array();
1542
+		}
1543
+		$per_page = absint($per_page);
1544
+		$offset = ($current_page - 1) * $per_page;
1545
+		return array('limit' => array($offset, $per_page));
1546
+	}
1547
+
1548
+
1549
+	public function get_registration_status_array()
1550
+	{
1551
+		return self::$_reg_status;
1552
+	}
1553
+
1554
+
1555
+
1556
+
1557
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1558
+	/**
1559
+	 *        generates HTML for the View Registration Details Admin page
1560
+	 *
1561
+	 * @access protected
1562
+	 * @return void
1563
+	 * @throws DomainException
1564
+	 * @throws EE_Error
1565
+	 * @throws InvalidArgumentException
1566
+	 * @throws InvalidDataTypeException
1567
+	 * @throws InvalidInterfaceException
1568
+	 * @throws EntityNotFoundException
1569
+	 */
1570
+	protected function _registration_details()
1571
+	{
1572
+		$this->_template_args = array();
1573
+		$this->_set_registration_object();
1574
+		if (is_object($this->_registration)) {
1575
+			$transaction = $this->_registration->transaction()
1576
+				? $this->_registration->transaction()
1577
+				: EE_Transaction::new_instance();
1578
+			$this->_session = $transaction->session_data();
1579
+			$event_id = $this->_registration->event_ID();
1580
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1581
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1582
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1583
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1584
+			$this->_template_args['grand_total'] = $transaction->total();
1585
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1586
+			// link back to overview
1587
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1588
+			$this->_template_args['registration'] = $this->_registration;
1589
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1590
+				array(
1591
+					'action'   => 'default',
1592
+					'event_id' => $event_id,
1593
+				),
1594
+				REG_ADMIN_URL
1595
+			);
1596
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1597
+				array(
1598
+					'action' => 'default',
1599
+					'EVT_ID' => $event_id,
1600
+					'page'   => 'espresso_transactions',
1601
+				),
1602
+				admin_url('admin.php')
1603
+			);
1604
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1605
+				array(
1606
+					'page'   => 'espresso_events',
1607
+					'action' => 'edit',
1608
+					'post'   => $event_id,
1609
+				),
1610
+				admin_url('admin.php')
1611
+			);
1612
+			// next and previous links
1613
+			$next_reg = $this->_registration->next(
1614
+				null,
1615
+				array(),
1616
+				'REG_ID'
1617
+			);
1618
+			$this->_template_args['next_registration'] = $next_reg
1619
+				? $this->_next_link(
1620
+					EE_Admin_Page::add_query_args_and_nonce(
1621
+						array(
1622
+							'action'  => 'view_registration',
1623
+							'_REG_ID' => $next_reg['REG_ID'],
1624
+						),
1625
+						REG_ADMIN_URL
1626
+					),
1627
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1628
+				)
1629
+				: '';
1630
+			$previous_reg = $this->_registration->previous(
1631
+				null,
1632
+				array(),
1633
+				'REG_ID'
1634
+			);
1635
+			$this->_template_args['previous_registration'] = $previous_reg
1636
+				? $this->_previous_link(
1637
+					EE_Admin_Page::add_query_args_and_nonce(
1638
+						array(
1639
+							'action'  => 'view_registration',
1640
+							'_REG_ID' => $previous_reg['REG_ID'],
1641
+						),
1642
+						REG_ADMIN_URL
1643
+					),
1644
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1645
+				)
1646
+				: '';
1647
+			// grab header
1648
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1649
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1650
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1651
+				$template_path,
1652
+				$this->_template_args,
1653
+				true
1654
+			);
1655
+		} else {
1656
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1657
+		}
1658
+		// the details template wrapper
1659
+		$this->display_admin_page_with_sidebar();
1660
+	}
1661
+
1662
+
1663
+	protected function _registration_details_metaboxes()
1664
+	{
1665
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1666
+		$this->_set_registration_object();
1667
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1668
+		add_meta_box(
1669
+			'edit-reg-status-mbox',
1670
+			esc_html__('Registration Status', 'event_espresso'),
1671
+			array($this, 'set_reg_status_buttons_metabox'),
1672
+			$this->wp_page_slug,
1673
+			'normal',
1674
+			'high'
1675
+		);
1676
+		add_meta_box(
1677
+			'edit-reg-details-mbox',
1678
+			esc_html__('Registration Details', 'event_espresso'),
1679
+			array($this, '_reg_details_meta_box'),
1680
+			$this->wp_page_slug,
1681
+			'normal',
1682
+			'high'
1683
+		);
1684
+		if ($attendee instanceof EE_Attendee
1685
+			&& EE_Registry::instance()->CAP->current_user_can(
1686
+				'ee_read_registration',
1687
+				'edit-reg-questions-mbox',
1688
+				$this->_registration->ID()
1689
+			)
1690
+		) {
1691
+			add_meta_box(
1692
+				'edit-reg-questions-mbox',
1693
+				esc_html__('Registration Form Answers', 'event_espresso'),
1694
+				array($this, '_reg_questions_meta_box'),
1695
+				$this->wp_page_slug,
1696
+				'normal',
1697
+				'high'
1698
+			);
1699
+		}
1700
+		add_meta_box(
1701
+			'edit-reg-registrant-mbox',
1702
+			esc_html__('Contact Details', 'event_espresso'),
1703
+			array($this, '_reg_registrant_side_meta_box'),
1704
+			$this->wp_page_slug,
1705
+			'side',
1706
+			'high'
1707
+		);
1708
+		if ($this->_registration->group_size() > 1) {
1709
+			add_meta_box(
1710
+				'edit-reg-attendees-mbox',
1711
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1712
+				array($this, '_reg_attendees_meta_box'),
1713
+				$this->wp_page_slug,
1714
+				'normal',
1715
+				'high'
1716
+			);
1717
+		}
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 * set_reg_status_buttons_metabox
1723
+	 *
1724
+	 * @access protected
1725
+	 * @return string
1726
+	 * @throws \EE_Error
1727
+	 */
1728
+	public function set_reg_status_buttons_metabox()
1729
+	{
1730
+		$this->_set_registration_object();
1731
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1732
+		echo $change_reg_status_form->form_open(
1733
+			self::add_query_args_and_nonce(
1734
+				array(
1735
+					'action' => 'change_reg_status',
1736
+				),
1737
+				REG_ADMIN_URL
1738
+			)
1739
+		);
1740
+		echo $change_reg_status_form->get_html();
1741
+		echo $change_reg_status_form->form_close();
1742
+	}
1743
+
1744
+
1745
+	/**
1746
+	 * @return EE_Form_Section_Proper
1747
+	 * @throws EE_Error
1748
+	 * @throws InvalidArgumentException
1749
+	 * @throws InvalidDataTypeException
1750
+	 * @throws InvalidInterfaceException
1751
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1752
+	 */
1753
+	protected function _generate_reg_status_change_form()
1754
+	{
1755
+		$reg_status_change_form_array = array(
1756
+			'name'            => 'reg_status_change_form',
1757
+			'html_id'         => 'reg-status-change-form',
1758
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1759
+			'subsections'     => array(
1760
+				'return'             => new EE_Hidden_Input(
1761
+					array(
1762
+						'name'    => 'return',
1763
+						'default' => 'view_registration',
1764
+					)
1765
+				),
1766
+				'REG_ID'             => new EE_Hidden_Input(
1767
+					array(
1768
+						'name'    => 'REG_ID',
1769
+						'default' => $this->_registration->ID(),
1770
+					)
1771
+				),
1772
+				'current_status'     => new EE_Form_Section_HTML(
1773
+					EEH_HTML::tr(
1774
+						EEH_HTML::th(
1775
+							EEH_HTML::label(
1776
+								EEH_HTML::strong(
1777
+									esc_html__('Current Registration Status', 'event_espresso')
1778
+								)
1779
+							)
1780
+						)
1781
+						. EEH_HTML::td(
1782
+							EEH_HTML::strong(
1783
+								$this->_registration->pretty_status(),
1784
+								'',
1785
+								'status-' . $this->_registration->status_ID(),
1786
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1787
+							)
1788
+						)
1789
+					)
1790
+				)
1791
+			)
1792
+		);
1793
+		if (EE_Registry::instance()->CAP->current_user_can(
1794
+			'ee_edit_registration',
1795
+			'toggle_registration_status',
1796
+			$this->_registration->ID()
1797
+		)) {
1798
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1799
+				$this->_get_reg_statuses(),
1800
+				array(
1801
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1802
+					'default'         => $this->_registration->status_ID(),
1803
+				)
1804
+			);
1805
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1806
+				array(
1807
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1808
+					'default'         => false,
1809
+					'html_help_text'  => esc_html__(
1810
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1811
+						'event_espresso'
1812
+					)
1813
+				)
1814
+			);
1815
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1816
+				array(
1817
+					'html_class'      => 'button-primary',
1818
+					'html_label_text' => '&nbsp;',
1819
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1820
+				)
1821
+			);
1822
+		}
1823
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1829
+	 *
1830
+	 * @return array
1831
+	 * @throws EE_Error
1832
+	 * @throws InvalidArgumentException
1833
+	 * @throws InvalidDataTypeException
1834
+	 * @throws InvalidInterfaceException
1835
+	 * @throws EntityNotFoundException
1836
+	 */
1837
+	protected function _get_reg_statuses()
1838
+	{
1839
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1840
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1841
+		// get current reg status
1842
+		$current_status = $this->_registration->status_ID();
1843
+		// is registration for free event? This will determine whether to display the pending payment option
1844
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1845
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1846
+		) {
1847
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1848
+		}
1849
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1855
+	 *
1856
+	 * @param bool $status REG status given for changing registrations to.
1857
+	 * @param bool $notify Whether to send messages notifications or not.
1858
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1859
+	 * @throws EE_Error
1860
+	 * @throws InvalidArgumentException
1861
+	 * @throws InvalidDataTypeException
1862
+	 * @throws InvalidInterfaceException
1863
+	 * @throws ReflectionException
1864
+	 * @throws RuntimeException
1865
+	 * @throws EntityNotFoundException
1866
+	 */
1867
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1868
+	{
1869
+		if (isset($this->_req_data['reg_status_change_form'])) {
1870
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1871
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1872
+				: array();
1873
+		} else {
1874
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1875
+				? (array) $this->_req_data['_REG_ID']
1876
+				: array();
1877
+		}
1878
+		// sanitize $REG_IDs
1879
+		$REG_IDs = array_map('absint', $REG_IDs);
1880
+		// and remove empty entries
1881
+		$REG_IDs = array_filter($REG_IDs);
1882
+
1883
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1884
+
1885
+		/**
1886
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1887
+		 * Currently this value is used downstream by the _process_resend_registration method.
1888
+		 *
1889
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1890
+		 * @param bool                     $status           The status registrations were changed to.
1891
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1892
+		 * @param Registrations_Admin_Page $admin_page_object
1893
+		 */
1894
+		$this->_req_data['_REG_ID'] = apply_filters(
1895
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1896
+			$result['REG_ID'],
1897
+			$status,
1898
+			$result['success'],
1899
+			$this
1900
+		);
1901
+
1902
+		// notify?
1903
+		if ($notify
1904
+			&& $result['success']
1905
+			&& ! empty($this->_req_data['_REG_ID'])
1906
+			&& EE_Registry::instance()->CAP->current_user_can(
1907
+				'ee_send_message',
1908
+				'espresso_registrations_resend_registration'
1909
+			)
1910
+		) {
1911
+			$this->_process_resend_registration();
1912
+		}
1913
+		return $result;
1914
+	}
1915
+
1916
+
1917
+	/**
1918
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1919
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1920
+	 *
1921
+	 * @param array  $REG_IDs
1922
+	 * @param string $status
1923
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1924
+	 *                        slug sent with setting the registration status.
1925
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1926
+	 * @throws EE_Error
1927
+	 * @throws InvalidArgumentException
1928
+	 * @throws InvalidDataTypeException
1929
+	 * @throws InvalidInterfaceException
1930
+	 * @throws ReflectionException
1931
+	 * @throws RuntimeException
1932
+	 * @throws EntityNotFoundException
1933
+	 */
1934
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1935
+	{
1936
+		$success = false;
1937
+		// typecast $REG_IDs
1938
+		$REG_IDs = (array) $REG_IDs;
1939
+		if (! empty($REG_IDs)) {
1940
+			$success = true;
1941
+			// set default status if none is passed
1942
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1943
+			$status_context = $notify
1944
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1945
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1946
+			// loop through REG_ID's and change status
1947
+			foreach ($REG_IDs as $REG_ID) {
1948
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1949
+				if ($registration instanceof EE_Registration) {
1950
+					$registration->set_status(
1951
+						$status,
1952
+						false,
1953
+						new Context(
1954
+							$status_context,
1955
+							esc_html__(
1956
+								'Manually triggered status change on a Registration Admin Page route.',
1957
+								'event_espresso'
1958
+							)
1959
+						)
1960
+					);
1961
+					$result = $registration->save();
1962
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1963
+					$success = $result !== false ? $success : false;
1964
+				}
1965
+			}
1966
+		}
1967
+
1968
+		// return $success and processed registrations
1969
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1970
+	}
1971
+
1972
+
1973
+	/**
1974
+	 * Common logic for setting up success message and redirecting to appropriate route
1975
+	 *
1976
+	 * @param  string $STS_ID status id for the registration changed to
1977
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1978
+	 * @return void
1979
+	 * @throws EE_Error
1980
+	 */
1981
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1982
+	{
1983
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1984
+			: array('success' => false);
1985
+		$success = isset($result['success']) && $result['success'];
1986
+		// setup success message
1987
+		if ($success) {
1988
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1989
+				$msg = sprintf(
1990
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1991
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1992
+				);
1993
+			} else {
1994
+				$msg = sprintf(
1995
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1996
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1997
+				);
1998
+			}
1999
+			EE_Error::add_success($msg);
2000
+		} else {
2001
+			EE_Error::add_error(
2002
+				esc_html__(
2003
+					'Something went wrong, and the status was not changed',
2004
+					'event_espresso'
2005
+				),
2006
+				__FILE__,
2007
+				__LINE__,
2008
+				__FUNCTION__
2009
+			);
2010
+		}
2011
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2012
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2013
+		} else {
2014
+			$route = array('action' => 'default');
2015
+		}
2016
+		// unset nonces
2017
+		foreach ($this->_req_data as $ref => $value) {
2018
+			if (strpos($ref, 'nonce') !== false) {
2019
+				unset($this->_req_data[ $ref ]);
2020
+				continue;
2021
+			}
2022
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2023
+			$this->_req_data[ $ref ] = $value;
2024
+		}
2025
+		// merge request vars so that the reloaded list table contains any existing filter query params
2026
+		$route = array_merge($this->_req_data, $route);
2027
+		$this->_redirect_after_action($success, '', '', $route, true);
2028
+	}
2029
+
2030
+
2031
+	/**
2032
+	 * incoming reg status change from reg details page.
2033
+	 *
2034
+	 * @return void
2035
+	 */
2036
+	protected function _change_reg_status()
2037
+	{
2038
+		$this->_req_data['return'] = 'view_registration';
2039
+		// set notify based on whether the send notifications toggle is set or not
2040
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2041
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2042
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2043
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2044
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2045
+			case EEM_Registration::status_id_approved:
2046
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2047
+				$this->approve_registration($notify);
2048
+				break;
2049
+			case EEM_Registration::status_id_pending_payment:
2050
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2051
+				$this->pending_registration($notify);
2052
+				break;
2053
+			case EEM_Registration::status_id_not_approved:
2054
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2055
+				$this->not_approve_registration($notify);
2056
+				break;
2057
+			case EEM_Registration::status_id_declined:
2058
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2059
+				$this->decline_registration($notify);
2060
+				break;
2061
+			case EEM_Registration::status_id_cancelled:
2062
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2063
+				$this->cancel_registration($notify);
2064
+				break;
2065
+			case EEM_Registration::status_id_wait_list:
2066
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2067
+				$this->wait_list_registration($notify);
2068
+				break;
2069
+			case EEM_Registration::status_id_incomplete:
2070
+			default:
2071
+				$result['success'] = false;
2072
+				unset($this->_req_data['return']);
2073
+				$this->_reg_status_change_return('', false);
2074
+				break;
2075
+		}
2076
+	}
2077
+
2078
+
2079
+	/**
2080
+	 * Callback for bulk action routes.
2081
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2082
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2083
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2084
+	 * when an action is happening on just a single registration).
2085
+	 *
2086
+	 * @param      $action
2087
+	 * @param bool $notify
2088
+	 */
2089
+	protected function bulk_action_on_registrations($action, $notify = false)
2090
+	{
2091
+		do_action(
2092
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2093
+			$this,
2094
+			$action,
2095
+			$notify
2096
+		);
2097
+		$method = $action . '_registration';
2098
+		if (method_exists($this, $method)) {
2099
+			$this->$method($notify);
2100
+		}
2101
+	}
2102
+
2103
+
2104
+	/**
2105
+	 * approve_registration
2106
+	 *
2107
+	 * @access protected
2108
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2109
+	 * @return void
2110
+	 */
2111
+	protected function approve_registration($notify = false)
2112
+	{
2113
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2114
+	}
2115
+
2116
+
2117
+	/**
2118
+	 *        decline_registration
2119
+	 *
2120
+	 * @access protected
2121
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2122
+	 * @return void
2123
+	 */
2124
+	protected function decline_registration($notify = false)
2125
+	{
2126
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2127
+	}
2128
+
2129
+
2130
+	/**
2131
+	 *        cancel_registration
2132
+	 *
2133
+	 * @access protected
2134
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2135
+	 * @return void
2136
+	 */
2137
+	protected function cancel_registration($notify = false)
2138
+	{
2139
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2140
+	}
2141
+
2142
+
2143
+	/**
2144
+	 *        not_approve_registration
2145
+	 *
2146
+	 * @access protected
2147
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2148
+	 * @return void
2149
+	 */
2150
+	protected function not_approve_registration($notify = false)
2151
+	{
2152
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2153
+	}
2154
+
2155
+
2156
+	/**
2157
+	 *        decline_registration
2158
+	 *
2159
+	 * @access protected
2160
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2161
+	 * @return void
2162
+	 */
2163
+	protected function pending_registration($notify = false)
2164
+	{
2165
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2166
+	}
2167
+
2168
+
2169
+	/**
2170
+	 * waitlist_registration
2171
+	 *
2172
+	 * @access protected
2173
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2174
+	 * @return void
2175
+	 */
2176
+	protected function wait_list_registration($notify = false)
2177
+	{
2178
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2179
+	}
2180
+
2181
+
2182
+	/**
2183
+	 *        generates HTML for the Registration main meta box
2184
+	 *
2185
+	 * @access public
2186
+	 * @return void
2187
+	 * @throws DomainException
2188
+	 * @throws EE_Error
2189
+	 * @throws InvalidArgumentException
2190
+	 * @throws InvalidDataTypeException
2191
+	 * @throws InvalidInterfaceException
2192
+	 * @throws ReflectionException
2193
+	 * @throws EntityNotFoundException
2194
+	 */
2195
+	public function _reg_details_meta_box()
2196
+	{
2197
+		EEH_Autoloader::register_line_item_display_autoloaders();
2198
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2199
+		EE_Registry::instance()->load_helper('Line_Item');
2200
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2201
+			: EE_Transaction::new_instance();
2202
+		$this->_session = $transaction->session_data();
2203
+		$filters = new EE_Line_Item_Filter_Collection();
2204
+		// $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2205
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2206
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2207
+			$filters,
2208
+			$transaction->total_line_item()
2209
+		);
2210
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2211
+		$line_item_display = new EE_Line_Item_Display(
2212
+			'reg_admin_table',
2213
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2214
+		);
2215
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2216
+			$filtered_line_item_tree,
2217
+			array('EE_Registration' => $this->_registration)
2218
+		);
2219
+		$attendee = $this->_registration->attendee();
2220
+		if (EE_Registry::instance()->CAP->current_user_can(
2221
+			'ee_read_transaction',
2222
+			'espresso_transactions_view_transaction'
2223
+		)) {
2224
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2225
+				EE_Admin_Page::add_query_args_and_nonce(
2226
+					array(
2227
+						'action' => 'view_transaction',
2228
+						'TXN_ID' => $transaction->ID(),
2229
+					),
2230
+					TXN_ADMIN_URL
2231
+				),
2232
+				esc_html__(' View Transaction', 'event_espresso'),
2233
+				'button secondary-button right',
2234
+				'dashicons dashicons-cart'
2235
+			);
2236
+		} else {
2237
+			$this->_template_args['view_transaction_button'] = '';
2238
+		}
2239
+		if ($attendee instanceof EE_Attendee
2240
+			&& EE_Registry::instance()->CAP->current_user_can(
2241
+				'ee_send_message',
2242
+				'espresso_registrations_resend_registration'
2243
+			)
2244
+		) {
2245
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2246
+				EE_Admin_Page::add_query_args_and_nonce(
2247
+					array(
2248
+						'action'      => 'resend_registration',
2249
+						'_REG_ID'     => $this->_registration->ID(),
2250
+						'redirect_to' => 'view_registration',
2251
+					),
2252
+					REG_ADMIN_URL
2253
+				),
2254
+				esc_html__(' Resend Registration', 'event_espresso'),
2255
+				'button secondary-button right',
2256
+				'dashicons dashicons-email-alt'
2257
+			);
2258
+		} else {
2259
+			$this->_template_args['resend_registration_button'] = '';
2260
+		}
2261
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2262
+		$payment = $transaction->get_first_related('Payment');
2263
+		$payment = ! $payment instanceof EE_Payment
2264
+			? EE_Payment::new_instance()
2265
+			: $payment;
2266
+		$payment_method = $payment->get_first_related('Payment_Method');
2267
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2268
+			? EE_Payment_Method::new_instance()
2269
+			: $payment_method;
2270
+		$reg_details = array(
2271
+			'payment_method'       => $payment_method->name(),
2272
+			'response_msg'         => $payment->gateway_response(),
2273
+			'registration_id'      => $this->_registration->get('REG_code'),
2274
+			'registration_session' => $this->_registration->session_ID(),
2275
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2276
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2277
+		);
2278
+		if (isset($reg_details['registration_id'])) {
2279
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2280
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2281
+				'Registration ID',
2282
+				'event_espresso'
2283
+			);
2284
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2285
+		}
2286
+		if (isset($reg_details['payment_method'])) {
2287
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2288
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2289
+				'Most Recent Payment Method',
2290
+				'event_espresso'
2291
+			);
2292
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2293
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2294
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2295
+				'Payment method response',
2296
+				'event_espresso'
2297
+			);
2298
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2299
+		}
2300
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2301
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2302
+			'Registration Session',
2303
+			'event_espresso'
2304
+		);
2305
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2306
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2307
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2308
+			'Registration placed from IP',
2309
+			'event_espresso'
2310
+		);
2311
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2312
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2313
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2314
+			'Registrant User Agent',
2315
+			'event_espresso'
2316
+		);
2317
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2318
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2319
+			array(
2320
+				'action'   => 'default',
2321
+				'event_id' => $this->_registration->event_ID(),
2322
+			),
2323
+			REG_ADMIN_URL
2324
+		);
2325
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2326
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2327
+		$template_path =
2328
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2329
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * generates HTML for the Registration Questions meta box.
2335
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2336
+	 * otherwise uses new forms system
2337
+	 *
2338
+	 * @access public
2339
+	 * @return void
2340
+	 * @throws DomainException
2341
+	 * @throws EE_Error
2342
+	 */
2343
+	public function _reg_questions_meta_box()
2344
+	{
2345
+		// allow someone to override this method entirely
2346
+		if (apply_filters(
2347
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2348
+			true,
2349
+			$this,
2350
+			$this->_registration
2351
+		)) {
2352
+			$form = $this->_get_reg_custom_questions_form(
2353
+				$this->_registration->ID()
2354
+			);
2355
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2356
+				? $form->get_html_and_js()
2357
+				: '';
2358
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2359
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2360
+			$template_path =
2361
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2362
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2363
+		}
2364
+	}
2365
+
2366
+
2367
+	/**
2368
+	 * form_before_question_group
2369
+	 *
2370
+	 * @deprecated    as of 4.8.32.rc.000
2371
+	 * @access        public
2372
+	 * @param        string $output
2373
+	 * @return        string
2374
+	 */
2375
+	public function form_before_question_group($output)
2376
+	{
2377
+		EE_Error::doing_it_wrong(
2378
+			__CLASS__ . '::' . __FUNCTION__,
2379
+			esc_html__(
2380
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2381
+				'event_espresso'
2382
+			),
2383
+			'4.8.32.rc.000'
2384
+		);
2385
+		return '
2386 2386
 	<table class="form-table ee-width-100">
2387 2387
 		<tbody>
2388 2388
 			';
2389
-    }
2390
-
2391
-
2392
-    /**
2393
-     * form_after_question_group
2394
-     *
2395
-     * @deprecated    as of 4.8.32.rc.000
2396
-     * @access        public
2397
-     * @param        string $output
2398
-     * @return        string
2399
-     */
2400
-    public function form_after_question_group($output)
2401
-    {
2402
-        EE_Error::doing_it_wrong(
2403
-            __CLASS__ . '::' . __FUNCTION__,
2404
-            esc_html__(
2405
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2406
-                'event_espresso'
2407
-            ),
2408
-            '4.8.32.rc.000'
2409
-        );
2410
-        return '
2389
+	}
2390
+
2391
+
2392
+	/**
2393
+	 * form_after_question_group
2394
+	 *
2395
+	 * @deprecated    as of 4.8.32.rc.000
2396
+	 * @access        public
2397
+	 * @param        string $output
2398
+	 * @return        string
2399
+	 */
2400
+	public function form_after_question_group($output)
2401
+	{
2402
+		EE_Error::doing_it_wrong(
2403
+			__CLASS__ . '::' . __FUNCTION__,
2404
+			esc_html__(
2405
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2406
+				'event_espresso'
2407
+			),
2408
+			'4.8.32.rc.000'
2409
+		);
2410
+		return '
2411 2411
 			<tr class="hide-if-no-js">
2412 2412
 				<th> </th>
2413 2413
 				<td class="reg-admin-edit-attendee-question-td">
2414 2414
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2415
-               . esc_attr__('click to edit question', 'event_espresso')
2416
-               . '">
2415
+			   . esc_attr__('click to edit question', 'event_espresso')
2416
+			   . '">
2417 2417
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2418
-               . esc_html__('edit the above question group', 'event_espresso')
2419
-               . '</span>
2418
+			   . esc_html__('edit the above question group', 'event_espresso')
2419
+			   . '</span>
2420 2420
 						<div class="dashicons dashicons-edit"></div>
2421 2421
 					</a>
2422 2422
 				</td>
@@ -2424,606 +2424,606 @@  discard block
 block discarded – undo
2424 2424
 		</tbody>
2425 2425
 	</table>
2426 2426
 ';
2427
-    }
2428
-
2429
-
2430
-    /**
2431
-     * form_form_field_label_wrap
2432
-     *
2433
-     * @deprecated    as of 4.8.32.rc.000
2434
-     * @access        public
2435
-     * @param        string $label
2436
-     * @return        string
2437
-     */
2438
-    public function form_form_field_label_wrap($label)
2439
-    {
2440
-        EE_Error::doing_it_wrong(
2441
-            __CLASS__ . '::' . __FUNCTION__,
2442
-            esc_html__(
2443
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2444
-                'event_espresso'
2445
-            ),
2446
-            '4.8.32.rc.000'
2447
-        );
2448
-        return '
2427
+	}
2428
+
2429
+
2430
+	/**
2431
+	 * form_form_field_label_wrap
2432
+	 *
2433
+	 * @deprecated    as of 4.8.32.rc.000
2434
+	 * @access        public
2435
+	 * @param        string $label
2436
+	 * @return        string
2437
+	 */
2438
+	public function form_form_field_label_wrap($label)
2439
+	{
2440
+		EE_Error::doing_it_wrong(
2441
+			__CLASS__ . '::' . __FUNCTION__,
2442
+			esc_html__(
2443
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2444
+				'event_espresso'
2445
+			),
2446
+			'4.8.32.rc.000'
2447
+		);
2448
+		return '
2449 2449
 			<tr>
2450 2450
 				<th>
2451 2451
 					' . $label . '
2452 2452
 				</th>';
2453
-    }
2454
-
2455
-
2456
-    /**
2457
-     * form_form_field_input__wrap
2458
-     *
2459
-     * @deprecated    as of 4.8.32.rc.000
2460
-     * @access        public
2461
-     * @param        string $input
2462
-     * @return        string
2463
-     */
2464
-    public function form_form_field_input__wrap($input)
2465
-    {
2466
-        EE_Error::doing_it_wrong(
2467
-            __CLASS__ . '::' . __FUNCTION__,
2468
-            esc_html__(
2469
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2470
-                'event_espresso'
2471
-            ),
2472
-            '4.8.32.rc.000'
2473
-        );
2474
-        return '
2453
+	}
2454
+
2455
+
2456
+	/**
2457
+	 * form_form_field_input__wrap
2458
+	 *
2459
+	 * @deprecated    as of 4.8.32.rc.000
2460
+	 * @access        public
2461
+	 * @param        string $input
2462
+	 * @return        string
2463
+	 */
2464
+	public function form_form_field_input__wrap($input)
2465
+	{
2466
+		EE_Error::doing_it_wrong(
2467
+			__CLASS__ . '::' . __FUNCTION__,
2468
+			esc_html__(
2469
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2470
+				'event_espresso'
2471
+			),
2472
+			'4.8.32.rc.000'
2473
+		);
2474
+		return '
2475 2475
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2476 2476
 					' . $input . '
2477 2477
 				</td>
2478 2478
 			</tr>';
2479
-    }
2480
-
2481
-
2482
-    /**
2483
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2484
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2485
-     * to display the page
2486
-     *
2487
-     * @access protected
2488
-     * @return void
2489
-     * @throws EE_Error
2490
-     */
2491
-    protected function _update_attendee_registration_form()
2492
-    {
2493
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2494
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2495
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2496
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2497
-            if ($success) {
2498
-                $what = esc_html__('Registration Form', 'event_espresso');
2499
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2500
-                    : array('action' => 'default');
2501
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2502
-            }
2503
-        }
2504
-    }
2505
-
2506
-
2507
-    /**
2508
-     * Gets the form for saving registrations custom questions (if done
2509
-     * previously retrieves the cached form object, which may have validation errors in it)
2510
-     *
2511
-     * @param int $REG_ID
2512
-     * @return EE_Registration_Custom_Questions_Form
2513
-     * @throws EE_Error
2514
-     * @throws InvalidArgumentException
2515
-     * @throws InvalidDataTypeException
2516
-     * @throws InvalidInterfaceException
2517
-     */
2518
-    protected function _get_reg_custom_questions_form($REG_ID)
2519
-    {
2520
-        if (! $this->_reg_custom_questions_form) {
2521
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2522
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2523
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2524
-            );
2525
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2526
-        }
2527
-        return $this->_reg_custom_questions_form;
2528
-    }
2529
-
2530
-
2531
-    /**
2532
-     * Saves
2533
-     *
2534
-     * @access private
2535
-     * @param bool $REG_ID
2536
-     * @return bool
2537
-     * @throws EE_Error
2538
-     * @throws InvalidArgumentException
2539
-     * @throws InvalidDataTypeException
2540
-     * @throws InvalidInterfaceException
2541
-     */
2542
-    private function _save_reg_custom_questions_form($REG_ID = false)
2543
-    {
2544
-        if (! $REG_ID) {
2545
-            EE_Error::add_error(
2546
-                esc_html__(
2547
-                    'An error occurred. No registration ID was received.',
2548
-                    'event_espresso'
2549
-                ),
2550
-                __FILE__,
2551
-                __FUNCTION__,
2552
-                __LINE__
2553
-            );
2554
-        }
2555
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2556
-        $form->receive_form_submission($this->_req_data);
2557
-        $success = false;
2558
-        if ($form->is_valid()) {
2559
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2560
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2561
-                    $where_conditions = array(
2562
-                        'QST_ID' => $question_id,
2563
-                        'REG_ID' => $REG_ID,
2564
-                    );
2565
-                    $possibly_new_values = array(
2566
-                        'ANS_value' => $input->normalized_value(),
2567
-                    );
2568
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2569
-                    if ($answer instanceof EE_Answer) {
2570
-                        $success = $answer->save($possibly_new_values);
2571
-                    } else {
2572
-                        // insert it then
2573
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2574
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2575
-                        $success = $answer->save();
2576
-                    }
2577
-                }
2578
-            }
2579
-        } else {
2580
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2581
-        }
2582
-        return $success;
2583
-    }
2584
-
2585
-
2586
-    /**
2587
-     *        generates HTML for the Registration main meta box
2588
-     *
2589
-     * @access public
2590
-     * @return void
2591
-     * @throws DomainException
2592
-     * @throws EE_Error
2593
-     * @throws InvalidArgumentException
2594
-     * @throws InvalidDataTypeException
2595
-     * @throws InvalidInterfaceException
2596
-     */
2597
-    public function _reg_attendees_meta_box()
2598
-    {
2599
-        $REG = EEM_Registration::instance();
2600
-        // get all other registrations on this transaction, and cache
2601
-        // the attendees for them so we don't have to run another query using force_join
2602
-        $registrations = $REG->get_all(
2603
-            array(
2604
-                array(
2605
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2606
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2607
-                ),
2608
-                'force_join' => array('Attendee'),
2609
-            )
2610
-        );
2611
-        $this->_template_args['attendees'] = array();
2612
-        $this->_template_args['attendee_notice'] = '';
2613
-        if (empty($registrations)
2614
-            || (is_array($registrations)
2615
-                && ! EEH_Array::get_one_item_from_array($registrations))
2616
-        ) {
2617
-            EE_Error::add_error(
2618
-                esc_html__(
2619
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2620
-                    'event_espresso'
2621
-                ),
2622
-                __FILE__,
2623
-                __FUNCTION__,
2624
-                __LINE__
2625
-            );
2626
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2627
-        } else {
2628
-            $att_nmbr = 1;
2629
-            foreach ($registrations as $registration) {
2630
-                /* @var $registration EE_Registration */
2631
-                $attendee = $registration->attendee()
2632
-                    ? $registration->attendee()
2633
-                    : EEM_Attendee::instance()
2634
-                                  ->create_default_object();
2635
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2636
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2637
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2638
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2639
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2640
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2641
-                    ', ',
2642
-                    $attendee->full_address_as_array()
2643
-                );
2644
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2645
-                    array(
2646
-                        'action' => 'edit_attendee',
2647
-                        'post'   => $attendee->ID(),
2648
-                    ),
2649
-                    REG_ADMIN_URL
2650
-                );
2651
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj()->name();
2652
-                $att_nmbr++;
2653
-            }
2654
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2655
-        }
2656
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2657
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     *        generates HTML for the Edit Registration side meta box
2663
-     *
2664
-     * @access public
2665
-     * @return void
2666
-     * @throws DomainException
2667
-     * @throws EE_Error
2668
-     * @throws InvalidArgumentException
2669
-     * @throws InvalidDataTypeException
2670
-     * @throws InvalidInterfaceException
2671
-     */
2672
-    public function _reg_registrant_side_meta_box()
2673
-    {
2674
-        /*@var $attendee EE_Attendee */
2675
-        $att_check = $this->_registration->attendee();
2676
-        $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2677
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2678
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2679
-        // primary registration object (that way we know if we need to show create button or not)
2680
-        if (! $this->_registration->is_primary_registrant()) {
2681
-            $primary_registration = $this->_registration->get_primary_registration();
2682
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2683
-                : null;
2684
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2685
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2686
-                // custom attendee object so let's not worry about the primary reg.
2687
-                $primary_registration = null;
2688
-            }
2689
-        } else {
2690
-            $primary_registration = null;
2691
-        }
2692
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2693
-        $this->_template_args['fname'] = $attendee->fname();
2694
-        $this->_template_args['lname'] = $attendee->lname();
2695
-        $this->_template_args['email'] = $attendee->email();
2696
-        $this->_template_args['phone'] = $attendee->phone();
2697
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2698
-        // edit link
2699
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2700
-            array(
2701
-                'action' => 'edit_attendee',
2702
-                'post'   => $attendee->ID(),
2703
-            ),
2704
-            REG_ADMIN_URL
2705
-        );
2706
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2707
-        // create link
2708
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2709
-            ? EE_Admin_Page::add_query_args_and_nonce(
2710
-                array(
2711
-                    'action'  => 'duplicate_attendee',
2712
-                    '_REG_ID' => $this->_registration->ID(),
2713
-                ),
2714
-                REG_ADMIN_URL
2715
-            ) : '';
2716
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2717
-        $this->_template_args['att_check'] = $att_check;
2718
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2719
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2720
-    }
2721
-
2722
-
2723
-    /**
2724
-     * trash or restore registrations
2725
-     *
2726
-     * @param  boolean $trash whether to archive or restore
2727
-     * @return void
2728
-     * @throws EE_Error
2729
-     * @throws InvalidArgumentException
2730
-     * @throws InvalidDataTypeException
2731
-     * @throws InvalidInterfaceException
2732
-     * @throws RuntimeException
2733
-     * @access protected
2734
-     */
2735
-    protected function _trash_or_restore_registrations($trash = true)
2736
-    {
2737
-        // if empty _REG_ID then get out because there's nothing to do
2738
-        if (empty($this->_req_data['_REG_ID'])) {
2739
-            EE_Error::add_error(
2740
-                sprintf(
2741
-                    esc_html__(
2742
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2743
-                        'event_espresso'
2744
-                    ),
2745
-                    $trash ? 'trash' : 'restore'
2746
-                ),
2747
-                __FILE__,
2748
-                __LINE__,
2749
-                __FUNCTION__
2750
-            );
2751
-            $this->_redirect_after_action(false, '', '', array(), true);
2752
-        }
2753
-        $success = 0;
2754
-        $overwrite_msgs = false;
2755
-        // Checkboxes
2756
-        if (! is_array($this->_req_data['_REG_ID'])) {
2757
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2758
-        }
2759
-        $reg_count = count($this->_req_data['_REG_ID']);
2760
-        // cycle thru checkboxes
2761
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2762
-            /** @var EE_Registration $REG */
2763
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2764
-            $payments = $REG->registration_payments();
2765
-            if (! empty($payments)) {
2766
-                $name = $REG->attendee() instanceof EE_Attendee
2767
-                    ? $REG->attendee()->full_name()
2768
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2769
-                $overwrite_msgs = true;
2770
-                EE_Error::add_error(
2771
-                    sprintf(
2772
-                        esc_html__(
2773
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2774
-                            'event_espresso'
2775
-                        ),
2776
-                        $name
2777
-                    ),
2778
-                    __FILE__,
2779
-                    __FUNCTION__,
2780
-                    __LINE__
2781
-                );
2782
-                // can't trash this registration because it has payments.
2783
-                continue;
2784
-            }
2785
-            $updated = $trash ? $REG->delete() : $REG->restore();
2786
-            if ($updated) {
2787
-                $success++;
2788
-            }
2789
-        }
2790
-        $this->_redirect_after_action(
2791
-            $success === $reg_count, // were ALL registrations affected?
2792
-            $success > 1
2793
-                ? esc_html__('Registrations', 'event_espresso')
2794
-                : esc_html__('Registration', 'event_espresso'),
2795
-            $trash
2796
-                ? esc_html__('moved to the trash', 'event_espresso')
2797
-                : esc_html__('restored', 'event_espresso'),
2798
-            array('action' => 'default'),
2799
-            $overwrite_msgs
2800
-        );
2801
-    }
2802
-
2803
-
2804
-    /**
2805
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2806
-     * registration but also.
2807
-     * 1. Removing relations to EE_Attendee
2808
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2809
-     * ALSO trashed.
2810
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2811
-     * 4. Removing relationships between all tickets and the related registrations
2812
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2813
-     * 6. Deleting permanently any related Checkins.
2814
-     *
2815
-     * @return void
2816
-     * @throws EE_Error
2817
-     * @throws InvalidArgumentException
2818
-     * @throws InvalidDataTypeException
2819
-     * @throws InvalidInterfaceException
2820
-     */
2821
-    protected function _delete_registrations()
2822
-    {
2823
-        $REG_MDL = EEM_Registration::instance();
2824
-        $success = 1;
2825
-        // Checkboxes
2826
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2827
-            // if array has more than one element than success message should be plural
2828
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2829
-            // cycle thru checkboxes
2830
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2831
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2832
-                if (! $REG instanceof EE_Registration) {
2833
-                    continue;
2834
-                }
2835
-                $deleted = $this->_delete_registration($REG);
2836
-                if (! $deleted) {
2837
-                    $success = 0;
2838
-                }
2839
-            }
2840
-        } else {
2841
-            // grab single id and delete
2842
-            $REG_ID = $this->_req_data['_REG_ID'];
2843
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2844
-            $deleted = $this->_delete_registration($REG);
2845
-            if (! $deleted) {
2846
-                $success = 0;
2847
-            }
2848
-        }
2849
-        $what = $success > 1
2850
-            ? esc_html__('Registrations', 'event_espresso')
2851
-            : esc_html__('Registration', 'event_espresso');
2852
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2853
-        $this->_redirect_after_action(
2854
-            $success,
2855
-            $what,
2856
-            $action_desc,
2857
-            array('action' => 'default'),
2858
-            true
2859
-        );
2860
-    }
2861
-
2862
-
2863
-    /**
2864
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2865
-     * models get affected.
2866
-     *
2867
-     * @param  EE_Registration $REG registration to be deleted permenantly
2868
-     * @return bool true = successful deletion, false = fail.
2869
-     * @throws EE_Error
2870
-     */
2871
-    protected function _delete_registration(EE_Registration $REG)
2872
-    {
2873
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2874
-        // registrations on the transaction that are NOT trashed.
2875
-        $TXN = $REG->get_first_related('Transaction');
2876
-        $REGS = $TXN->get_many_related('Registration');
2877
-        $all_trashed = true;
2878
-        foreach ($REGS as $registration) {
2879
-            if (! $registration->get('REG_deleted')) {
2880
-                $all_trashed = false;
2881
-            }
2882
-        }
2883
-        if (! $all_trashed) {
2884
-            EE_Error::add_error(
2885
-                esc_html__(
2886
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2887
-                    'event_espresso'
2888
-                ),
2889
-                __FILE__,
2890
-                __FUNCTION__,
2891
-                __LINE__
2892
-            );
2893
-            return false;
2894
-        }
2895
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2896
-        // separately from THIS one).
2897
-        foreach ($REGS as $registration) {
2898
-            // delete related answers
2899
-            $registration->delete_related_permanently('Answer');
2900
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2901
-            $attendee = $registration->get_first_related('Attendee');
2902
-            if ($attendee instanceof EE_Attendee) {
2903
-                $registration->_remove_relation_to($attendee, 'Attendee');
2904
-            }
2905
-            // now remove relationships to tickets on this registration.
2906
-            $registration->_remove_relations('Ticket');
2907
-            // now delete permanently the checkins related to this registration.
2908
-            $registration->delete_related_permanently('Checkin');
2909
-            if ($registration->ID() === $REG->ID()) {
2910
-                continue;
2911
-            } //we don't want to delete permanently the existing registration just yet.
2912
-            // remove relation to transaction for these registrations if NOT the existing registrations
2913
-            $registration->_remove_relations('Transaction');
2914
-            // delete permanently any related messages.
2915
-            $registration->delete_related_permanently('Message');
2916
-            // now delete this registration permanently
2917
-            $registration->delete_permanently();
2918
-        }
2919
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2920
-        // (the transaction and line items should be all that's left).
2921
-        // delete the line items related to the transaction for this registration.
2922
-        $TXN->delete_related_permanently('Line_Item');
2923
-        // we need to remove all the relationships on the transaction
2924
-        $TXN->delete_related_permanently('Payment');
2925
-        $TXN->delete_related_permanently('Extra_Meta');
2926
-        $TXN->delete_related_permanently('Message');
2927
-        // now we can delete this REG permanently (and the transaction of course)
2928
-        $REG->delete_related_permanently('Transaction');
2929
-        return $REG->delete_permanently();
2930
-    }
2931
-
2932
-
2933
-    /**
2934
-     *    generates HTML for the Register New Attendee Admin page
2935
-     *
2936
-     * @access private
2937
-     * @throws DomainException
2938
-     * @throws EE_Error
2939
-     */
2940
-    public function new_registration()
2941
-    {
2942
-        if (! $this->_set_reg_event()) {
2943
-            throw new EE_Error(
2944
-                esc_html__(
2945
-                    'Unable to continue with registering because there is no Event ID in the request',
2946
-                    'event_espresso'
2947
-                )
2948
-            );
2949
-        }
2950
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2951
-        // gotta start with a clean slate if we're not coming here via ajax
2952
-        if (! defined('DOING_AJAX')
2953
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2954
-        ) {
2955
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2956
-        }
2957
-        $this->_template_args['event_name'] = '';
2958
-        // event name
2959
-        if ($this->_reg_event) {
2960
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2961
-            $edit_event_url = self::add_query_args_and_nonce(
2962
-                array(
2963
-                    'action' => 'edit',
2964
-                    'post'   => $this->_reg_event->ID(),
2965
-                ),
2966
-                EVENTS_ADMIN_URL
2967
-            );
2968
-            $edit_event_lnk = '<a href="'
2969
-                              . $edit_event_url
2970
-                              . '" title="'
2971
-                              . esc_attr__('Edit ', 'event_espresso')
2972
-                              . $this->_reg_event->name()
2973
-                              . '">'
2974
-                              . esc_html__('Edit Event', 'event_espresso')
2975
-                              . '</a>';
2976
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2977
-                                                   . $edit_event_lnk
2978
-                                                   . '</span>';
2979
-        }
2980
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2981
-        if (defined('DOING_AJAX')) {
2982
-            $this->_return_json();
2983
-        }
2984
-        // grab header
2985
-        $template_path =
2986
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2987
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2988
-            $template_path,
2989
-            $this->_template_args,
2990
-            true
2991
-        );
2992
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2993
-        // the details template wrapper
2994
-        $this->display_admin_page_with_sidebar();
2995
-    }
2996
-
2997
-
2998
-    /**
2999
-     * This returns the content for a registration step
3000
-     *
3001
-     * @access protected
3002
-     * @return string html
3003
-     * @throws DomainException
3004
-     * @throws EE_Error
3005
-     * @throws InvalidArgumentException
3006
-     * @throws InvalidDataTypeException
3007
-     * @throws InvalidInterfaceException
3008
-     */
3009
-    protected function _get_registration_step_content()
3010
-    {
3011
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3012
-            $warning_msg = sprintf(
3013
-                esc_html__(
3014
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
3015
-                    'event_espresso'
3016
-                ),
3017
-                '<br />',
3018
-                '<h3 class="important-notice">',
3019
-                '</h3>',
3020
-                '<div class="float-right">',
3021
-                '<span id="redirect_timer" class="important-notice">30</span>',
3022
-                '</div>',
3023
-                '<b>',
3024
-                '</b>'
3025
-            );
3026
-            return '
2479
+	}
2480
+
2481
+
2482
+	/**
2483
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2484
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2485
+	 * to display the page
2486
+	 *
2487
+	 * @access protected
2488
+	 * @return void
2489
+	 * @throws EE_Error
2490
+	 */
2491
+	protected function _update_attendee_registration_form()
2492
+	{
2493
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2494
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2495
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2496
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2497
+			if ($success) {
2498
+				$what = esc_html__('Registration Form', 'event_espresso');
2499
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2500
+					: array('action' => 'default');
2501
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2502
+			}
2503
+		}
2504
+	}
2505
+
2506
+
2507
+	/**
2508
+	 * Gets the form for saving registrations custom questions (if done
2509
+	 * previously retrieves the cached form object, which may have validation errors in it)
2510
+	 *
2511
+	 * @param int $REG_ID
2512
+	 * @return EE_Registration_Custom_Questions_Form
2513
+	 * @throws EE_Error
2514
+	 * @throws InvalidArgumentException
2515
+	 * @throws InvalidDataTypeException
2516
+	 * @throws InvalidInterfaceException
2517
+	 */
2518
+	protected function _get_reg_custom_questions_form($REG_ID)
2519
+	{
2520
+		if (! $this->_reg_custom_questions_form) {
2521
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2522
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2523
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2524
+			);
2525
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2526
+		}
2527
+		return $this->_reg_custom_questions_form;
2528
+	}
2529
+
2530
+
2531
+	/**
2532
+	 * Saves
2533
+	 *
2534
+	 * @access private
2535
+	 * @param bool $REG_ID
2536
+	 * @return bool
2537
+	 * @throws EE_Error
2538
+	 * @throws InvalidArgumentException
2539
+	 * @throws InvalidDataTypeException
2540
+	 * @throws InvalidInterfaceException
2541
+	 */
2542
+	private function _save_reg_custom_questions_form($REG_ID = false)
2543
+	{
2544
+		if (! $REG_ID) {
2545
+			EE_Error::add_error(
2546
+				esc_html__(
2547
+					'An error occurred. No registration ID was received.',
2548
+					'event_espresso'
2549
+				),
2550
+				__FILE__,
2551
+				__FUNCTION__,
2552
+				__LINE__
2553
+			);
2554
+		}
2555
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2556
+		$form->receive_form_submission($this->_req_data);
2557
+		$success = false;
2558
+		if ($form->is_valid()) {
2559
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2560
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2561
+					$where_conditions = array(
2562
+						'QST_ID' => $question_id,
2563
+						'REG_ID' => $REG_ID,
2564
+					);
2565
+					$possibly_new_values = array(
2566
+						'ANS_value' => $input->normalized_value(),
2567
+					);
2568
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2569
+					if ($answer instanceof EE_Answer) {
2570
+						$success = $answer->save($possibly_new_values);
2571
+					} else {
2572
+						// insert it then
2573
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2574
+						$answer = EE_Answer::new_instance($cols_n_vals);
2575
+						$success = $answer->save();
2576
+					}
2577
+				}
2578
+			}
2579
+		} else {
2580
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2581
+		}
2582
+		return $success;
2583
+	}
2584
+
2585
+
2586
+	/**
2587
+	 *        generates HTML for the Registration main meta box
2588
+	 *
2589
+	 * @access public
2590
+	 * @return void
2591
+	 * @throws DomainException
2592
+	 * @throws EE_Error
2593
+	 * @throws InvalidArgumentException
2594
+	 * @throws InvalidDataTypeException
2595
+	 * @throws InvalidInterfaceException
2596
+	 */
2597
+	public function _reg_attendees_meta_box()
2598
+	{
2599
+		$REG = EEM_Registration::instance();
2600
+		// get all other registrations on this transaction, and cache
2601
+		// the attendees for them so we don't have to run another query using force_join
2602
+		$registrations = $REG->get_all(
2603
+			array(
2604
+				array(
2605
+					'TXN_ID' => $this->_registration->transaction_ID(),
2606
+					'REG_ID' => array('!=', $this->_registration->ID()),
2607
+				),
2608
+				'force_join' => array('Attendee'),
2609
+			)
2610
+		);
2611
+		$this->_template_args['attendees'] = array();
2612
+		$this->_template_args['attendee_notice'] = '';
2613
+		if (empty($registrations)
2614
+			|| (is_array($registrations)
2615
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2616
+		) {
2617
+			EE_Error::add_error(
2618
+				esc_html__(
2619
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2620
+					'event_espresso'
2621
+				),
2622
+				__FILE__,
2623
+				__FUNCTION__,
2624
+				__LINE__
2625
+			);
2626
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2627
+		} else {
2628
+			$att_nmbr = 1;
2629
+			foreach ($registrations as $registration) {
2630
+				/* @var $registration EE_Registration */
2631
+				$attendee = $registration->attendee()
2632
+					? $registration->attendee()
2633
+					: EEM_Attendee::instance()
2634
+								  ->create_default_object();
2635
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2636
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2637
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2638
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2639
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2640
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2641
+					', ',
2642
+					$attendee->full_address_as_array()
2643
+				);
2644
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2645
+					array(
2646
+						'action' => 'edit_attendee',
2647
+						'post'   => $attendee->ID(),
2648
+					),
2649
+					REG_ADMIN_URL
2650
+				);
2651
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj()->name();
2652
+				$att_nmbr++;
2653
+			}
2654
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2655
+		}
2656
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2657
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 *        generates HTML for the Edit Registration side meta box
2663
+	 *
2664
+	 * @access public
2665
+	 * @return void
2666
+	 * @throws DomainException
2667
+	 * @throws EE_Error
2668
+	 * @throws InvalidArgumentException
2669
+	 * @throws InvalidDataTypeException
2670
+	 * @throws InvalidInterfaceException
2671
+	 */
2672
+	public function _reg_registrant_side_meta_box()
2673
+	{
2674
+		/*@var $attendee EE_Attendee */
2675
+		$att_check = $this->_registration->attendee();
2676
+		$attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2677
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2678
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2679
+		// primary registration object (that way we know if we need to show create button or not)
2680
+		if (! $this->_registration->is_primary_registrant()) {
2681
+			$primary_registration = $this->_registration->get_primary_registration();
2682
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2683
+				: null;
2684
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2685
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2686
+				// custom attendee object so let's not worry about the primary reg.
2687
+				$primary_registration = null;
2688
+			}
2689
+		} else {
2690
+			$primary_registration = null;
2691
+		}
2692
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2693
+		$this->_template_args['fname'] = $attendee->fname();
2694
+		$this->_template_args['lname'] = $attendee->lname();
2695
+		$this->_template_args['email'] = $attendee->email();
2696
+		$this->_template_args['phone'] = $attendee->phone();
2697
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2698
+		// edit link
2699
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2700
+			array(
2701
+				'action' => 'edit_attendee',
2702
+				'post'   => $attendee->ID(),
2703
+			),
2704
+			REG_ADMIN_URL
2705
+		);
2706
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2707
+		// create link
2708
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2709
+			? EE_Admin_Page::add_query_args_and_nonce(
2710
+				array(
2711
+					'action'  => 'duplicate_attendee',
2712
+					'_REG_ID' => $this->_registration->ID(),
2713
+				),
2714
+				REG_ADMIN_URL
2715
+			) : '';
2716
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2717
+		$this->_template_args['att_check'] = $att_check;
2718
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2719
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2720
+	}
2721
+
2722
+
2723
+	/**
2724
+	 * trash or restore registrations
2725
+	 *
2726
+	 * @param  boolean $trash whether to archive or restore
2727
+	 * @return void
2728
+	 * @throws EE_Error
2729
+	 * @throws InvalidArgumentException
2730
+	 * @throws InvalidDataTypeException
2731
+	 * @throws InvalidInterfaceException
2732
+	 * @throws RuntimeException
2733
+	 * @access protected
2734
+	 */
2735
+	protected function _trash_or_restore_registrations($trash = true)
2736
+	{
2737
+		// if empty _REG_ID then get out because there's nothing to do
2738
+		if (empty($this->_req_data['_REG_ID'])) {
2739
+			EE_Error::add_error(
2740
+				sprintf(
2741
+					esc_html__(
2742
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2743
+						'event_espresso'
2744
+					),
2745
+					$trash ? 'trash' : 'restore'
2746
+				),
2747
+				__FILE__,
2748
+				__LINE__,
2749
+				__FUNCTION__
2750
+			);
2751
+			$this->_redirect_after_action(false, '', '', array(), true);
2752
+		}
2753
+		$success = 0;
2754
+		$overwrite_msgs = false;
2755
+		// Checkboxes
2756
+		if (! is_array($this->_req_data['_REG_ID'])) {
2757
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2758
+		}
2759
+		$reg_count = count($this->_req_data['_REG_ID']);
2760
+		// cycle thru checkboxes
2761
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2762
+			/** @var EE_Registration $REG */
2763
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2764
+			$payments = $REG->registration_payments();
2765
+			if (! empty($payments)) {
2766
+				$name = $REG->attendee() instanceof EE_Attendee
2767
+					? $REG->attendee()->full_name()
2768
+					: esc_html__('Unknown Attendee', 'event_espresso');
2769
+				$overwrite_msgs = true;
2770
+				EE_Error::add_error(
2771
+					sprintf(
2772
+						esc_html__(
2773
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2774
+							'event_espresso'
2775
+						),
2776
+						$name
2777
+					),
2778
+					__FILE__,
2779
+					__FUNCTION__,
2780
+					__LINE__
2781
+				);
2782
+				// can't trash this registration because it has payments.
2783
+				continue;
2784
+			}
2785
+			$updated = $trash ? $REG->delete() : $REG->restore();
2786
+			if ($updated) {
2787
+				$success++;
2788
+			}
2789
+		}
2790
+		$this->_redirect_after_action(
2791
+			$success === $reg_count, // were ALL registrations affected?
2792
+			$success > 1
2793
+				? esc_html__('Registrations', 'event_espresso')
2794
+				: esc_html__('Registration', 'event_espresso'),
2795
+			$trash
2796
+				? esc_html__('moved to the trash', 'event_espresso')
2797
+				: esc_html__('restored', 'event_espresso'),
2798
+			array('action' => 'default'),
2799
+			$overwrite_msgs
2800
+		);
2801
+	}
2802
+
2803
+
2804
+	/**
2805
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2806
+	 * registration but also.
2807
+	 * 1. Removing relations to EE_Attendee
2808
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2809
+	 * ALSO trashed.
2810
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2811
+	 * 4. Removing relationships between all tickets and the related registrations
2812
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2813
+	 * 6. Deleting permanently any related Checkins.
2814
+	 *
2815
+	 * @return void
2816
+	 * @throws EE_Error
2817
+	 * @throws InvalidArgumentException
2818
+	 * @throws InvalidDataTypeException
2819
+	 * @throws InvalidInterfaceException
2820
+	 */
2821
+	protected function _delete_registrations()
2822
+	{
2823
+		$REG_MDL = EEM_Registration::instance();
2824
+		$success = 1;
2825
+		// Checkboxes
2826
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2827
+			// if array has more than one element than success message should be plural
2828
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2829
+			// cycle thru checkboxes
2830
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2831
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2832
+				if (! $REG instanceof EE_Registration) {
2833
+					continue;
2834
+				}
2835
+				$deleted = $this->_delete_registration($REG);
2836
+				if (! $deleted) {
2837
+					$success = 0;
2838
+				}
2839
+			}
2840
+		} else {
2841
+			// grab single id and delete
2842
+			$REG_ID = $this->_req_data['_REG_ID'];
2843
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2844
+			$deleted = $this->_delete_registration($REG);
2845
+			if (! $deleted) {
2846
+				$success = 0;
2847
+			}
2848
+		}
2849
+		$what = $success > 1
2850
+			? esc_html__('Registrations', 'event_espresso')
2851
+			: esc_html__('Registration', 'event_espresso');
2852
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2853
+		$this->_redirect_after_action(
2854
+			$success,
2855
+			$what,
2856
+			$action_desc,
2857
+			array('action' => 'default'),
2858
+			true
2859
+		);
2860
+	}
2861
+
2862
+
2863
+	/**
2864
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2865
+	 * models get affected.
2866
+	 *
2867
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2868
+	 * @return bool true = successful deletion, false = fail.
2869
+	 * @throws EE_Error
2870
+	 */
2871
+	protected function _delete_registration(EE_Registration $REG)
2872
+	{
2873
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2874
+		// registrations on the transaction that are NOT trashed.
2875
+		$TXN = $REG->get_first_related('Transaction');
2876
+		$REGS = $TXN->get_many_related('Registration');
2877
+		$all_trashed = true;
2878
+		foreach ($REGS as $registration) {
2879
+			if (! $registration->get('REG_deleted')) {
2880
+				$all_trashed = false;
2881
+			}
2882
+		}
2883
+		if (! $all_trashed) {
2884
+			EE_Error::add_error(
2885
+				esc_html__(
2886
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2887
+					'event_espresso'
2888
+				),
2889
+				__FILE__,
2890
+				__FUNCTION__,
2891
+				__LINE__
2892
+			);
2893
+			return false;
2894
+		}
2895
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2896
+		// separately from THIS one).
2897
+		foreach ($REGS as $registration) {
2898
+			// delete related answers
2899
+			$registration->delete_related_permanently('Answer');
2900
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2901
+			$attendee = $registration->get_first_related('Attendee');
2902
+			if ($attendee instanceof EE_Attendee) {
2903
+				$registration->_remove_relation_to($attendee, 'Attendee');
2904
+			}
2905
+			// now remove relationships to tickets on this registration.
2906
+			$registration->_remove_relations('Ticket');
2907
+			// now delete permanently the checkins related to this registration.
2908
+			$registration->delete_related_permanently('Checkin');
2909
+			if ($registration->ID() === $REG->ID()) {
2910
+				continue;
2911
+			} //we don't want to delete permanently the existing registration just yet.
2912
+			// remove relation to transaction for these registrations if NOT the existing registrations
2913
+			$registration->_remove_relations('Transaction');
2914
+			// delete permanently any related messages.
2915
+			$registration->delete_related_permanently('Message');
2916
+			// now delete this registration permanently
2917
+			$registration->delete_permanently();
2918
+		}
2919
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2920
+		// (the transaction and line items should be all that's left).
2921
+		// delete the line items related to the transaction for this registration.
2922
+		$TXN->delete_related_permanently('Line_Item');
2923
+		// we need to remove all the relationships on the transaction
2924
+		$TXN->delete_related_permanently('Payment');
2925
+		$TXN->delete_related_permanently('Extra_Meta');
2926
+		$TXN->delete_related_permanently('Message');
2927
+		// now we can delete this REG permanently (and the transaction of course)
2928
+		$REG->delete_related_permanently('Transaction');
2929
+		return $REG->delete_permanently();
2930
+	}
2931
+
2932
+
2933
+	/**
2934
+	 *    generates HTML for the Register New Attendee Admin page
2935
+	 *
2936
+	 * @access private
2937
+	 * @throws DomainException
2938
+	 * @throws EE_Error
2939
+	 */
2940
+	public function new_registration()
2941
+	{
2942
+		if (! $this->_set_reg_event()) {
2943
+			throw new EE_Error(
2944
+				esc_html__(
2945
+					'Unable to continue with registering because there is no Event ID in the request',
2946
+					'event_espresso'
2947
+				)
2948
+			);
2949
+		}
2950
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2951
+		// gotta start with a clean slate if we're not coming here via ajax
2952
+		if (! defined('DOING_AJAX')
2953
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2954
+		) {
2955
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2956
+		}
2957
+		$this->_template_args['event_name'] = '';
2958
+		// event name
2959
+		if ($this->_reg_event) {
2960
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2961
+			$edit_event_url = self::add_query_args_and_nonce(
2962
+				array(
2963
+					'action' => 'edit',
2964
+					'post'   => $this->_reg_event->ID(),
2965
+				),
2966
+				EVENTS_ADMIN_URL
2967
+			);
2968
+			$edit_event_lnk = '<a href="'
2969
+							  . $edit_event_url
2970
+							  . '" title="'
2971
+							  . esc_attr__('Edit ', 'event_espresso')
2972
+							  . $this->_reg_event->name()
2973
+							  . '">'
2974
+							  . esc_html__('Edit Event', 'event_espresso')
2975
+							  . '</a>';
2976
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2977
+												   . $edit_event_lnk
2978
+												   . '</span>';
2979
+		}
2980
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2981
+		if (defined('DOING_AJAX')) {
2982
+			$this->_return_json();
2983
+		}
2984
+		// grab header
2985
+		$template_path =
2986
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2987
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2988
+			$template_path,
2989
+			$this->_template_args,
2990
+			true
2991
+		);
2992
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2993
+		// the details template wrapper
2994
+		$this->display_admin_page_with_sidebar();
2995
+	}
2996
+
2997
+
2998
+	/**
2999
+	 * This returns the content for a registration step
3000
+	 *
3001
+	 * @access protected
3002
+	 * @return string html
3003
+	 * @throws DomainException
3004
+	 * @throws EE_Error
3005
+	 * @throws InvalidArgumentException
3006
+	 * @throws InvalidDataTypeException
3007
+	 * @throws InvalidInterfaceException
3008
+	 */
3009
+	protected function _get_registration_step_content()
3010
+	{
3011
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3012
+			$warning_msg = sprintf(
3013
+				esc_html__(
3014
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
3015
+					'event_espresso'
3016
+				),
3017
+				'<br />',
3018
+				'<h3 class="important-notice">',
3019
+				'</h3>',
3020
+				'<div class="float-right">',
3021
+				'<span id="redirect_timer" class="important-notice">30</span>',
3022
+				'</div>',
3023
+				'<b>',
3024
+				'</b>'
3025
+			);
3026
+			return '
3027 3027
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3028 3028
 	<script >
3029 3029
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -3036,855 +3036,855 @@  discard block
 block discarded – undo
3036 3036
 	        }
3037 3037
 	    }, 800 );
3038 3038
 	</script >';
3039
-        }
3040
-        $template_args = array(
3041
-            'title'                    => '',
3042
-            'content'                  => '',
3043
-            'step_button_text'         => '',
3044
-            'show_notification_toggle' => false,
3045
-        );
3046
-        // to indicate we're processing a new registration
3047
-        $hidden_fields = array(
3048
-            'processing_registration' => array(
3049
-                'type'  => 'hidden',
3050
-                'value' => 0,
3051
-            ),
3052
-            'event_id'                => array(
3053
-                'type'  => 'hidden',
3054
-                'value' => $this->_reg_event->ID(),
3055
-            ),
3056
-        );
3057
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
3058
-        $cart = EE_Registry::instance()->SSN->cart();
3059
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3060
-        switch ($step) {
3061
-            case 'ticket':
3062
-                $hidden_fields['processing_registration']['value'] = 1;
3063
-                $template_args['title'] = esc_html__(
3064
-                    'Step One: Select the Ticket for this registration',
3065
-                    'event_espresso'
3066
-                );
3067
-                $template_args['content'] =
3068
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3069
-                $template_args['step_button_text'] = esc_html__(
3070
-                    'Add Tickets and Continue to Registrant Details',
3071
-                    'event_espresso'
3072
-                );
3073
-                $template_args['show_notification_toggle'] = false;
3074
-                break;
3075
-            case 'questions':
3076
-                $hidden_fields['processing_registration']['value'] = 2;
3077
-                $template_args['title'] = esc_html__(
3078
-                    'Step Two: Add Registrant Details for this Registration',
3079
-                    'event_espresso'
3080
-                );
3081
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3082
-                // properly by the first process_reg_step run.
3083
-                $template_args['content'] =
3084
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
3085
-                $template_args['step_button_text'] = esc_html__(
3086
-                    'Save Registration and Continue to Details',
3087
-                    'event_espresso'
3088
-                );
3089
-                $template_args['show_notification_toggle'] = true;
3090
-                break;
3091
-        }
3092
-        // we come back to the process_registration_step route.
3093
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3094
-        return EEH_Template::display_template(
3095
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3096
-            $template_args,
3097
-            true
3098
-        );
3099
-    }
3100
-
3101
-
3102
-    /**
3103
-     *        set_reg_event
3104
-     *
3105
-     * @access private
3106
-     * @return bool
3107
-     * @throws EE_Error
3108
-     * @throws InvalidArgumentException
3109
-     * @throws InvalidDataTypeException
3110
-     * @throws InvalidInterfaceException
3111
-     */
3112
-    private function _set_reg_event()
3113
-    {
3114
-        if (is_object($this->_reg_event)) {
3115
-            return true;
3116
-        }
3117
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3118
-        if (! $EVT_ID) {
3119
-            return false;
3120
-        }
3121
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3122
-        return true;
3123
-    }
3124
-
3125
-
3126
-    /**
3127
-     * process_reg_step
3128
-     *
3129
-     * @access        public
3130
-     * @return string
3131
-     * @throws DomainException
3132
-     * @throws EE_Error
3133
-     * @throws InvalidArgumentException
3134
-     * @throws InvalidDataTypeException
3135
-     * @throws InvalidInterfaceException
3136
-     * @throws ReflectionException
3137
-     * @throws RuntimeException
3138
-     */
3139
-    public function process_reg_step()
3140
-    {
3141
-        EE_System::do_not_cache();
3142
-        $this->_set_reg_event();
3143
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3144
-        EE_Registry::instance()->REQ->set('uts', time());
3145
-        // what step are we on?
3146
-        $cart = EE_Registry::instance()->SSN->cart();
3147
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3148
-        // if doing ajax then we need to verify the nonce
3149
-        if (defined('DOING_AJAX')) {
3150
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3151
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3152
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3153
-        }
3154
-        switch ($step) {
3155
-            case 'ticket':
3156
-                // process ticket selection
3157
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3158
-                if ($success) {
3159
-                    EE_Error::add_success(
3160
-                        esc_html__(
3161
-                            'Tickets Selected. Now complete the registration.',
3162
-                            'event_espresso'
3163
-                        )
3164
-                    );
3165
-                } else {
3166
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3167
-                }
3168
-                if (defined('DOING_AJAX')) {
3169
-                    $this->new_registration(); // display next step
3170
-                } else {
3171
-                    $query_args = array(
3172
-                        'action'                  => 'new_registration',
3173
-                        'processing_registration' => 1,
3174
-                        'event_id'                => $this->_reg_event->ID(),
3175
-                        'uts'                     => time(),
3176
-                    );
3177
-                    $this->_redirect_after_action(
3178
-                        false,
3179
-                        '',
3180
-                        '',
3181
-                        $query_args,
3182
-                        true
3183
-                    );
3184
-                }
3185
-                break;
3186
-            case 'questions':
3187
-                if (! isset(
3188
-                    $this->_req_data['txn_reg_status_change'],
3189
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3190
-                )
3191
-                ) {
3192
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3193
-                }
3194
-                // process registration
3195
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3196
-                if ($cart instanceof EE_Cart) {
3197
-                    $grand_total = $cart->get_cart_grand_total();
3198
-                    if ($grand_total instanceof EE_Line_Item) {
3199
-                        $grand_total->save_this_and_descendants_to_txn();
3200
-                    }
3201
-                }
3202
-                if (! $transaction instanceof EE_Transaction) {
3203
-                    $query_args = array(
3204
-                        'action'                  => 'new_registration',
3205
-                        'processing_registration' => 2,
3206
-                        'event_id'                => $this->_reg_event->ID(),
3207
-                        'uts'                     => time(),
3208
-                    );
3209
-                    if (defined('DOING_AJAX')) {
3210
-                        // display registration form again because there are errors (maybe validation?)
3211
-                        $this->new_registration();
3212
-                        return;
3213
-                    } else {
3214
-                        $this->_redirect_after_action(
3215
-                            false,
3216
-                            '',
3217
-                            '',
3218
-                            $query_args,
3219
-                            true
3220
-                        );
3221
-                        return;
3222
-                    }
3223
-                }
3224
-                // maybe update status, and make sure to save transaction if not done already
3225
-                if (! $transaction->update_status_based_on_total_paid()) {
3226
-                    $transaction->save();
3227
-                }
3228
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3229
-                $this->_req_data = array();
3230
-                $query_args = array(
3231
-                    'action'        => 'redirect_to_txn',
3232
-                    'TXN_ID'        => $transaction->ID(),
3233
-                    'EVT_ID'        => $this->_reg_event->ID(),
3234
-                    'event_name'    => urlencode($this->_reg_event->name()),
3235
-                    'redirect_from' => 'new_registration',
3236
-                );
3237
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3238
-                break;
3239
-        }
3240
-        // what are you looking here for?  Should be nothing to do at this point.
3241
-    }
3242
-
3243
-
3244
-    /**
3245
-     * redirect_to_txn
3246
-     *
3247
-     * @access public
3248
-     * @return void
3249
-     * @throws EE_Error
3250
-     * @throws InvalidArgumentException
3251
-     * @throws InvalidDataTypeException
3252
-     * @throws InvalidInterfaceException
3253
-     */
3254
-    public function redirect_to_txn()
3255
-    {
3256
-        EE_System::do_not_cache();
3257
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3258
-        $query_args = array(
3259
-            'action' => 'view_transaction',
3260
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3261
-            'page'   => 'espresso_transactions',
3262
-        );
3263
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3264
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3265
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3266
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3267
-        }
3268
-        EE_Error::add_success(
3269
-            esc_html__(
3270
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3271
-                'event_espresso'
3272
-            )
3273
-        );
3274
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3275
-    }
3276
-
3277
-
3278
-    /**
3279
-     *        generates HTML for the Attendee Contact List
3280
-     *
3281
-     * @access protected
3282
-     * @return void
3283
-     */
3284
-    protected function _attendee_contact_list_table()
3285
-    {
3286
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3287
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3288
-        $this->display_admin_list_table_page_with_no_sidebar();
3289
-    }
3290
-
3291
-
3292
-    /**
3293
-     *        get_attendees
3294
-     *
3295
-     * @param      $per_page
3296
-     * @param bool $count whether to return count or data.
3297
-     * @param bool $trash
3298
-     * @return array
3299
-     * @throws EE_Error
3300
-     * @throws InvalidArgumentException
3301
-     * @throws InvalidDataTypeException
3302
-     * @throws InvalidInterfaceException
3303
-     * @access public
3304
-     */
3305
-    public function get_attendees($per_page, $count = false, $trash = false)
3306
-    {
3307
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3308
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3309
-        $ATT_MDL = EEM_Attendee::instance();
3310
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3311
-        switch ($this->_req_data['orderby']) {
3312
-            case 'ATT_ID':
3313
-                $orderby = 'ATT_ID';
3314
-                break;
3315
-            case 'ATT_fname':
3316
-                $orderby = 'ATT_fname';
3317
-                break;
3318
-            case 'ATT_email':
3319
-                $orderby = 'ATT_email';
3320
-                break;
3321
-            case 'ATT_city':
3322
-                $orderby = 'ATT_city';
3323
-                break;
3324
-            case 'STA_ID':
3325
-                $orderby = 'STA_ID';
3326
-                break;
3327
-            case 'CNT_ID':
3328
-                $orderby = 'CNT_ID';
3329
-                break;
3330
-            case 'Registration_Count':
3331
-                $orderby = 'Registration_Count';
3332
-                break;
3333
-            default:
3334
-                $orderby = 'ATT_lname';
3335
-        }
3336
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3337
-            ? $this->_req_data['order']
3338
-            : 'ASC';
3339
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3340
-            ? $this->_req_data['paged']
3341
-            : 1;
3342
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3343
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3344
-            ? $this->_req_data['perpage']
3345
-            : $per_page;
3346
-        $_where = array();
3347
-        if (! empty($this->_req_data['s'])) {
3348
-            $sstr = '%' . $this->_req_data['s'] . '%';
3349
-            $_where['OR'] = array(
3350
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3351
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3352
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3353
-                'ATT_fname'                         => array('LIKE', $sstr),
3354
-                'ATT_lname'                         => array('LIKE', $sstr),
3355
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3356
-                'ATT_email'                         => array('LIKE', $sstr),
3357
-                'ATT_address'                       => array('LIKE', $sstr),
3358
-                'ATT_address2'                      => array('LIKE', $sstr),
3359
-                'ATT_city'                          => array('LIKE', $sstr),
3360
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3361
-                'State.STA_name'                    => array('LIKE', $sstr),
3362
-                'ATT_phone'                         => array('LIKE', $sstr),
3363
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3364
-                'Registration.REG_code'             => array('LIKE', $sstr),
3365
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3366
-            );
3367
-        }
3368
-        $offset = ($current_page - 1) * $per_page;
3369
-        $limit = $count ? null : array($offset, $per_page);
3370
-        $query_args = array(
3371
-            $_where,
3372
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3373
-            'limit'         => $limit,
3374
-        );
3375
-        if (! $count) {
3376
-            $query_args['order_by'] = array($orderby => $sort);
3377
-        }
3378
-        if ($trash) {
3379
-            $query_args[0]['status'] = array('!=', 'publish');
3380
-            $all_attendees = $count
3381
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3382
-                : $ATT_MDL->get_all($query_args);
3383
-        } else {
3384
-            $query_args[0]['status'] = array('IN', array('publish'));
3385
-            $all_attendees = $count
3386
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3387
-                : $ATT_MDL->get_all($query_args);
3388
-        }
3389
-        return $all_attendees;
3390
-    }
3391
-
3392
-
3393
-    /**
3394
-     * This is just taking care of resending the registration confirmation
3395
-     *
3396
-     * @access protected
3397
-     * @return void
3398
-     */
3399
-    protected function _resend_registration()
3400
-    {
3401
-        $this->_process_resend_registration();
3402
-        $query_args = isset($this->_req_data['redirect_to'])
3403
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3404
-            : array('action' => 'default');
3405
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3406
-    }
3407
-
3408
-    /**
3409
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3410
-     * to use when selecting registrations
3411
-     *
3412
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3413
-     *                                                     the query parameters from the request
3414
-     * @return void ends the request with a redirect or download
3415
-     */
3416
-    public function _registrations_report_base($method_name_for_getting_query_params)
3417
-    {
3418
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3419
-            wp_redirect(
3420
-                EE_Admin_Page::add_query_args_and_nonce(
3421
-                    array(
3422
-                        'page'        => 'espresso_batch',
3423
-                        'batch'       => 'file',
3424
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3425
-                        'filters'     => urlencode(
3426
-                            serialize(
3427
-                                call_user_func(
3428
-                                    array($this, $method_name_for_getting_query_params),
3429
-                                    EEH_Array::is_set(
3430
-                                        $this->_req_data,
3431
-                                        'filters',
3432
-                                        array()
3433
-                                    )
3434
-                                )
3435
-                            )
3436
-                        ),
3437
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3438
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3439
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3440
-                    )
3441
-                )
3442
-            );
3443
-        } else {
3444
-            $new_request_args = array(
3445
-                'export' => 'report',
3446
-                'action' => 'registrations_report_for_event',
3447
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3448
-            );
3449
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3450
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3451
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3452
-                $EE_Export = EE_Export::instance($this->_req_data);
3453
-                $EE_Export->export();
3454
-            }
3455
-        }
3456
-    }
3457
-
3458
-
3459
-    /**
3460
-     * Creates a registration report using only query parameters in the request
3461
-     *
3462
-     * @return void
3463
-     */
3464
-    public function _registrations_report()
3465
-    {
3466
-        $this->_registrations_report_base('_get_registration_query_parameters');
3467
-    }
3468
-
3469
-
3470
-    public function _contact_list_export()
3471
-    {
3472
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3473
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3474
-            $EE_Export = EE_Export::instance($this->_req_data);
3475
-            $EE_Export->export_attendees();
3476
-        }
3477
-    }
3478
-
3479
-
3480
-    public function _contact_list_report()
3481
-    {
3482
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3483
-            wp_redirect(
3484
-                EE_Admin_Page::add_query_args_and_nonce(
3485
-                    array(
3486
-                        'page'        => 'espresso_batch',
3487
-                        'batch'       => 'file',
3488
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3489
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3490
-                    )
3491
-                )
3492
-            );
3493
-        } else {
3494
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3495
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3496
-                $EE_Export = EE_Export::instance($this->_req_data);
3497
-                $EE_Export->report_attendees();
3498
-            }
3499
-        }
3500
-    }
3501
-
3502
-
3503
-
3504
-
3505
-
3506
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3507
-    /**
3508
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3509
-     *
3510
-     * @return void
3511
-     * @throws EE_Error
3512
-     * @throws InvalidArgumentException
3513
-     * @throws InvalidDataTypeException
3514
-     * @throws InvalidInterfaceException
3515
-     */
3516
-    protected function _duplicate_attendee()
3517
-    {
3518
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3519
-        // verify we have necessary info
3520
-        if (empty($this->_req_data['_REG_ID'])) {
3521
-            EE_Error::add_error(
3522
-                esc_html__(
3523
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3524
-                    'event_espresso'
3525
-                ),
3526
-                __FILE__,
3527
-                __LINE__,
3528
-                __FUNCTION__
3529
-            );
3530
-            $query_args = array('action' => $action);
3531
-            $this->_redirect_after_action('', '', '', $query_args, true);
3532
-        }
3533
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3534
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3535
-        $attendee = $registration->attendee();
3536
-        // remove relation of existing attendee on registration
3537
-        $registration->_remove_relation_to($attendee, 'Attendee');
3538
-        // new attendee
3539
-        $new_attendee = clone $attendee;
3540
-        $new_attendee->set('ATT_ID', 0);
3541
-        $new_attendee->save();
3542
-        // add new attendee to reg
3543
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3544
-        EE_Error::add_success(
3545
-            esc_html__(
3546
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3547
-                'event_espresso'
3548
-            )
3549
-        );
3550
-        // redirect to edit page for attendee
3551
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3552
-        $this->_redirect_after_action('', '', '', $query_args, true);
3553
-    }
3554
-
3555
-
3556
-    /**
3557
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3558
-     *
3559
-     * @param int     $post_id
3560
-     * @param WP_POST $post
3561
-     * @throws DomainException
3562
-     * @throws EE_Error
3563
-     * @throws InvalidArgumentException
3564
-     * @throws InvalidDataTypeException
3565
-     * @throws InvalidInterfaceException
3566
-     * @throws LogicException
3567
-     * @throws InvalidFormSubmissionException
3568
-     */
3569
-    protected function _insert_update_cpt_item($post_id, $post)
3570
-    {
3571
-        $success = true;
3572
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3573
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3574
-            : null;
3575
-        // for attendee updates
3576
-        if ($attendee instanceof EE_Attendee) {
3577
-            // note we should only be UPDATING attendees at this point.
3578
-            $updated_fields = array(
3579
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3580
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3581
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3582
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3583
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3584
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3585
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3586
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3587
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3588
-            );
3589
-            foreach ($updated_fields as $field => $value) {
3590
-                $attendee->set($field, $value);
3591
-            }
3592
-
3593
-            // process contact details metabox form handler (which will also save the attendee)
3594
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3595
-            $success = $contact_details_form->process($this->_req_data);
3596
-
3597
-            $attendee_update_callbacks = apply_filters(
3598
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3599
-                array()
3600
-            );
3601
-            foreach ($attendee_update_callbacks as $a_callback) {
3602
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3603
-                    throw new EE_Error(
3604
-                        sprintf(
3605
-                            esc_html__(
3606
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3607
-                                'event_espresso'
3608
-                            ),
3609
-                            $a_callback
3610
-                        )
3611
-                    );
3612
-                }
3613
-            }
3614
-        }
3615
-
3616
-        if ($success === false) {
3617
-            EE_Error::add_error(
3618
-                esc_html__(
3619
-                    'Something went wrong with updating the meta table data for the registration.',
3620
-                    'event_espresso'
3621
-                ),
3622
-                __FILE__,
3623
-                __FUNCTION__,
3624
-                __LINE__
3625
-            );
3626
-        }
3627
-    }
3628
-
3629
-
3630
-    public function trash_cpt_item($post_id)
3631
-    {
3632
-    }
3633
-
3634
-
3635
-    public function delete_cpt_item($post_id)
3636
-    {
3637
-    }
3638
-
3639
-
3640
-    public function restore_cpt_item($post_id)
3641
-    {
3642
-    }
3643
-
3644
-
3645
-    protected function _restore_cpt_item($post_id, $revision_id)
3646
-    {
3647
-    }
3648
-
3649
-
3650
-    public function attendee_editor_metaboxes()
3651
-    {
3652
-        $this->verify_cpt_object();
3653
-        remove_meta_box(
3654
-            'postexcerpt',
3655
-            esc_html__('Excerpt', 'event_espresso'),
3656
-            'post_excerpt_meta_box',
3657
-            $this->_cpt_routes[ $this->_req_action ],
3658
-            'normal',
3659
-            'core'
3660
-        );
3661
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3662
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3663
-            add_meta_box(
3664
-                'postexcerpt',
3665
-                esc_html__('Short Biography', 'event_espresso'),
3666
-                'post_excerpt_meta_box',
3667
-                $this->_cpt_routes[ $this->_req_action ],
3668
-                'normal'
3669
-            );
3670
-        }
3671
-        if (post_type_supports('espresso_attendees', 'comments')) {
3672
-            add_meta_box(
3673
-                'commentsdiv',
3674
-                esc_html__('Notes on the Contact', 'event_espresso'),
3675
-                'post_comment_meta_box',
3676
-                $this->_cpt_routes[ $this->_req_action ],
3677
-                'normal',
3678
-                'core'
3679
-            );
3680
-        }
3681
-        add_meta_box(
3682
-            'attendee_contact_info',
3683
-            esc_html__('Contact Info', 'event_espresso'),
3684
-            array($this, 'attendee_contact_info'),
3685
-            $this->_cpt_routes[ $this->_req_action ],
3686
-            'side',
3687
-            'core'
3688
-        );
3689
-        add_meta_box(
3690
-            'attendee_details_address',
3691
-            esc_html__('Address Details', 'event_espresso'),
3692
-            array($this, 'attendee_address_details'),
3693
-            $this->_cpt_routes[ $this->_req_action ],
3694
-            'normal',
3695
-            'core'
3696
-        );
3697
-        add_meta_box(
3698
-            'attendee_registrations',
3699
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3700
-            array($this, 'attendee_registrations_meta_box'),
3701
-            $this->_cpt_routes[ $this->_req_action ],
3702
-            'normal',
3703
-            'high'
3704
-        );
3705
-    }
3706
-
3707
-
3708
-    /**
3709
-     * Metabox for attendee contact info
3710
-     *
3711
-     * @param  WP_Post $post wp post object
3712
-     * @return string attendee contact info ( and form )
3713
-     * @throws EE_Error
3714
-     * @throws InvalidArgumentException
3715
-     * @throws InvalidDataTypeException
3716
-     * @throws InvalidInterfaceException
3717
-     * @throws LogicException
3718
-     * @throws DomainException
3719
-     */
3720
-    public function attendee_contact_info($post)
3721
-    {
3722
-        // get attendee object ( should already have it )
3723
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3724
-        $form->enqueueStylesAndScripts();
3725
-        echo $form->display();
3726
-    }
3727
-
3728
-
3729
-    /**
3730
-     * Return form handler for the contact details metabox
3731
-     *
3732
-     * @param EE_Attendee $attendee
3733
-     * @return AttendeeContactDetailsMetaboxFormHandler
3734
-     * @throws DomainException
3735
-     * @throws InvalidArgumentException
3736
-     * @throws InvalidDataTypeException
3737
-     * @throws InvalidInterfaceException
3738
-     */
3739
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3740
-    {
3741
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3742
-    }
3743
-
3744
-
3745
-    /**
3746
-     * Metabox for attendee details
3747
-     *
3748
-     * @param  WP_Post $post wp post object
3749
-     * @throws DomainException
3750
-     */
3751
-    public function attendee_address_details($post)
3752
-    {
3753
-        // get attendee object (should already have it)
3754
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3755
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3756
-            new EE_Question_Form_Input(
3757
-                EE_Question::new_instance(
3758
-                    array(
3759
-                        'QST_ID'           => 0,
3760
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3761
-                        'QST_system'       => 'admin-state',
3762
-                    )
3763
-                ),
3764
-                EE_Answer::new_instance(
3765
-                    array(
3766
-                        'ANS_ID'    => 0,
3767
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3768
-                    )
3769
-                ),
3770
-                array(
3771
-                    'input_id'       => 'STA_ID',
3772
-                    'input_name'     => 'STA_ID',
3773
-                    'input_prefix'   => '',
3774
-                    'append_qstn_id' => false,
3775
-                )
3776
-            )
3777
-        );
3778
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3779
-            new EE_Question_Form_Input(
3780
-                EE_Question::new_instance(
3781
-                    array(
3782
-                        'QST_ID'           => 0,
3783
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3784
-                        'QST_system'       => 'admin-country',
3785
-                    )
3786
-                ),
3787
-                EE_Answer::new_instance(
3788
-                    array(
3789
-                        'ANS_ID'    => 0,
3790
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3791
-                    )
3792
-                ),
3793
-                array(
3794
-                    'input_id'       => 'CNT_ISO',
3795
-                    'input_name'     => 'CNT_ISO',
3796
-                    'input_prefix'   => '',
3797
-                    'append_qstn_id' => false,
3798
-                )
3799
-            )
3800
-        );
3801
-        $template =
3802
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3803
-        EEH_Template::display_template($template, $this->_template_args);
3804
-    }
3805
-
3806
-
3807
-    /**
3808
-     *        _attendee_details
3809
-     *
3810
-     * @access protected
3811
-     * @param $post
3812
-     * @return void
3813
-     * @throws DomainException
3814
-     * @throws EE_Error
3815
-     */
3816
-    public function attendee_registrations_meta_box($post)
3817
-    {
3818
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3819
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3820
-        $template =
3821
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3822
-        EEH_Template::display_template($template, $this->_template_args);
3823
-    }
3824
-
3825
-
3826
-    /**
3827
-     * add in the form fields for the attendee edit
3828
-     *
3829
-     * @param  WP_Post $post wp post object
3830
-     * @return string html for new form.
3831
-     * @throws DomainException
3832
-     */
3833
-    public function after_title_form_fields($post)
3834
-    {
3835
-        if ($post->post_type == 'espresso_attendees') {
3836
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3837
-            $template_args['attendee'] = $this->_cpt_model_obj;
3838
-            EEH_Template::display_template($template, $template_args);
3839
-        }
3840
-    }
3841
-
3842
-
3843
-    /**
3844
-     *        _trash_or_restore_attendee
3845
-     *
3846
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3847
-     * @return void
3848
-     * @throws EE_Error
3849
-     * @throws InvalidArgumentException
3850
-     * @throws InvalidDataTypeException
3851
-     * @throws InvalidInterfaceException
3852
-     * @access protected
3853
-     */
3854
-    protected function _trash_or_restore_attendees($trash = true)
3855
-    {
3856
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3857
-        $ATT_MDL = EEM_Attendee::instance();
3858
-        $success = 1;
3859
-        // Checkboxes
3860
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3861
-            // if array has more than one element than success message should be plural
3862
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3863
-            // cycle thru checkboxes
3864
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3865
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3866
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3867
-                if (! $updated) {
3868
-                    $success = 0;
3869
-                }
3870
-            }
3871
-        } else {
3872
-            // grab single id and delete
3873
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3874
-            // get attendee
3875
-            $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3876
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3877
-            $updated = $att->save();
3878
-            if (! $updated) {
3879
-                $success = 0;
3880
-            }
3881
-        }
3882
-        $what = $success > 1
3883
-            ? esc_html__('Contacts', 'event_espresso')
3884
-            : esc_html__('Contact', 'event_espresso');
3885
-        $action_desc = $trash
3886
-            ? esc_html__('moved to the trash', 'event_espresso')
3887
-            : esc_html__('restored', 'event_espresso');
3888
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3889
-    }
3039
+		}
3040
+		$template_args = array(
3041
+			'title'                    => '',
3042
+			'content'                  => '',
3043
+			'step_button_text'         => '',
3044
+			'show_notification_toggle' => false,
3045
+		);
3046
+		// to indicate we're processing a new registration
3047
+		$hidden_fields = array(
3048
+			'processing_registration' => array(
3049
+				'type'  => 'hidden',
3050
+				'value' => 0,
3051
+			),
3052
+			'event_id'                => array(
3053
+				'type'  => 'hidden',
3054
+				'value' => $this->_reg_event->ID(),
3055
+			),
3056
+		);
3057
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
3058
+		$cart = EE_Registry::instance()->SSN->cart();
3059
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3060
+		switch ($step) {
3061
+			case 'ticket':
3062
+				$hidden_fields['processing_registration']['value'] = 1;
3063
+				$template_args['title'] = esc_html__(
3064
+					'Step One: Select the Ticket for this registration',
3065
+					'event_espresso'
3066
+				);
3067
+				$template_args['content'] =
3068
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3069
+				$template_args['step_button_text'] = esc_html__(
3070
+					'Add Tickets and Continue to Registrant Details',
3071
+					'event_espresso'
3072
+				);
3073
+				$template_args['show_notification_toggle'] = false;
3074
+				break;
3075
+			case 'questions':
3076
+				$hidden_fields['processing_registration']['value'] = 2;
3077
+				$template_args['title'] = esc_html__(
3078
+					'Step Two: Add Registrant Details for this Registration',
3079
+					'event_espresso'
3080
+				);
3081
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3082
+				// properly by the first process_reg_step run.
3083
+				$template_args['content'] =
3084
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
3085
+				$template_args['step_button_text'] = esc_html__(
3086
+					'Save Registration and Continue to Details',
3087
+					'event_espresso'
3088
+				);
3089
+				$template_args['show_notification_toggle'] = true;
3090
+				break;
3091
+		}
3092
+		// we come back to the process_registration_step route.
3093
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3094
+		return EEH_Template::display_template(
3095
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3096
+			$template_args,
3097
+			true
3098
+		);
3099
+	}
3100
+
3101
+
3102
+	/**
3103
+	 *        set_reg_event
3104
+	 *
3105
+	 * @access private
3106
+	 * @return bool
3107
+	 * @throws EE_Error
3108
+	 * @throws InvalidArgumentException
3109
+	 * @throws InvalidDataTypeException
3110
+	 * @throws InvalidInterfaceException
3111
+	 */
3112
+	private function _set_reg_event()
3113
+	{
3114
+		if (is_object($this->_reg_event)) {
3115
+			return true;
3116
+		}
3117
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3118
+		if (! $EVT_ID) {
3119
+			return false;
3120
+		}
3121
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3122
+		return true;
3123
+	}
3124
+
3125
+
3126
+	/**
3127
+	 * process_reg_step
3128
+	 *
3129
+	 * @access        public
3130
+	 * @return string
3131
+	 * @throws DomainException
3132
+	 * @throws EE_Error
3133
+	 * @throws InvalidArgumentException
3134
+	 * @throws InvalidDataTypeException
3135
+	 * @throws InvalidInterfaceException
3136
+	 * @throws ReflectionException
3137
+	 * @throws RuntimeException
3138
+	 */
3139
+	public function process_reg_step()
3140
+	{
3141
+		EE_System::do_not_cache();
3142
+		$this->_set_reg_event();
3143
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3144
+		EE_Registry::instance()->REQ->set('uts', time());
3145
+		// what step are we on?
3146
+		$cart = EE_Registry::instance()->SSN->cart();
3147
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3148
+		// if doing ajax then we need to verify the nonce
3149
+		if (defined('DOING_AJAX')) {
3150
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3151
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3152
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3153
+		}
3154
+		switch ($step) {
3155
+			case 'ticket':
3156
+				// process ticket selection
3157
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3158
+				if ($success) {
3159
+					EE_Error::add_success(
3160
+						esc_html__(
3161
+							'Tickets Selected. Now complete the registration.',
3162
+							'event_espresso'
3163
+						)
3164
+					);
3165
+				} else {
3166
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3167
+				}
3168
+				if (defined('DOING_AJAX')) {
3169
+					$this->new_registration(); // display next step
3170
+				} else {
3171
+					$query_args = array(
3172
+						'action'                  => 'new_registration',
3173
+						'processing_registration' => 1,
3174
+						'event_id'                => $this->_reg_event->ID(),
3175
+						'uts'                     => time(),
3176
+					);
3177
+					$this->_redirect_after_action(
3178
+						false,
3179
+						'',
3180
+						'',
3181
+						$query_args,
3182
+						true
3183
+					);
3184
+				}
3185
+				break;
3186
+			case 'questions':
3187
+				if (! isset(
3188
+					$this->_req_data['txn_reg_status_change'],
3189
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3190
+				)
3191
+				) {
3192
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3193
+				}
3194
+				// process registration
3195
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3196
+				if ($cart instanceof EE_Cart) {
3197
+					$grand_total = $cart->get_cart_grand_total();
3198
+					if ($grand_total instanceof EE_Line_Item) {
3199
+						$grand_total->save_this_and_descendants_to_txn();
3200
+					}
3201
+				}
3202
+				if (! $transaction instanceof EE_Transaction) {
3203
+					$query_args = array(
3204
+						'action'                  => 'new_registration',
3205
+						'processing_registration' => 2,
3206
+						'event_id'                => $this->_reg_event->ID(),
3207
+						'uts'                     => time(),
3208
+					);
3209
+					if (defined('DOING_AJAX')) {
3210
+						// display registration form again because there are errors (maybe validation?)
3211
+						$this->new_registration();
3212
+						return;
3213
+					} else {
3214
+						$this->_redirect_after_action(
3215
+							false,
3216
+							'',
3217
+							'',
3218
+							$query_args,
3219
+							true
3220
+						);
3221
+						return;
3222
+					}
3223
+				}
3224
+				// maybe update status, and make sure to save transaction if not done already
3225
+				if (! $transaction->update_status_based_on_total_paid()) {
3226
+					$transaction->save();
3227
+				}
3228
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3229
+				$this->_req_data = array();
3230
+				$query_args = array(
3231
+					'action'        => 'redirect_to_txn',
3232
+					'TXN_ID'        => $transaction->ID(),
3233
+					'EVT_ID'        => $this->_reg_event->ID(),
3234
+					'event_name'    => urlencode($this->_reg_event->name()),
3235
+					'redirect_from' => 'new_registration',
3236
+				);
3237
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3238
+				break;
3239
+		}
3240
+		// what are you looking here for?  Should be nothing to do at this point.
3241
+	}
3242
+
3243
+
3244
+	/**
3245
+	 * redirect_to_txn
3246
+	 *
3247
+	 * @access public
3248
+	 * @return void
3249
+	 * @throws EE_Error
3250
+	 * @throws InvalidArgumentException
3251
+	 * @throws InvalidDataTypeException
3252
+	 * @throws InvalidInterfaceException
3253
+	 */
3254
+	public function redirect_to_txn()
3255
+	{
3256
+		EE_System::do_not_cache();
3257
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3258
+		$query_args = array(
3259
+			'action' => 'view_transaction',
3260
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3261
+			'page'   => 'espresso_transactions',
3262
+		);
3263
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3264
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3265
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3266
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3267
+		}
3268
+		EE_Error::add_success(
3269
+			esc_html__(
3270
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3271
+				'event_espresso'
3272
+			)
3273
+		);
3274
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3275
+	}
3276
+
3277
+
3278
+	/**
3279
+	 *        generates HTML for the Attendee Contact List
3280
+	 *
3281
+	 * @access protected
3282
+	 * @return void
3283
+	 */
3284
+	protected function _attendee_contact_list_table()
3285
+	{
3286
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3287
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3288
+		$this->display_admin_list_table_page_with_no_sidebar();
3289
+	}
3290
+
3291
+
3292
+	/**
3293
+	 *        get_attendees
3294
+	 *
3295
+	 * @param      $per_page
3296
+	 * @param bool $count whether to return count or data.
3297
+	 * @param bool $trash
3298
+	 * @return array
3299
+	 * @throws EE_Error
3300
+	 * @throws InvalidArgumentException
3301
+	 * @throws InvalidDataTypeException
3302
+	 * @throws InvalidInterfaceException
3303
+	 * @access public
3304
+	 */
3305
+	public function get_attendees($per_page, $count = false, $trash = false)
3306
+	{
3307
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3308
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3309
+		$ATT_MDL = EEM_Attendee::instance();
3310
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3311
+		switch ($this->_req_data['orderby']) {
3312
+			case 'ATT_ID':
3313
+				$orderby = 'ATT_ID';
3314
+				break;
3315
+			case 'ATT_fname':
3316
+				$orderby = 'ATT_fname';
3317
+				break;
3318
+			case 'ATT_email':
3319
+				$orderby = 'ATT_email';
3320
+				break;
3321
+			case 'ATT_city':
3322
+				$orderby = 'ATT_city';
3323
+				break;
3324
+			case 'STA_ID':
3325
+				$orderby = 'STA_ID';
3326
+				break;
3327
+			case 'CNT_ID':
3328
+				$orderby = 'CNT_ID';
3329
+				break;
3330
+			case 'Registration_Count':
3331
+				$orderby = 'Registration_Count';
3332
+				break;
3333
+			default:
3334
+				$orderby = 'ATT_lname';
3335
+		}
3336
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3337
+			? $this->_req_data['order']
3338
+			: 'ASC';
3339
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3340
+			? $this->_req_data['paged']
3341
+			: 1;
3342
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3343
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3344
+			? $this->_req_data['perpage']
3345
+			: $per_page;
3346
+		$_where = array();
3347
+		if (! empty($this->_req_data['s'])) {
3348
+			$sstr = '%' . $this->_req_data['s'] . '%';
3349
+			$_where['OR'] = array(
3350
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3351
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3352
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3353
+				'ATT_fname'                         => array('LIKE', $sstr),
3354
+				'ATT_lname'                         => array('LIKE', $sstr),
3355
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3356
+				'ATT_email'                         => array('LIKE', $sstr),
3357
+				'ATT_address'                       => array('LIKE', $sstr),
3358
+				'ATT_address2'                      => array('LIKE', $sstr),
3359
+				'ATT_city'                          => array('LIKE', $sstr),
3360
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3361
+				'State.STA_name'                    => array('LIKE', $sstr),
3362
+				'ATT_phone'                         => array('LIKE', $sstr),
3363
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3364
+				'Registration.REG_code'             => array('LIKE', $sstr),
3365
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3366
+			);
3367
+		}
3368
+		$offset = ($current_page - 1) * $per_page;
3369
+		$limit = $count ? null : array($offset, $per_page);
3370
+		$query_args = array(
3371
+			$_where,
3372
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3373
+			'limit'         => $limit,
3374
+		);
3375
+		if (! $count) {
3376
+			$query_args['order_by'] = array($orderby => $sort);
3377
+		}
3378
+		if ($trash) {
3379
+			$query_args[0]['status'] = array('!=', 'publish');
3380
+			$all_attendees = $count
3381
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3382
+				: $ATT_MDL->get_all($query_args);
3383
+		} else {
3384
+			$query_args[0]['status'] = array('IN', array('publish'));
3385
+			$all_attendees = $count
3386
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3387
+				: $ATT_MDL->get_all($query_args);
3388
+		}
3389
+		return $all_attendees;
3390
+	}
3391
+
3392
+
3393
+	/**
3394
+	 * This is just taking care of resending the registration confirmation
3395
+	 *
3396
+	 * @access protected
3397
+	 * @return void
3398
+	 */
3399
+	protected function _resend_registration()
3400
+	{
3401
+		$this->_process_resend_registration();
3402
+		$query_args = isset($this->_req_data['redirect_to'])
3403
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3404
+			: array('action' => 'default');
3405
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3406
+	}
3407
+
3408
+	/**
3409
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3410
+	 * to use when selecting registrations
3411
+	 *
3412
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3413
+	 *                                                     the query parameters from the request
3414
+	 * @return void ends the request with a redirect or download
3415
+	 */
3416
+	public function _registrations_report_base($method_name_for_getting_query_params)
3417
+	{
3418
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3419
+			wp_redirect(
3420
+				EE_Admin_Page::add_query_args_and_nonce(
3421
+					array(
3422
+						'page'        => 'espresso_batch',
3423
+						'batch'       => 'file',
3424
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3425
+						'filters'     => urlencode(
3426
+							serialize(
3427
+								call_user_func(
3428
+									array($this, $method_name_for_getting_query_params),
3429
+									EEH_Array::is_set(
3430
+										$this->_req_data,
3431
+										'filters',
3432
+										array()
3433
+									)
3434
+								)
3435
+							)
3436
+						),
3437
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3438
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3439
+						'return_url'  => urlencode($this->_req_data['return_url']),
3440
+					)
3441
+				)
3442
+			);
3443
+		} else {
3444
+			$new_request_args = array(
3445
+				'export' => 'report',
3446
+				'action' => 'registrations_report_for_event',
3447
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3448
+			);
3449
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3450
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3451
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3452
+				$EE_Export = EE_Export::instance($this->_req_data);
3453
+				$EE_Export->export();
3454
+			}
3455
+		}
3456
+	}
3457
+
3458
+
3459
+	/**
3460
+	 * Creates a registration report using only query parameters in the request
3461
+	 *
3462
+	 * @return void
3463
+	 */
3464
+	public function _registrations_report()
3465
+	{
3466
+		$this->_registrations_report_base('_get_registration_query_parameters');
3467
+	}
3468
+
3469
+
3470
+	public function _contact_list_export()
3471
+	{
3472
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3473
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3474
+			$EE_Export = EE_Export::instance($this->_req_data);
3475
+			$EE_Export->export_attendees();
3476
+		}
3477
+	}
3478
+
3479
+
3480
+	public function _contact_list_report()
3481
+	{
3482
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3483
+			wp_redirect(
3484
+				EE_Admin_Page::add_query_args_and_nonce(
3485
+					array(
3486
+						'page'        => 'espresso_batch',
3487
+						'batch'       => 'file',
3488
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3489
+						'return_url'  => urlencode($this->_req_data['return_url']),
3490
+					)
3491
+				)
3492
+			);
3493
+		} else {
3494
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3495
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3496
+				$EE_Export = EE_Export::instance($this->_req_data);
3497
+				$EE_Export->report_attendees();
3498
+			}
3499
+		}
3500
+	}
3501
+
3502
+
3503
+
3504
+
3505
+
3506
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3507
+	/**
3508
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3509
+	 *
3510
+	 * @return void
3511
+	 * @throws EE_Error
3512
+	 * @throws InvalidArgumentException
3513
+	 * @throws InvalidDataTypeException
3514
+	 * @throws InvalidInterfaceException
3515
+	 */
3516
+	protected function _duplicate_attendee()
3517
+	{
3518
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3519
+		// verify we have necessary info
3520
+		if (empty($this->_req_data['_REG_ID'])) {
3521
+			EE_Error::add_error(
3522
+				esc_html__(
3523
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3524
+					'event_espresso'
3525
+				),
3526
+				__FILE__,
3527
+				__LINE__,
3528
+				__FUNCTION__
3529
+			);
3530
+			$query_args = array('action' => $action);
3531
+			$this->_redirect_after_action('', '', '', $query_args, true);
3532
+		}
3533
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3534
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3535
+		$attendee = $registration->attendee();
3536
+		// remove relation of existing attendee on registration
3537
+		$registration->_remove_relation_to($attendee, 'Attendee');
3538
+		// new attendee
3539
+		$new_attendee = clone $attendee;
3540
+		$new_attendee->set('ATT_ID', 0);
3541
+		$new_attendee->save();
3542
+		// add new attendee to reg
3543
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3544
+		EE_Error::add_success(
3545
+			esc_html__(
3546
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3547
+				'event_espresso'
3548
+			)
3549
+		);
3550
+		// redirect to edit page for attendee
3551
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3552
+		$this->_redirect_after_action('', '', '', $query_args, true);
3553
+	}
3554
+
3555
+
3556
+	/**
3557
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3558
+	 *
3559
+	 * @param int     $post_id
3560
+	 * @param WP_POST $post
3561
+	 * @throws DomainException
3562
+	 * @throws EE_Error
3563
+	 * @throws InvalidArgumentException
3564
+	 * @throws InvalidDataTypeException
3565
+	 * @throws InvalidInterfaceException
3566
+	 * @throws LogicException
3567
+	 * @throws InvalidFormSubmissionException
3568
+	 */
3569
+	protected function _insert_update_cpt_item($post_id, $post)
3570
+	{
3571
+		$success = true;
3572
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3573
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3574
+			: null;
3575
+		// for attendee updates
3576
+		if ($attendee instanceof EE_Attendee) {
3577
+			// note we should only be UPDATING attendees at this point.
3578
+			$updated_fields = array(
3579
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3580
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3581
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3582
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3583
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3584
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3585
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3586
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3587
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3588
+			);
3589
+			foreach ($updated_fields as $field => $value) {
3590
+				$attendee->set($field, $value);
3591
+			}
3592
+
3593
+			// process contact details metabox form handler (which will also save the attendee)
3594
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3595
+			$success = $contact_details_form->process($this->_req_data);
3596
+
3597
+			$attendee_update_callbacks = apply_filters(
3598
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3599
+				array()
3600
+			);
3601
+			foreach ($attendee_update_callbacks as $a_callback) {
3602
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3603
+					throw new EE_Error(
3604
+						sprintf(
3605
+							esc_html__(
3606
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3607
+								'event_espresso'
3608
+							),
3609
+							$a_callback
3610
+						)
3611
+					);
3612
+				}
3613
+			}
3614
+		}
3615
+
3616
+		if ($success === false) {
3617
+			EE_Error::add_error(
3618
+				esc_html__(
3619
+					'Something went wrong with updating the meta table data for the registration.',
3620
+					'event_espresso'
3621
+				),
3622
+				__FILE__,
3623
+				__FUNCTION__,
3624
+				__LINE__
3625
+			);
3626
+		}
3627
+	}
3628
+
3629
+
3630
+	public function trash_cpt_item($post_id)
3631
+	{
3632
+	}
3633
+
3634
+
3635
+	public function delete_cpt_item($post_id)
3636
+	{
3637
+	}
3638
+
3639
+
3640
+	public function restore_cpt_item($post_id)
3641
+	{
3642
+	}
3643
+
3644
+
3645
+	protected function _restore_cpt_item($post_id, $revision_id)
3646
+	{
3647
+	}
3648
+
3649
+
3650
+	public function attendee_editor_metaboxes()
3651
+	{
3652
+		$this->verify_cpt_object();
3653
+		remove_meta_box(
3654
+			'postexcerpt',
3655
+			esc_html__('Excerpt', 'event_espresso'),
3656
+			'post_excerpt_meta_box',
3657
+			$this->_cpt_routes[ $this->_req_action ],
3658
+			'normal',
3659
+			'core'
3660
+		);
3661
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3662
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3663
+			add_meta_box(
3664
+				'postexcerpt',
3665
+				esc_html__('Short Biography', 'event_espresso'),
3666
+				'post_excerpt_meta_box',
3667
+				$this->_cpt_routes[ $this->_req_action ],
3668
+				'normal'
3669
+			);
3670
+		}
3671
+		if (post_type_supports('espresso_attendees', 'comments')) {
3672
+			add_meta_box(
3673
+				'commentsdiv',
3674
+				esc_html__('Notes on the Contact', 'event_espresso'),
3675
+				'post_comment_meta_box',
3676
+				$this->_cpt_routes[ $this->_req_action ],
3677
+				'normal',
3678
+				'core'
3679
+			);
3680
+		}
3681
+		add_meta_box(
3682
+			'attendee_contact_info',
3683
+			esc_html__('Contact Info', 'event_espresso'),
3684
+			array($this, 'attendee_contact_info'),
3685
+			$this->_cpt_routes[ $this->_req_action ],
3686
+			'side',
3687
+			'core'
3688
+		);
3689
+		add_meta_box(
3690
+			'attendee_details_address',
3691
+			esc_html__('Address Details', 'event_espresso'),
3692
+			array($this, 'attendee_address_details'),
3693
+			$this->_cpt_routes[ $this->_req_action ],
3694
+			'normal',
3695
+			'core'
3696
+		);
3697
+		add_meta_box(
3698
+			'attendee_registrations',
3699
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3700
+			array($this, 'attendee_registrations_meta_box'),
3701
+			$this->_cpt_routes[ $this->_req_action ],
3702
+			'normal',
3703
+			'high'
3704
+		);
3705
+	}
3706
+
3707
+
3708
+	/**
3709
+	 * Metabox for attendee contact info
3710
+	 *
3711
+	 * @param  WP_Post $post wp post object
3712
+	 * @return string attendee contact info ( and form )
3713
+	 * @throws EE_Error
3714
+	 * @throws InvalidArgumentException
3715
+	 * @throws InvalidDataTypeException
3716
+	 * @throws InvalidInterfaceException
3717
+	 * @throws LogicException
3718
+	 * @throws DomainException
3719
+	 */
3720
+	public function attendee_contact_info($post)
3721
+	{
3722
+		// get attendee object ( should already have it )
3723
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3724
+		$form->enqueueStylesAndScripts();
3725
+		echo $form->display();
3726
+	}
3727
+
3728
+
3729
+	/**
3730
+	 * Return form handler for the contact details metabox
3731
+	 *
3732
+	 * @param EE_Attendee $attendee
3733
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3734
+	 * @throws DomainException
3735
+	 * @throws InvalidArgumentException
3736
+	 * @throws InvalidDataTypeException
3737
+	 * @throws InvalidInterfaceException
3738
+	 */
3739
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3740
+	{
3741
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3742
+	}
3743
+
3744
+
3745
+	/**
3746
+	 * Metabox for attendee details
3747
+	 *
3748
+	 * @param  WP_Post $post wp post object
3749
+	 * @throws DomainException
3750
+	 */
3751
+	public function attendee_address_details($post)
3752
+	{
3753
+		// get attendee object (should already have it)
3754
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3755
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3756
+			new EE_Question_Form_Input(
3757
+				EE_Question::new_instance(
3758
+					array(
3759
+						'QST_ID'           => 0,
3760
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3761
+						'QST_system'       => 'admin-state',
3762
+					)
3763
+				),
3764
+				EE_Answer::new_instance(
3765
+					array(
3766
+						'ANS_ID'    => 0,
3767
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3768
+					)
3769
+				),
3770
+				array(
3771
+					'input_id'       => 'STA_ID',
3772
+					'input_name'     => 'STA_ID',
3773
+					'input_prefix'   => '',
3774
+					'append_qstn_id' => false,
3775
+				)
3776
+			)
3777
+		);
3778
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3779
+			new EE_Question_Form_Input(
3780
+				EE_Question::new_instance(
3781
+					array(
3782
+						'QST_ID'           => 0,
3783
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3784
+						'QST_system'       => 'admin-country',
3785
+					)
3786
+				),
3787
+				EE_Answer::new_instance(
3788
+					array(
3789
+						'ANS_ID'    => 0,
3790
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3791
+					)
3792
+				),
3793
+				array(
3794
+					'input_id'       => 'CNT_ISO',
3795
+					'input_name'     => 'CNT_ISO',
3796
+					'input_prefix'   => '',
3797
+					'append_qstn_id' => false,
3798
+				)
3799
+			)
3800
+		);
3801
+		$template =
3802
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3803
+		EEH_Template::display_template($template, $this->_template_args);
3804
+	}
3805
+
3806
+
3807
+	/**
3808
+	 *        _attendee_details
3809
+	 *
3810
+	 * @access protected
3811
+	 * @param $post
3812
+	 * @return void
3813
+	 * @throws DomainException
3814
+	 * @throws EE_Error
3815
+	 */
3816
+	public function attendee_registrations_meta_box($post)
3817
+	{
3818
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3819
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3820
+		$template =
3821
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3822
+		EEH_Template::display_template($template, $this->_template_args);
3823
+	}
3824
+
3825
+
3826
+	/**
3827
+	 * add in the form fields for the attendee edit
3828
+	 *
3829
+	 * @param  WP_Post $post wp post object
3830
+	 * @return string html for new form.
3831
+	 * @throws DomainException
3832
+	 */
3833
+	public function after_title_form_fields($post)
3834
+	{
3835
+		if ($post->post_type == 'espresso_attendees') {
3836
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3837
+			$template_args['attendee'] = $this->_cpt_model_obj;
3838
+			EEH_Template::display_template($template, $template_args);
3839
+		}
3840
+	}
3841
+
3842
+
3843
+	/**
3844
+	 *        _trash_or_restore_attendee
3845
+	 *
3846
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3847
+	 * @return void
3848
+	 * @throws EE_Error
3849
+	 * @throws InvalidArgumentException
3850
+	 * @throws InvalidDataTypeException
3851
+	 * @throws InvalidInterfaceException
3852
+	 * @access protected
3853
+	 */
3854
+	protected function _trash_or_restore_attendees($trash = true)
3855
+	{
3856
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3857
+		$ATT_MDL = EEM_Attendee::instance();
3858
+		$success = 1;
3859
+		// Checkboxes
3860
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3861
+			// if array has more than one element than success message should be plural
3862
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3863
+			// cycle thru checkboxes
3864
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3865
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3866
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3867
+				if (! $updated) {
3868
+					$success = 0;
3869
+				}
3870
+			}
3871
+		} else {
3872
+			// grab single id and delete
3873
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3874
+			// get attendee
3875
+			$att = $ATT_MDL->get_one_by_ID($ATT_ID);
3876
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3877
+			$updated = $att->save();
3878
+			if (! $updated) {
3879
+				$success = 0;
3880
+			}
3881
+		}
3882
+		$what = $success > 1
3883
+			? esc_html__('Contacts', 'event_espresso')
3884
+			: esc_html__('Contact', 'event_espresso');
3885
+		$action_desc = $trash
3886
+			? esc_html__('moved to the trash', 'event_espresso')
3887
+			: esc_html__('restored', 'event_espresso');
3888
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3889
+	}
3890 3890
 }
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         // when adding a new registration...
66 66
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67 67
             EE_System::do_not_cache();
68
-            if (! isset($this->_req_data['processing_registration'])
68
+            if ( ! isset($this->_req_data['processing_registration'])
69 69
                 || absint($this->_req_data['processing_registration']) !== 1
70 70
             ) {
71 71
                 // and it's NOT the attendee information reg step
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
         // style
659 659
         wp_register_style(
660 660
             'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
661
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
662 662
             array('ee-admin-css'),
663 663
             EVENT_ESPRESSO_VERSION
664 664
         );
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
         // script
667 667
         wp_register_script(
668 668
             'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
669
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
670 670
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671 671
             EVENT_ESPRESSO_VERSION,
672 672
             true
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         wp_dequeue_style('espresso_reg');
705 705
         wp_register_style(
706 706
             'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
707
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
708 708
             array('ee-admin-css'),
709 709
             EVENT_ESPRESSO_VERSION
710 710
         );
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     {
717 717
         wp_register_script(
718 718
             'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
719
+            REG_ASSETS_URL.'spco_for_admin.js',
720 720
             array('underscore', 'jquery'),
721 721
             EVENT_ESPRESSO_VERSION,
722 722
             true
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         }
951 951
         $sc_items = array(
952 952
             'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_approved,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_pending_payment,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_wait_list,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_incomplete,
980 980
                     false,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 ),
983 983
             ),
984 984
             'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
986 986
                 'desc'  => EEH_Template::pretty_status(
987 987
                     EEM_Registration::status_id_not_approved,
988 988
                     false,
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
                 ),
991 991
             ),
992 992
             'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
994 994
                 'desc'  => EEH_Template::pretty_status(
995 995
                     EEM_Registration::status_id_declined,
996 996
                     false,
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
                 ),
999 999
             ),
1000 1000
             'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1002 1002
                 'desc'  => EEH_Template::pretty_status(
1003 1003
                     EEM_Registration::status_id_cancelled,
1004 1004
                     false,
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
                         'event_espresso'
1034 1034
                     ),
1035 1035
                     '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1036
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
1037 1037
                         array(
1038 1038
                             'action' => 'edit_attendee',
1039 1039
                             'post'   => $ATT_ID,
1040 1040
                         ),
1041 1041
                         REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1042
+                    ).'">'.$attendee->full_name().'</a>',
1043 1043
                     '</h3>'
1044 1044
                 );
1045 1045
             }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
                 'espresso_registrations_new_registration',
1051 1051
                 $EVT_ID
1052 1052
             )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1053
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1054 1054
                     'new_registration',
1055 1055
                     'add-registrant',
1056 1056
                     array('event_id' => $EVT_ID),
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091 1091
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092 1092
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1093
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1094 1094
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1095 1095
             }
1096 1096
         }
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
             return true;
1117 1117
         }
1118 1118
         $REG = EEM_Registration::instance();
1119
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1119
+        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120 1120
         if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121 1121
             return true;
1122 1122
         } else {
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
             'caps'                     => EEM_Registration::caps_read_admin,
1199 1199
             'default_where_conditions' => 'this_model_only',
1200 1200
         );
1201
-        if (! $count) {
1201
+        if ( ! $count) {
1202 1202
             $query_params = array_merge(
1203 1203
                 $query_params,
1204 1204
                 $this->_get_orderby_for_registrations_query(),
@@ -1219,7 +1219,7 @@  discard block
 block discarded – undo
1219 1219
     protected function addAttendeeIdToWhereConditions(array $request)
1220 1220
     {
1221 1221
         $where = array();
1222
-        if (! empty($request['ATT_ID'])) {
1222
+        if ( ! empty($request['ATT_ID'])) {
1223 1223
             $where['ATT_ID'] = absint($request['ATT_ID']);
1224 1224
         }
1225 1225
         return $where;
@@ -1235,7 +1235,7 @@  discard block
 block discarded – undo
1235 1235
     protected function _add_event_id_to_where_conditions(array $request)
1236 1236
     {
1237 1237
         $where = array();
1238
-        if (! empty($request['event_id'])) {
1238
+        if ( ! empty($request['event_id'])) {
1239 1239
             $where['EVT_ID'] = absint($request['event_id']);
1240 1240
         }
1241 1241
         return $where;
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
     protected function _add_category_id_to_where_conditions(array $request)
1252 1252
     {
1253 1253
         $where = array();
1254
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1254
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1255 1255
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1256 1256
         }
1257 1257
         return $where;
@@ -1267,10 +1267,10 @@  discard block
 block discarded – undo
1267 1267
     protected function _add_datetime_id_to_where_conditions(array $request)
1268 1268
     {
1269 1269
         $where = array();
1270
-        if (! empty($request['datetime_id'])) {
1270
+        if ( ! empty($request['datetime_id'])) {
1271 1271
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1272 1272
         }
1273
-        if (! empty($request['DTT_ID'])) {
1273
+        if ( ! empty($request['DTT_ID'])) {
1274 1274
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1275 1275
         }
1276 1276
         return $where;
@@ -1296,7 +1296,7 @@  discard block
 block discarded – undo
1296 1296
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1297 1297
          * UNLESS viewing trashed registrations.
1298 1298
          */
1299
-        if (! empty($registration_status)) {
1299
+        if ( ! empty($registration_status)) {
1300 1300
             $where['STS_ID'] = $registration_status;
1301 1301
         } else {
1302 1302
             // make sure we exclude incomplete registrations, but only if not trashed.
@@ -1339,12 +1339,12 @@  discard block
 block discarded – undo
1339 1339
                 array(
1340 1340
                     EEM_Registration::instance()->convert_datetime_for_query(
1341 1341
                         'REG_date',
1342
-                        $now . ' 00:00:00',
1342
+                        $now.' 00:00:00',
1343 1343
                         'Y-m-d H:i:s'
1344 1344
                     ),
1345 1345
                     EEM_Registration::instance()->convert_datetime_for_query(
1346 1346
                         'REG_date',
1347
-                        $now . ' 23:59:59',
1347
+                        $now.' 23:59:59',
1348 1348
                         'Y-m-d H:i:s'
1349 1349
                     ),
1350 1350
                 ),
@@ -1357,12 +1357,12 @@  discard block
 block discarded – undo
1357 1357
                 array(
1358 1358
                     EEM_Registration::instance()->convert_datetime_for_query(
1359 1359
                         'REG_date',
1360
-                        $current_year_and_month . '-01 00:00:00',
1360
+                        $current_year_and_month.'-01 00:00:00',
1361 1361
                         'Y-m-d H:i:s'
1362 1362
                     ),
1363 1363
                     EEM_Registration::instance()->convert_datetime_for_query(
1364 1364
                         'REG_date',
1365
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1365
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1366 1366
                         'Y-m-d H:i:s'
1367 1367
                     ),
1368 1368
                 ),
@@ -1377,18 +1377,18 @@  discard block
 block discarded – undo
1377 1377
                 : '';
1378 1378
             // if there is not a month or year then we can't go further
1379 1379
             if ($month_requested && $year_requested) {
1380
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1380
+                $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1381 1381
                 $where['REG_date'] = array(
1382 1382
                     'BETWEEN',
1383 1383
                     array(
1384 1384
                         EEM_Registration::instance()->convert_datetime_for_query(
1385 1385
                             'REG_date',
1386
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1386
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1387 1387
                             'Y-m-d H:i:s'
1388 1388
                         ),
1389 1389
                         EEM_Registration::instance()->convert_datetime_for_query(
1390 1390
                             'REG_date',
1391
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1391
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1392 1392
                             'Y-m-d H:i:s'
1393 1393
                         ),
1394 1394
                     ),
@@ -1408,8 +1408,8 @@  discard block
 block discarded – undo
1408 1408
     protected function _add_search_to_where_conditions(array $request)
1409 1409
     {
1410 1410
         $where = array();
1411
-        if (! empty($request['s'])) {
1412
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1411
+        if ( ! empty($request['s'])) {
1412
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1413 1413
             $where['OR*search_conditions'] = array(
1414 1414
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1415 1415
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1645,7 +1645,7 @@  discard block
 block discarded – undo
1645 1645
                 )
1646 1646
                 : '';
1647 1647
             // grab header
1648
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1648
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1649 1649
             $this->_template_args['REG_ID'] = $this->_registration->ID();
1650 1650
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1651 1651
                 $template_path,
@@ -1782,7 +1782,7 @@  discard block
 block discarded – undo
1782 1782
                             EEH_HTML::strong(
1783 1783
                                 $this->_registration->pretty_status(),
1784 1784
                                 '',
1785
-                                'status-' . $this->_registration->status_ID(),
1785
+                                'status-'.$this->_registration->status_ID(),
1786 1786
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1787 1787
                             )
1788 1788
                         )
@@ -1837,14 +1837,14 @@  discard block
 block discarded – undo
1837 1837
     protected function _get_reg_statuses()
1838 1838
     {
1839 1839
         $reg_status_array = EEM_Registration::instance()->reg_status_array();
1840
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1840
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1841 1841
         // get current reg status
1842 1842
         $current_status = $this->_registration->status_ID();
1843 1843
         // is registration for free event? This will determine whether to display the pending payment option
1844 1844
         if ($current_status !== EEM_Registration::status_id_pending_payment
1845 1845
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1846 1846
         ) {
1847
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1847
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1848 1848
         }
1849 1849
         return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1850 1850
     }
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
         $success = false;
1937 1937
         // typecast $REG_IDs
1938 1938
         $REG_IDs = (array) $REG_IDs;
1939
-        if (! empty($REG_IDs)) {
1939
+        if ( ! empty($REG_IDs)) {
1940 1940
             $success = true;
1941 1941
             // set default status if none is passed
1942 1942
             $status = $status ? $status : EEM_Registration::status_id_pending_payment;
@@ -2016,11 +2016,11 @@  discard block
 block discarded – undo
2016 2016
         // unset nonces
2017 2017
         foreach ($this->_req_data as $ref => $value) {
2018 2018
             if (strpos($ref, 'nonce') !== false) {
2019
-                unset($this->_req_data[ $ref ]);
2019
+                unset($this->_req_data[$ref]);
2020 2020
                 continue;
2021 2021
             }
2022 2022
             $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2023
-            $this->_req_data[ $ref ] = $value;
2023
+            $this->_req_data[$ref] = $value;
2024 2024
         }
2025 2025
         // merge request vars so that the reloaded list table contains any existing filter query params
2026 2026
         $route = array_merge($this->_req_data, $route);
@@ -2094,7 +2094,7 @@  discard block
 block discarded – undo
2094 2094
             $action,
2095 2095
             $notify
2096 2096
         );
2097
-        $method = $action . '_registration';
2097
+        $method = $action.'_registration';
2098 2098
         if (method_exists($this, $method)) {
2099 2099
             $this->$method($notify);
2100 2100
         }
@@ -2325,7 +2325,7 @@  discard block
 block discarded – undo
2325 2325
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2326 2326
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2327 2327
         $template_path =
2328
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2328
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2329 2329
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2330 2330
     }
2331 2331
 
@@ -2358,7 +2358,7 @@  discard block
 block discarded – undo
2358 2358
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2359 2359
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2360 2360
             $template_path =
2361
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2361
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2362 2362
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2363 2363
         }
2364 2364
     }
@@ -2375,7 +2375,7 @@  discard block
 block discarded – undo
2375 2375
     public function form_before_question_group($output)
2376 2376
     {
2377 2377
         EE_Error::doing_it_wrong(
2378
-            __CLASS__ . '::' . __FUNCTION__,
2378
+            __CLASS__.'::'.__FUNCTION__,
2379 2379
             esc_html__(
2380 2380
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2381 2381
                 'event_espresso'
@@ -2400,7 +2400,7 @@  discard block
 block discarded – undo
2400 2400
     public function form_after_question_group($output)
2401 2401
     {
2402 2402
         EE_Error::doing_it_wrong(
2403
-            __CLASS__ . '::' . __FUNCTION__,
2403
+            __CLASS__.'::'.__FUNCTION__,
2404 2404
             esc_html__(
2405 2405
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2406 2406
                 'event_espresso'
@@ -2438,7 +2438,7 @@  discard block
 block discarded – undo
2438 2438
     public function form_form_field_label_wrap($label)
2439 2439
     {
2440 2440
         EE_Error::doing_it_wrong(
2441
-            __CLASS__ . '::' . __FUNCTION__,
2441
+            __CLASS__.'::'.__FUNCTION__,
2442 2442
             esc_html__(
2443 2443
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2444 2444
                 'event_espresso'
@@ -2448,7 +2448,7 @@  discard block
 block discarded – undo
2448 2448
         return '
2449 2449
 			<tr>
2450 2450
 				<th>
2451
-					' . $label . '
2451
+					' . $label.'
2452 2452
 				</th>';
2453 2453
     }
2454 2454
 
@@ -2464,7 +2464,7 @@  discard block
 block discarded – undo
2464 2464
     public function form_form_field_input__wrap($input)
2465 2465
     {
2466 2466
         EE_Error::doing_it_wrong(
2467
-            __CLASS__ . '::' . __FUNCTION__,
2467
+            __CLASS__.'::'.__FUNCTION__,
2468 2468
             esc_html__(
2469 2469
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2470 2470
                 'event_espresso'
@@ -2473,7 +2473,7 @@  discard block
 block discarded – undo
2473 2473
         );
2474 2474
         return '
2475 2475
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2476
-					' . $input . '
2476
+					' . $input.'
2477 2477
 				</td>
2478 2478
 			</tr>';
2479 2479
     }
@@ -2517,8 +2517,8 @@  discard block
 block discarded – undo
2517 2517
      */
2518 2518
     protected function _get_reg_custom_questions_form($REG_ID)
2519 2519
     {
2520
-        if (! $this->_reg_custom_questions_form) {
2521
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2520
+        if ( ! $this->_reg_custom_questions_form) {
2521
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2522 2522
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2523 2523
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2524 2524
             );
@@ -2541,7 +2541,7 @@  discard block
 block discarded – undo
2541 2541
      */
2542 2542
     private function _save_reg_custom_questions_form($REG_ID = false)
2543 2543
     {
2544
-        if (! $REG_ID) {
2544
+        if ( ! $REG_ID) {
2545 2545
             EE_Error::add_error(
2546 2546
                 esc_html__(
2547 2547
                     'An error occurred. No registration ID was received.',
@@ -2632,28 +2632,28 @@  discard block
 block discarded – undo
2632 2632
                     ? $registration->attendee()
2633 2633
                     : EEM_Attendee::instance()
2634 2634
                                   ->create_default_object();
2635
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2636
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2637
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2638
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2639
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2640
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2635
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID();
2636
+                $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();
2637
+                $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();
2638
+                $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();
2639
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2640
+                $this->_template_args['attendees'][$att_nmbr]['address'] = implode(
2641 2641
                     ', ',
2642 2642
                     $attendee->full_address_as_array()
2643 2643
                 );
2644
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2644
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2645 2645
                     array(
2646 2646
                         'action' => 'edit_attendee',
2647 2647
                         'post'   => $attendee->ID(),
2648 2648
                     ),
2649 2649
                     REG_ADMIN_URL
2650 2650
                 );
2651
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj()->name();
2651
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2652 2652
                 $att_nmbr++;
2653 2653
             }
2654 2654
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2655 2655
         }
2656
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2656
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2657 2657
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2658 2658
     }
2659 2659
 
@@ -2677,11 +2677,11 @@  discard block
 block discarded – undo
2677 2677
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2678 2678
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2679 2679
         // primary registration object (that way we know if we need to show create button or not)
2680
-        if (! $this->_registration->is_primary_registrant()) {
2680
+        if ( ! $this->_registration->is_primary_registrant()) {
2681 2681
             $primary_registration = $this->_registration->get_primary_registration();
2682 2682
             $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2683 2683
                 : null;
2684
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2684
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2685 2685
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2686 2686
                 // custom attendee object so let's not worry about the primary reg.
2687 2687
                 $primary_registration = null;
@@ -2715,7 +2715,7 @@  discard block
 block discarded – undo
2715 2715
             ) : '';
2716 2716
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2717 2717
         $this->_template_args['att_check'] = $att_check;
2718
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2718
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2719 2719
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2720 2720
     }
2721 2721
 
@@ -2753,7 +2753,7 @@  discard block
 block discarded – undo
2753 2753
         $success = 0;
2754 2754
         $overwrite_msgs = false;
2755 2755
         // Checkboxes
2756
-        if (! is_array($this->_req_data['_REG_ID'])) {
2756
+        if ( ! is_array($this->_req_data['_REG_ID'])) {
2757 2757
             $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2758 2758
         }
2759 2759
         $reg_count = count($this->_req_data['_REG_ID']);
@@ -2762,7 +2762,7 @@  discard block
 block discarded – undo
2762 2762
             /** @var EE_Registration $REG */
2763 2763
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2764 2764
             $payments = $REG->registration_payments();
2765
-            if (! empty($payments)) {
2765
+            if ( ! empty($payments)) {
2766 2766
                 $name = $REG->attendee() instanceof EE_Attendee
2767 2767
                     ? $REG->attendee()->full_name()
2768 2768
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2823,17 +2823,17 @@  discard block
 block discarded – undo
2823 2823
         $REG_MDL = EEM_Registration::instance();
2824 2824
         $success = 1;
2825 2825
         // Checkboxes
2826
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2826
+        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2827 2827
             // if array has more than one element than success message should be plural
2828 2828
             $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2829 2829
             // cycle thru checkboxes
2830 2830
             while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2831 2831
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2832
-                if (! $REG instanceof EE_Registration) {
2832
+                if ( ! $REG instanceof EE_Registration) {
2833 2833
                     continue;
2834 2834
                 }
2835 2835
                 $deleted = $this->_delete_registration($REG);
2836
-                if (! $deleted) {
2836
+                if ( ! $deleted) {
2837 2837
                     $success = 0;
2838 2838
                 }
2839 2839
             }
@@ -2842,7 +2842,7 @@  discard block
 block discarded – undo
2842 2842
             $REG_ID = $this->_req_data['_REG_ID'];
2843 2843
             $REG = $REG_MDL->get_one_by_ID($REG_ID);
2844 2844
             $deleted = $this->_delete_registration($REG);
2845
-            if (! $deleted) {
2845
+            if ( ! $deleted) {
2846 2846
                 $success = 0;
2847 2847
             }
2848 2848
         }
@@ -2876,11 +2876,11 @@  discard block
 block discarded – undo
2876 2876
         $REGS = $TXN->get_many_related('Registration');
2877 2877
         $all_trashed = true;
2878 2878
         foreach ($REGS as $registration) {
2879
-            if (! $registration->get('REG_deleted')) {
2879
+            if ( ! $registration->get('REG_deleted')) {
2880 2880
                 $all_trashed = false;
2881 2881
             }
2882 2882
         }
2883
-        if (! $all_trashed) {
2883
+        if ( ! $all_trashed) {
2884 2884
             EE_Error::add_error(
2885 2885
                 esc_html__(
2886 2886
                     'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
@@ -2939,7 +2939,7 @@  discard block
 block discarded – undo
2939 2939
      */
2940 2940
     public function new_registration()
2941 2941
     {
2942
-        if (! $this->_set_reg_event()) {
2942
+        if ( ! $this->_set_reg_event()) {
2943 2943
             throw new EE_Error(
2944 2944
                 esc_html__(
2945 2945
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2949,8 +2949,8 @@  discard block
 block discarded – undo
2949 2949
         }
2950 2950
         EE_Registry::instance()->REQ->set_espresso_page(true);
2951 2951
         // gotta start with a clean slate if we're not coming here via ajax
2952
-        if (! defined('DOING_AJAX')
2953
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2952
+        if ( ! defined('DOING_AJAX')
2953
+            && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2954 2954
         ) {
2955 2955
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2956 2956
         }
@@ -2983,7 +2983,7 @@  discard block
 block discarded – undo
2983 2983
         }
2984 2984
         // grab header
2985 2985
         $template_path =
2986
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2986
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2987 2987
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2988 2988
             $template_path,
2989 2989
             $this->_template_args,
@@ -3024,7 +3024,7 @@  discard block
 block discarded – undo
3024 3024
                 '</b>'
3025 3025
             );
3026 3026
             return '
3027
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3027
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
3028 3028
 	<script >
3029 3029
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
3030 3030
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -3092,7 +3092,7 @@  discard block
 block discarded – undo
3092 3092
         // we come back to the process_registration_step route.
3093 3093
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3094 3094
         return EEH_Template::display_template(
3095
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3095
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
3096 3096
             $template_args,
3097 3097
             true
3098 3098
         );
@@ -3114,8 +3114,8 @@  discard block
 block discarded – undo
3114 3114
         if (is_object($this->_reg_event)) {
3115 3115
             return true;
3116 3116
         }
3117
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3118
-        if (! $EVT_ID) {
3117
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3118
+        if ( ! $EVT_ID) {
3119 3119
             return false;
3120 3120
         }
3121 3121
         $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
@@ -3147,8 +3147,8 @@  discard block
 block discarded – undo
3147 3147
         $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3148 3148
         // if doing ajax then we need to verify the nonce
3149 3149
         if (defined('DOING_AJAX')) {
3150
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3151
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3150
+            $nonce = isset($this->_req_data[$this->_req_nonce])
3151
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3152 3152
             $this->_verify_nonce($nonce, $this->_req_nonce);
3153 3153
         }
3154 3154
         switch ($step) {
@@ -3184,7 +3184,7 @@  discard block
 block discarded – undo
3184 3184
                 }
3185 3185
                 break;
3186 3186
             case 'questions':
3187
-                if (! isset(
3187
+                if ( ! isset(
3188 3188
                     $this->_req_data['txn_reg_status_change'],
3189 3189
                     $this->_req_data['txn_reg_status_change']['send_notifications']
3190 3190
                 )
@@ -3199,7 +3199,7 @@  discard block
 block discarded – undo
3199 3199
                         $grand_total->save_this_and_descendants_to_txn();
3200 3200
                     }
3201 3201
                 }
3202
-                if (! $transaction instanceof EE_Transaction) {
3202
+                if ( ! $transaction instanceof EE_Transaction) {
3203 3203
                     $query_args = array(
3204 3204
                         'action'                  => 'new_registration',
3205 3205
                         'processing_registration' => 2,
@@ -3222,7 +3222,7 @@  discard block
 block discarded – undo
3222 3222
                     }
3223 3223
                 }
3224 3224
                 // maybe update status, and make sure to save transaction if not done already
3225
-                if (! $transaction->update_status_based_on_total_paid()) {
3225
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3226 3226
                     $transaction->save();
3227 3227
                 }
3228 3228
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3305,7 +3305,7 @@  discard block
 block discarded – undo
3305 3305
     public function get_attendees($per_page, $count = false, $trash = false)
3306 3306
     {
3307 3307
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3308
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3308
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3309 3309
         $ATT_MDL = EEM_Attendee::instance();
3310 3310
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3311 3311
         switch ($this->_req_data['orderby']) {
@@ -3344,8 +3344,8 @@  discard block
 block discarded – undo
3344 3344
             ? $this->_req_data['perpage']
3345 3345
             : $per_page;
3346 3346
         $_where = array();
3347
-        if (! empty($this->_req_data['s'])) {
3348
-            $sstr = '%' . $this->_req_data['s'] . '%';
3347
+        if ( ! empty($this->_req_data['s'])) {
3348
+            $sstr = '%'.$this->_req_data['s'].'%';
3349 3349
             $_where['OR'] = array(
3350 3350
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3351 3351
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3372,7 +3372,7 @@  discard block
 block discarded – undo
3372 3372
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3373 3373
             'limit'         => $limit,
3374 3374
         );
3375
-        if (! $count) {
3375
+        if ( ! $count) {
3376 3376
             $query_args['order_by'] = array($orderby => $sort);
3377 3377
         }
3378 3378
         if ($trash) {
@@ -3415,7 +3415,7 @@  discard block
 block discarded – undo
3415 3415
      */
3416 3416
     public function _registrations_report_base($method_name_for_getting_query_params)
3417 3417
     {
3418
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3418
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3419 3419
             wp_redirect(
3420 3420
                 EE_Admin_Page::add_query_args_and_nonce(
3421 3421
                     array(
@@ -3447,8 +3447,8 @@  discard block
 block discarded – undo
3447 3447
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3448 3448
             );
3449 3449
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3450
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3451
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3450
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3451
+                require_once(EE_CLASSES.'EE_Export.class.php');
3452 3452
                 $EE_Export = EE_Export::instance($this->_req_data);
3453 3453
                 $EE_Export->export();
3454 3454
             }
@@ -3469,8 +3469,8 @@  discard block
 block discarded – undo
3469 3469
 
3470 3470
     public function _contact_list_export()
3471 3471
     {
3472
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3473
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3472
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3473
+            require_once(EE_CLASSES.'EE_Export.class.php');
3474 3474
             $EE_Export = EE_Export::instance($this->_req_data);
3475 3475
             $EE_Export->export_attendees();
3476 3476
         }
@@ -3479,7 +3479,7 @@  discard block
 block discarded – undo
3479 3479
 
3480 3480
     public function _contact_list_report()
3481 3481
     {
3482
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3482
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3483 3483
             wp_redirect(
3484 3484
                 EE_Admin_Page::add_query_args_and_nonce(
3485 3485
                     array(
@@ -3491,8 +3491,8 @@  discard block
 block discarded – undo
3491 3491
                 )
3492 3492
             );
3493 3493
         } else {
3494
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3495
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3494
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3495
+                require_once(EE_CLASSES.'EE_Export.class.php');
3496 3496
                 $EE_Export = EE_Export::instance($this->_req_data);
3497 3497
                 $EE_Export->report_attendees();
3498 3498
             }
@@ -3578,7 +3578,7 @@  discard block
 block discarded – undo
3578 3578
             $updated_fields = array(
3579 3579
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3580 3580
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3581
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3581
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3582 3582
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3583 3583
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3584 3584
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3654,17 +3654,17 @@  discard block
 block discarded – undo
3654 3654
             'postexcerpt',
3655 3655
             esc_html__('Excerpt', 'event_espresso'),
3656 3656
             'post_excerpt_meta_box',
3657
-            $this->_cpt_routes[ $this->_req_action ],
3657
+            $this->_cpt_routes[$this->_req_action],
3658 3658
             'normal',
3659 3659
             'core'
3660 3660
         );
3661
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3661
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3662 3662
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3663 3663
             add_meta_box(
3664 3664
                 'postexcerpt',
3665 3665
                 esc_html__('Short Biography', 'event_espresso'),
3666 3666
                 'post_excerpt_meta_box',
3667
-                $this->_cpt_routes[ $this->_req_action ],
3667
+                $this->_cpt_routes[$this->_req_action],
3668 3668
                 'normal'
3669 3669
             );
3670 3670
         }
@@ -3673,7 +3673,7 @@  discard block
 block discarded – undo
3673 3673
                 'commentsdiv',
3674 3674
                 esc_html__('Notes on the Contact', 'event_espresso'),
3675 3675
                 'post_comment_meta_box',
3676
-                $this->_cpt_routes[ $this->_req_action ],
3676
+                $this->_cpt_routes[$this->_req_action],
3677 3677
                 'normal',
3678 3678
                 'core'
3679 3679
             );
@@ -3682,7 +3682,7 @@  discard block
 block discarded – undo
3682 3682
             'attendee_contact_info',
3683 3683
             esc_html__('Contact Info', 'event_espresso'),
3684 3684
             array($this, 'attendee_contact_info'),
3685
-            $this->_cpt_routes[ $this->_req_action ],
3685
+            $this->_cpt_routes[$this->_req_action],
3686 3686
             'side',
3687 3687
             'core'
3688 3688
         );
@@ -3690,7 +3690,7 @@  discard block
 block discarded – undo
3690 3690
             'attendee_details_address',
3691 3691
             esc_html__('Address Details', 'event_espresso'),
3692 3692
             array($this, 'attendee_address_details'),
3693
-            $this->_cpt_routes[ $this->_req_action ],
3693
+            $this->_cpt_routes[$this->_req_action],
3694 3694
             'normal',
3695 3695
             'core'
3696 3696
         );
@@ -3698,7 +3698,7 @@  discard block
 block discarded – undo
3698 3698
             'attendee_registrations',
3699 3699
             esc_html__('Registrations for this Contact', 'event_espresso'),
3700 3700
             array($this, 'attendee_registrations_meta_box'),
3701
-            $this->_cpt_routes[ $this->_req_action ],
3701
+            $this->_cpt_routes[$this->_req_action],
3702 3702
             'normal',
3703 3703
             'high'
3704 3704
         );
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
             )
3800 3800
         );
3801 3801
         $template =
3802
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3802
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3803 3803
         EEH_Template::display_template($template, $this->_template_args);
3804 3804
     }
3805 3805
 
@@ -3818,7 +3818,7 @@  discard block
 block discarded – undo
3818 3818
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3819 3819
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3820 3820
         $template =
3821
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3821
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3822 3822
         EEH_Template::display_template($template, $this->_template_args);
3823 3823
     }
3824 3824
 
@@ -3833,7 +3833,7 @@  discard block
 block discarded – undo
3833 3833
     public function after_title_form_fields($post)
3834 3834
     {
3835 3835
         if ($post->post_type == 'espresso_attendees') {
3836
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3836
+            $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3837 3837
             $template_args['attendee'] = $this->_cpt_model_obj;
3838 3838
             EEH_Template::display_template($template, $template_args);
3839 3839
         }
@@ -3857,14 +3857,14 @@  discard block
 block discarded – undo
3857 3857
         $ATT_MDL = EEM_Attendee::instance();
3858 3858
         $success = 1;
3859 3859
         // Checkboxes
3860
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3860
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3861 3861
             // if array has more than one element than success message should be plural
3862 3862
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3863 3863
             // cycle thru checkboxes
3864 3864
             while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3865 3865
                 $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3866 3866
                     : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3867
-                if (! $updated) {
3867
+                if ( ! $updated) {
3868 3868
                     $success = 0;
3869 3869
                 }
3870 3870
             }
@@ -3875,7 +3875,7 @@  discard block
 block discarded – undo
3875 3875
             $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3876 3876
             $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3877 3877
             $updated = $att->save();
3878
-            if (! $updated) {
3878
+            if ( ! $updated) {
3879 3879
                 $success = 0;
3880 3880
             }
3881 3881
         }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +386 added lines, -386 removed lines patch added patch discarded remove patch
@@ -29,405 +29,405 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
56
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
57 57
 
58
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
58
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
59 59
 
60
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
60
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
61 61
 
62
-    const JS_HANDLE_EE_CORE = 'espresso_core';
63
-
64
-    const JS_HANDLE_EE_I18N = 'eei18n';
65
-
66
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
67
-
68
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
69
-
70
-    // EE CSS assets handles
71
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
72
-
73
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
74
-
75
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
76
-
77
-    /**
78
-     * @var EE_Currency_Config $currency_config
79
-     */
80
-    protected $currency_config;
81
-
82
-    /**
83
-     * @var EE_Template_Config $template_config
84
-     */
85
-    protected $template_config;
86
-
87
-
88
-    /**
89
-     * CoreAssetRegister constructor.
90
-     *
91
-     * @param AssetCollection    $assets
92
-     * @param EE_Currency_Config $currency_config
93
-     * @param EE_Template_Config $template_config
94
-     * @param DomainInterface    $domain
95
-     * @param Registry           $registry
96
-     */
97
-    public function __construct(
98
-        AssetCollection $assets,
99
-        EE_Currency_Config $currency_config,
100
-        EE_Template_Config $template_config,
101
-        DomainInterface $domain,
102
-        Registry $registry
103
-    ) {
104
-        $this->currency_config = $currency_config;
105
-        $this->template_config = $template_config;
106
-        parent::__construct($domain, $assets, $registry);
107
-    }
108
-
109
-
110
-    /**
111
-     * @since 4.9.62.p
112
-     * @throws DuplicateCollectionIdentifierException
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidEntityException
116
-     */
117
-    public function addAssets()
118
-    {
119
-        $this->addJavascriptFiles();
120
-        $this->addStylesheetFiles();
121
-    }
122
-
123
-
124
-    /**
125
-     * @since 4.9.62.p
126
-     * @throws DuplicateCollectionIdentifierException
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidEntityException
130
-     */
131
-    public function addJavascriptFiles()
132
-    {
133
-        $this->loadCoreJs();
134
-        $this->loadJqueryValidate();
135
-        $this->loadAccountingJs();
136
-        add_action(
137
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
138
-            array($this, 'loadQtipJs')
139
-        );
140
-        $this->registerAdminAssets();
141
-    }
142
-
143
-
144
-    /**
145
-     * @since 4.9.62.p
146
-     * @throws DuplicateCollectionIdentifierException
147
-     * @throws InvalidDataTypeException
148
-     * @throws InvalidEntityException
149
-     */
150
-    public function addStylesheetFiles()
151
-    {
152
-        $this->loadCoreCss();
153
-    }
154
-
155
-
156
-    /**
157
-     * core default javascript
158
-     *
159
-     * @since 4.9.62.p
160
-     * @throws DuplicateCollectionIdentifierException
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidEntityException
164
-     */
165
-    private function loadCoreJs()
166
-    {
167
-        $this->addJavascript(
168
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
169
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
170
-        );
171
-
172
-        $this->addJavascript(
173
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
174
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
175
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
176
-        )
177
-        ->setHasInlineData();
178
-
179
-        $this->addJavascript(
180
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
181
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
182
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
183
-        );
184
-
185
-        $this->addJavascript(
186
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
187
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
188
-            array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
189
-        )
190
-        ->setRequiresTranslation();
191
-
192
-        $this->addJavascript(
193
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
194
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
195
-        )->setRequiresTranslation();
196
-
197
-        $this->addJavascript(
198
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
199
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
200
-            array(
201
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
202
-            )
203
-        )->setRequiresTranslation();
204
-
205
-        $this->addJavascript(
206
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
207
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
208
-            array(
209
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
-                CoreAssetManager::JS_HANDLE_EE_HELPERS,
211
-                'wp-components',
212
-            )
213
-        )->setRequiresTranslation();
214
-
215
-        $this->addJavascript(
216
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
217
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
218
-            array(
219
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
-                CoreAssetManager::JS_HANDLE_EE_HELPERS,
221
-                'wp-components',
222
-            )
223
-        )
224
-        ->setRequiresTranslation();
225
-
226
-        global $wp_version;
227
-        if (version_compare($wp_version, '4.4.0', '>')) {
228
-            //js.api
229
-            $this->addJavascript(
230
-                CoreAssetManager::JS_HANDLE_EE_JS_API,
231
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
232
-                array(
233
-                    CoreAssetManager::JS_HANDLE_UNDERSCORE,
234
-                    CoreAssetManager::JS_HANDLE_EE_JS_CORE
235
-                )
236
-            );
237
-            $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
238
-            $this->registry->addData(
239
-                'paths',
240
-                array(
241
-                    'rest_route' => rest_url('ee/v4.8.36/'),
242
-                    'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
243
-                    'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
62
+	const JS_HANDLE_EE_CORE = 'espresso_core';
63
+
64
+	const JS_HANDLE_EE_I18N = 'eei18n';
65
+
66
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
67
+
68
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
69
+
70
+	// EE CSS assets handles
71
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
72
+
73
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
74
+
75
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
76
+
77
+	/**
78
+	 * @var EE_Currency_Config $currency_config
79
+	 */
80
+	protected $currency_config;
81
+
82
+	/**
83
+	 * @var EE_Template_Config $template_config
84
+	 */
85
+	protected $template_config;
86
+
87
+
88
+	/**
89
+	 * CoreAssetRegister constructor.
90
+	 *
91
+	 * @param AssetCollection    $assets
92
+	 * @param EE_Currency_Config $currency_config
93
+	 * @param EE_Template_Config $template_config
94
+	 * @param DomainInterface    $domain
95
+	 * @param Registry           $registry
96
+	 */
97
+	public function __construct(
98
+		AssetCollection $assets,
99
+		EE_Currency_Config $currency_config,
100
+		EE_Template_Config $template_config,
101
+		DomainInterface $domain,
102
+		Registry $registry
103
+	) {
104
+		$this->currency_config = $currency_config;
105
+		$this->template_config = $template_config;
106
+		parent::__construct($domain, $assets, $registry);
107
+	}
108
+
109
+
110
+	/**
111
+	 * @since 4.9.62.p
112
+	 * @throws DuplicateCollectionIdentifierException
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidEntityException
116
+	 */
117
+	public function addAssets()
118
+	{
119
+		$this->addJavascriptFiles();
120
+		$this->addStylesheetFiles();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @since 4.9.62.p
126
+	 * @throws DuplicateCollectionIdentifierException
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidEntityException
130
+	 */
131
+	public function addJavascriptFiles()
132
+	{
133
+		$this->loadCoreJs();
134
+		$this->loadJqueryValidate();
135
+		$this->loadAccountingJs();
136
+		add_action(
137
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
138
+			array($this, 'loadQtipJs')
139
+		);
140
+		$this->registerAdminAssets();
141
+	}
142
+
143
+
144
+	/**
145
+	 * @since 4.9.62.p
146
+	 * @throws DuplicateCollectionIdentifierException
147
+	 * @throws InvalidDataTypeException
148
+	 * @throws InvalidEntityException
149
+	 */
150
+	public function addStylesheetFiles()
151
+	{
152
+		$this->loadCoreCss();
153
+	}
154
+
155
+
156
+	/**
157
+	 * core default javascript
158
+	 *
159
+	 * @since 4.9.62.p
160
+	 * @throws DuplicateCollectionIdentifierException
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidEntityException
164
+	 */
165
+	private function loadCoreJs()
166
+	{
167
+		$this->addJavascript(
168
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
169
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
170
+		);
171
+
172
+		$this->addJavascript(
173
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
174
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
175
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
176
+		)
177
+		->setHasInlineData();
178
+
179
+		$this->addJavascript(
180
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
181
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
182
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
183
+		);
184
+
185
+		$this->addJavascript(
186
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
187
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
188
+			array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
189
+		)
190
+		->setRequiresTranslation();
191
+
192
+		$this->addJavascript(
193
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
194
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
195
+		)->setRequiresTranslation();
196
+
197
+		$this->addJavascript(
198
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
199
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
200
+			array(
201
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
202
+			)
203
+		)->setRequiresTranslation();
204
+
205
+		$this->addJavascript(
206
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
207
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
208
+			array(
209
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
210
+				CoreAssetManager::JS_HANDLE_EE_HELPERS,
211
+				'wp-components',
212
+			)
213
+		)->setRequiresTranslation();
214
+
215
+		$this->addJavascript(
216
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
217
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
218
+			array(
219
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
+				CoreAssetManager::JS_HANDLE_EE_HELPERS,
221
+				'wp-components',
222
+			)
223
+		)
224
+		->setRequiresTranslation();
225
+
226
+		global $wp_version;
227
+		if (version_compare($wp_version, '4.4.0', '>')) {
228
+			//js.api
229
+			$this->addJavascript(
230
+				CoreAssetManager::JS_HANDLE_EE_JS_API,
231
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
232
+				array(
233
+					CoreAssetManager::JS_HANDLE_UNDERSCORE,
234
+					CoreAssetManager::JS_HANDLE_EE_JS_CORE
235
+				)
236
+			);
237
+			$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
238
+			$this->registry->addData(
239
+				'paths',
240
+				array(
241
+					'rest_route' => rest_url('ee/v4.8.36/'),
242
+					'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
243
+					'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
244 244
 					'site_url' => site_url('/'),
245
-                    'admin_url' => admin_url('/'),
246
-                )
247
-            );
248
-            /** site formatting values **/
249
-            $this->registry->addData(
250
-                'site_formats',
251
-                array(
252
-                    'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
253
-                )
254
-            );
255
-        }
256
-
257
-        $this->addJavascript(
258
-            CoreAssetManager::JS_HANDLE_EE_CORE,
259
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
260
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
261
-        )
262
-        ->setInlineDataCallback(
263
-            function () {
264
-                wp_localize_script(
265
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
266
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
267
-                    EE_Registry::$i18n_js_strings
268
-                );
269
-            }
270
-        );
271
-    }
272
-
273
-
274
-    /**
275
-     * @since 4.9.62.p
276
-     * @throws DuplicateCollectionIdentifierException
277
-     * @throws InvalidDataTypeException
278
-     * @throws InvalidEntityException
279
-     */
280
-    private function loadCoreCss()
281
-    {
282
-        if ($this->template_config->enable_default_style && ! is_admin()) {
283
-            $this->addStylesheet(
284
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
285
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
286
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
287
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
288
-                array('dashicons')
289
-            );
290
-            //Load custom style sheet if available
291
-            if ($this->template_config->custom_style_sheet !== null) {
292
-                $this->addStylesheet(
293
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
294
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
295
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
296
-                );
297
-            }
298
-        }
299
-        $this->addStylesheet(
300
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
301
-            $this->registry->getCssUrl(
302
-                $this->domain->assetNamespace(),
303
-                'components'
304
-            )
305
-        );
306
-    }
307
-
308
-
309
-    /**
310
-     * jQuery Validate for form validation
311
-     *
312
-     * @since 4.9.62.p
313
-     * @throws DuplicateCollectionIdentifierException
314
-     * @throws InvalidDataTypeException
315
-     * @throws InvalidEntityException
316
-     */
317
-    private function loadJqueryValidate()
318
-    {
319
-        $this->addJavascript(
320
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
321
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
322
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
323
-        )
324
-        ->setVersion('1.15.0');
325
-
326
-        $this->addJavascript(
327
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
328
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
329
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
330
-        )
331
-        ->setVersion('1.15.0');
332
-    }
333
-
334
-
335
-    /**
336
-     * accounting.js for performing client-side calculations
337
-     *
338
-     * @since 4.9.62.p
339
-     * @throws DuplicateCollectionIdentifierException
340
-     * @throws InvalidDataTypeException
341
-     * @throws InvalidEntityException
342
-     */
343
-    private function loadAccountingJs()
344
-    {
345
-        //accounting.js library
346
-        // @link http://josscrowcroft.github.io/accounting.js/
347
-        $this->addJavascript(
348
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
349
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
350
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
351
-        )
352
-        ->setVersion('0.3.2');
353
-
354
-        $currency_config = $this->currency_config;
355
-        $this->addJavascript(
356
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
357
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
358
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
359
-        )
360
-        ->setInlineDataCallback(
361
-            function () use ($currency_config) {
362
-                 wp_localize_script(
363
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
364
-                     'EE_ACCOUNTING_CFG',
365
-                     array(
366
-                         'currency' => array(
367
-                             'symbol'    => $currency_config->sign,
368
-                             'format'    => array(
369
-                                 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
370
-                                 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
371
-                                 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
372
-                             ),
373
-                             'decimal'   => $currency_config->dec_mrk,
374
-                             'thousand'  => $currency_config->thsnds,
375
-                             'precision' => $currency_config->dec_plc,
376
-                         ),
377
-                         'number'   => array(
378
-                             'precision' => $currency_config->dec_plc,
379
-                             'thousand'  => $currency_config->thsnds,
380
-                             'decimal'   => $currency_config->dec_mrk,
381
-                         ),
382
-                     )
383
-                 );
384
-            }
385
-        )
386
-        ->setVersion();
387
-    }
388
-
389
-
390
-    /**
391
-     * registers assets for cleaning your ears
392
-     *
393
-     * @param JavascriptAsset $script
394
-     */
395
-    public function loadQtipJs(JavascriptAsset $script)
396
-    {
397
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
398
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
399
-        if (
400
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
401
-            && apply_filters('FHEE_load_qtip', false)
402
-        ) {
403
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
404
-        }
405
-    }
406
-
407
-
408
-    /**
409
-     * assets that are used in the WordPress admin
410
-     *
411
-     * @since 4.9.62.p
412
-     * @throws DuplicateCollectionIdentifierException
413
-     * @throws InvalidDataTypeException
414
-     * @throws InvalidEntityException
415
-     */
416
-    private function registerAdminAssets()
417
-    {
418
-        $this->addJavascript(
419
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
420
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
421
-            array(
422
-                CoreAssetManager::JS_HANDLE_JQUERY,
423
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
424
-            )
425
-        )
426
-        ->setRequiresTranslation();
427
-
428
-        $this->addStylesheet(
429
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
430
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
431
-        );
432
-    }
245
+					'admin_url' => admin_url('/'),
246
+				)
247
+			);
248
+			/** site formatting values **/
249
+			$this->registry->addData(
250
+				'site_formats',
251
+				array(
252
+					'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
253
+				)
254
+			);
255
+		}
256
+
257
+		$this->addJavascript(
258
+			CoreAssetManager::JS_HANDLE_EE_CORE,
259
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
260
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
261
+		)
262
+		->setInlineDataCallback(
263
+			function () {
264
+				wp_localize_script(
265
+					CoreAssetManager::JS_HANDLE_EE_CORE,
266
+					CoreAssetManager::JS_HANDLE_EE_I18N,
267
+					EE_Registry::$i18n_js_strings
268
+				);
269
+			}
270
+		);
271
+	}
272
+
273
+
274
+	/**
275
+	 * @since 4.9.62.p
276
+	 * @throws DuplicateCollectionIdentifierException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws InvalidEntityException
279
+	 */
280
+	private function loadCoreCss()
281
+	{
282
+		if ($this->template_config->enable_default_style && ! is_admin()) {
283
+			$this->addStylesheet(
284
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
285
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
286
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
287
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
288
+				array('dashicons')
289
+			);
290
+			//Load custom style sheet if available
291
+			if ($this->template_config->custom_style_sheet !== null) {
292
+				$this->addStylesheet(
293
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
294
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
295
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
296
+				);
297
+			}
298
+		}
299
+		$this->addStylesheet(
300
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
301
+			$this->registry->getCssUrl(
302
+				$this->domain->assetNamespace(),
303
+				'components'
304
+			)
305
+		);
306
+	}
307
+
308
+
309
+	/**
310
+	 * jQuery Validate for form validation
311
+	 *
312
+	 * @since 4.9.62.p
313
+	 * @throws DuplicateCollectionIdentifierException
314
+	 * @throws InvalidDataTypeException
315
+	 * @throws InvalidEntityException
316
+	 */
317
+	private function loadJqueryValidate()
318
+	{
319
+		$this->addJavascript(
320
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
321
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
322
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
323
+		)
324
+		->setVersion('1.15.0');
325
+
326
+		$this->addJavascript(
327
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
328
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
329
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
330
+		)
331
+		->setVersion('1.15.0');
332
+	}
333
+
334
+
335
+	/**
336
+	 * accounting.js for performing client-side calculations
337
+	 *
338
+	 * @since 4.9.62.p
339
+	 * @throws DuplicateCollectionIdentifierException
340
+	 * @throws InvalidDataTypeException
341
+	 * @throws InvalidEntityException
342
+	 */
343
+	private function loadAccountingJs()
344
+	{
345
+		//accounting.js library
346
+		// @link http://josscrowcroft.github.io/accounting.js/
347
+		$this->addJavascript(
348
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
349
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
350
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
351
+		)
352
+		->setVersion('0.3.2');
353
+
354
+		$currency_config = $this->currency_config;
355
+		$this->addJavascript(
356
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
357
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
358
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
359
+		)
360
+		->setInlineDataCallback(
361
+			function () use ($currency_config) {
362
+				 wp_localize_script(
363
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
364
+					 'EE_ACCOUNTING_CFG',
365
+					 array(
366
+						 'currency' => array(
367
+							 'symbol'    => $currency_config->sign,
368
+							 'format'    => array(
369
+								 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
370
+								 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
371
+								 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
372
+							 ),
373
+							 'decimal'   => $currency_config->dec_mrk,
374
+							 'thousand'  => $currency_config->thsnds,
375
+							 'precision' => $currency_config->dec_plc,
376
+						 ),
377
+						 'number'   => array(
378
+							 'precision' => $currency_config->dec_plc,
379
+							 'thousand'  => $currency_config->thsnds,
380
+							 'decimal'   => $currency_config->dec_mrk,
381
+						 ),
382
+					 )
383
+				 );
384
+			}
385
+		)
386
+		->setVersion();
387
+	}
388
+
389
+
390
+	/**
391
+	 * registers assets for cleaning your ears
392
+	 *
393
+	 * @param JavascriptAsset $script
394
+	 */
395
+	public function loadQtipJs(JavascriptAsset $script)
396
+	{
397
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
398
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
399
+		if (
400
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
401
+			&& apply_filters('FHEE_load_qtip', false)
402
+		) {
403
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
404
+		}
405
+	}
406
+
407
+
408
+	/**
409
+	 * assets that are used in the WordPress admin
410
+	 *
411
+	 * @since 4.9.62.p
412
+	 * @throws DuplicateCollectionIdentifierException
413
+	 * @throws InvalidDataTypeException
414
+	 * @throws InvalidEntityException
415
+	 */
416
+	private function registerAdminAssets()
417
+	{
418
+		$this->addJavascript(
419
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
420
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
421
+			array(
422
+				CoreAssetManager::JS_HANDLE_JQUERY,
423
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
424
+			)
425
+		)
426
+		->setRequiresTranslation();
427
+
428
+		$this->addStylesheet(
429
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
430
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
431
+		);
432
+	}
433 433
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
         EE_Maintenance_Mode $maintenance_mode = null
142 142
     ) {
143 143
         // check if class object is instantiated
144
-        if (! self::$_instance instanceof EE_System) {
144
+        if ( ! self::$_instance instanceof EE_System) {
145 145
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
146 146
         }
147 147
         return self::$_instance;
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
259 259
         add_action(
260 260
             'AHEE__EE_Capabilities__init_caps__before_initialization',
261
-            function () {
261
+            function() {
262 262
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
263 263
             }
264 264
         );
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
     {
300 300
         // set autoloaders for all of the classes implementing EEI_Plugin_API
301 301
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
302
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
302
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
303 303
         $this->loader->getShared('EE_Request_Handler');
304 304
     }
305 305
 
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
         $load_callback,
320 320
         $plugin_file_constant
321 321
     ) {
322
-        if (! defined($version_constant)) {
322
+        if ( ! defined($version_constant)) {
323 323
             return;
324 324
         }
325 325
         $addon_version = constant($version_constant);
326 326
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
327 327
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
328
-            if (! function_exists('deactivate_plugins')) {
329
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
328
+            if ( ! function_exists('deactivate_plugins')) {
329
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
330 330
             }
331 331
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
332 332
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
                     $min_version_required
341 341
                 ),
342 342
                 __FILE__,
343
-                __FUNCTION__ . "({$addon_name})",
343
+                __FUNCTION__."({$addon_name})",
344 344
                 __LINE__
345 345
             );
346 346
             EE_Error::get_notices(false, true);
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
                 true
391 391
             )
392 392
         ) {
393
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
393
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
394 394
         }
395 395
         do_action('AHEE__EE_System__load_espresso_addons__complete');
396 396
     }
@@ -492,11 +492,11 @@  discard block
 block discarded – undo
492 492
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
493 493
     {
494 494
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
495
-        if (! $espresso_db_update) {
495
+        if ( ! $espresso_db_update) {
496 496
             $espresso_db_update = get_option('espresso_db_update');
497 497
         }
498 498
         // check that option is an array
499
-        if (! is_array($espresso_db_update)) {
499
+        if ( ! is_array($espresso_db_update)) {
500 500
             // if option is FALSE, then it never existed
501 501
             if ($espresso_db_update === false) {
502 502
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -516,10 +516,10 @@  discard block
 block discarded – undo
516 516
                     // so it must be numerically-indexed, where values are versions installed...
517 517
                     // fix it!
518 518
                     $version_string = $should_be_array;
519
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
519
+                    $corrected_db_update[$version_string] = array('unknown-date');
520 520
                 } else {
521 521
                     // ok it checks out
522
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
522
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
523 523
                 }
524 524
             }
525 525
             $espresso_db_update = $corrected_db_update;
@@ -602,13 +602,13 @@  discard block
 block discarded – undo
602 602
      */
603 603
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
604 604
     {
605
-        if (! $version_history) {
605
+        if ( ! $version_history) {
606 606
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
607 607
         }
608 608
         if ($current_version_to_add === null) {
609 609
             $current_version_to_add = espresso_version();
610 610
         }
611
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
611
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
612 612
         // re-save
613 613
         return update_option('espresso_db_update', $version_history);
614 614
     }
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
         if ($activation_history_for_addon) {
699 699
             // it exists, so this isn't a completely new install
700 700
             // check if this version already in that list of previously installed versions
701
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
701
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
702 702
                 // it a version we haven't seen before
703 703
                 if ($version_is_higher === 1) {
704 704
                     $req_type = EE_System::req_type_upgrade;
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
             foreach ($activation_history as $version => $times_activated) {
777 777
                 // check there is a record of when this version was activated. Otherwise,
778 778
                 // mark it as unknown
779
-                if (! $times_activated) {
779
+                if ( ! $times_activated) {
780 780
                     $times_activated = array('unknown-date');
781 781
                 }
782 782
                 if (is_string($times_activated)) {
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
     {
808 808
         $notices = EE_Error::get_notices(false);
809 809
         // if current user is an admin and it's not an ajax or rest request
810
-        if (! isset($notices['errors'])
810
+        if ( ! isset($notices['errors'])
811 811
             && $this->request->isAdmin()
812 812
             && apply_filters(
813 813
                 'FHEE__EE_System__redirect_to_about_ee__do_redirect',
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
     private function _parse_model_names()
877 877
     {
878 878
         // get all the files in the EE_MODELS folder that end in .model.php
879
-        $models = glob(EE_MODELS . '*.model.php');
879
+        $models = glob(EE_MODELS.'*.model.php');
880 880
         $model_names = array();
881 881
         $non_abstract_db_models = array();
882 882
         foreach ($models as $model) {
@@ -885,9 +885,9 @@  discard block
 block discarded – undo
885 885
             $short_name = str_replace('EEM_', '', $classname);
886 886
             $reflectionClass = new ReflectionClass($classname);
887 887
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
888
-                $non_abstract_db_models[ $short_name ] = $classname;
888
+                $non_abstract_db_models[$short_name] = $classname;
889 889
             }
890
-            $model_names[ $short_name ] = $classname;
890
+            $model_names[$short_name] = $classname;
891 891
         }
892 892
         $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
893 893
         $this->registry->non_abstract_db_models = apply_filters(
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
             )
923 923
         );
924 924
         if ($domain->isCaffeinated()) {
925
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
925
+            require_once EE_CAFF_PATH.'brewing_regular.php';
926 926
         }
927 927
     }
928 928
 
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974 974
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
975 975
         );
976
-        if (! empty($class_names)) {
976
+        if ( ! empty($class_names)) {
977 977
             $msg = __(
978 978
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979 979
                 'event_espresso'
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
                             array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
986 986
                             '',
987 987
                             $class_name
988
-                        ) . '</b></li>';
988
+                        ).'</b></li>';
989 989
             }
990 990
             $msg .= '</ul>';
991 991
             $msg .= __(
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     private function _deactivate_incompatible_addons()
1055 1055
     {
1056 1056
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1057
+        if ( ! empty($incompatible_addons)) {
1058 1058
             $active_plugins = get_option('active_plugins', array());
1059 1059
             foreach ($active_plugins as $active_plugin) {
1060 1060
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
     {
1122 1122
         do_action('AHEE__EE_System__load_controllers__start');
1123 1123
         // let's get it started
1124
-        if (! $this->maintenance_mode->level()
1124
+        if ( ! $this->maintenance_mode->level()
1125 1125
             && ($this->request->isFrontend() || $this->request->isFrontAjax())
1126 1126
         ) {
1127 1127
             do_action('AHEE__EE_System__load_controllers__load_front_controllers');
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
         do_action('AHEE__EE_System__core_loaded_and_ready');
1164 1164
         // always load template tags, because it's faster than checking if it's a front-end request, and many page
1165 1165
         // builders require these even on the front-end
1166
-        require_once EE_PUBLIC . 'template_tags.php';
1166
+        require_once EE_PUBLIC.'template_tags.php';
1167 1167
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1168 1168
     }
1169 1169
 
@@ -1229,13 +1229,13 @@  discard block
 block discarded – undo
1229 1229
     public static function do_not_cache()
1230 1230
     {
1231 1231
         // set no cache constants
1232
-        if (! defined('DONOTCACHEPAGE')) {
1232
+        if ( ! defined('DONOTCACHEPAGE')) {
1233 1233
             define('DONOTCACHEPAGE', true);
1234 1234
         }
1235
-        if (! defined('DONOTCACHCEOBJECT')) {
1235
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1236 1236
             define('DONOTCACHCEOBJECT', true);
1237 1237
         }
1238
-        if (! defined('DONOTCACHEDB')) {
1238
+        if ( ! defined('DONOTCACHEDB')) {
1239 1239
             define('DONOTCACHEDB', true);
1240 1240
         }
1241 1241
         // add no cache headers
Please login to merge, or discard this patch.
Indentation   +1265 added lines, -1265 removed lines patch added patch discarded remove patch
@@ -27,1269 +27,1269 @@
 block discarded – undo
27 27
 final class EE_System implements ResettableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
-     */
34
-    const req_type_normal = 0;
35
-
36
-    /**
37
-     * Indicates this is a brand new installation of EE so we should install
38
-     * tables and default data etc
39
-     */
40
-    const req_type_new_activation = 1;
41
-
42
-    /**
43
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
-     * and we just exited maintenance mode). We MUST check the database is setup properly
45
-     * and that default data is setup too
46
-     */
47
-    const req_type_reactivation = 2;
48
-
49
-    /**
50
-     * indicates that EE has been upgraded since its previous request.
51
-     * We may have data migration scripts to call and will want to trigger maintenance mode
52
-     */
53
-    const req_type_upgrade = 3;
54
-
55
-    /**
56
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
-     */
58
-    const req_type_downgrade = 4;
59
-
60
-    /**
61
-     * @deprecated since version 4.6.0.dev.006
62
-     * Now whenever a new_activation is detected the request type is still just
63
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
-     * (Specifically, when the migration manager indicates migrations are finished
67
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
-     */
69
-    const req_type_activation_but_not_installed = 5;
70
-
71
-    /**
72
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
-     */
74
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
-
76
-    /**
77
-     * @var EE_System $_instance
78
-     */
79
-    private static $_instance;
80
-
81
-    /**
82
-     * @var EE_Registry $registry
83
-     */
84
-    private $registry;
85
-
86
-    /**
87
-     * @var LoaderInterface $loader
88
-     */
89
-    private $loader;
90
-
91
-    /**
92
-     * @var EE_Capabilities $capabilities
93
-     */
94
-    private $capabilities;
95
-
96
-    /**
97
-     * @var RequestInterface $request
98
-     */
99
-    private $request;
100
-
101
-    /**
102
-     * @var EE_Maintenance_Mode $maintenance_mode
103
-     */
104
-    private $maintenance_mode;
105
-
106
-    /**
107
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
-     *
110
-     * @var int $_req_type
111
-     */
112
-    private $_req_type;
113
-
114
-    /**
115
-     * Whether or not there was a non-micro version change in EE core version during this request
116
-     *
117
-     * @var boolean $_major_version_change
118
-     */
119
-    private $_major_version_change = false;
120
-
121
-    /**
122
-     * A Context DTO dedicated solely to identifying the current request type.
123
-     *
124
-     * @var RequestTypeContextCheckerInterface $request_type
125
-     */
126
-    private $request_type;
127
-
128
-
129
-    /**
130
-     * @singleton method used to instantiate class object
131
-     * @param EE_Registry|null         $registry
132
-     * @param LoaderInterface|null     $loader
133
-     * @param RequestInterface|null    $request
134
-     * @param EE_Maintenance_Mode|null $maintenance_mode
135
-     * @return EE_System
136
-     */
137
-    public static function instance(
138
-        EE_Registry $registry = null,
139
-        LoaderInterface $loader = null,
140
-        RequestInterface $request = null,
141
-        EE_Maintenance_Mode $maintenance_mode = null
142
-    ) {
143
-        // check if class object is instantiated
144
-        if (! self::$_instance instanceof EE_System) {
145
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
146
-        }
147
-        return self::$_instance;
148
-    }
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        // make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        // we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-    /**
170
-     * sets hooks for running rest of system
171
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
172
-     * starting EE Addons from any other point may lead to problems
173
-     *
174
-     * @param EE_Registry         $registry
175
-     * @param LoaderInterface     $loader
176
-     * @param RequestInterface    $request
177
-     * @param EE_Maintenance_Mode $maintenance_mode
178
-     */
179
-    private function __construct(
180
-        EE_Registry $registry,
181
-        LoaderInterface $loader,
182
-        RequestInterface $request,
183
-        EE_Maintenance_Mode $maintenance_mode
184
-    ) {
185
-        $this->registry = $registry;
186
-        $this->loader = $loader;
187
-        $this->request = $request;
188
-        $this->maintenance_mode = $maintenance_mode;
189
-        do_action('AHEE__EE_System__construct__begin', $this);
190
-        add_action(
191
-            'AHEE__EE_Bootstrap__load_espresso_addons',
192
-            array($this, 'loadCapabilities'),
193
-            5
194
-        );
195
-        add_action(
196
-            'AHEE__EE_Bootstrap__load_espresso_addons',
197
-            array($this, 'loadCommandBus'),
198
-            7
199
-        );
200
-        add_action(
201
-            'AHEE__EE_Bootstrap__load_espresso_addons',
202
-            array($this, 'loadPluginApi'),
203
-            9
204
-        );
205
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
206
-        add_action(
207
-            'AHEE__EE_Bootstrap__load_espresso_addons',
208
-            array($this, 'load_espresso_addons')
209
-        );
210
-        // when an ee addon is activated, we want to call the core hook(s) again
211
-        // because the newly-activated addon didn't get a chance to run at all
212
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
213
-        // detect whether install or upgrade
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
216
-            array($this, 'detect_activations_or_upgrades'),
217
-            3
218
-        );
219
-        // load EE_Config, EE_Textdomain, etc
220
-        add_action(
221
-            'AHEE__EE_Bootstrap__load_core_configuration',
222
-            array($this, 'load_core_configuration'),
223
-            5
224
-        );
225
-        // load EE_Config, EE_Textdomain, etc
226
-        add_action(
227
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
228
-            array($this, 'register_shortcodes_modules_and_widgets'),
229
-            7
230
-        );
231
-        // you wanna get going? I wanna get going... let's get going!
232
-        add_action(
233
-            'AHEE__EE_Bootstrap__brew_espresso',
234
-            array($this, 'brew_espresso'),
235
-            9
236
-        );
237
-        // other housekeeping
238
-        // exclude EE critical pages from wp_list_pages
239
-        add_filter(
240
-            'wp_list_pages_excludes',
241
-            array($this, 'remove_pages_from_wp_list_pages'),
242
-            10
243
-        );
244
-        // ALL EE Addons should use the following hook point to attach their initial setup too
245
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
246
-        do_action('AHEE__EE_System__construct__complete', $this);
247
-    }
248
-
249
-
250
-    /**
251
-     * load and setup EE_Capabilities
252
-     *
253
-     * @return void
254
-     * @throws EE_Error
255
-     */
256
-    public function loadCapabilities()
257
-    {
258
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
259
-        add_action(
260
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
261
-            function () {
262
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
263
-            }
264
-        );
265
-    }
266
-
267
-
268
-    /**
269
-     * create and cache the CommandBus, and also add middleware
270
-     * The CapChecker middleware requires the use of EE_Capabilities
271
-     * which is why we need to load the CommandBus after Caps are set up
272
-     *
273
-     * @return void
274
-     * @throws EE_Error
275
-     */
276
-    public function loadCommandBus()
277
-    {
278
-        $this->loader->getShared(
279
-            'CommandBusInterface',
280
-            array(
281
-                null,
282
-                apply_filters(
283
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
284
-                    array(
285
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
286
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
287
-                    )
288
-                ),
289
-            )
290
-        );
291
-    }
292
-
293
-
294
-    /**
295
-     * @return void
296
-     * @throws EE_Error
297
-     */
298
-    public function loadPluginApi()
299
-    {
300
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
301
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
302
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
303
-        $this->loader->getShared('EE_Request_Handler');
304
-    }
305
-
306
-
307
-    /**
308
-     * @param string $addon_name
309
-     * @param string $version_constant
310
-     * @param string $min_version_required
311
-     * @param string $load_callback
312
-     * @param string $plugin_file_constant
313
-     * @return void
314
-     */
315
-    private function deactivateIncompatibleAddon(
316
-        $addon_name,
317
-        $version_constant,
318
-        $min_version_required,
319
-        $load_callback,
320
-        $plugin_file_constant
321
-    ) {
322
-        if (! defined($version_constant)) {
323
-            return;
324
-        }
325
-        $addon_version = constant($version_constant);
326
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
327
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
328
-            if (! function_exists('deactivate_plugins')) {
329
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
330
-            }
331
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
332
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
333
-            EE_Error::add_error(
334
-                sprintf(
335
-                    esc_html__(
336
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
337
-                        'event_espresso'
338
-                    ),
339
-                    $addon_name,
340
-                    $min_version_required
341
-                ),
342
-                __FILE__,
343
-                __FUNCTION__ . "({$addon_name})",
344
-                __LINE__
345
-            );
346
-            EE_Error::get_notices(false, true);
347
-        }
348
-    }
349
-
350
-
351
-    /**
352
-     * load_espresso_addons
353
-     * allow addons to load first so that they can set hooks for running DMS's, etc
354
-     * this is hooked into both:
355
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
356
-     *        which runs during the WP 'plugins_loaded' action at priority 5
357
-     *    and the WP 'activate_plugin' hook point
358
-     *
359
-     * @access public
360
-     * @return void
361
-     */
362
-    public function load_espresso_addons()
363
-    {
364
-        $this->deactivateIncompatibleAddon(
365
-            'Wait Lists',
366
-            'EE_WAIT_LISTS_VERSION',
367
-            '1.0.0.beta.074',
368
-            'load_espresso_wait_lists',
369
-            'EE_WAIT_LISTS_PLUGIN_FILE'
370
-        );
371
-        $this->deactivateIncompatibleAddon(
372
-            'Automated Upcoming Event Notifications',
373
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
374
-            '1.0.0.beta.091',
375
-            'load_espresso_automated_upcoming_event_notification',
376
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
377
-        );
378
-        do_action('AHEE__EE_System__load_espresso_addons');
379
-        // if the WP API basic auth plugin isn't already loaded, load it now.
380
-        // We want it for mobile apps. Just include the entire plugin
381
-        // also, don't load the basic auth when a plugin is getting activated, because
382
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
383
-        // and causes a fatal error
384
-        if ($this->request->getRequestParam('activate') !== 'true'
385
-            && ! function_exists('json_basic_auth_handler')
386
-            && ! function_exists('json_basic_auth_error')
387
-            && ! in_array(
388
-                $this->request->getRequestParam('action'),
389
-                array('activate', 'activate-selected'),
390
-                true
391
-            )
392
-        ) {
393
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
394
-        }
395
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
396
-    }
397
-
398
-
399
-    /**
400
-     * detect_activations_or_upgrades
401
-     * Checks for activation or upgrade of core first;
402
-     * then also checks if any registered addons have been activated or upgraded
403
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
-     * which runs during the WP 'plugins_loaded' action at priority 3
405
-     *
406
-     * @access public
407
-     * @return void
408
-     */
409
-    public function detect_activations_or_upgrades()
410
-    {
411
-        // first off: let's make sure to handle core
412
-        $this->detect_if_activation_or_upgrade();
413
-        foreach ($this->registry->addons as $addon) {
414
-            if ($addon instanceof EE_Addon) {
415
-                // detect teh request type for that addon
416
-                $addon->detect_activation_or_upgrade();
417
-            }
418
-        }
419
-    }
420
-
421
-
422
-    /**
423
-     * detect_if_activation_or_upgrade
424
-     * Takes care of detecting whether this is a brand new install or code upgrade,
425
-     * and either setting up the DB or setting up maintenance mode etc.
426
-     *
427
-     * @access public
428
-     * @return void
429
-     */
430
-    public function detect_if_activation_or_upgrade()
431
-    {
432
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
433
-        // check if db has been updated, or if its a brand-new installation
434
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
435
-        $request_type = $this->detect_req_type($espresso_db_update);
436
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
437
-        switch ($request_type) {
438
-            case EE_System::req_type_new_activation:
439
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
440
-                $this->_handle_core_version_change($espresso_db_update);
441
-                break;
442
-            case EE_System::req_type_reactivation:
443
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
444
-                $this->_handle_core_version_change($espresso_db_update);
445
-                break;
446
-            case EE_System::req_type_upgrade:
447
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
448
-                // migrations may be required now that we've upgraded
449
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
450
-                $this->_handle_core_version_change($espresso_db_update);
451
-                break;
452
-            case EE_System::req_type_downgrade:
453
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
454
-                // its possible migrations are no longer required
455
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
456
-                $this->_handle_core_version_change($espresso_db_update);
457
-                break;
458
-            case EE_System::req_type_normal:
459
-            default:
460
-                break;
461
-        }
462
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
463
-    }
464
-
465
-
466
-    /**
467
-     * Updates the list of installed versions and sets hooks for
468
-     * initializing the database later during the request
469
-     *
470
-     * @param array $espresso_db_update
471
-     */
472
-    private function _handle_core_version_change($espresso_db_update)
473
-    {
474
-        $this->update_list_of_installed_versions($espresso_db_update);
475
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
476
-        add_action(
477
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
478
-            array($this, 'initialize_db_if_no_migrations_required')
479
-        );
480
-    }
481
-
482
-
483
-    /**
484
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
485
-     * information about what versions of EE have been installed and activated,
486
-     * NOT necessarily the state of the database
487
-     *
488
-     * @param mixed $espresso_db_update           the value of the WordPress option.
489
-     *                                            If not supplied, fetches it from the options table
490
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
491
-     */
492
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
493
-    {
494
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
495
-        if (! $espresso_db_update) {
496
-            $espresso_db_update = get_option('espresso_db_update');
497
-        }
498
-        // check that option is an array
499
-        if (! is_array($espresso_db_update)) {
500
-            // if option is FALSE, then it never existed
501
-            if ($espresso_db_update === false) {
502
-                // make $espresso_db_update an array and save option with autoload OFF
503
-                $espresso_db_update = array();
504
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
505
-            } else {
506
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
507
-                $espresso_db_update = array($espresso_db_update => array());
508
-                update_option('espresso_db_update', $espresso_db_update);
509
-            }
510
-        } else {
511
-            $corrected_db_update = array();
512
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
513
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
514
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
515
-                    // the key is an int, and the value IS NOT an array
516
-                    // so it must be numerically-indexed, where values are versions installed...
517
-                    // fix it!
518
-                    $version_string = $should_be_array;
519
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
520
-                } else {
521
-                    // ok it checks out
522
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
523
-                }
524
-            }
525
-            $espresso_db_update = $corrected_db_update;
526
-            update_option('espresso_db_update', $espresso_db_update);
527
-        }
528
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
529
-        return $espresso_db_update;
530
-    }
531
-
532
-
533
-    /**
534
-     * Does the traditional work of setting up the plugin's database and adding default data.
535
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
536
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
537
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
538
-     * so that it will be done when migrations are finished
539
-     *
540
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
541
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
542
-     *                                       This is a resource-intensive job
543
-     *                                       so we prefer to only do it when necessary
544
-     * @return void
545
-     * @throws EE_Error
546
-     */
547
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
548
-    {
549
-        $request_type = $this->detect_req_type();
550
-        // only initialize system if we're not in maintenance mode.
551
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
552
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
553
-            $rewrite_rules = $this->loader->getShared(
554
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
555
-            );
556
-            $rewrite_rules->flush();
557
-            if ($verify_schema) {
558
-                EEH_Activation::initialize_db_and_folders();
559
-            }
560
-            EEH_Activation::initialize_db_content();
561
-            EEH_Activation::system_initialization();
562
-            if ($initialize_addons_too) {
563
-                $this->initialize_addons();
564
-            }
565
-        } else {
566
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
567
-        }
568
-        if ($request_type === EE_System::req_type_new_activation
569
-            || $request_type === EE_System::req_type_reactivation
570
-            || (
571
-                $request_type === EE_System::req_type_upgrade
572
-                && $this->is_major_version_change()
573
-            )
574
-        ) {
575
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
576
-        }
577
-    }
578
-
579
-
580
-    /**
581
-     * Initializes the db for all registered addons
582
-     *
583
-     * @throws EE_Error
584
-     */
585
-    public function initialize_addons()
586
-    {
587
-        // foreach registered addon, make sure its db is up-to-date too
588
-        foreach ($this->registry->addons as $addon) {
589
-            if ($addon instanceof EE_Addon) {
590
-                $addon->initialize_db_if_no_migrations_required();
591
-            }
592
-        }
593
-    }
594
-
595
-
596
-    /**
597
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
598
-     *
599
-     * @param    array  $version_history
600
-     * @param    string $current_version_to_add version to be added to the version history
601
-     * @return    boolean success as to whether or not this option was changed
602
-     */
603
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
604
-    {
605
-        if (! $version_history) {
606
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
607
-        }
608
-        if ($current_version_to_add === null) {
609
-            $current_version_to_add = espresso_version();
610
-        }
611
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
612
-        // re-save
613
-        return update_option('espresso_db_update', $version_history);
614
-    }
615
-
616
-
617
-    /**
618
-     * Detects if the current version indicated in the has existed in the list of
619
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
620
-     *
621
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
622
-     *                                  If not supplied, fetches it from the options table.
623
-     *                                  Also, caches its result so later parts of the code can also know whether
624
-     *                                  there's been an update or not. This way we can add the current version to
625
-     *                                  espresso_db_update, but still know if this is a new install or not
626
-     * @return int one of the constants on EE_System::req_type_
627
-     */
628
-    public function detect_req_type($espresso_db_update = null)
629
-    {
630
-        if ($this->_req_type === null) {
631
-            $espresso_db_update = ! empty($espresso_db_update)
632
-                ? $espresso_db_update
633
-                : $this->fix_espresso_db_upgrade_option();
634
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
635
-                $espresso_db_update,
636
-                'ee_espresso_activation',
637
-                espresso_version()
638
-            );
639
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
640
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
641
-        }
642
-        return $this->_req_type;
643
-    }
644
-
645
-
646
-    /**
647
-     * Returns whether or not there was a non-micro version change (ie, change in either
648
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
649
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
650
-     *
651
-     * @param $activation_history
652
-     * @return bool
653
-     */
654
-    private function _detect_major_version_change($activation_history)
655
-    {
656
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
657
-        $previous_version_parts = explode('.', $previous_version);
658
-        $current_version_parts = explode('.', espresso_version());
659
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
660
-               && ($previous_version_parts[0] !== $current_version_parts[0]
661
-                   || $previous_version_parts[1] !== $current_version_parts[1]
662
-               );
663
-    }
664
-
665
-
666
-    /**
667
-     * Returns true if either the major or minor version of EE changed during this request.
668
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
669
-     *
670
-     * @return bool
671
-     */
672
-    public function is_major_version_change()
673
-    {
674
-        return $this->_major_version_change;
675
-    }
676
-
677
-
678
-    /**
679
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
680
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
681
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
682
-     * just activated to (for core that will always be espresso_version())
683
-     *
684
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
685
-     *                                                 ee plugin. for core that's 'espresso_db_update'
686
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
687
-     *                                                 indicate that this plugin was just activated
688
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
689
-     *                                                 espresso_version())
690
-     * @return int one of the constants on EE_System::req_type_*
691
-     */
692
-    public static function detect_req_type_given_activation_history(
693
-        $activation_history_for_addon,
694
-        $activation_indicator_option_name,
695
-        $version_to_upgrade_to
696
-    ) {
697
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
698
-        if ($activation_history_for_addon) {
699
-            // it exists, so this isn't a completely new install
700
-            // check if this version already in that list of previously installed versions
701
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
702
-                // it a version we haven't seen before
703
-                if ($version_is_higher === 1) {
704
-                    $req_type = EE_System::req_type_upgrade;
705
-                } else {
706
-                    $req_type = EE_System::req_type_downgrade;
707
-                }
708
-                delete_option($activation_indicator_option_name);
709
-            } else {
710
-                // its not an update. maybe a reactivation?
711
-                if (get_option($activation_indicator_option_name, false)) {
712
-                    if ($version_is_higher === -1) {
713
-                        $req_type = EE_System::req_type_downgrade;
714
-                    } elseif ($version_is_higher === 0) {
715
-                        // we've seen this version before, but it's an activation. must be a reactivation
716
-                        $req_type = EE_System::req_type_reactivation;
717
-                    } else {// $version_is_higher === 1
718
-                        $req_type = EE_System::req_type_upgrade;
719
-                    }
720
-                    delete_option($activation_indicator_option_name);
721
-                } else {
722
-                    // we've seen this version before and the activation indicate doesn't show it was just activated
723
-                    if ($version_is_higher === -1) {
724
-                        $req_type = EE_System::req_type_downgrade;
725
-                    } elseif ($version_is_higher === 0) {
726
-                        // we've seen this version before and it's not an activation. its normal request
727
-                        $req_type = EE_System::req_type_normal;
728
-                    } else {// $version_is_higher === 1
729
-                        $req_type = EE_System::req_type_upgrade;
730
-                    }
731
-                }
732
-            }
733
-        } else {
734
-            // brand new install
735
-            $req_type = EE_System::req_type_new_activation;
736
-            delete_option($activation_indicator_option_name);
737
-        }
738
-        return $req_type;
739
-    }
740
-
741
-
742
-    /**
743
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
744
-     * the $activation_history_for_addon
745
-     *
746
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
747
-     *                                             sometimes containing 'unknown-date'
748
-     * @param string $version_to_upgrade_to        (current version)
749
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
750
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
751
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
752
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
753
-     */
754
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
755
-    {
756
-        // find the most recently-activated version
757
-        $most_recently_active_version =
758
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
759
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
760
-    }
761
-
762
-
763
-    /**
764
-     * Gets the most recently active version listed in the activation history,
765
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
766
-     *
767
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
768
-     *                                   sometimes containing 'unknown-date'
769
-     * @return string
770
-     */
771
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
772
-    {
773
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
774
-        $most_recently_active_version = '0.0.0.dev.000';
775
-        if (is_array($activation_history)) {
776
-            foreach ($activation_history as $version => $times_activated) {
777
-                // check there is a record of when this version was activated. Otherwise,
778
-                // mark it as unknown
779
-                if (! $times_activated) {
780
-                    $times_activated = array('unknown-date');
781
-                }
782
-                if (is_string($times_activated)) {
783
-                    $times_activated = array($times_activated);
784
-                }
785
-                foreach ($times_activated as $an_activation) {
786
-                    if ($an_activation !== 'unknown-date'
787
-                        && $an_activation
788
-                           > $most_recently_active_version_activation) {
789
-                        $most_recently_active_version = $version;
790
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
791
-                            ? '1970-01-01 00:00:00'
792
-                            : $an_activation;
793
-                    }
794
-                }
795
-            }
796
-        }
797
-        return $most_recently_active_version;
798
-    }
799
-
800
-
801
-    /**
802
-     * This redirects to the about EE page after activation
803
-     *
804
-     * @return void
805
-     */
806
-    public function redirect_to_about_ee()
807
-    {
808
-        $notices = EE_Error::get_notices(false);
809
-        // if current user is an admin and it's not an ajax or rest request
810
-        if (! isset($notices['errors'])
811
-            && $this->request->isAdmin()
812
-            && apply_filters(
813
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
814
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
815
-            )
816
-        ) {
817
-            $query_params = array('page' => 'espresso_about');
818
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
819
-                $query_params['new_activation'] = true;
820
-            }
821
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
822
-                $query_params['reactivation'] = true;
823
-            }
824
-            $url = add_query_arg($query_params, admin_url('admin.php'));
825
-            wp_safe_redirect($url);
826
-            exit();
827
-        }
828
-    }
829
-
830
-
831
-    /**
832
-     * load_core_configuration
833
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
834
-     * which runs during the WP 'plugins_loaded' action at priority 5
835
-     *
836
-     * @return void
837
-     * @throws ReflectionException
838
-     */
839
-    public function load_core_configuration()
840
-    {
841
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
842
-        $this->loader->getShared('EE_Load_Textdomain');
843
-        // load textdomain
844
-        EE_Load_Textdomain::load_textdomain();
845
-        // load and setup EE_Config and EE_Network_Config
846
-        $config = $this->loader->getShared('EE_Config');
847
-        $this->loader->getShared('EE_Network_Config');
848
-        // setup autoloaders
849
-        // enable logging?
850
-        if ($config->admin->use_full_logging) {
851
-            $this->loader->getShared('EE_Log');
852
-        }
853
-        // check for activation errors
854
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
855
-        if ($activation_errors) {
856
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
857
-            update_option('ee_plugin_activation_errors', false);
858
-        }
859
-        // get model names
860
-        $this->_parse_model_names();
861
-        // load caf stuff a chance to play during the activation process too.
862
-        $this->_maybe_brew_regular();
863
-        // configure custom post type definitions
864
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
865
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
866
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
867
-    }
868
-
869
-
870
-    /**
871
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
872
-     *
873
-     * @return void
874
-     * @throws ReflectionException
875
-     */
876
-    private function _parse_model_names()
877
-    {
878
-        // get all the files in the EE_MODELS folder that end in .model.php
879
-        $models = glob(EE_MODELS . '*.model.php');
880
-        $model_names = array();
881
-        $non_abstract_db_models = array();
882
-        foreach ($models as $model) {
883
-            // get model classname
884
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
885
-            $short_name = str_replace('EEM_', '', $classname);
886
-            $reflectionClass = new ReflectionClass($classname);
887
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
888
-                $non_abstract_db_models[ $short_name ] = $classname;
889
-            }
890
-            $model_names[ $short_name ] = $classname;
891
-        }
892
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
893
-        $this->registry->non_abstract_db_models = apply_filters(
894
-            'FHEE__EE_System__parse_implemented_model_names',
895
-            $non_abstract_db_models
896
-        );
897
-    }
898
-
899
-
900
-    /**
901
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
902
-     * that need to be setup before our EE_System launches.
903
-     *
904
-     * @return void
905
-     * @throws DomainException
906
-     * @throws InvalidArgumentException
907
-     * @throws InvalidDataTypeException
908
-     * @throws InvalidInterfaceException
909
-     * @throws InvalidClassException
910
-     * @throws InvalidFilePathException
911
-     */
912
-    private function _maybe_brew_regular()
913
-    {
914
-        /** @var Domain $domain */
915
-        $domain = DomainFactory::getShared(
916
-            new FullyQualifiedName(
917
-                'EventEspresso\core\domain\Domain'
918
-            ),
919
-            array(
920
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
921
-                Version::fromString(espresso_version()),
922
-            )
923
-        );
924
-        if ($domain->isCaffeinated()) {
925
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
926
-        }
927
-    }
928
-
929
-
930
-    /**
931
-     * register_shortcodes_modules_and_widgets
932
-     * generate lists of shortcodes and modules, then verify paths and classes
933
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
934
-     * which runs during the WP 'plugins_loaded' action at priority 7
935
-     *
936
-     * @access public
937
-     * @return void
938
-     * @throws Exception
939
-     */
940
-    public function register_shortcodes_modules_and_widgets()
941
-    {
942
-        if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
943
-            try {
944
-                // load, register, and add shortcodes the new way
945
-                $this->loader->getShared(
946
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
947
-                    array(
948
-                        // and the old way, but we'll put it under control of the new system
949
-                        EE_Config::getLegacyShortcodesManager(),
950
-                    )
951
-                );
952
-            } catch (Exception $exception) {
953
-                new ExceptionStackTraceDisplay($exception);
954
-            }
955
-        }
956
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
957
-        // check for addons using old hook point
958
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
959
-            $this->_incompatible_addon_error();
960
-        }
961
-    }
962
-
963
-
964
-    /**
965
-     * _incompatible_addon_error
966
-     *
967
-     * @access public
968
-     * @return void
969
-     */
970
-    private function _incompatible_addon_error()
971
-    {
972
-        // get array of classes hooking into here
973
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
-        );
976
-        if (! empty($class_names)) {
977
-            $msg = __(
978
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
-                'event_espresso'
980
-            );
981
-            $msg .= '<ul>';
982
-            foreach ($class_names as $class_name) {
983
-                $msg .= '<li><b>Event Espresso - '
984
-                        . str_replace(
985
-                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
986
-                            '',
987
-                            $class_name
988
-                        ) . '</b></li>';
989
-            }
990
-            $msg .= '</ul>';
991
-            $msg .= __(
992
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
993
-                'event_espresso'
994
-            );
995
-            // save list of incompatible addons to wp-options for later use
996
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
997
-            if (is_admin()) {
998
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
-            }
1000
-        }
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * brew_espresso
1006
-     * begins the process of setting hooks for initializing EE in the correct order
1007
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1008
-     * which runs during the WP 'plugins_loaded' action at priority 9
1009
-     *
1010
-     * @return void
1011
-     */
1012
-    public function brew_espresso()
1013
-    {
1014
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1015
-        // load some final core systems
1016
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1017
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1018
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1019
-        add_action('init', array($this, 'load_controllers'), 7);
1020
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1021
-        add_action('init', array($this, 'initialize'), 10);
1022
-        add_action('init', array($this, 'initialize_last'), 100);
1023
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1024
-            // pew pew pew
1025
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1026
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1027
-        }
1028
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1029
-    }
1030
-
1031
-
1032
-    /**
1033
-     *    set_hooks_for_core
1034
-     *
1035
-     * @access public
1036
-     * @return    void
1037
-     * @throws EE_Error
1038
-     */
1039
-    public function set_hooks_for_core()
1040
-    {
1041
-        $this->_deactivate_incompatible_addons();
1042
-        do_action('AHEE__EE_System__set_hooks_for_core');
1043
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1044
-        // caps need to be initialized on every request so that capability maps are set.
1045
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1046
-        $this->registry->CAP->init_caps();
1047
-    }
1048
-
1049
-
1050
-    /**
1051
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1052
-     * deactivates any addons considered incompatible with the current version of EE
1053
-     */
1054
-    private function _deactivate_incompatible_addons()
1055
-    {
1056
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1058
-            $active_plugins = get_option('active_plugins', array());
1059
-            foreach ($active_plugins as $active_plugin) {
1060
-                foreach ($incompatible_addons as $incompatible_addon) {
1061
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
-                        unset($_GET['activate']);
1063
-                        espresso_deactivate_plugin($active_plugin);
1064
-                    }
1065
-                }
1066
-            }
1067
-        }
1068
-    }
1069
-
1070
-
1071
-    /**
1072
-     *    perform_activations_upgrades_and_migrations
1073
-     *
1074
-     * @access public
1075
-     * @return    void
1076
-     */
1077
-    public function perform_activations_upgrades_and_migrations()
1078
-    {
1079
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1080
-    }
1081
-
1082
-
1083
-    /**
1084
-     * @return void
1085
-     * @throws DomainException
1086
-     */
1087
-    public function load_CPTs_and_session()
1088
-    {
1089
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1090
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1091
-        $register_custom_taxonomies = $this->loader->getShared(
1092
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1093
-        );
1094
-        $register_custom_taxonomies->registerCustomTaxonomies();
1095
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1096
-        $register_custom_post_types = $this->loader->getShared(
1097
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1098
-        );
1099
-        $register_custom_post_types->registerCustomPostTypes();
1100
-        /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1101
-        $register_custom_taxonomy_terms = $this->loader->getShared(
1102
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1103
-        );
1104
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1105
-        // load legacy Custom Post Types and Taxonomies
1106
-        $this->loader->getShared('EE_Register_CPTs');
1107
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1108
-    }
1109
-
1110
-
1111
-    /**
1112
-     * load_controllers
1113
-     * this is the best place to load any additional controllers that needs access to EE core.
1114
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1115
-     * time
1116
-     *
1117
-     * @access public
1118
-     * @return void
1119
-     */
1120
-    public function load_controllers()
1121
-    {
1122
-        do_action('AHEE__EE_System__load_controllers__start');
1123
-        // let's get it started
1124
-        if (! $this->maintenance_mode->level()
1125
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1126
-        ) {
1127
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1128
-            $this->loader->getShared('EE_Front_Controller');
1129
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1130
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1131
-            $this->loader->getShared('EE_Admin');
1132
-        }
1133
-        do_action('AHEE__EE_System__load_controllers__complete');
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * core_loaded_and_ready
1139
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1140
-     *
1141
-     * @access public
1142
-     * @return void
1143
-     * @throws Exception
1144
-     */
1145
-    public function core_loaded_and_ready()
1146
-    {
1147
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1148
-            try {
1149
-                $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1150
-                $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1151
-                if (function_exists('register_block_type')) {
1152
-                    $this->loader->getShared(
1153
-                        'EventEspresso\core\services\editor\BlockRegistrationManager'
1154
-                    );
1155
-                }
1156
-            } catch (Exception $exception) {
1157
-                new ExceptionStackTraceDisplay($exception);
1158
-            }
1159
-        }
1160
-        if ($this->request->isAdmin()
1161
-            || $this->request->isEeAjax()
1162
-            || $this->request->isFrontend()
1163
-        ) {
1164
-            $this->loader->getShared('EE_Session');
1165
-        }
1166
-        // integrate WP_Query with the EE models
1167
-        $this->loader->getShared('EE_CPT_Strategy');
1168
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1169
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1170
-        // builders require these even on the front-end
1171
-        require_once EE_PUBLIC . 'template_tags.php';
1172
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1173
-    }
1174
-
1175
-
1176
-    /**
1177
-     * initialize
1178
-     * this is the best place to begin initializing client code
1179
-     *
1180
-     * @access public
1181
-     * @return void
1182
-     */
1183
-    public function initialize()
1184
-    {
1185
-        do_action('AHEE__EE_System__initialize');
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * initialize_last
1191
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1192
-     * initialize has done so
1193
-     *
1194
-     * @access public
1195
-     * @return void
1196
-     */
1197
-    public function initialize_last()
1198
-    {
1199
-        do_action('AHEE__EE_System__initialize_last');
1200
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1201
-        $rewrite_rules = $this->loader->getShared(
1202
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1203
-        );
1204
-        $rewrite_rules->flushRewriteRules();
1205
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1206
-        if (($this->request->isAjax() || $this->request->isAdmin())
1207
-            && $this->maintenance_mode->models_can_query()) {
1208
-            $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1209
-            $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1210
-        }
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * @return void
1216
-     * @throws EE_Error
1217
-     */
1218
-    public function addEspressoToolbar()
1219
-    {
1220
-        $this->loader->getShared(
1221
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1222
-            array($this->registry->CAP)
1223
-        );
1224
-    }
1225
-
1226
-
1227
-    /**
1228
-     * do_not_cache
1229
-     * sets no cache headers and defines no cache constants for WP plugins
1230
-     *
1231
-     * @access public
1232
-     * @return void
1233
-     */
1234
-    public static function do_not_cache()
1235
-    {
1236
-        // set no cache constants
1237
-        if (! defined('DONOTCACHEPAGE')) {
1238
-            define('DONOTCACHEPAGE', true);
1239
-        }
1240
-        if (! defined('DONOTCACHCEOBJECT')) {
1241
-            define('DONOTCACHCEOBJECT', true);
1242
-        }
1243
-        if (! defined('DONOTCACHEDB')) {
1244
-            define('DONOTCACHEDB', true);
1245
-        }
1246
-        // add no cache headers
1247
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1248
-        // plus a little extra for nginx and Google Chrome
1249
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1250
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1251
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     *    extra_nocache_headers
1257
-     *
1258
-     * @access    public
1259
-     * @param $headers
1260
-     * @return    array
1261
-     */
1262
-    public static function extra_nocache_headers($headers)
1263
-    {
1264
-        // for NGINX
1265
-        $headers['X-Accel-Expires'] = 0;
1266
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1267
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1268
-        return $headers;
1269
-    }
1270
-
1271
-
1272
-    /**
1273
-     *    nocache_headers
1274
-     *
1275
-     * @access    public
1276
-     * @return    void
1277
-     */
1278
-    public static function nocache_headers()
1279
-    {
1280
-        nocache_headers();
1281
-    }
1282
-
1283
-
1284
-    /**
1285
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1286
-     * never returned with the function.
1287
-     *
1288
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1289
-     * @return array
1290
-     */
1291
-    public function remove_pages_from_wp_list_pages($exclude_array)
1292
-    {
1293
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1294
-    }
30
+	/**
31
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
+	 */
34
+	const req_type_normal = 0;
35
+
36
+	/**
37
+	 * Indicates this is a brand new installation of EE so we should install
38
+	 * tables and default data etc
39
+	 */
40
+	const req_type_new_activation = 1;
41
+
42
+	/**
43
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
45
+	 * and that default data is setup too
46
+	 */
47
+	const req_type_reactivation = 2;
48
+
49
+	/**
50
+	 * indicates that EE has been upgraded since its previous request.
51
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
52
+	 */
53
+	const req_type_upgrade = 3;
54
+
55
+	/**
56
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
+	 */
58
+	const req_type_downgrade = 4;
59
+
60
+	/**
61
+	 * @deprecated since version 4.6.0.dev.006
62
+	 * Now whenever a new_activation is detected the request type is still just
63
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
+	 * (Specifically, when the migration manager indicates migrations are finished
67
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
+	 */
69
+	const req_type_activation_but_not_installed = 5;
70
+
71
+	/**
72
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
+	 */
74
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
+
76
+	/**
77
+	 * @var EE_System $_instance
78
+	 */
79
+	private static $_instance;
80
+
81
+	/**
82
+	 * @var EE_Registry $registry
83
+	 */
84
+	private $registry;
85
+
86
+	/**
87
+	 * @var LoaderInterface $loader
88
+	 */
89
+	private $loader;
90
+
91
+	/**
92
+	 * @var EE_Capabilities $capabilities
93
+	 */
94
+	private $capabilities;
95
+
96
+	/**
97
+	 * @var RequestInterface $request
98
+	 */
99
+	private $request;
100
+
101
+	/**
102
+	 * @var EE_Maintenance_Mode $maintenance_mode
103
+	 */
104
+	private $maintenance_mode;
105
+
106
+	/**
107
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
+	 *
110
+	 * @var int $_req_type
111
+	 */
112
+	private $_req_type;
113
+
114
+	/**
115
+	 * Whether or not there was a non-micro version change in EE core version during this request
116
+	 *
117
+	 * @var boolean $_major_version_change
118
+	 */
119
+	private $_major_version_change = false;
120
+
121
+	/**
122
+	 * A Context DTO dedicated solely to identifying the current request type.
123
+	 *
124
+	 * @var RequestTypeContextCheckerInterface $request_type
125
+	 */
126
+	private $request_type;
127
+
128
+
129
+	/**
130
+	 * @singleton method used to instantiate class object
131
+	 * @param EE_Registry|null         $registry
132
+	 * @param LoaderInterface|null     $loader
133
+	 * @param RequestInterface|null    $request
134
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
135
+	 * @return EE_System
136
+	 */
137
+	public static function instance(
138
+		EE_Registry $registry = null,
139
+		LoaderInterface $loader = null,
140
+		RequestInterface $request = null,
141
+		EE_Maintenance_Mode $maintenance_mode = null
142
+	) {
143
+		// check if class object is instantiated
144
+		if (! self::$_instance instanceof EE_System) {
145
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
146
+		}
147
+		return self::$_instance;
148
+	}
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		// make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		// we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+	/**
170
+	 * sets hooks for running rest of system
171
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
172
+	 * starting EE Addons from any other point may lead to problems
173
+	 *
174
+	 * @param EE_Registry         $registry
175
+	 * @param LoaderInterface     $loader
176
+	 * @param RequestInterface    $request
177
+	 * @param EE_Maintenance_Mode $maintenance_mode
178
+	 */
179
+	private function __construct(
180
+		EE_Registry $registry,
181
+		LoaderInterface $loader,
182
+		RequestInterface $request,
183
+		EE_Maintenance_Mode $maintenance_mode
184
+	) {
185
+		$this->registry = $registry;
186
+		$this->loader = $loader;
187
+		$this->request = $request;
188
+		$this->maintenance_mode = $maintenance_mode;
189
+		do_action('AHEE__EE_System__construct__begin', $this);
190
+		add_action(
191
+			'AHEE__EE_Bootstrap__load_espresso_addons',
192
+			array($this, 'loadCapabilities'),
193
+			5
194
+		);
195
+		add_action(
196
+			'AHEE__EE_Bootstrap__load_espresso_addons',
197
+			array($this, 'loadCommandBus'),
198
+			7
199
+		);
200
+		add_action(
201
+			'AHEE__EE_Bootstrap__load_espresso_addons',
202
+			array($this, 'loadPluginApi'),
203
+			9
204
+		);
205
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
206
+		add_action(
207
+			'AHEE__EE_Bootstrap__load_espresso_addons',
208
+			array($this, 'load_espresso_addons')
209
+		);
210
+		// when an ee addon is activated, we want to call the core hook(s) again
211
+		// because the newly-activated addon didn't get a chance to run at all
212
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
213
+		// detect whether install or upgrade
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
216
+			array($this, 'detect_activations_or_upgrades'),
217
+			3
218
+		);
219
+		// load EE_Config, EE_Textdomain, etc
220
+		add_action(
221
+			'AHEE__EE_Bootstrap__load_core_configuration',
222
+			array($this, 'load_core_configuration'),
223
+			5
224
+		);
225
+		// load EE_Config, EE_Textdomain, etc
226
+		add_action(
227
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
228
+			array($this, 'register_shortcodes_modules_and_widgets'),
229
+			7
230
+		);
231
+		// you wanna get going? I wanna get going... let's get going!
232
+		add_action(
233
+			'AHEE__EE_Bootstrap__brew_espresso',
234
+			array($this, 'brew_espresso'),
235
+			9
236
+		);
237
+		// other housekeeping
238
+		// exclude EE critical pages from wp_list_pages
239
+		add_filter(
240
+			'wp_list_pages_excludes',
241
+			array($this, 'remove_pages_from_wp_list_pages'),
242
+			10
243
+		);
244
+		// ALL EE Addons should use the following hook point to attach their initial setup too
245
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
246
+		do_action('AHEE__EE_System__construct__complete', $this);
247
+	}
248
+
249
+
250
+	/**
251
+	 * load and setup EE_Capabilities
252
+	 *
253
+	 * @return void
254
+	 * @throws EE_Error
255
+	 */
256
+	public function loadCapabilities()
257
+	{
258
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
259
+		add_action(
260
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
261
+			function () {
262
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
263
+			}
264
+		);
265
+	}
266
+
267
+
268
+	/**
269
+	 * create and cache the CommandBus, and also add middleware
270
+	 * The CapChecker middleware requires the use of EE_Capabilities
271
+	 * which is why we need to load the CommandBus after Caps are set up
272
+	 *
273
+	 * @return void
274
+	 * @throws EE_Error
275
+	 */
276
+	public function loadCommandBus()
277
+	{
278
+		$this->loader->getShared(
279
+			'CommandBusInterface',
280
+			array(
281
+				null,
282
+				apply_filters(
283
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
284
+					array(
285
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
286
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
287
+					)
288
+				),
289
+			)
290
+		);
291
+	}
292
+
293
+
294
+	/**
295
+	 * @return void
296
+	 * @throws EE_Error
297
+	 */
298
+	public function loadPluginApi()
299
+	{
300
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
301
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
302
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
303
+		$this->loader->getShared('EE_Request_Handler');
304
+	}
305
+
306
+
307
+	/**
308
+	 * @param string $addon_name
309
+	 * @param string $version_constant
310
+	 * @param string $min_version_required
311
+	 * @param string $load_callback
312
+	 * @param string $plugin_file_constant
313
+	 * @return void
314
+	 */
315
+	private function deactivateIncompatibleAddon(
316
+		$addon_name,
317
+		$version_constant,
318
+		$min_version_required,
319
+		$load_callback,
320
+		$plugin_file_constant
321
+	) {
322
+		if (! defined($version_constant)) {
323
+			return;
324
+		}
325
+		$addon_version = constant($version_constant);
326
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
327
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
328
+			if (! function_exists('deactivate_plugins')) {
329
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
330
+			}
331
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
332
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
333
+			EE_Error::add_error(
334
+				sprintf(
335
+					esc_html__(
336
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
337
+						'event_espresso'
338
+					),
339
+					$addon_name,
340
+					$min_version_required
341
+				),
342
+				__FILE__,
343
+				__FUNCTION__ . "({$addon_name})",
344
+				__LINE__
345
+			);
346
+			EE_Error::get_notices(false, true);
347
+		}
348
+	}
349
+
350
+
351
+	/**
352
+	 * load_espresso_addons
353
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
354
+	 * this is hooked into both:
355
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
356
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
357
+	 *    and the WP 'activate_plugin' hook point
358
+	 *
359
+	 * @access public
360
+	 * @return void
361
+	 */
362
+	public function load_espresso_addons()
363
+	{
364
+		$this->deactivateIncompatibleAddon(
365
+			'Wait Lists',
366
+			'EE_WAIT_LISTS_VERSION',
367
+			'1.0.0.beta.074',
368
+			'load_espresso_wait_lists',
369
+			'EE_WAIT_LISTS_PLUGIN_FILE'
370
+		);
371
+		$this->deactivateIncompatibleAddon(
372
+			'Automated Upcoming Event Notifications',
373
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
374
+			'1.0.0.beta.091',
375
+			'load_espresso_automated_upcoming_event_notification',
376
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
377
+		);
378
+		do_action('AHEE__EE_System__load_espresso_addons');
379
+		// if the WP API basic auth plugin isn't already loaded, load it now.
380
+		// We want it for mobile apps. Just include the entire plugin
381
+		// also, don't load the basic auth when a plugin is getting activated, because
382
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
383
+		// and causes a fatal error
384
+		if ($this->request->getRequestParam('activate') !== 'true'
385
+			&& ! function_exists('json_basic_auth_handler')
386
+			&& ! function_exists('json_basic_auth_error')
387
+			&& ! in_array(
388
+				$this->request->getRequestParam('action'),
389
+				array('activate', 'activate-selected'),
390
+				true
391
+			)
392
+		) {
393
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
394
+		}
395
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
396
+	}
397
+
398
+
399
+	/**
400
+	 * detect_activations_or_upgrades
401
+	 * Checks for activation or upgrade of core first;
402
+	 * then also checks if any registered addons have been activated or upgraded
403
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
404
+	 * which runs during the WP 'plugins_loaded' action at priority 3
405
+	 *
406
+	 * @access public
407
+	 * @return void
408
+	 */
409
+	public function detect_activations_or_upgrades()
410
+	{
411
+		// first off: let's make sure to handle core
412
+		$this->detect_if_activation_or_upgrade();
413
+		foreach ($this->registry->addons as $addon) {
414
+			if ($addon instanceof EE_Addon) {
415
+				// detect teh request type for that addon
416
+				$addon->detect_activation_or_upgrade();
417
+			}
418
+		}
419
+	}
420
+
421
+
422
+	/**
423
+	 * detect_if_activation_or_upgrade
424
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
425
+	 * and either setting up the DB or setting up maintenance mode etc.
426
+	 *
427
+	 * @access public
428
+	 * @return void
429
+	 */
430
+	public function detect_if_activation_or_upgrade()
431
+	{
432
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
433
+		// check if db has been updated, or if its a brand-new installation
434
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
435
+		$request_type = $this->detect_req_type($espresso_db_update);
436
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
437
+		switch ($request_type) {
438
+			case EE_System::req_type_new_activation:
439
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
440
+				$this->_handle_core_version_change($espresso_db_update);
441
+				break;
442
+			case EE_System::req_type_reactivation:
443
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
444
+				$this->_handle_core_version_change($espresso_db_update);
445
+				break;
446
+			case EE_System::req_type_upgrade:
447
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
448
+				// migrations may be required now that we've upgraded
449
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
450
+				$this->_handle_core_version_change($espresso_db_update);
451
+				break;
452
+			case EE_System::req_type_downgrade:
453
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
454
+				// its possible migrations are no longer required
455
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
456
+				$this->_handle_core_version_change($espresso_db_update);
457
+				break;
458
+			case EE_System::req_type_normal:
459
+			default:
460
+				break;
461
+		}
462
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
463
+	}
464
+
465
+
466
+	/**
467
+	 * Updates the list of installed versions and sets hooks for
468
+	 * initializing the database later during the request
469
+	 *
470
+	 * @param array $espresso_db_update
471
+	 */
472
+	private function _handle_core_version_change($espresso_db_update)
473
+	{
474
+		$this->update_list_of_installed_versions($espresso_db_update);
475
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
476
+		add_action(
477
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
478
+			array($this, 'initialize_db_if_no_migrations_required')
479
+		);
480
+	}
481
+
482
+
483
+	/**
484
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
485
+	 * information about what versions of EE have been installed and activated,
486
+	 * NOT necessarily the state of the database
487
+	 *
488
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
489
+	 *                                            If not supplied, fetches it from the options table
490
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
491
+	 */
492
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
493
+	{
494
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
495
+		if (! $espresso_db_update) {
496
+			$espresso_db_update = get_option('espresso_db_update');
497
+		}
498
+		// check that option is an array
499
+		if (! is_array($espresso_db_update)) {
500
+			// if option is FALSE, then it never existed
501
+			if ($espresso_db_update === false) {
502
+				// make $espresso_db_update an array and save option with autoload OFF
503
+				$espresso_db_update = array();
504
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
505
+			} else {
506
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
507
+				$espresso_db_update = array($espresso_db_update => array());
508
+				update_option('espresso_db_update', $espresso_db_update);
509
+			}
510
+		} else {
511
+			$corrected_db_update = array();
512
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
513
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
514
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
515
+					// the key is an int, and the value IS NOT an array
516
+					// so it must be numerically-indexed, where values are versions installed...
517
+					// fix it!
518
+					$version_string = $should_be_array;
519
+					$corrected_db_update[ $version_string ] = array('unknown-date');
520
+				} else {
521
+					// ok it checks out
522
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
523
+				}
524
+			}
525
+			$espresso_db_update = $corrected_db_update;
526
+			update_option('espresso_db_update', $espresso_db_update);
527
+		}
528
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
529
+		return $espresso_db_update;
530
+	}
531
+
532
+
533
+	/**
534
+	 * Does the traditional work of setting up the plugin's database and adding default data.
535
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
536
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
537
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
538
+	 * so that it will be done when migrations are finished
539
+	 *
540
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
541
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
542
+	 *                                       This is a resource-intensive job
543
+	 *                                       so we prefer to only do it when necessary
544
+	 * @return void
545
+	 * @throws EE_Error
546
+	 */
547
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
548
+	{
549
+		$request_type = $this->detect_req_type();
550
+		// only initialize system if we're not in maintenance mode.
551
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
552
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
553
+			$rewrite_rules = $this->loader->getShared(
554
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
555
+			);
556
+			$rewrite_rules->flush();
557
+			if ($verify_schema) {
558
+				EEH_Activation::initialize_db_and_folders();
559
+			}
560
+			EEH_Activation::initialize_db_content();
561
+			EEH_Activation::system_initialization();
562
+			if ($initialize_addons_too) {
563
+				$this->initialize_addons();
564
+			}
565
+		} else {
566
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
567
+		}
568
+		if ($request_type === EE_System::req_type_new_activation
569
+			|| $request_type === EE_System::req_type_reactivation
570
+			|| (
571
+				$request_type === EE_System::req_type_upgrade
572
+				&& $this->is_major_version_change()
573
+			)
574
+		) {
575
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
576
+		}
577
+	}
578
+
579
+
580
+	/**
581
+	 * Initializes the db for all registered addons
582
+	 *
583
+	 * @throws EE_Error
584
+	 */
585
+	public function initialize_addons()
586
+	{
587
+		// foreach registered addon, make sure its db is up-to-date too
588
+		foreach ($this->registry->addons as $addon) {
589
+			if ($addon instanceof EE_Addon) {
590
+				$addon->initialize_db_if_no_migrations_required();
591
+			}
592
+		}
593
+	}
594
+
595
+
596
+	/**
597
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
598
+	 *
599
+	 * @param    array  $version_history
600
+	 * @param    string $current_version_to_add version to be added to the version history
601
+	 * @return    boolean success as to whether or not this option was changed
602
+	 */
603
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
604
+	{
605
+		if (! $version_history) {
606
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
607
+		}
608
+		if ($current_version_to_add === null) {
609
+			$current_version_to_add = espresso_version();
610
+		}
611
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
612
+		// re-save
613
+		return update_option('espresso_db_update', $version_history);
614
+	}
615
+
616
+
617
+	/**
618
+	 * Detects if the current version indicated in the has existed in the list of
619
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
620
+	 *
621
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
622
+	 *                                  If not supplied, fetches it from the options table.
623
+	 *                                  Also, caches its result so later parts of the code can also know whether
624
+	 *                                  there's been an update or not. This way we can add the current version to
625
+	 *                                  espresso_db_update, but still know if this is a new install or not
626
+	 * @return int one of the constants on EE_System::req_type_
627
+	 */
628
+	public function detect_req_type($espresso_db_update = null)
629
+	{
630
+		if ($this->_req_type === null) {
631
+			$espresso_db_update = ! empty($espresso_db_update)
632
+				? $espresso_db_update
633
+				: $this->fix_espresso_db_upgrade_option();
634
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
635
+				$espresso_db_update,
636
+				'ee_espresso_activation',
637
+				espresso_version()
638
+			);
639
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
640
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
641
+		}
642
+		return $this->_req_type;
643
+	}
644
+
645
+
646
+	/**
647
+	 * Returns whether or not there was a non-micro version change (ie, change in either
648
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
649
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
650
+	 *
651
+	 * @param $activation_history
652
+	 * @return bool
653
+	 */
654
+	private function _detect_major_version_change($activation_history)
655
+	{
656
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
657
+		$previous_version_parts = explode('.', $previous_version);
658
+		$current_version_parts = explode('.', espresso_version());
659
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
660
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
661
+				   || $previous_version_parts[1] !== $current_version_parts[1]
662
+			   );
663
+	}
664
+
665
+
666
+	/**
667
+	 * Returns true if either the major or minor version of EE changed during this request.
668
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
669
+	 *
670
+	 * @return bool
671
+	 */
672
+	public function is_major_version_change()
673
+	{
674
+		return $this->_major_version_change;
675
+	}
676
+
677
+
678
+	/**
679
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
680
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
681
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
682
+	 * just activated to (for core that will always be espresso_version())
683
+	 *
684
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
685
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
686
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
687
+	 *                                                 indicate that this plugin was just activated
688
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
689
+	 *                                                 espresso_version())
690
+	 * @return int one of the constants on EE_System::req_type_*
691
+	 */
692
+	public static function detect_req_type_given_activation_history(
693
+		$activation_history_for_addon,
694
+		$activation_indicator_option_name,
695
+		$version_to_upgrade_to
696
+	) {
697
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
698
+		if ($activation_history_for_addon) {
699
+			// it exists, so this isn't a completely new install
700
+			// check if this version already in that list of previously installed versions
701
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
702
+				// it a version we haven't seen before
703
+				if ($version_is_higher === 1) {
704
+					$req_type = EE_System::req_type_upgrade;
705
+				} else {
706
+					$req_type = EE_System::req_type_downgrade;
707
+				}
708
+				delete_option($activation_indicator_option_name);
709
+			} else {
710
+				// its not an update. maybe a reactivation?
711
+				if (get_option($activation_indicator_option_name, false)) {
712
+					if ($version_is_higher === -1) {
713
+						$req_type = EE_System::req_type_downgrade;
714
+					} elseif ($version_is_higher === 0) {
715
+						// we've seen this version before, but it's an activation. must be a reactivation
716
+						$req_type = EE_System::req_type_reactivation;
717
+					} else {// $version_is_higher === 1
718
+						$req_type = EE_System::req_type_upgrade;
719
+					}
720
+					delete_option($activation_indicator_option_name);
721
+				} else {
722
+					// we've seen this version before and the activation indicate doesn't show it was just activated
723
+					if ($version_is_higher === -1) {
724
+						$req_type = EE_System::req_type_downgrade;
725
+					} elseif ($version_is_higher === 0) {
726
+						// we've seen this version before and it's not an activation. its normal request
727
+						$req_type = EE_System::req_type_normal;
728
+					} else {// $version_is_higher === 1
729
+						$req_type = EE_System::req_type_upgrade;
730
+					}
731
+				}
732
+			}
733
+		} else {
734
+			// brand new install
735
+			$req_type = EE_System::req_type_new_activation;
736
+			delete_option($activation_indicator_option_name);
737
+		}
738
+		return $req_type;
739
+	}
740
+
741
+
742
+	/**
743
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
744
+	 * the $activation_history_for_addon
745
+	 *
746
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
747
+	 *                                             sometimes containing 'unknown-date'
748
+	 * @param string $version_to_upgrade_to        (current version)
749
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
750
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
751
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
752
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
753
+	 */
754
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
755
+	{
756
+		// find the most recently-activated version
757
+		$most_recently_active_version =
758
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
759
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
760
+	}
761
+
762
+
763
+	/**
764
+	 * Gets the most recently active version listed in the activation history,
765
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
766
+	 *
767
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
768
+	 *                                   sometimes containing 'unknown-date'
769
+	 * @return string
770
+	 */
771
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
772
+	{
773
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
774
+		$most_recently_active_version = '0.0.0.dev.000';
775
+		if (is_array($activation_history)) {
776
+			foreach ($activation_history as $version => $times_activated) {
777
+				// check there is a record of when this version was activated. Otherwise,
778
+				// mark it as unknown
779
+				if (! $times_activated) {
780
+					$times_activated = array('unknown-date');
781
+				}
782
+				if (is_string($times_activated)) {
783
+					$times_activated = array($times_activated);
784
+				}
785
+				foreach ($times_activated as $an_activation) {
786
+					if ($an_activation !== 'unknown-date'
787
+						&& $an_activation
788
+						   > $most_recently_active_version_activation) {
789
+						$most_recently_active_version = $version;
790
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
791
+							? '1970-01-01 00:00:00'
792
+							: $an_activation;
793
+					}
794
+				}
795
+			}
796
+		}
797
+		return $most_recently_active_version;
798
+	}
799
+
800
+
801
+	/**
802
+	 * This redirects to the about EE page after activation
803
+	 *
804
+	 * @return void
805
+	 */
806
+	public function redirect_to_about_ee()
807
+	{
808
+		$notices = EE_Error::get_notices(false);
809
+		// if current user is an admin and it's not an ajax or rest request
810
+		if (! isset($notices['errors'])
811
+			&& $this->request->isAdmin()
812
+			&& apply_filters(
813
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
814
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
815
+			)
816
+		) {
817
+			$query_params = array('page' => 'espresso_about');
818
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
819
+				$query_params['new_activation'] = true;
820
+			}
821
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
822
+				$query_params['reactivation'] = true;
823
+			}
824
+			$url = add_query_arg($query_params, admin_url('admin.php'));
825
+			wp_safe_redirect($url);
826
+			exit();
827
+		}
828
+	}
829
+
830
+
831
+	/**
832
+	 * load_core_configuration
833
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
834
+	 * which runs during the WP 'plugins_loaded' action at priority 5
835
+	 *
836
+	 * @return void
837
+	 * @throws ReflectionException
838
+	 */
839
+	public function load_core_configuration()
840
+	{
841
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
842
+		$this->loader->getShared('EE_Load_Textdomain');
843
+		// load textdomain
844
+		EE_Load_Textdomain::load_textdomain();
845
+		// load and setup EE_Config and EE_Network_Config
846
+		$config = $this->loader->getShared('EE_Config');
847
+		$this->loader->getShared('EE_Network_Config');
848
+		// setup autoloaders
849
+		// enable logging?
850
+		if ($config->admin->use_full_logging) {
851
+			$this->loader->getShared('EE_Log');
852
+		}
853
+		// check for activation errors
854
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
855
+		if ($activation_errors) {
856
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
857
+			update_option('ee_plugin_activation_errors', false);
858
+		}
859
+		// get model names
860
+		$this->_parse_model_names();
861
+		// load caf stuff a chance to play during the activation process too.
862
+		$this->_maybe_brew_regular();
863
+		// configure custom post type definitions
864
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
865
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
866
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
867
+	}
868
+
869
+
870
+	/**
871
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
872
+	 *
873
+	 * @return void
874
+	 * @throws ReflectionException
875
+	 */
876
+	private function _parse_model_names()
877
+	{
878
+		// get all the files in the EE_MODELS folder that end in .model.php
879
+		$models = glob(EE_MODELS . '*.model.php');
880
+		$model_names = array();
881
+		$non_abstract_db_models = array();
882
+		foreach ($models as $model) {
883
+			// get model classname
884
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
885
+			$short_name = str_replace('EEM_', '', $classname);
886
+			$reflectionClass = new ReflectionClass($classname);
887
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
888
+				$non_abstract_db_models[ $short_name ] = $classname;
889
+			}
890
+			$model_names[ $short_name ] = $classname;
891
+		}
892
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
893
+		$this->registry->non_abstract_db_models = apply_filters(
894
+			'FHEE__EE_System__parse_implemented_model_names',
895
+			$non_abstract_db_models
896
+		);
897
+	}
898
+
899
+
900
+	/**
901
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
902
+	 * that need to be setup before our EE_System launches.
903
+	 *
904
+	 * @return void
905
+	 * @throws DomainException
906
+	 * @throws InvalidArgumentException
907
+	 * @throws InvalidDataTypeException
908
+	 * @throws InvalidInterfaceException
909
+	 * @throws InvalidClassException
910
+	 * @throws InvalidFilePathException
911
+	 */
912
+	private function _maybe_brew_regular()
913
+	{
914
+		/** @var Domain $domain */
915
+		$domain = DomainFactory::getShared(
916
+			new FullyQualifiedName(
917
+				'EventEspresso\core\domain\Domain'
918
+			),
919
+			array(
920
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
921
+				Version::fromString(espresso_version()),
922
+			)
923
+		);
924
+		if ($domain->isCaffeinated()) {
925
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
926
+		}
927
+	}
928
+
929
+
930
+	/**
931
+	 * register_shortcodes_modules_and_widgets
932
+	 * generate lists of shortcodes and modules, then verify paths and classes
933
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
934
+	 * which runs during the WP 'plugins_loaded' action at priority 7
935
+	 *
936
+	 * @access public
937
+	 * @return void
938
+	 * @throws Exception
939
+	 */
940
+	public function register_shortcodes_modules_and_widgets()
941
+	{
942
+		if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
943
+			try {
944
+				// load, register, and add shortcodes the new way
945
+				$this->loader->getShared(
946
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
947
+					array(
948
+						// and the old way, but we'll put it under control of the new system
949
+						EE_Config::getLegacyShortcodesManager(),
950
+					)
951
+				);
952
+			} catch (Exception $exception) {
953
+				new ExceptionStackTraceDisplay($exception);
954
+			}
955
+		}
956
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
957
+		// check for addons using old hook point
958
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
959
+			$this->_incompatible_addon_error();
960
+		}
961
+	}
962
+
963
+
964
+	/**
965
+	 * _incompatible_addon_error
966
+	 *
967
+	 * @access public
968
+	 * @return void
969
+	 */
970
+	private function _incompatible_addon_error()
971
+	{
972
+		// get array of classes hooking into here
973
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
+		);
976
+		if (! empty($class_names)) {
977
+			$msg = __(
978
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
+				'event_espresso'
980
+			);
981
+			$msg .= '<ul>';
982
+			foreach ($class_names as $class_name) {
983
+				$msg .= '<li><b>Event Espresso - '
984
+						. str_replace(
985
+							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
986
+							'',
987
+							$class_name
988
+						) . '</b></li>';
989
+			}
990
+			$msg .= '</ul>';
991
+			$msg .= __(
992
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
993
+				'event_espresso'
994
+			);
995
+			// save list of incompatible addons to wp-options for later use
996
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
997
+			if (is_admin()) {
998
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
999
+			}
1000
+		}
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * brew_espresso
1006
+	 * begins the process of setting hooks for initializing EE in the correct order
1007
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1008
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1009
+	 *
1010
+	 * @return void
1011
+	 */
1012
+	public function brew_espresso()
1013
+	{
1014
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1015
+		// load some final core systems
1016
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1017
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1018
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1019
+		add_action('init', array($this, 'load_controllers'), 7);
1020
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1021
+		add_action('init', array($this, 'initialize'), 10);
1022
+		add_action('init', array($this, 'initialize_last'), 100);
1023
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1024
+			// pew pew pew
1025
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1026
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1027
+		}
1028
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1029
+	}
1030
+
1031
+
1032
+	/**
1033
+	 *    set_hooks_for_core
1034
+	 *
1035
+	 * @access public
1036
+	 * @return    void
1037
+	 * @throws EE_Error
1038
+	 */
1039
+	public function set_hooks_for_core()
1040
+	{
1041
+		$this->_deactivate_incompatible_addons();
1042
+		do_action('AHEE__EE_System__set_hooks_for_core');
1043
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1044
+		// caps need to be initialized on every request so that capability maps are set.
1045
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1046
+		$this->registry->CAP->init_caps();
1047
+	}
1048
+
1049
+
1050
+	/**
1051
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1052
+	 * deactivates any addons considered incompatible with the current version of EE
1053
+	 */
1054
+	private function _deactivate_incompatible_addons()
1055
+	{
1056
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1057
+		if (! empty($incompatible_addons)) {
1058
+			$active_plugins = get_option('active_plugins', array());
1059
+			foreach ($active_plugins as $active_plugin) {
1060
+				foreach ($incompatible_addons as $incompatible_addon) {
1061
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
+						unset($_GET['activate']);
1063
+						espresso_deactivate_plugin($active_plugin);
1064
+					}
1065
+				}
1066
+			}
1067
+		}
1068
+	}
1069
+
1070
+
1071
+	/**
1072
+	 *    perform_activations_upgrades_and_migrations
1073
+	 *
1074
+	 * @access public
1075
+	 * @return    void
1076
+	 */
1077
+	public function perform_activations_upgrades_and_migrations()
1078
+	{
1079
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1080
+	}
1081
+
1082
+
1083
+	/**
1084
+	 * @return void
1085
+	 * @throws DomainException
1086
+	 */
1087
+	public function load_CPTs_and_session()
1088
+	{
1089
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1090
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */
1091
+		$register_custom_taxonomies = $this->loader->getShared(
1092
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
1093
+		);
1094
+		$register_custom_taxonomies->registerCustomTaxonomies();
1095
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
1096
+		$register_custom_post_types = $this->loader->getShared(
1097
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
1098
+		);
1099
+		$register_custom_post_types->registerCustomPostTypes();
1100
+		/** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */
1101
+		$register_custom_taxonomy_terms = $this->loader->getShared(
1102
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
1103
+		);
1104
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1105
+		// load legacy Custom Post Types and Taxonomies
1106
+		$this->loader->getShared('EE_Register_CPTs');
1107
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1108
+	}
1109
+
1110
+
1111
+	/**
1112
+	 * load_controllers
1113
+	 * this is the best place to load any additional controllers that needs access to EE core.
1114
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1115
+	 * time
1116
+	 *
1117
+	 * @access public
1118
+	 * @return void
1119
+	 */
1120
+	public function load_controllers()
1121
+	{
1122
+		do_action('AHEE__EE_System__load_controllers__start');
1123
+		// let's get it started
1124
+		if (! $this->maintenance_mode->level()
1125
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1126
+		) {
1127
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1128
+			$this->loader->getShared('EE_Front_Controller');
1129
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1130
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1131
+			$this->loader->getShared('EE_Admin');
1132
+		}
1133
+		do_action('AHEE__EE_System__load_controllers__complete');
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * core_loaded_and_ready
1139
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1140
+	 *
1141
+	 * @access public
1142
+	 * @return void
1143
+	 * @throws Exception
1144
+	 */
1145
+	public function core_loaded_and_ready()
1146
+	{
1147
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1148
+			try {
1149
+				$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1150
+				$this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1151
+				if (function_exists('register_block_type')) {
1152
+					$this->loader->getShared(
1153
+						'EventEspresso\core\services\editor\BlockRegistrationManager'
1154
+					);
1155
+				}
1156
+			} catch (Exception $exception) {
1157
+				new ExceptionStackTraceDisplay($exception);
1158
+			}
1159
+		}
1160
+		if ($this->request->isAdmin()
1161
+			|| $this->request->isEeAjax()
1162
+			|| $this->request->isFrontend()
1163
+		) {
1164
+			$this->loader->getShared('EE_Session');
1165
+		}
1166
+		// integrate WP_Query with the EE models
1167
+		$this->loader->getShared('EE_CPT_Strategy');
1168
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1169
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1170
+		// builders require these even on the front-end
1171
+		require_once EE_PUBLIC . 'template_tags.php';
1172
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1173
+	}
1174
+
1175
+
1176
+	/**
1177
+	 * initialize
1178
+	 * this is the best place to begin initializing client code
1179
+	 *
1180
+	 * @access public
1181
+	 * @return void
1182
+	 */
1183
+	public function initialize()
1184
+	{
1185
+		do_action('AHEE__EE_System__initialize');
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * initialize_last
1191
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1192
+	 * initialize has done so
1193
+	 *
1194
+	 * @access public
1195
+	 * @return void
1196
+	 */
1197
+	public function initialize_last()
1198
+	{
1199
+		do_action('AHEE__EE_System__initialize_last');
1200
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1201
+		$rewrite_rules = $this->loader->getShared(
1202
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1203
+		);
1204
+		$rewrite_rules->flushRewriteRules();
1205
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1206
+		if (($this->request->isAjax() || $this->request->isAdmin())
1207
+			&& $this->maintenance_mode->models_can_query()) {
1208
+			$this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1209
+			$this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1210
+		}
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * @return void
1216
+	 * @throws EE_Error
1217
+	 */
1218
+	public function addEspressoToolbar()
1219
+	{
1220
+		$this->loader->getShared(
1221
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1222
+			array($this->registry->CAP)
1223
+		);
1224
+	}
1225
+
1226
+
1227
+	/**
1228
+	 * do_not_cache
1229
+	 * sets no cache headers and defines no cache constants for WP plugins
1230
+	 *
1231
+	 * @access public
1232
+	 * @return void
1233
+	 */
1234
+	public static function do_not_cache()
1235
+	{
1236
+		// set no cache constants
1237
+		if (! defined('DONOTCACHEPAGE')) {
1238
+			define('DONOTCACHEPAGE', true);
1239
+		}
1240
+		if (! defined('DONOTCACHCEOBJECT')) {
1241
+			define('DONOTCACHCEOBJECT', true);
1242
+		}
1243
+		if (! defined('DONOTCACHEDB')) {
1244
+			define('DONOTCACHEDB', true);
1245
+		}
1246
+		// add no cache headers
1247
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1248
+		// plus a little extra for nginx and Google Chrome
1249
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1250
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1251
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 *    extra_nocache_headers
1257
+	 *
1258
+	 * @access    public
1259
+	 * @param $headers
1260
+	 * @return    array
1261
+	 */
1262
+	public static function extra_nocache_headers($headers)
1263
+	{
1264
+		// for NGINX
1265
+		$headers['X-Accel-Expires'] = 0;
1266
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1267
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1268
+		return $headers;
1269
+	}
1270
+
1271
+
1272
+	/**
1273
+	 *    nocache_headers
1274
+	 *
1275
+	 * @access    public
1276
+	 * @return    void
1277
+	 */
1278
+	public static function nocache_headers()
1279
+	{
1280
+		nocache_headers();
1281
+	}
1282
+
1283
+
1284
+	/**
1285
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1286
+	 * never returned with the function.
1287
+	 *
1288
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1289
+	 * @return array
1290
+	 */
1291
+	public function remove_pages_from_wp_list_pages($exclude_array)
1292
+	{
1293
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1294
+	}
1295 1295
 }
Please login to merge, or discard this patch.